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.
171 lines
5.1 KiB
TypeScript
171 lines
5.1 KiB
TypeScript
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) => (
|
||
<div className="max-w-md">
|
||
<Story />
|
||
</div>
|
||
),
|
||
],
|
||
} satisfies Meta<typeof FeaturedTextArea>
|
||
|
||
export default meta
|
||
type Story = StoryObj<typeof meta>
|
||
|
||
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) => (
|
||
<div className="grid gap-5">
|
||
{TEXT_FIELD_VARIANTS.map((variant) => (
|
||
<div key={variant} className="grid gap-3">
|
||
<FeaturedTextArea {...args} variant={variant} rows={2} label={`${variant[0].toUpperCase()}${variant.slice(1)}, empty`} />
|
||
<FeaturedTextArea
|
||
{...args}
|
||
variant={variant}
|
||
rows={2}
|
||
label={`${variant[0].toUpperCase()}${variant.slice(1)}, filled`}
|
||
defaultValue="Ring the bell twice."
|
||
/>
|
||
</div>
|
||
))}
|
||
</div>
|
||
),
|
||
}
|
||
|
||
export const Sizes: Story = {
|
||
render: (args) => (
|
||
<div className="grid gap-5">
|
||
{SIZES.map((size) => (
|
||
<div key={size} className="grid grid-cols-2 gap-3">
|
||
<FeaturedTextArea {...args} size={size} rows={2} label={`Size ${size}`} />
|
||
<FeaturedTextArea {...args} size={size} rows={2} label={`Size ${size}`} defaultValue="Jane Doe" />
|
||
</div>
|
||
))}
|
||
</div>
|
||
),
|
||
}
|
||
|
||
export const Uncontrolled: Story = {
|
||
args: { defaultValue: note, maxLength: 280 },
|
||
}
|
||
|
||
function ControlledFeaturedTextArea(args: Story['args']) {
|
||
const [value, setValue] = useState('Ring the bell twice.')
|
||
return (
|
||
<div className="grid gap-2">
|
||
<FeaturedTextArea
|
||
{...args}
|
||
maxLength={200}
|
||
value={value}
|
||
onValueChange={(next) => {
|
||
setValue(next)
|
||
args?.onValueChange?.(next)
|
||
}}
|
||
/>
|
||
<p className="text-sm text-fg-muted">Value: {value || '(empty)'}</p>
|
||
</div>
|
||
)
|
||
}
|
||
|
||
export const Controlled: Story = {
|
||
render: (args) => <ControlledFeaturedTextArea {...args} />,
|
||
}
|