import type { Meta, StoryObj } from '@storybook/react'; import React, { useState } from 'react'; import { AmountInput } from '../AmountInput'; import { Icon } from '../../Icon'; import { SnapshotContainer } from '../../../test-utils/SnapshotsContainer'; import { FormField } from '../../FormField'; import { LOCALES } from '../../GrapesProvider/exampleLocales'; import { GrapesProvider } from '../../GrapesProvider'; const currencies = [ { key: 'EUR', label: '€ - Euro' }, { key: 'GBP', label: '£ - British Pound', }, { key: 'USD', label: '$ - US Dollar', }, { key: 'JPY', label: '¥ - Yen' }, ]; const meta: Meta = { title: 'Form/AmountInput', component: AmountInput, args: { currency: currencies[0], }, }; export default meta; type Story = StoryObj; export const Default: Story = { render: (args) => { const [selectedValue, setSelectedValue] = useState(null); return (
{ setSelectedValue(newValue); }} />
); }, }; export const ParentFit: Story = { args: { fit: 'parent', }, render: Default.render, }; export const MagicGradient: Story = { args: { variant: 'magicGradient', }, render: Default.render, }; export const WithLeftAddon: Story = { args: { leftAddon: (
), }, render: Default.render, }; export const Disabled: Story = { args: { isDisabled: true, }, render: Default.render, }; export const InADisabledFieldset: Story = { render: (args) => { const [selectedValue, setSelectedValue] = useState(null); return (
{ setSelectedValue(newValue); }} />
); }, }; export const Invalid: Story = { args: { isInvalid: true, }, render: Default.render, }; export const NegativeValueAllowed: Story = { args: { hasNegativeValueAllowed: true, }, render: Default.render, }; export const EditableCurrency: Story = { render: (args) => { const [amount, setAmount] = useState(null); const [currency, setCurrency] = useState(currencies[0]); return ( { setAmount(newValue); }} value={amount} currency={currency} currencies={currencies} onSelectCurrency={(selectedCurrency) => { setCurrency(selectedCurrency); }} /> ); }, }; export const DisabledEditableCurrency: Story = { render: (args) => { const [amount, setAmount] = useState(null); const [currency, setCurrency] = useState(currencies[0]); return ( { setAmount(event.target.valueAsNumber); }} value={amount} currency={currency} currencies={currencies} onSelectCurrency={(selectedCurrency) => { setCurrency(selectedCurrency); }} /> ); }, }; export const Snapshot: Story = { parameters: { chromatic: { disableSnapshot: false }, }, render: () => ( ), };