This commit is contained in:
Tobias Johansson
2025-03-25 17:27:09 +01:00
committed by Simon Emanuelsson
parent 93962e4c59
commit 310a5a7a68
17 changed files with 914 additions and 523 deletions

View File

@@ -0,0 +1,150 @@
import type { Meta, StoryObj } from '@storybook/react'
import CodeRateCard from '.'
const meta: Meta<typeof CodeRateCard> = {
title: 'Components/RateCard/Code',
component: CodeRateCard,
decorators: [
(Story) => (
<div style={{ maxWidth: '400px' }}>
<Story />
</div>
),
],
argTypes: {
rateTitle: { control: 'text' },
paymentTerm: { control: 'text' },
rate: { control: 'object' },
approximateRate: { control: 'object' },
},
}
export default meta
type Story = StoryObj<typeof CodeRateCard>
export const Default: Story = {
args: {
rateTitle: 'FREE CANCELLATION',
paymentTerm: 'PAY LATER',
bannerText: 'Campaign ∙ Breakfast excluded',
rate: {
label: "Valentine's Special",
price: '1989',
unit: 'EUR/night',
},
approximateRate: {
price: '1989',
label: 'Approx.',
unit: 'EUR',
},
},
}
export const Voucher: Story = {
args: {
rateTitle: 'FREE CANCELLATION',
paymentTerm: 'PAY LATER',
bannerText: 'VOG ∙ Breakfast included',
rate: {
label: 'Promotional name here',
price: '1',
unit: 'VOUCHER',
},
},
}
export const CorporateCheck: Story = {
args: {
rateTitle: 'FREE CANCELLATION',
paymentTerm: 'PAY LATER',
bannerText: 'VOG ∙ Breakfast included',
rate: {
label: 'Promotional name here',
price: '2cc + 800',
unit: 'SEK',
},
approximateRate: {
price: '76',
label: 'Approx.',
unit: 'EUR',
},
},
}
export const DNumberDefault: Story = {
args: {
rateTitle: 'FREE CANCELLATION',
paymentTerm: 'PAY LATER',
bannerText: 'D0043148 ∙ Breakfast included',
rate: {
label: 'Helsinki Partners Oy',
price: '1989',
unit: 'EUR/NIGHT',
},
approximateRate: {
price: '76',
label: 'Approx.',
unit: 'EUR',
},
},
}
export const DNumberHighlightedRate: Story = {
args: {
rateTitle: 'FREE CANCELLATION',
paymentTerm: 'PAY LATER',
bannerText: 'D0043148 ∙ Breakfast included',
rate: {
label: 'Helsinki Partners Oy',
price: '198',
unit: 'EUR/NIGHT',
},
approximateRate: {
price: '76',
label: 'Approx.',
unit: 'EUR',
},
isHighlightedRate: true,
},
}
export const LNumberDefault: Story = {
args: {
rateTitle: 'NON-REFUNDABLE',
paymentTerm: 'PAY NOW',
bannerText: 'L0043148 ∙ Breakfast included',
rate: {
label: 'Nordic Team Travel',
price: '198',
unit: 'EUR/NIGHT',
},
approximateRate: {
price: '76',
label: 'Approx.',
unit: 'EUR',
},
},
}
export const LNumberStrikethrough: Story = {
args: {
rateTitle: 'NON-REFUNDABLE',
paymentTerm: 'PAY NOW',
bannerText: 'L0043148 ∙ Breakfast included',
rate: {
label: 'Nordic Team Travel',
price: '198',
unit: 'EUR/NIGHT',
},
comparisonRate: {
price: '249',
unit: 'EUR/NIGHT',
},
approximateRate: {
price: '230/218',
label: 'Approx.',
unit: 'EUR',
},
},
}

View File

@@ -0,0 +1,122 @@
import { Rate } from '../types'
import styles from '../rate-card.module.css'
import { Typography } from '../../Typography'
import { Button } from '../../Button'
import InfoCircleIcon from '../../Icons/InfoCircle'
import { variants } from '../variants'
interface CodeRateCardProps {
name: string
value: string
isSelected: boolean
rateTitle: string
paymentTerm: string
rate: Rate
bannerText: string
comparisonRate?: Omit<Rate, 'label'>
approximateRate?: Rate
isHighlightedRate?: boolean
handleChange: () => void
handleTermsClick?: () => void
}
export default function CodeRateCard({
name,
value,
isSelected,
rateTitle,
paymentTerm,
rate,
approximateRate,
comparisonRate,
bannerText,
isHighlightedRate,
handleChange,
handleTermsClick,
}: CodeRateCardProps) {
const classNames = variants({
variant: 'Code',
})
return (
<label>
<input
className={styles.radio}
type="radio"
name={name}
value={value}
checked={isSelected}
onChange={handleChange}
/>
<div className={classNames}>
<Typography variant="Tag/sm">
<p className={styles.banner}>{bannerText}</p>
</Typography>
<div className={styles.container}>
<header>
<Typography variant="Tag/sm">
<h3 className={styles.title}>
<Button
variant="Icon"
color="IconDefault"
size="Small"
onPress={handleTermsClick}
>
<InfoCircleIcon height={20} width={20} />
</Button>
{rateTitle}
<span className={styles.textSecondary}>
{` / ${paymentTerm}`}
</span>
</h3>
</Typography>
</header>
<div className={styles.content}>
<div
className={`${styles.rateRow} ${isHighlightedRate ? styles.highlightedRate : ''}`}
>
<Typography variant="Body/Supporting text (caption)/smBold">
<p>{rate.label}</p>
</Typography>
<Typography variant="Title/Subtitle/md">
<p>
{rate.price}{' '}
<Typography variant="Body/Supporting text (caption)/smBold">
<span>{rate.unit}</span>
</Typography>
</p>
</Typography>
</div>
{comparisonRate ? (
<div className={`${styles.rateRow} ${styles.comparisonRate}`}>
<Typography variant="Title/Subtitle/md">
<p>
<span className={styles.strikethrough}>{rate.price}</span>{' '}
<Typography variant="Body/Supporting text (caption)/smBold">
<span className={styles.strikethrough}>
{comparisonRate.unit}
</span>
</Typography>
</p>
</Typography>
</div>
) : null}
{approximateRate ? (
<div className={`${styles.rateRow} ${styles.approximateRate}`}>
<Typography variant="Body/Supporting text (caption)/smRegular">
<p>{approximateRate.label}</p>
</Typography>
<Typography variant="Body/Supporting text (caption)/smRegular">
<p>
{approximateRate.price} {approximateRate.unit}
</p>
</Typography>
</div>
) : null}
</div>
</div>
</div>
</label>
)
}