import { Card, Cog, Email, Jar, Plus, Settings, Travel } from '@transferwise/icons'; import { Meta, StoryObj } from '@storybook/react-webpack5'; import { useTheme } from '@wise/components-theming'; import { useRtlDiffI18n, withRTLDiff } from '../../../.storybook/decorators/RtlDiffDecorator'; import { withVariantConfig } from '../../../.storybook/helpers'; import Body from '../../Body'; import type { CardContainerSpotlight } from '../../CardContainer'; import List from '../../List'; import ListItem from '../../ListItem'; import type { ListItemProps } from '../../ListItem'; import Title from '../../Title'; import CardWidget from '..'; import type { CardWidgetProps } from '..'; const meta: Meta = { component: CardWidget, tags: ['!autodocs', '!manifest'], title: 'Layouts/CardWidget/Tests', }; export default meta; type Story = StoryObj; const SPOTLIGHTS: (CardContainerSpotlight | undefined)[] = [undefined, 'active', 'inactive']; const ACTIONS = { action: { label: 'Order card', icon: }, actionSecondary: { 'aria-label': 'Settings', icon: }, }; const ThemeTitle = () => { const { theme, screenMode } = useTheme(); return ( {theme} / {screenMode} ); }; /** A full header on every spotlight against every theme. */ export const AllVariants: Story = { ...withVariantConfig([ 'default', 'dark', 'bright-green', 'forest-green', 'business', 'business--bright-green', 'business--forest-green', 'platform', 'platform--forest-green', ]), render: () => (
{SPOTLIGHTS.map((spotlight) => ( First line of content. Second line, to show the content stacks flush. ))}
), }; /** Every combination of title link and the two action slots. */ export const HeaderCombinations: Story = { render: () => (
Content Content Content Content Content , iconPosition: 'start' }, }} > Content }, actionSecondary: ACTIONS.actionSecondary, }} > Content }, actionSecondary: { label: 'Manage', icon: , iconPosition: 'start' }, }} > Content Content No header — the content starts at the card's top padding.
), }; const LIST_ITEMS = [ { title: '•••• 1582', subtitle: 'Current account', icon: }, { title: '•••• 9982', subtitle: 'Jar', icon: }, { title: '•••• 5507', subtitle: 'Travel', icon: }, ]; const CardListItem = ({ index, spotlight, }: { index: number; spotlight?: ListItemProps['spotlight']; }) => { const { title, subtitle, icon } = LIST_ITEMS[index]; return ( {icon}} control={} /> ); }; /** * A `List` with every mix of spotlight and non-spotlight items. Non-spotlight items draw their * hover and focus backgrounds 8px out of bounds, into the card's padding. */ export const ListCombinations: Story = { render: () => (
), }; /** * Two spotlighted widgets side by side: one with a title-only header and text, the other with * action buttons and a `List`. Each header is at least as tall as the 32px action buttons, so the * first line of content starts at the same height in both. */ export const SideBySide: Story = { render: () => (
Your virtual card is ready to use. Spend in 40+ currencies with the real exchange rate.
), }; /** * When the header is 360px wide or narrower, its action corner stays beside a title that fits on * one line next to it, and moves under a longer title. Above that width, a long title wraps beside * the actions instead. */ export const NarrowHeader: Story = { render: () => (
{[320, 394, 420].map((width) => (
{['Cards', `A longer title in a card ${width}px wide`].map((title) => ( Content ))}
))}
), }; /** * In RTL the action cluster should move to the left and the title's trailing chevron should point * left. The `actionSecondary` slot must stay on the inline-start side of `action` in both * directions. * * Every widget is rendered wide (480px, actions beside the title) and narrow (320px). At 320px the * short titles keep their actions beside them, and the long title's actions stack under it, * aligned to the inline end. The long title wraps, so its chevron should follow the last word on * the inline-end side in both directions. */ export const RTLDiff: Story = { render: () => { const i18n = useRtlDiffI18n(); const actions = { action: { label: i18n.orderCard, icon: }, actionSecondary: { 'aria-label': i18n.settings, icon: }, }; const widgets = ( <> {i18n.content} {i18n.content} {i18n.content} {i18n.content} ); return (
{[480, 320].map((width) => (
{widgets}
))}
); }, ...withRTLDiff({ i18n: { cards: { en: 'Cards', ar: 'البطاقات' }, content: { en: 'Your virtual card is ready to use.', ar: 'بطاقتك الافتراضية جاهزة للاستخدام.', }, orderCard: { en: 'Order card', ar: 'اطلب بطاقة' }, settings: { en: 'Card settings', ar: 'إعدادات البطاقة' }, longTitle: { en: 'Cards, accounts and everything else you hold with us', ar: 'البطاقات والحسابات وكل ما تحتفظ به لدينا', }, }, }), };