import { useState } from 'react'; import type { Meta, StoryObj } from '@storybook/react'; import Box from '@mui/material/Box'; import { CompareBar } from './CompareBar'; import type { CompareBarPackage } from './CompareBar'; import { Button } from '../../atoms/Button'; import { Typography } from '../../atoms/Typography'; const samplePackages: CompareBarPackage[] = [ { id: '1', name: 'Everyday Funeral Package', providerName: 'Wollongong City Funerals' }, { id: '2', name: 'Traditional Cremation Service', providerName: 'Mackay Family Funerals' }, { id: '3', name: 'Essential Burial Package', providerName: 'Inglewood Chapel' }, ]; const meta: Meta = { title: 'Molecules/CompareBar', component: CompareBar, tags: ['autodocs'], parameters: { layout: 'fullscreen', }, decorators: [ (Story) => ( The compare bar floats at the bottom of the viewport. ), ], }; export default meta; type Story = StoryObj; // --- Default (2 packages) --------------------------------------------------- /** Two packages selected — "2 packages ready to compare" */ export const Default: Story = { args: { packages: samplePackages.slice(0, 2), onCompare: () => alert('Compare clicked'), }, }; // --- Single Package ---------------------------------------------------------- /** One package — "Add another package to compare", CTA disabled */ export const SinglePackage: Story = { args: { packages: samplePackages.slice(0, 1), onCompare: () => alert('Compare clicked'), }, }; // --- Three Packages (Maximum) ------------------------------------------------ /** Maximum 3 packages */ export const ThreePackages: Story = { args: { packages: samplePackages, onCompare: () => alert('Compare clicked'), }, }; // --- With Error -------------------------------------------------------------- /** Error message when user tries to add a 4th package */ export const WithError: Story = { args: { packages: samplePackages, onCompare: () => alert('Compare clicked'), error: 'Maximum 3 packages', }, }; // --- Empty (Hidden) ---------------------------------------------------------- /** No packages — bar is hidden */ export const Empty: Story = { args: { packages: [], onCompare: () => {}, }, }; // --- Mobile ------------------------------------------------------------------ /** Mobile viewport — expanded by default, with a grey-filled right-chevron * on the right of the pill. Tap the chevron to retract the pill to the * right corner (the middle content animates to width:0, so the pill * visually shrinks as one unit rather than swapping into a separate mini * pill). Tap the left-chevron on the collapsed pill to expand. On add * while collapsed, the full bar auto-peeks for 3s, then re-collapses. */ export const Mobile: Story = { args: { packages: samplePackages.slice(0, 2), onCompare: () => alert('Compare clicked'), }, parameters: { viewport: { defaultViewport: 'mobile1' }, }, }; /** Mobile — single package state. Same behaviour as `Mobile`, Compare * CTA disabled ("Add another to compare"). */ export const MobileSingle: Story = { args: { packages: samplePackages.slice(0, 1), onCompare: () => alert('Compare clicked'), }, parameters: { viewport: { defaultViewport: 'mobile1' }, }, }; // --- Interactive Demo -------------------------------------------------------- /** Interactive demo — add packages and see the bar update */ export const Interactive: Story = { render: () => { const [selected, setSelected] = useState([]); const [error, setError] = useState(); const allPackages = [ ...samplePackages, { id: '4', name: 'Catholic Service', providerName: "St Mary's Funeral Services" }, ]; const handleToggle = (pkg: CompareBarPackage) => { const isSelected = selected.some((s) => s.id === pkg.id); if (isSelected) { setSelected(selected.filter((s) => s.id !== pkg.id)); setError(undefined); } else { if (selected.length >= 3) { setError('Maximum 3 packages'); setTimeout(() => setError(undefined), 3000); return; } setSelected([...selected, pkg]); setError(undefined); } }; return ( Select packages to compare {allPackages.map((pkg) => { const isSelected = selected.some((s) => s.id === pkg.id); return ( {pkg.name} {pkg.providerName} ); })} alert(`Comparing: ${selected.map((s) => s.name).join(', ')}`)} error={error} /> ); }, };