import { Cog, Email, Plus, Settings } from '@transferwise/icons'; import { Meta, StoryObj } from '@storybook/react-webpack5'; import { createSandboxStory, globalScope, } from '../../../.storybook/components/sandbox/SandboxEditor'; import Body from '../../Body'; import type { CardContainerSpotlight } from '../../CardContainer'; import { CardsList, SampleContent } from '../../CardContainer/_stories/helpers'; import { Typography } from '../../common'; import CardWidget from '..'; /** * A `CardContainer` with an optional header above its content. The `header` prop takes a `title`, * a `titleAction` that turns the title into a link, and up to two actions. */ const meta: Meta = { component: CardWidget, title: 'Layouts/CardWidget', tags: ['early-access'], argTypes: { header: { control: 'object', table: { type: { summary: 'CardWidgetHeader' } }, }, spotlight: { control: 'radio', options: [undefined, 'active', 'inactive'], table: { defaultValue: { summary: 'undefined' }, type: { summary: 'CardContainerSpotlight' }, }, }, as: { control: 'radio', options: ['div', 'section', 'article'], table: { defaultValue: { summary: "'div'" }, type: { summary: 'string' } }, }, children: { control: false, table: { type: { summary: 'ReactNode' } }, }, className: { control: 'text', table: { type: { summary: 'string' } } }, 'data-testid': { control: 'text', table: { type: { summary: 'string' } } }, }, args: { spotlight: 'active', as: 'div', header: { title: 'Cards', titleAction: { href: '#cards' }, action: { label: 'Order card' }, }, }, }; export default meta; type Story = StoryObj; /** Experiment with the widget's props. */ export const Playground: Story = { render: (args) => (
), }; export const Sandbox = createSandboxStory({ code: ` Your virtual card is ready to use. Spend in 40+ currencies with the real exchange rate. `, scope: { ...globalScope, CardWidget }, }); /** `titleAction` turns the title into a link to the widget's own screen and appends a chevron. */ export const TitleLink: Story = { parameters: { controls: { disable: true } }, render: () => ( ), }; /** * An action object with a `label` renders a small button, and one with only an `icon` a 32px icon * button, which requires an `aria-label`. A labelled action's icon follows its label, or leads * it with `iconPosition: 'start'`. `actionSecondary` renders before `action` at a lower * emphasis; two actions is the maximum, to keep the title legible. When the header is 360px wide * or narrower, the actions move under a title that doesn't fit beside them on one line. */ export const Actions: Story = { parameters: { controls: { disable: true } }, render: () => { const header = { title: 'Cards', titleAction: { href: '#cards' }, action: { label: 'Order card', icon: }, actionSecondary: { 'aria-label': 'Card settings', icon: }, }; return (
, iconPosition: 'start' }, }} > }, actionSecondary: { label: 'Manage', icon: , iconPosition: 'start' }, }} >
); }, }; /** A title too long for its line wraps. A linked title keeps its chevron after its last word. */ export const LongTitle: Story = { parameters: { controls: { disable: true } }, render: () => (
}, actionSecondary: { 'aria-label': 'Card settings', icon: }, }} >
), }; /** The action slots also take any node, for content the button actions do not cover. */ export const CustomAction: Story = { parameters: { controls: { disable: true } }, render: () => ( £1,240.00 ), }} > ), }; /** A header followed by a list, as in a dashboard's cards module. */ export const WithList: Story = { parameters: { controls: { disable: true } }, render: () => ( }, }} > ), }; /** * A widget stretched to a fixed-height container, with a footer of small print after its content. * The content fills the rest of the card's height, so the footer's `margin-top: auto` pushes it to * the bottom of the card. */ export const FixedHeight: Story = { parameters: { controls: { disable: true } }, render: () => (
, iconPosition: 'start' }, }} > 10,250.00 GBP Your money is held with our partner banks.
Interest rates are variable and can change. Capital at risk. Terms and conditions apply.
), }; /** * The card shows as hovered or pressed while the title link is, and as hovered while the link has * keyboard focus. Hovering or pressing the rest of * the card, or its actions, leaves it at rest. */ export const Interactive: Story = { parameters: { controls: { disable: true } }, render: () => (
{([undefined, 'active', 'inactive'] as (CardContainerSpotlight | undefined)[]).map( (spotlight) => ( }, actionSecondary: { 'aria-label': 'Card settings', icon: }, }} > Your virtual card is ready to use. ), )}
), }; /** The same header on each spotlight. */ export const Spotlight: Story = { parameters: { controls: { disable: true } }, render: () => (
{([undefined, 'active', 'inactive'] as (CardContainerSpotlight | undefined)[]).map( (spotlight) => ( }, }} > ), )}
), };