import type { Meta, StoryObj } from '@storybook/react-vite' import { AtSign, Search } from 'lucide-react' import { useState } from 'react' import { fn } from 'storybook/test' import { SIZES } from '../lib/styles' import { Input } from './Input' const meta = { title: 'Forms/Input', component: Input, tags: ['autodocs'], // Fields read best at form width, not stretched across the canvas. decorators: [ (Story) => (
), ], parameters: { docs: { description: { component: 'A single-line text input with its label above. `description` and `error` are linked to the input for screen readers. For a floating label, use `FeaturedInput`.', }, }, }, argTypes: { label: { control: 'text' }, description: { control: 'text' }, error: { control: 'text' }, placeholder: { control: 'text' }, size: { control: 'inline-radio', options: SIZES, table: { defaultValue: { summary: 'md' } } }, variant: { control: 'inline-radio', options: ['outline', 'filled', 'underline'], table: { defaultValue: { summary: 'outline' } }, }, type: { control: 'select', options: ['text', 'email', 'password', 'number', 'search', 'tel', 'url'] }, required: { control: 'boolean' }, disabled: { control: 'boolean' }, readOnly: { control: 'boolean' }, startAddon: { control: 'text' }, endAddon: { control: 'text' }, startIcon: { control: false }, endIcon: { control: false }, }, args: { label: 'Work email', placeholder: 'name@company.com', type: 'email', size: 'md', variant: 'outline', required: false, disabled: false, readOnly: false, onValueChange: fn(), }, } satisfies Meta export default meta type Story = StoryObj export const Playground: Story = {} export const WithDescription: Story = { args: { description: 'Payslips are sent to this address.' }, } export const WithError: Story = { args: { defaultValue: 'jane.doe@', error: 'Enter a full email address, like name@example.com.' }, } export const Required: Story = { args: { required: true }, } export const Disabled: Story = { args: { disabled: true, defaultValue: 'jane@example.com' }, } export const ReadOnly: Story = { args: { readOnly: true, defaultValue: 'jane@example.com', description: 'Managed by your identity provider.' }, } export const Variants: Story = { render: (args) => (
), } export const Sizes: Story = { render: (args) => (
{SIZES.map((size) => ( ))}
), } export const WithIcons: Story = { render: (args) => (
} /> } />
), } export const WithAddons: Story = { render: (args) => (
), } function ControlledInput(args: Story['args']) { const [value, setValue] = useState('Jane Doe') return (

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

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