import type { Meta, StoryObj } from '@storybook/react-vite' import { AtSign, Lock, Mail, Search, UserRound } from 'lucide-react' import { useState } from 'react' import { fn } from 'storybook/test' import { SIZES } from '../lib/styles' import { FeaturedInput } from './FeaturedInput' import { TEXT_FIELD_VARIANTS } from './featuredinput.tokens' const meta = { title: 'Forms/FeaturedInput', component: FeaturedInput, tags: ['autodocs'], parameters: { docs: { description: { component: 'A single-line text input whose label sits inside the box and floats up when the input is focused or filled. The float is pure CSS, so it works controlled, uncontrolled and with browser autofill. Same API as `Input`, plus a password reveal toggle (`type="password"`), `loading` and `clearable`. The label stays the accessible name; `description` and `error` are linked to the input.', }, }, }, argTypes: { label: { control: 'text' }, description: { control: 'text' }, error: { control: 'text' }, placeholder: { control: 'text', description: 'Shown once the label has floated, while the input is focused and empty.' }, type: { control: 'select', options: ['text', 'email', 'password', 'search', 'tel', 'url'] }, size: { control: 'inline-radio', options: SIZES, table: { defaultValue: { summary: 'md' } } }, variant: { control: 'inline-radio', options: TEXT_FIELD_VARIANTS, table: { defaultValue: { summary: 'outline' } }, }, required: { control: 'boolean' }, disabled: { control: 'boolean' }, readOnly: { control: 'boolean' }, loading: { control: 'boolean' }, clearable: { control: 'boolean' }, value: { control: 'text' }, defaultValue: { control: 'text' }, name: { control: 'text' }, className: { control: 'text' }, inputClassName: { control: 'text' }, startIcon: { control: false }, endIcon: { control: false }, onValueChange: { control: false }, onChange: { control: false }, }, args: { label: 'Work email', type: 'email', size: 'md', variant: 'outline', required: false, disabled: false, readOnly: false, loading: false, clearable: false, onValueChange: fn(), onChange: fn(), }, decorators: [ (Story) => (
), ], } satisfies Meta export default meta type Story = StoryObj export const Playground: Story = {} export const Filled: Story = { args: { defaultValue: 'jane.doe@example.com' }, } export const WithDescription: Story = { args: { description: 'Invoices from Acme Corporation are sent here.' }, } 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, description: 'We never share your email.' }, } export const Disabled: Story = { args: { disabled: true, defaultValue: 'jane.doe@example.com' }, } export const ReadOnly: Story = { args: { readOnly: true, defaultValue: 'jane.doe@example.com', description: 'Managed by your identity provider.' }, } export const Loading: Story = { args: { label: 'Username', type: 'text', loading: true, defaultValue: 'janedoe', description: 'Checking availability…' }, } export const Clearable: Story = { args: { label: 'Search people', type: 'search', clearable: true, defaultValue: 'Jane Doe', startIcon: }, } export const Password: Story = { args: { label: 'Password', type: 'password', defaultValue: 'correct-horse-battery', required: true, description: 'At least 12 characters.', autoComplete: 'current-password', }, } export const Variants: Story = { render: (args) => (
{TEXT_FIELD_VARIANTS.map((variant) => (
))}
), } export const Sizes: Story = { render: (args) => (
{SIZES.map((size) => (
))}
), } export const WithIcons: Story = { render: (args) => (
} /> } defaultValue="Jane Doe" /> } defaultValue="janedoe" /> } defaultValue="sk_test_4eC39HqLyjWDarjtT1" clearable />
), } export const AllStates: Story = { render: (args) => (
), } export const Uncontrolled: Story = { args: { label: 'Company', type: 'text', defaultValue: 'Acme Corporation', clearable: true }, } function ControlledFeaturedInput(args: Story['args']) { const [value, setValue] = useState('Jane Doe') return (
{ setValue(next) args?.onValueChange?.(next) }} />

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

) } export const Controlled: Story = { render: (args) => , } export const SignInForm: Story = { render: (args) => (
e.preventDefault()}> } /> } /> ), }