);
/**
* Interactive playground with all controls.
*/
export const Playground: StoryObj = {
args: {
previewMedia: undefined,
previewSecondaryAction: true,
},
argTypes: {
...previewArgTypes,
},
render: function Render(args: PreviewStoryArgs) {
const { previewMedia, previewSecondaryAction, ...props } = args;
const [expanded, setExpanded] = useState(args.expanded);
useEffect(() => {
setExpanded(args.expanded);
}, [args.expanded]);
return (
setExpanded(!expanded)}
/>
);
},
};
export const Sandbox = createSandboxStory({
code: `const App = () => {
const [expanded, setExpanded] = React.useState(true);
return (
console.log('verify') }}
actionSecondary={{ label: 'Learn more', onClick: () => console.log('learn more') }}
media={{ avatar: { asset: } }}
expanded={expanded}
onToggle={() => setExpanded((prev) => !prev)}
/>
);
};`,
scope: globalScope,
});
/**
* There are four sentiments, with negative being the default.
*/
export const Sentiments: Story = {
decorators: [ContainerDecorator('2rem')],
parameters: {
docs: {
source: {
code: ``,
},
},
},
argTypes: hiddenArgTypes,
render: function Render() {
return (
<>
{(['negative', 'warning', 'neutral', 'success'] as const).map((sentiment) => (
))}
>
);
},
};
/**
* Banners can have just a primary action, both primary and secondary, or no actions at all.
*/
export const Actions: Story = {
decorators: [ContainerDecorator('2rem')],
parameters: {
docs: {
source: {
code: ` {} }} />
{} }}
actionSecondary={{ label: 'Contact support', onClick: () => {} }}
/>`,
},
},
},
argTypes: hiddenArgTypes,
render: function Render() {
return (
<>
>
);
},
};
/**
* Each sentiment has a default status icon. Override it with a custom image or an AvatarView.
*/
export const MediaTypes: Story = {
args: {
sentiment: 'neutral',
},
decorators: [ContainerDecorator('2rem')],
parameters: {
docs: {
source: {
code: `{/* Change sentiment using the story controls */}
{/* Default — sentiment icon */}
{/* Custom image */}
{/* Avatar with photo */}
{/* Avatar with initials */}
{/* Avatar with custom icon */}
} }} ... />
{/* Business Profile with flag badge */}
`,
},
},
},
argTypes: {
...hiddenArgTypes,
sentiment: {
control: 'radio',
options: ['negative', 'warning', 'neutral', 'success'],
},
},
render: function Render({ sentiment }) {
const [expandedStates, setExpandedStates] = useState>({
default: true,
image: true,
avatarPhoto: true,
avatarInitials: true,
avatarIcon: true,
businessBadge: true,
personalBadge: true,
});
const toggle = (key: string) => setExpandedStates((prev) => ({ ...prev, [key]: !prev[key] }));
return (
<>
toggle('default')}
/>
toggle('image')}
/>
toggle('avatarPhoto')}
/>
toggle('avatarInitials')}
/>
} }}
action={{ label: 'Connect bank', onClick: fn() }}
expanded={expandedStates.avatarIcon}
onToggle={() => toggle('avatarIcon')}
/>
toggle('businessBadge')}
/>
>
);
},
};
/**
* The banner can be fully controlled — the parent can pass in the `expanded` state.
* Clicking the chevron calls `onToggle`, and external buttons can also toggle expansion.
* We recommend tracking the state that the user has set `expanded` to and keeping it there on page refresh.
*
* When the banner is shown on wider screens, it will always be fully expanded.
*/
export const Expanded: Story = {
argTypes: hiddenArgTypes,
render: function Render() {
const [expanded, setExpanded] = useState(true);
return (
<>
setExpanded(!expanded)}
/>
>
);
},
parameters: {
docs: {
source: {
code: `const [expanded, setExpanded] = useState(true);
setExpanded(!expanded)}
/>`,
},
},
},
};
/**
* When the banner has no title, the description remains visible when collapsed and
* is clamped to 2 lines. With a title, only the title is shown when collapsed.
*/
export const CollapsedBehaviour: Story = {
decorators: [ContainerDecorator()],
argTypes: hiddenArgTypes,
render: function Render() {
const [expanded1, setExpanded1] = useState(false);
const [expanded2, setExpanded2] = useState(false);
return (
setExpanded1(!expanded1)}
/>
setExpanded2(!expanded2)}
/>
);
},
parameters: {
docs: {
canvas: { sourceState: 'hidden' },
},
},
};
/**
* Above 768px the collapse toggle disappears and the banner is always fully expanded. The buttons are not block displayed.
* Below 768px the user can collapse and expand the banner and the buttons are displayed as block elements.
* Eventually the buttons stack.
*/
export const Responsiveness: Story = {
parameters: {
docs: {
canvas: { sourceState: 'hidden' },
},
},
argTypes: hiddenArgTypes,
render: function Render() {
return (
{[200, 350, 800].map((width) => (
))}
);
},
};
/**
* Mobile viewport regression test for the overhang.
* The overhang is always applied below 600px.
*/
export const MobileOverhang: Story = {
argTypes: hiddenArgTypes,
render: function Render() {
return (
);
},
parameters: {
docs: {
canvas: { sourceState: 'hidden' },
},
},
};
/** The banner waits 500ms, then reveals from above when it enters the page. */
export const AnimatedEntry: Story = {
args: {
title: 'Your account is restricted.',
description: 'Review your personal details to get your account active again.',
action: { label: 'Review details', onClick: fn() },
},
argTypes: hiddenArgTypes,
render: (args) => ,
parameters: {
layout: 'fullscreen',
docs: {
canvas: { sourceState: 'hidden' },
},
},
};
/** The banner can mount immediately without replaying its entry animation. */
export const WithoutEntryAnimation: Story = {
args: {
animateEntry: false,
title: 'Your account is restricted.',
description: 'Review your personal details to get your account active again.',
action: { label: 'Review details', onClick: fn() },
},
argTypes: hiddenArgTypes,
parameters: {
layout: 'fullscreen',
docs: {
canvas: { sourceState: 'hidden' },
},
},
};
/**
* The text container is capped at 480px for optimal readability, even though
* the banner itself stretches to the full available width.
*/
export const ParagraphWidth: Story = {
parameters: {
docs: {
canvas: { sourceState: 'hidden' },
},
},
argTypes: hiddenArgTypes,
render: function Render() {
const [expanded, setExpanded] = useState(true);
return (
setExpanded(!expanded)}
/>
);
},
};