import type { Meta, StoryObj } from '@storybook/react-webpack5'; import { userEvent, within } from 'storybook/test'; import { useRtlDiffI18n, withRTLDiff } from '../../../.storybook/decorators/RtlDiffDecorator'; import Field from '../../Field/Field'; import MoneyInput from '..'; export default { component: MoneyInput, title: 'Forms/MoneyInput/Tests/RTL Diff', tags: ['!autodocs', '!manifest'], } satisfies Meta; type Story = StoryObj; const eurCurrency = { value: 'EUR', label: 'EUR', note: 'Euro', currency: 'eur', } as const; const gbpCurrency = { value: 'GBP', label: 'GBP', note: 'British pound', currency: 'gbp', } as const; const multipleCurrencies = [eurCurrency, gbpCurrency] as const; /** * `note` holds the currency's full name and renders only in the open dropdown, so only * OpenDropdown needs the localised variants. */ const getLocalisedCurrencies = (i18n: Record) => [ { ...eurCurrency, note: i18n.euro }, { ...gbpCurrency, note: i18n.britishPound }, ]; const sharedProps = { amount: 1000, id: 'money-input', onAmountChange: () => {}, onCurrencyChange: () => {}, } as const; export const TriggerVariants: Story = { render: () => ( <> ), ...withRTLDiff({ fixedRows: { heights: 'auto' }, }), }; export const OpenDropdown: Story = { render: () => { const i18n = useRtlDiffI18n(); const currencies = getLocalisedCurrencies(i18n); return ( ); }, play: async ({ canvasElement }) => { const canvas = within(canvasElement); const trigger = canvas.queryByRole('combobox'); if (!trigger) return; await userEvent.click(trigger); }, ...withRTLDiff({ renderAs: 'iframe', width: '40%', i18n: { searchPlaceholder: { en: 'Search currencies or countries', ar: 'ابحث عن العملات أو الدول' }, euro: { en: 'Euro', ar: 'اليورو' }, britishPound: { en: 'British pound', ar: 'الجنيه الإسترليني' }, }, }), };