import { useEffect, useState } from 'react';
import {
Badge,
Button,
FlexContainer,
Icon,
} from '@pantheon-systems/pds-toolkit-react';
import { Meta, StoryObj } from '@storybook/react-vite';
import {
CardSequence,
CardSequenceCard,
CardSequenceProps,
CardSequenceText,
} from './CardSequence';
// Story-only sample content. The cards are whatever the screen needs.
const businessAccountCards: CardSequenceCard[] = [
{
content: (
<CardSequenceText
subtitle='Contains your workspaces and billing'
title='Business account'
/>
),
icon: <Icon iconName='building' size='l' />,
},
{
content: (
<CardSequenceText subtitle='Contains your sites' title='Workspace' />
),
icon: <Icon iconName='folder' size='l' />,
},
];
const threeCards: CardSequenceCard[] = [
{
content: (
<CardSequenceText subtitle='Copying your repository' title='Code' />
),
icon: <Icon iconName='code' size='l' />,
},
{
content: <CardSequenceText subtitle='Copying your data' title='Data' />,
icon: <Icon iconName='server' size='l' />,
},
{
content: <CardSequenceText subtitle='Copying your uploads' title='Files' />,
icon: <Icon iconName='files' size='l' />,
},
];
const fourCards: CardSequenceCard[] = [
...threeCards,
{
content: (
<CardSequenceText subtitle='Applying your settings' title='Settings' />
),
icon: <Icon iconName='gear' size='l' />,
},
];
// A card with no title and subtitle: any content works.
const freeContentCards: CardSequenceCard[] = [
{
content: (
<FlexContainer
alignItems='center'
gap='xs'
justifyContent='space-between'
>
<span className='pds-copy-m'>Checking your details</span>
<Badge color='info-muted' label='Step 1' />
</FlexContainer>
),
},
{
content: (
<FlexContainer
alignItems='center'
gap='xs'
justifyContent='space-between'
>
<span className='pds-copy-m'>Creating your space</span>
<Badge color='info-muted' label='Step 2' />
</FlexContainer>
),
},
];
/**
* Story-only helper: runs the animation, marks the work done after `doneAfter`
* milliseconds, and has a Replay button well below it. A real
* screen sets `isComplete` from the actual work.
*/
const Demo = ({
doneAfter,
...args
}: CardSequenceProps & { doneAfter: number | null }) => {
const [run, setRun] = useState(0);
const [isDone, setIsDone] = useState(false);
const [isPlaying, setIsPlaying] = useState(true);
useEffect(() => {
setIsDone(false);
if (doneAfter === null) {
return undefined;
}
const timer = setTimeout(() => setIsDone(true), doneAfter);
return () => clearTimeout(timer);
}, [doneAfter, run]);
return (
<FlexContainer alignItems='center' flexDirection='column' gap='5xl'>
<CardSequence
key={`${run}-${args.workingLabel}`}
{...args}
isComplete={args.isComplete || isDone}
onComplete={() => {
setIsPlaying(false);
args.onComplete?.();
}}
/>
<Button
disabled={isPlaying}
label={isPlaying ? 'Playing animation...' : 'Replay'}
onClick={() => {
setIsPlaying(true);
setRun(run + 1);
}}
variant='secondary'
/>
</FlexContainer>
);
};
const meta: Meta<typeof CardSequence> = {
tags: ['new-pattern', 'ready-for-dev'],
title: 'Component Proposals/Loading Indicators/Card Sequence',
component: CardSequence,
parameters: {
docs: {
description: {
component:
'Two to four cards appear one after the other with a line between them while a piece of work runs. Their text shimmers; when the work is done it lands on a headline such as "You\'re all set." The cards hold any content. First use: the end of the business account creation flow. New pattern: not in PDS v2 today.',
},
},
},
argTypes: {
cards: { control: false, table: { category: 'Content' } },
className: { table: { category: 'Base attributes' } },
completeLabel: { table: { category: 'Content' } },
isComplete: { table: { category: 'Component configuration' } },
onComplete: { table: { category: 'Functions' } },
workingLabel: { table: { category: 'Content' } },
},
args: {
cards: businessAccountCards,
completeLabel: 'You’re all set.',
isComplete: false,
workingLabel: 'Setting things up.',
},
};
export default meta;
type Story = StoryObj<typeof meta>;
export const Default: Story = {
parameters: {
docs: {
description: {
story:
'The business account creation flow: two cards, a title and subtitle in each. Plays the full animation and lands after 5 seconds, as a demo. Replay is story-only. In a real screen, `isComplete` follows the actual work.',
},
},
},
render: (args) => <Demo {...args} doneAfter={5000} />,
};
export const ThreeCards: Story = {
parameters: {
docs: {
description: {
story:
'Three cards. Each step takes about 3 seconds, so the minimum is about 8 seconds. The content is a story-only example.',
},
},
},
args: { cards: threeCards, workingLabel: 'Copying your site.' },
render: (args) => <Demo {...args} doneAfter={8000} />,
};
export const FourCards: Story = {
parameters: {
docs: {
description: {
story:
'Four cards, the most it shows. The minimum is about 11 seconds.',
},
},
},
args: { cards: fourCards, workingLabel: 'Copying your site.' },
render: (args) => <Demo {...args} doneAfter={11000} />,
};
export const FreeContent: Story = {
parameters: {
docs: {
description: {
story:
'The cards hold any content, not only a title and subtitle, and no icon. Any text in the slot shimmers while the card works.',
},
},
},
args: { cards: freeContentCards },
render: (args) => <Demo {...args} doneAfter={5000} />,
};
export const StillWorking: Story = {
parameters: {
docs: {
description: {
story:
'`isComplete` is false and stays false: the last card keeps shimmering. Use the control to finish it.',
},
},
},
render: (args) => <Demo {...args} doneAfter={null} />,
};
Card Sequence
A new component, CardSequence, in the loading indicators family.
Net-new componentOpen in Storybook