import type { Meta, StoryObj } from '@storybook/react-vite' import { useState } from 'react' import { fn } from 'storybook/test' import { SIZES } from '../lib/styles' import { FeaturedTextArea } from './FeaturedTextArea' import { TEXT_FIELD_VARIANTS } from './featuredinput.tokens' const meta = { title: 'Forms/FeaturedTextArea', component: FeaturedTextArea, tags: ['autodocs'], parameters: { docs: { description: { component: 'The floating-label version of `TextArea`, with the same props. The label rests where the first line of text goes and floats to the top of the box when the textarea is focused or filled (CSS only). The box reserves room for the floated label, so scrolled text never runs under it.', }, }, }, argTypes: { label: { control: 'text' }, description: { control: 'text' }, error: { control: 'text' }, placeholder: { control: 'text', description: 'Shown once the label has floated, while the textarea is focused and empty.' }, size: { control: 'inline-radio', options: SIZES, table: { defaultValue: { summary: 'md' } } }, variant: { control: 'inline-radio', options: TEXT_FIELD_VARIANTS, table: { defaultValue: { summary: 'outline' } }, }, rows: { control: { type: 'number', min: 1, max: 12 }, table: { defaultValue: { summary: '3' } } }, resize: { control: 'inline-radio', options: ['none', 'vertical', 'both'], table: { defaultValue: { summary: 'vertical' } }, }, autoResize: { control: 'boolean' }, maxRows: { control: { type: 'number', min: 1, max: 20 } }, maxLength: { control: { type: 'number', min: 1 } }, required: { control: 'boolean' }, disabled: { control: 'boolean' }, readOnly: { control: 'boolean' }, value: { control: 'text' }, defaultValue: { control: 'text' }, name: { control: 'text' }, className: { control: 'text' }, textareaClassName: { control: 'text' }, onValueChange: { control: false }, onChange: { control: false }, }, args: { label: 'Delivery instructions', placeholder: 'Gate code, where to leave the parcel…', size: 'md', variant: 'outline', rows: 3, resize: 'vertical', autoResize: false, required: false, disabled: false, readOnly: false, onValueChange: fn(), onChange: fn(), }, decorators: [ (Story) => (
), ], } satisfies Meta export default meta type Story = StoryObj const note = 'Leave the parcel with reception at Acme Corporation, 2nd floor. If nobody answers, call Jane Doe on the number in my profile.' export const Playground: Story = {} export const Filled: Story = { args: { defaultValue: note }, } export const WithDescription: Story = { args: { description: 'Shared with the courier only.' }, } export const WithError: Story = { args: { required: true, error: 'Add instructions so the courier can find you.' }, } export const Required: Story = { args: { required: true }, } export const Disabled: Story = { args: { disabled: true, defaultValue: note }, } export const ReadOnly: Story = { args: { readOnly: true, defaultValue: note, description: 'The order has shipped, so this can’t change.' }, } export const CharacterCounter: Story = { args: { maxLength: 200, defaultValue: 'Ring the bell twice.' }, } export const AutoResize: Story = { args: { autoResize: true, rows: 2, maxRows: 5, defaultValue: `${note} ${note}` }, } export const Variants: Story = { render: (args) => (
{TEXT_FIELD_VARIANTS.map((variant) => (
))}
), } export const Sizes: Story = { render: (args) => (
{SIZES.map((size) => (
))}
), } export const Uncontrolled: Story = { args: { defaultValue: note, maxLength: 280 }, } function ControlledFeaturedTextArea(args: Story['args']) { const [value, setValue] = useState('Ring the bell twice.') return (
{ setValue(next) args?.onValueChange?.(next) }} />

Value: {value || '(empty)'}

) } export const Controlled: Story = { render: (args) => , }