import { Meta, StoryObj } from '@storybook/react-webpack5'; import { createSandboxStory, globalScope, } from '../../../.storybook/components/sandbox/SandboxEditor'; import Body from '../../Body'; import Link from '../../Link'; import CardContainer from '..'; import type { CardContainerPadding, CardContainerSpotlight } from '..'; import { CardsList, SampleContent } from './helpers'; /** * A bounded surface that groups related content. It has no slots of its own: any content passed * as children is stacked with no gap, inside the card's padding. * * For a card with a title, a title link or actions, use `CardWidget`. */ const meta: Meta = { component: CardContainer, title: 'Layouts/CardContainer', tags: ['early-access'], argTypes: { spotlight: { control: 'radio', options: [undefined, 'active', 'inactive'], table: { defaultValue: { summary: 'undefined' }, type: { summary: 'CardContainerSpotlight' }, }, }, padding: { control: 'radio', options: ['md', 'none'], table: { defaultValue: { summary: "'md'" }, type: { summary: 'CardContainerPadding' } }, }, as: { control: 'radio', options: ['div', 'section', 'article'], table: { defaultValue: { summary: "'div'" }, type: { summary: 'string' } }, }, interactive: { control: 'boolean', table: { defaultValue: { summary: 'false' }, type: { summary: 'boolean' } }, }, 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', padding: 'md', as: 'div', }, }; export default meta; type Story = StoryObj; /** Experiment with the card'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, CardContainer }, }); /** * `spotlight` matches `ListItem`'s: `active` is raised, for live content, and `inactive` is * recessed with a dashed stroke, for a feature not set up yet. Without a spotlight the card is * flat. */ export const Spotlight: Story = { parameters: { controls: { disable: true } }, render: () => (
{([undefined, 'active', 'inactive'] as (CardContainerSpotlight | undefined)[]).map( (spotlight) => ( Spotlight: {spotlight ?? 'not set'} ), )}
), }; /** * `padding="md"` insets the content by 8px, and by 16px from the `md` breakpoint up. * `padding="none"` lets content such as images or charts run to the card's edges, clipped to its * rounded corners. The grey boxes fill the content area, so their edges show where the padding * ends. * * Focus rings are clipped at the edges too, so keep `none` for non-interactive content, and lists * on `md`. * * The last three cards are `interactive`, with a link as their content. */ export const Padding: Story = { parameters: { controls: { disable: true } }, render: () => (
{(['md', 'none'] as CardContainerPadding[]).map((padding) => ([undefined, 'active', 'inactive'] as (CardContainerSpotlight | undefined)[]).map( (spotlight) => (
), ), )} {([undefined, 'active', 'inactive'] as (CardContainerSpotlight | undefined)[]).map( (spotlight) => ( ), )}
), }; /** * `interactive` shows the card as hovered or pressed while a direct child link or button is, and * as hovered while that child has keyboard focus. A link or button that is the card's only child * covers the card's padding too. A link nested deeper, such as inside text, doesn't trigger the * states. */ export const Interactive: Story = { parameters: { controls: { disable: true } }, render: () => (
{([undefined, 'active', 'inactive'] as (CardContainerSpotlight | undefined)[]).map( (spotlight) => ( Direct child link, spotlight: {spotlight ?? 'not set'} ), )} A nested link isn't a direct child, so this card has no states.
), }; /** A `List` placed directly in the card. */ export const WithList: Story = { parameters: { controls: { disable: true } }, render: () => ( ), };