import { ReactElement } from 'react'; import { Bank, Freeze, People, Suitcase } from '@transferwise/icons'; import { action } from 'storybook/actions'; import { fn } from 'storybook/test'; import { ActionPrompt } from '../ActionPrompt'; import { Body, Title } from '../../..'; import { StoryObj } from '@storybook/react-webpack5'; import { allModes } from '../../../../.storybook/modes'; import { useRtlDiffI18n, withRTLDiff } from '../../../../.storybook/decorators/RtlDiffDecorator'; import { withVariantConfig } from '../../../../.storybook/helpers'; import { lorem10 } from '../../../test-utils'; const withComponentGrid = ({ gap = '1rem' } = {}) => (Story: () => ReactElement) => (
); export default { title: 'Prompts/ActionPrompt/Tests', component: ActionPrompt, tags: ['!manifest', '!autodocs', 'new'], }; type Story = StoryObj; export const VariousA11yFeatures: Story = { name: 'Various a11y features', render: () => { return ( Neutral Prompt with Avatar Image and Custom label for media { action('send'); }, }} actionSecondary={{ label: 'Decline', onClick: () => { action('decline'); }, }} onDismiss={() => action('dismiss')} /> Warning Prompt { action('renew'); }, }} actionSecondary={{ label: 'Notify later', onClick: () => { action('notifyLater'); }, }} onDismiss={() => action('dismiss')} /> Warning Prompt Avatar Icon } }} title="Your Wise Card expires soon" description="Renew your card to keep spending" action={{ label: 'Renew card', onClick: () => { action('renew'); }, }} onDismiss={() => { action('dismiss'); }} /> Proposition Prompt Avatar Icon } }} title="Sync contacts for a faster experience" description="Find contacts on Wise — it’s simple, secure and you pick who you add." action={{ label: 'Sync contacts', onClick: () => { action('sync'); }, }} onDismiss={() => { action('dismiss'); }} /> Negative Prompt Avatar Icon + muted media }, 'aria-hidden': true }} title="Sync contacts for a faster experience" description="Find contacts on Wise — it’s simple, secure and you pick who you add." action={{ label: 'Sync contacts', onClick: () => { action('sync'); }, }} onDismiss={() => { action('dismiss'); }} /> Negative Prompt + override content with custom message via aria-label } }} title="Sync contacts for a faster experience" description="Find contacts on Wise — it's simple, secure and you pick who you add." action={{ label: 'Sync contacts', onClick: () => { action('sync'); }, }} onDismiss={() => { action('dismiss'); }} /> ); }, }; /** * ActionPrompt can be shown with or without a description. */ export const WithoutDescription: Story = { render: () => { return ( <> ); }, decorators: [withComponentGrid()], }; export const AllThemesAndSentiments: Story = { render: () => { return ( <> {(['negative', 'warning', 'neutral', 'success', 'proposition'] as const).map( (sentiment) => ( ), )} ); }, decorators: [withComponentGrid({ gap: '1.5rem' })], parameters: { padding: '16px', variants: ['default', 'dark', 'bright-green', 'forest-green'], chromatic: { dark: allModes.dark, brightGreen: allModes.brightGreen, forestGreen: allModes.forestGreen, }, }, }; export const TinyScreen: Story = { render: () => ( ), ...withVariantConfig(['400%']), }; /** * ActionPrompt adapts its layout to its own width (container queries), not the viewport. * Below a 600px content width the buttons go full width, otherwise they sit side by side. */ export const Responsiveness: Story = { render: () => (
{[ { width: 320, layout: 'Full width' }, { width: 480, layout: 'Full width' }, { width: 800, layout: 'Side by side' }, ].map(({ width, layout }) => (
} }} action={{ label: 'Primary action', onClick: fn() }} actionSecondary={{ label: 'Secondary', onClick: fn() }} onDismiss={fn()} />
))}
), parameters: { docs: { canvas: { sourceState: 'hidden', }, }, }, }; export const RTLDiff: Story = { render: () => { const i18n = useRtlDiffI18n(); return ( <> } }} action={{ label: i18n.connectBankAction }} /> } }} action={{ label: i18n.confirmAction }} actionSecondary={{ label: i18n.cancelAction }} /> } }} action={{ label: i18n.confirmAction }} actionSecondary={{ label: i18n.cancelAction }} onDismiss={() => {}} /> ); }, ...withRTLDiff({ fixedRows: { heights: 'auto' }, i18n: { defaultIconTitle: { en: 'Default status icon', ar: 'أيقونة الحالة الافتراضية' }, defaultIconDescription: { en: 'No media provided, uses default sentiment icon.', ar: 'لا توجد وسائط، يتم استخدام أيقونة الحالة الافتراضية.', }, continueAction: { en: 'Continue', ar: 'متابعة' }, customImageTitle: { en: 'Custom image', ar: 'صورة مخصصة' }, customImageDescription: { en: 'Media with a custom image source.', ar: 'وسائط مع مصدر صورة مخصص.', }, viewCardAction: { en: 'View card', ar: 'عرض البطاقة' }, avatarIconTitle: { en: 'Avatar with icon', ar: 'صورة رمزية مع أيقونة' }, avatarIconDescription: { en: 'Media with an avatar containing a custom icon.', ar: 'وسائط مع صورة رمزية تحتوي على أيقونة مخصصة.', }, connectBankAction: { en: 'Connect bank', ar: 'ربط البنك' }, twoActionsTitle: { en: 'Primary and secondary actions', ar: 'إجراءات أساسية وثانوية' }, twoActionsDescription: { en: 'Both action buttons present.', ar: 'زرّا الإجراء موجودان معًا.', }, confirmAction: { en: 'Confirm', ar: 'تأكيد' }, cancelAction: { en: 'Cancel', ar: 'إلغاء' }, dismissibleTitle: { en: 'Dismissible with two actions', ar: 'قابل للإغلاق مع إجراءين' }, dismissibleDescription: { en: 'Close button and both action buttons.', ar: 'زر الإغلاق وزرّا الإجراء.', }, }, }), };