← All proposals

Card Sequence

A new component, CardSequence, in the loading indicators family.

Net-new componentOpen in Storybook

proposals/CardSequence/CardSequence.mdx62 lines · View on GitHub
import { Canvas, Controls, Meta, Title } from '@storybook/addon-docs/blocks';

import * as CardSequenceStories from './CardSequence.stories';

<Meta of={CardSequenceStories} name='Usage' />

<Title />

## Purpose

Two to four cards appear one after the other, with a line drawn between them, while a piece of work runs. The text in each card shimmers while it works. When the work is done it lands on a headline with a yellow marker bar behind it.

The cards hold any content. The first use is the end of the business account creation flow, after the person submits the form: a Business account card, then a Workspace card. It is meant to be reused in other flows and products that create several things in a row. For a short or single-stage wait, use the Spinner; for a list of timed steps with one text at a time, use the Spinner Sequence.

## Usage

- The component only animates. Your screen owns the work and the redirect: set `isComplete` when the work is done and move on from `onComplete`.
- Give it 2 to 4 `cards`. Each has a `content` slot and an optional `icon`. For a title with a smaller subtitle, put `CardSequenceText` in the slot; anything else works too.
- Each card takes about 3 seconds: it appears, its text settles, the line is drawn and the next card appears. The last card keeps shimmering until `isComplete` is `true`. Two cards give a minimum of 5 seconds, three about 8 and four about 11.
- The animation always plays in full first. If the work is done sooner, the landing waits for it. If the work takes longer, the last card keeps shimmering.
- `onComplete` fires once, 2 seconds after the landing starts so "all set" can be read. The person always sees the whole animation before they are redirected.
- A trailing full stop in `workingLabel` is drawn in the brand color.
- There is no error state. If the work fails, stop showing the component and show an error instead (for example a critical Section Message with a Retry button), written for what failed. Set your own timeout too: without one, an unfinished sequence keeps shimmering with no end.
- What follows (for example a Spinner and "Taking you to your business account" while the next page loads) belongs to the screen, not to this component.

## Accessibility

- One polite live region (`role='status'`) holds `workingLabel`, then `completeLabel` when the animation has landed. The visible headline is hidden from assistive technology so it is not read twice.
- The text in the cards is real text and is read once; the shimmer is a visual mask over it. The tiles, icons and line are decorative and hidden from assistive technology. Put anything that must be read in the `content` slot, not in `icon`.
- Nothing in the component is interactive: no focus and no keyboard behavior. Do not put interactive elements in the slots; the cards animate and fade in.
- With reduced motion there is no movement and no shimmer: the final layout shows at once and the landing does not wait.
- Every text comes from props or the slots, so it can be translated.
- The marker bar is yellow in both themes and its text is the dark Badge brand foreground in both themes (`--pds-color-badge-brand-foreground` on `--pds-color-badge-brand-background`). While a card is working its text is dimmed by the shimmer; check contrast of your content in light and dark.

## Footprint

- The marker bar is a pseudo-element about half an em wider than the headline on each side. It adds no layout size, but a parent with `overflow: hidden` that is tighter than the headline would clip it.
- The component is at most 300px wide (`18.75rem`) and centers itself in its parent. Cards are full width of that column, so long content wraps.

## Implementation

See the table below for the available props. The other stories show three and four cards, free content, and work that is not done yet.

- `cards` — the cards, 2 to 4 (any after the fourth are not shown). Each is `{ content, icon? }`.
- `completeLabel`, `workingLabel` — the headline and the screen-reader text for each state.
- `isComplete` — set to `true` when the real work is done.
- `onComplete` — called once, 2 seconds after the landing starts.
- `CardSequenceText` — `title` and optional `subtitle`, for the content of a card.

<hr />

<Canvas of={CardSequenceStories.Default} />
<Controls of={CardSequenceStories.Default} />

<hr />

<Canvas of={CardSequenceStories.ThreeCards} />

<hr />

<Canvas of={CardSequenceStories.FreeContent} />