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.
This commit is contained in:
thekhalidsha committed 2026-09-28 21:12:11 +05:30
1 parent dc5e6ff800
commit f01de83733
185 files changed
+22542 -5182

No files matched your search

+130
View File
@@ -0,0 +1,130 @@
# Component conventions
Every Tansy UI component follows these rules, so the kit reads as one API. The
reference implementations are `src/components/Button.tsx`, `Input.tsx` and
`Field.tsx`, with their stories and tests. When in doubt, copy them.
## Foundation
- **Headless base:** interactive parts are built on [Base UI](https://base-ui.com)
(`@base-ui/react`). Its docs ship in the package at
`node_modules/@base-ui/react/docs/react/components/*.md`, with Tailwind examples
and full API tables. Use Base UI for anything with focus management, keyboard
navigation, popups or ARIA state: Dialog, Popover, Menu, Select, Combobox,
Tooltip, Tabs, Accordion, Checkbox, Radio, Switch, Slider, Toast, Field and more.
Never hand-roll focus traps, dismissal or roving focus.
- **Styling:** Tailwind v4 utilities only. Shared class strings live in
`src/lib/styles.ts` (`focusRing`, `controlHeight`, `controlBox`, `popupSurface`,
`popupMotion`, `listItem`, `labelText`, `descriptionText`, `errorText`).
Use them instead of repeating utilities.
- **Class merging:** always `cn(...)` from `src/lib/cn.ts`, with the consumer's
`className` last so it wins.
- **Refs:** React 19 passes `ref` as a normal prop. Type props from
`ComponentProps<'element'>` and spread `...props` onto the root element (or
the main control for form fields). No `forwardRef`, and never copy refs in an effect.
- **Ids:** from `useId()` or Base UI. Never derive an `id` from `name`.
- **Files:** `Name.tsx` exports only components (Vite fast refresh). Style maps,
types and constants go in `name.tokens.ts`. Stories in `Name.stories.tsx`,
tests in `Name.test.tsx`.
## Tokens and theming
Use only these colour utilities, never Tailwind's built-in hues (`slate`, `gray`,
`red`, `blue`…) or hex codes:
| Purpose | Utilities |
|---|---|
| Neutral surfaces | `bg-background`, `bg-surface`, `bg-surface-muted`, `bg-surface-sunken` |
| Borders | `border-border`, `border-border-strong` |
| Text | `text-fg`, `text-fg-muted`, `text-fg-subtle` |
| Brand | `primary-50` … `primary-900` (re-themed by the palette) |
| Status | `success-*`, `warning-*`, `danger-*`, `info-*` (50 … 900, fixed across palettes) |
| Overlay | `bg-overlay`; popup shadow `shadow-popup` |
**Dark mode** is the `dark` class on `<html>`. Surface, border and text tokens
switch automatically. Brand and status colours need `dark:` variants where
contrast demands it. Patterns that work:
- soft fill: `bg-{c}-50 text-{c}-700 dark:bg-{c}-500/15 dark:text-{c}-300`
- outline: `border-{c}-300 text-{c}-700 dark:border-{c}-500/50 dark:text-{c}-300`
- text on light surfaces: `-700`, and `-800` for warning. White text on fills:
primary `500`, danger `600`, success and info `700`. Warning fills take
`text-warning-900`.
Every story must pass axe **colour contrast** in both light and dark mode.
## Props
| Concept | Prop | Values |
|---|---|---|
| Semantic colour | `color` | `'primary' \| 'neutral' \| 'success' \| 'warning' \| 'danger' \| 'info'` (type `Color` in `lib/styles.ts`) |
| Visual style | `variant` | Per component, e.g. Button `solid \| soft \| outline \| ghost \| link`; Alert and Badge `soft \| solid \| outline` |
| Size | `size` | `'sm' \| 'md' \| 'lg'`, default `md`. Control heights come from `controlHeight`: 32, 40 and 48 px |
| Icons | `startIcon`, `endIcon`, `icon` | `ReactNode`. Callers pass `<Mail />`. Never icon names as strings, never icon fonts |
| Field text | `label`, `description`, `error` | `ReactNode`. `error` marks the control invalid and replaces `description` |
| Required | `required` | Shows the mark and sets `required` on the control |
| Value | `value`, `defaultValue`, `onValueChange(value)` | Every component works both controlled and uncontrolled |
| Boolean state | `checked`, `defaultChecked`, `onCheckedChange(checked)` | Checkbox, Switch |
| Open state | `open`, `defaultOpen`, `onOpenChange(open)` | Dialog, Popover, Menu, Tooltip, Drawer, Alert (dismissible) |
| Disabled | `disabled` | Native `disabled` or Base UI's, with `data-disabled` styling |
Text inputs also keep the native `onChange`. Document every prop with a JSDoc
comment; Storybook's docs table reads them.
## Accessibility
- A visible focus ring on every interactive element (`focusRing`, or
`focusWithinRing` on wrappers around an input).
- Form controls sit in `Field` (or Base UI `Field.Root`), so the label,
description and error are linked (`aria-labelledby`, `aria-describedby`,
`aria-invalid`).
- Icon-only controls require `aria-label`. Decorative icons get `aria-hidden`.
- Popups: Escape closes, focus returns to the trigger, and the keyboard works
as the WAI-ARIA pattern describes. Base UI does this when used as documented.
- Respect `motion-reduce:` for animations.
## Stories
- `title`: `Group/Name`. Groups: `Actions`, `Forms`, `Overlays`, `Navigation`,
`Feedback`, `Display`, `Layout`.
- `tags: ['autodocs']`, a component description in
`parameters.docs.description.component`, and `argTypes` for **every public
prop** with a matching control (`inline-radio` for short enums, `select`
for long ones, `text`, `boolean`, `number`; `control: false` for nodes and
functions).
- Callbacks use `fn()` from `storybook/test`, so they appear in the Actions panel.
- Stories: `Playground` (args-driven), plus one per variant, colour, size and
state (disabled, error, required, loading, read-only, empty), `Controlled`
and `Uncontrolled` where values exist, and realistic compositions. Popups
should have a story that renders them **open** (`defaultOpen`), so they can
be reviewed without clicking.
- Realistic, generic sample content (Jane Doe, Acme Corporation,
name@example.com). No real people or companies.
## Tests
Every component has `Name.test.tsx` (Vitest, Testing Library, user-event):
- renders with the right role and accessible name,
- label, description and error wiring for form controls,
- controlled and uncontrolled behaviour,
- keyboard interaction for the component's pattern (Escape, arrows, Enter/Space),
- `await expectNoA11yViolations(container)` from `src/test/a11y.ts`.
Run `npx vitest run src/components/Name.test.tsx`.
## Checking in a real browser
```bash
npm run build-storybook
node scripts/check-stories.mjs --filter forms-input --mode light
node scripts/check-stories.mjs --filter forms-input --mode dark
python3 scripts/contact-sheet.py /tmp/tansy-story-check/light --prefix forms-input
```
Before a release, also run it with `--palette <name>` for each of the seven
palettes: a colour that passes in Classic Blue can fail in Amber.
`check-stories.mjs` reports runtime errors, failed requests and axe violations,
including contrast, and saves a screenshot of every story. Look at the contact
sheet, not just the report.
+84
View File
@@ -0,0 +1,84 @@
# Roadmap
Where Tansy UI stands against MUI and shadcn/ui, what's done, and what comes
before v1.
Last reviewed: 2026-09-28, at v0.3.0.
## Where things stand
| | Tansy UI (v0.3) | shadcn/ui | MUI (Material UI + Base UI) |
|---|---|---|---|
| Distribution | Library build (ES modules, types, tokens.css); not yet on npm | CLI and registries. CLI v4 installs a whole design system in one payload | npm packages |
| Components | 38 | 50+, plus blocks and charts | Material UI's full set; Base UI v1 has 35 unstyled parts; MUI X adds Data Grid, Charts, Date Pickers, Tree View |
| Accessibility base | Base UI primitives | Radix and Base UI primitives | Base UI primitives |
| Theming | Seven runtime palettes, scoped to any element; semantic tokens | CSS variables | `createTheme`, CSS variables |
| Dark mode | Yes, token-based | Yes | Yes |
| Tests | Unit and axe tests per component; every story checked in a real browser in both modes | Per primitive | Unit, visual and a11y suites |
| Docs | Storybook: a story per state, full controls, Introduction guides | Docs site, examples, blocks | Docs site, demos, templates |
Sources: [shadcn/ui changelog](https://ui.shadcn.com/docs/changelog),
[shadcn CLI v4](https://ui.shadcn.com/docs/changelog/2026-03-cli-v4),
[MUI: 2026 and beyond](https://mui.com/blog/2026-and-beyond/),
[Base UI v1](https://infoq.com/news/2026/02/baseui-v1-accessible/).
## Phase 0: Foundations (done in v0.3.0)
- [x] Visible keyboard focus on every interactive element
- [x] Labels, help text and errors linked to every field (`Field`)
- [x] Overlays, selects and menus on Base UI: focus traps, focus return,
Escape, roving focus, type-ahead, a real ARIA combobox
- [x] Alert roles by severity; tooltips on keyboard focus
- [x] One API: `color`, `variant`, `size`, `startIcon`/`endIcon` as nodes,
`value`/`defaultValue`/`onValueChange`, `label`/`description`/`error`
- [x] Controlled and uncontrolled use everywhere; ids from `useId`
- [x] Token-only colours, fixed Classic Blue ramp, semantic status ramps
- [x] Dark mode
- [x] Tests for every component, and a browser check of every story in both modes
- [x] Icons imported individually (no full `lucide-react` bundle)
- [x] Library build with per-component modules, types and `tokens.css`
## Phase 1: Components
Shipped in v0.3.0: Field, Input, FeaturedInput, TextArea, FeaturedTextArea,
NumberInput, Select, FeaturedSelect, Combobox, NativeSelect, Checkbox,
CheckboxGroup, Radio, Switch, Slider, ToggleGroup, Button, IconButton,
LinkButton, Dialog, AlertDialog, Drawer, Popover, Tooltip, InfoTip,
DropdownMenu, Tabs, Accordion, Breadcrumb, Pagination, Alert, Toast, Spinner,
Progress, Meter, Skeleton, Badge, CountBadge, Avatar, AvatarGroup, Card, Kbd,
Separator and Table.
Still to come:
1. Date Picker and Date Range Picker
2. Data Table (sorting, filtering, selection and pagination on top of Table)
3. Command palette
4. File upload with drag and drop
5. OTP / verification code input (Base UI OTPField)
6. Context menu, Menubar and Navigation menu (Base UI primitives exist)
7. Stepper and Timeline
Each ships with stories for every state, keyboard and a11y tests, tokens only,
and a docs page.
## Phase 2: Distribution
- [ ] Claim the npm scope and publish the library build.
- [ ] Serve the same components as a shadcn-compatible registry, so
`npx shadcn add <url>` copies a Tansy component into a project: the
same code as a dependency or as source you own.
- [ ] Ship the palettes as a registry base item (tokens, fonts and CSS
variables in one install).
- [ ] Automate releases (Changesets) from `CHANGELOG.md`.
## Phase 3: Where Tansy can lead
- **Scoped runtime palettes.** `applyPalette()` already themes any subtree at
runtime. Next: a palette builder that makes a full, contrast-checked 50–900
ramp from one brand colour and exports `tokens.css`.
- **Form-heavy business apps.** Floating labels, inline help, required marks,
validation states, currency and number inputs are built in, where shadcn
leaves them to the app. Extend with masked inputs and date ranges.
- **Owned or installed.** One source, as an npm package or registry code.
- **Every state verified.** Every story is rendered and checked in light and
dark mode on each release. Publish that report with the docs.