Files
tansy-ui/src/components/Input.stories.tsx
T
thekhalidsha f01de83733 Rebuild Tansy UI on Base UI with one API and dark mode (v0.3.0)
Every component is rebuilt on @base-ui/react with a single prop API,
token-only colours and dark mode, and 28 new components are added.

Components
- New: Field, FeaturedTextArea, NumberInput, Combobox, CheckboxGroup,
  Slider, ToggleGroup/Toggle, IconButton, Dialog/Modal, AlertDialog,
  Drawer/Sheet, Popover, InfoTip, DropdownMenu, Tabs, Breadcrumb,
  Pagination, Toast (Toaster, useToast), Progress, Meter, Skeleton,
  CountBadge, Avatar/AvatarGroup, Kbd, Separator, Table
- Rewritten: Button, Input, FeaturedInput, TextArea, Select,
  FeaturedSelect (real ARIA combobox), NativeSelect, Checkbox, Radio,
  Switch, Tooltip, Accordion, Alert, Spinner, Badge, Card
- Removed TextField (use Input) and sonner (use Toast)

Foundations
- Semantic tokens (surfaces, text, borders, status ramps) in
  src/styles/tokens.css, with class-based dark mode
- Visible focus rings, linked labels/descriptions/errors, alert roles by
  severity, keyboard support from Base UI
- Fixed the Classic Blue ramp; Emerald, Amber and Teal 500 steps now
  carry white text at AA
- Library build (per-component ES modules, types, tokens.css, exports)

Quality
- Vitest, Testing Library and axe tests for every component (289 tests)
- scripts/check-stories.mjs renders every story in Chrome and fails on
  errors or axe violations, including contrast; all 423 stories pass in
  light and dark mode and in all seven palettes
- Storybook: controls for every prop, open states for every popup,
  light/dark toolbar, Introduction guides, docs/CONVENTIONS.md

BREAKING CHANGE: component props changed across the kit; see CHANGELOG.md.
2026-09-28 21:12:11 +05:30

137 lines
3.9 KiB
TypeScript

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) => (
<div className="max-w-sm">
<Story />
</div>
),
],
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: '[email protected]',
type: 'email',
size: 'md',
variant: 'outline',
required: false,
disabled: false,
readOnly: false,
onValueChange: fn(),
},
} satisfies Meta<typeof Input>
export default meta
type Story = StoryObj<typeof meta>
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 [email protected].' },
}
export const Required: Story = {
args: { required: true },
}
export const Disabled: Story = {
args: { disabled: true, defaultValue: '[email protected]' },
}
export const ReadOnly: Story = {
args: { readOnly: true, defaultValue: '[email protected]', description: 'Managed by your identity provider.' },
}
export const Variants: Story = {
render: (args) => (
<div className="grid gap-5">
<Input {...args} variant="outline" label="Outline" />
<Input {...args} variant="filled" label="Filled" />
<Input {...args} variant="underline" label="Underline" />
</div>
),
}
export const Sizes: Story = {
render: (args) => (
<div className="grid gap-5">
{SIZES.map((size) => (
<Input key={size} {...args} size={size} label={`Size ${size}`} />
))}
</div>
),
}
export const WithIcons: Story = {
render: (args) => (
<div className="grid gap-5">
<Input {...args} label="Search" type="search" placeholder="Search employees" startIcon={<Search />} />
<Input {...args} label="Username" type="text" placeholder="jane" endIcon={<AtSign />} />
</div>
),
}
export const WithAddons: Story = {
render: (args) => (
<div className="grid gap-5">
<Input {...args} label="Website" type="text" placeholder="example" startAddon="https://" endAddon=".com" />
<Input {...args} label="Amount" type="number" placeholder="0.00" startAddon="$" endAddon="USD" />
</div>
),
}
function ControlledInput(args: Story['args']) {
const [value, setValue] = useState('Jane Doe')
return (
<div className="grid gap-2">
<Input {...args} label="Full name" type="text" value={value} onValueChange={setValue} />
<p className="text-sm text-fg-muted">Value: {value || '(empty)'}</p>
</div>
)
}
export const Controlled: Story = {
render: (args) => <ControlledInput {...args} />,
}