import { Meta, StoryObj } from '@storybook/react-webpack5'; import { Breakpoint } from '@transferwise/neptune-tokens'; import { useState } from 'react'; import { createSandboxStory, globalScope, } from '../../../.storybook/components/sandbox/SandboxEditor'; import AvatarView from '../../AvatarView'; import Body from '../../Body'; import Button from '../../Button'; import { ProfileType, Typography } from '../../common'; import Logo from '../../Logo'; import OverlayHeader from '../../_deprecated/OverlayHeader'; import { lorem10 } from '../../test-utils'; import Display from '../../Display'; import Sticky from '../../Sticky'; import FlowNavigation, { FlowNavigationProps } from '..'; import Container from '../../Container'; interface CustomControls { showCloseButton: boolean; showMobileBackButton: boolean; avatarURL?: string; profileType?: ProfileType; } export type StoryArgs = FlowNavigationProps & CustomControls; type Story = StoryObj; /** * FlowNavigation component for multi-step flows with progress tracking. * * **Border Behavior:** * - Non-composable (default): Border respects `done` prop when `showBottomBorder=true`. * - Composable: Border controlled only by `showBottomBorder`, ignoring the `done` property. **/ const meta: Meta = { component: FlowNavigation, title: 'Navigation/FlowNavigation', argTypes: { showCloseButton: { control: 'boolean', defaultValue: true }, showMobileBackButton: { control: 'boolean', defaultValue: true }, done: { control: 'boolean', defaultValue: false }, showBottomBorder: { control: 'boolean', defaultValue: true }, avatarURL: { control: 'text', defaultValue: '../tapestry-01.png' }, profileType: { control: 'radio', options: [ProfileType.PERSONAL, ProfileType.BUSINESS], defaultValue: ProfileType.PERSONAL, }, }, parameters: { docs: { source: { type: 'code' }, }, }, }; export default meta; const viewports = [ Breakpoint.EXTRA_SMALL - 10, Breakpoint.EXTRA_SMALL + 10, Breakpoint.SMALL + 10, Breakpoint.MEDIUM + 10, Breakpoint.LARGE + 10, ]; export const Sandbox = createSandboxStory({ code: `const App = () => { const [activeStep, setActiveStep] = React.useState(0); return ( } logo={} activeStep={activeStep} onClose={() => console.log('close')} onGoBack={() => setActiveStep((prev) => (prev > 0 ? prev - 1 : 0))} steps={[ { label: 'Amount', hoverLabel: '100 GBP', onClick: () => setActiveStep(0) }, { label: 'You', hoverLabel: 'Elena Durante', onClick: () => setActiveStep(1) }, { label: 'Recipient', hoverLabel: 'Daniele Tomboro', onClick: () => setActiveStep(2) }, { label: 'Review', onClick: () => setActiveStep(3) }, { label: 'Pay', onClick: () => setActiveStep(4) }, ]} /> ); };`, scope: globalScope, }); export const Variants: Story = { args: { profileType: ProfileType.PERSONAL, showCloseButton: true, showMobileBackButton: true, done: false, avatarURL: '../tapestry-01.png', }, parameters: { chromatic: { viewports, }, }, render: (args) => { const [activeStep, setActiveStep] = useState(2); const [closed, setClosed] = useState(false); if (closed) return <>; return ( <> : null} logo={} activeStep={activeStep} done={args.done} steps={[ { label: 'Amount', hoverLabel: 100 GBP, onClick: () => setActiveStep(0), }, { label: 'You', hoverLabel: <>Elena Durante - elenadurante@test.com, onClick: () => setActiveStep(1), }, { label: 'Recipient', hoverLabel: 'Daniele Tomboro', onClick: () => setActiveStep(2) }, { label: 'Review', hoverLabel: 'Antonio Dozortevo', onClick: () => setActiveStep(3) }, { label: 'Pay', hoverLabel: 'Enrico Gusso II', onClick: () => setActiveStep(4), }, ]} onClose={args.showCloseButton ? () => setClosed(true) : undefined} onGoBack={ args.showMobileBackButton ? () => setActiveStep(activeStep > 0 ? activeStep - 1 : 0) : undefined } />
100 GBP
0.2351 ETH ), onClick: () => setActiveStep(0), }, { label: 'You', hoverLabel: ( <>
Elena Durante
elenadurante@test.com ), onClick: () => setActiveStep(1), }, { label: 'Recipient', hoverLabel: 'Daniele Tomboro', onClick: () => setActiveStep(2) }, { label: 'Review', hoverLabel: 'Antonio Dozortevo', onClick: () => setActiveStep(3) }, { label: 'Pay', hoverLabel: 'Enrico Gusso II', onClick: () => setActiveStep(4), }, ]} onClose={args.showCloseButton ? () => setClosed(true) : undefined} onGoBack={ args.showMobileBackButton ? () => setActiveStep(activeStep - 1 > 0 ? activeStep - 1 : 0) : undefined } /> } activeStep={activeStep} steps={[ { label: 'Amount', hoverLabel: ( <>
100 GBP
0.2351 ETH ), onClick: () => setActiveStep(0), }, { label: 'You', hoverLabel: ( <>
Elena Durante
elenadurante@test.com ), onClick: () => setActiveStep(1), }, { label: 'Recipient', hoverLabel: 'Daniele Tomboro', onClick: () => setActiveStep(2) }, { label: 'Review', hoverLabel: 'Antonio Dozortevo', onClick: () => setActiveStep(3) }, { label: 'Pay', hoverLabel: 'Enrico Gusso II', onClick: () => setActiveStep(4), }, ]} onClose={args.showCloseButton ? () => setClosed(true) : undefined} onGoBack={ args.showMobileBackButton ? () => setActiveStep(activeStep - 1 > 0 ? activeStep - 1 : 0) : undefined } /> {/* Instance of always `done` FlowNav for visual testing */} } activeStep={activeStep} steps={[ { label: 'Recipient', hoverLabel: 'Daniele Tomboro', onClick: () => setActiveStep(0) }, { label: 'Review', hoverLabel: 'Antonio Dozortevo', onClick: () => setActiveStep(1) }, { label: 'Pay', hoverLabel: 'Enrico Gusso', onClick: () => setActiveStep(2) }, ]} onClose={args.showCloseButton ? () => setClosed(true) : undefined} onGoBack={ args.showMobileBackButton ? () => setActiveStep(activeStep - 1 > 0 ? activeStep - 1 : 0) : undefined } /> Content to test that the flow nav is centred ); }, }; export const SendFlow: Story = { args: { profileType: ProfileType.PERSONAL, showCloseButton: true, showMobileBackButton: true, done: false, avatarURL: '../tapestry-01.png', }, parameters: { padding: '0', }, render: (args) => { const [activeStep, setActiveStep] = useState(2); const steps = [ { label: 'Recipient', onClick: handleStepClick(0), }, { label: 'Amount', hoverLabel: ( <> You send 100 GBP
You get 99.39 GBP{' '} ), ...(activeStep > 1 && { onClick: handleStepClick(1) }), }, { label: 'Review', ...(activeStep > 2 && { onClick: handleStepClick(2) }), }, { label: 'Pay', ...(activeStep > 3 && { onClick: handleStepClick(3) }), }, ]; function handleStepClick(step: number) { return () => { setActiveStep(step); }; } return ( <> } logo={} activeStep={activeStep} steps={steps} onClose={() => alert('close & move away')} onGoBack={() => setActiveStep(activeStep > 0 ? activeStep - 1 : 0)} /> {steps[activeStep].label} Step
{lorem10}
); }, }; export const WithOverlayHeaderComparison: Story = { args: { profileType: ProfileType.PERSONAL, showCloseButton: true, showMobileBackButton: true, done: false, avatarURL: '../tapestry-01.png', }, parameters: { padding: '0', }, render: (args) => { const [activeStep, setActiveStep] = useState(4); const [closed, setClosed] = useState(false); if (closed) return <>; return ( <>
: null} activeStep={activeStep} done={args.done} steps={[]} onClose={args.showCloseButton ? () => setClosed(true) : undefined} onGoBack={ args.showMobileBackButton ? () => setActiveStep(activeStep > 0 ? activeStep - 1 : 0) : undefined } />
: null} onClose={args.showCloseButton ? () => setClosed(true) : undefined} />
); }, }; export const WithoutStepper: Story = { args: { profileType: ProfileType.PERSONAL, showCloseButton: true, avatarURL: '../tapestry-01.png', }, parameters: { chromatic: { viewports, }, }, render: (args) => { const [closed, setClosed] = useState(false); if (closed) return FlowNavigation closed; return ( } logo={} onClose={args.showCloseButton ? () => setClosed(true) : undefined} /> ); }, }; export const BorderControl: Story = { args: { profileType: ProfileType.PERSONAL, avatarURL: '../tapestry-01.png', }, parameters: { chromatic: { viewports, }, }, render: (args) => { const [activeStep, setActiveStep] = useState(2); const steps = [ { label: 'Recipient', onClick: () => setActiveStep(0), }, { label: 'Amount', hoverLabel: ( <> You send 100 GBP
You get 99.39 GBP{' '} ), ...(activeStep > 1 && { onClick: () => setActiveStep(1) }), }, { label: 'Review', ...(activeStep > 2 && { onClick: () => setActiveStep(2) }), }, { label: 'Pay', ...(activeStep > 3 && { onClick: () => setActiveStep(3) }), }, ]; return ( <> Non-composable Variant
Border controlled by done property only {/* Non-composable: done=false - SHOWS BORDER */} } logo={} activeStep={activeStep} done={false} steps={steps} onClose={() => {}} onGoBack={() => setActiveStep(activeStep > 0 ? activeStep - 1 : 0)} /> done=false → ✅ Border shown {/* Non-composable: done=true - HIDES BORDER */} } logo={} activeStep={activeStep} done steps={steps} onClose={() => {}} onGoBack={() => setActiveStep(activeStep > 0 ? activeStep - 1 : 0)} /> done=true → ❌ Border hidden Composable Variant
Border ignores done, follows showBottomBorder only {/* Composable: showBottomBorder=true, done=false - SHOWS BORDER */} } logo={} activeStep={activeStep} done={false} steps={steps} showBottomBorder onClose={() => {}} onGoBack={() => setActiveStep(activeStep > 0 ? activeStep - 1 : 0)} /> showBottomBorder=true, done=false → ✅ Border shown {/* Composable: showBottomBorder=true, done=true - SHOWS BORDER */} } logo={} activeStep={activeStep} done steps={steps} showBottomBorder onClose={() => {}} onGoBack={() => setActiveStep(activeStep > 0 ? activeStep - 1 : 0)} /> showBottomBorder=true, done=true → ✅ Border shown (ignores done) {/* Composable: showBottomBorder=false, done=false - HIDES BORDER */} } logo={} activeStep={activeStep} done={false} steps={steps} showBottomBorder={false} onClose={() => {}} onGoBack={() => setActiveStep(activeStep > 0 ? activeStep - 1 : 0)} /> showBottomBorder=false, done=false → ❌ Border hidden ); }, }; export const WithCriticalBanner: Story = { args: { profileType: ProfileType.PERSONAL, showCloseButton: true, showMobileBackButton: true, avatarURL: '../tapestry-01.png', }, parameters: { chromatic: { viewports, }, padding: '0', }, render: (args) => { const [activeStep, setActiveStep] = useState(2); const steps = [ { label: 'Recipient', onClick: () => setActiveStep(0), }, { label: 'Amount', hoverLabel: ( <> You send 100 GBP
You get 99.39 GBP{' '} ), ...(activeStep > 1 && { onClick: () => setActiveStep(1) }), }, { label: 'Review', ...(activeStep > 2 && { onClick: () => setActiveStep(2) }), }, { label: 'Pay', ...(activeStep > 3 && { onClick: () => setActiveStep(3) }), }, ]; return ( <> {/* With critical banner - negative sentiment */} } logo={} activeStep={activeStep} steps={steps} banner={{ sentiment: 'negative', title: 'Action required', description: 'Please verify your identity to continue with this transfer.', action: { label: 'Verify now', onClick: () => console.log('Verify clicked'), }, }} onClose={args.showCloseButton ? () => {} : undefined} onGoBack={ args.showMobileBackButton ? () => setActiveStep(activeStep > 0 ? activeStep - 1 : 0) : undefined } /> Critical Banner Examples {/* With critical banner - warning sentiment */} } logo={} activeStep={activeStep} steps={steps} banner={{ sentiment: 'warning', title: 'Rate expires soon', description: 'Your guaranteed rate will expire in 2 hours. Complete your transfer to lock it in.', action: { label: 'Continue', onClick: () => console.log('Continue clicked'), }, actionSecondary: { label: 'Cancel transfer', onClick: () => console.log('Cancel clicked'), }, }} onClose={args.showCloseButton ? () => {} : undefined} onGoBack={ args.showMobileBackButton ? () => setActiveStep(activeStep > 0 ? activeStep - 1 : 0) : undefined } /> Example content below the navigation ); }, }; export const WithLegacyCriticalBannerData: Story = { args: { profileType: ProfileType.PERSONAL, showCloseButton: true, showMobileBackButton: true, avatarURL: '../tapestry-01.png', }, parameters: { padding: '0', }, render: (args) => { const [activeStep, setActiveStep] = useState(2); const steps = [ { label: 'Recipient', onClick: () => setActiveStep(0) }, { label: 'Amount', ...(activeStep > 1 && { onClick: () => setActiveStep(1) }) }, { label: 'Review', ...(activeStep > 2 && { onClick: () => setActiveStep(2) }) }, { label: 'Pay', ...(activeStep > 3 && { onClick: () => setActiveStep(3) }) }, ]; return ( // Legacy backend banner data shape - mapped to CriticalBannerProps internally } logo={} activeStep={activeStep} steps={steps} banner={{ id: 'banner-123', title: 'Your account requires attention', subtitle: 'Action required', style: 'WARNING', action: { label: 'Take action', href: '#action', }, collapsed: false, }} onClose={args.showCloseButton ? () => {} : undefined} onGoBack={ args.showMobileBackButton ? () => setActiveStep(activeStep > 0 ? activeStep - 1 : 0) : undefined } /> ); }, };