Files
tansy-ui/README.md
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

187 lines
7.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<p align="center">
<img src="public/tansy-mark.svg" width="88" height="88" alt="Tansy UI logo" />
</p>
<h1 align="center">Tansy UI</h1>
<p align="center">
A themeable React component kit, with every state documented in Storybook.<br />
By OpenKhalix.
</p>
---
Tansy UI is named after the tansy flower, also called *golden buttons*: many small, round heads that together read as one bloom. The kit works the same way. It is a set of small, owned parts (buttons, fields, selects, feedback and overlays) that combine into a consistent interface.
Every part ships with:
- **Named variants.** A short list of deliberate choices, such as `variant="outline"`, instead of one-off styling.
- **Its states.** Error, disabled, loading and required are part of the component, and each has its own story.
- **Tokens, not hex codes.** Colours come from a 50–900 palette ramp, so switching the palette re-themes every part without a code change.
> **Status:** pre-release (v0.3.0). Tansy UI builds as a library (`npm run build:lib`) but is not published to npm yet. It is developed in this repository, with a landing page and a Storybook workshop as its showcase.
## Components
Built on [Base UI](https://base-ui.com) for accessible behaviour, styled with Tailwind CSS v4.
| Group | Components |
|---|---|
| Actions | `Button`, `IconButton`, `LinkButton`, `ToggleGroup`, `Toggle` |
| Forms | `Field`, `Input`, `FeaturedInput`, `TextArea`, `FeaturedTextArea`, `NumberInput`, `Select`, `FeaturedSelect`, `Combobox`, `NativeSelect`, `Checkbox`, `CheckboxGroup`, `Radio`, `Switch`, `Slider` |
| Overlays | `Dialog` (`Modal`), `AlertDialog`, `Drawer` (`Sheet`), `Popover`, `Tooltip`, `InfoTip`, `DropdownMenu` |
| Navigation | `Tabs`, `Accordion`, `Breadcrumb`, `Pagination` |
| Feedback | `Alert`, `Toast` (`Toaster`, `useToast`), `Spinner`, `Progress`, `Meter`, `Skeleton` |
| Display | `Badge`, `CountBadge`, `Avatar`, `AvatarGroup`, `Kbd`, `Table` |
| Layout | `Card`, `Separator` |
Every component follows one API (see [`docs/CONVENTIONS.md`](docs/CONVENTIONS.md)):
- `color` for meaning and `variant` for style;
- `size` of `sm`, `md` or `lg`;
- `startIcon` and `endIcon` as React nodes;
- `label`, `description` and `error` on every field;
- `value`, `defaultValue` and `onValueChange` for anything with a value.
## Usage
```css
/* app.css */
@import "tailwindcss";
@import "tansy-ui/tokens.css";
@source "../node_modules/tansy-ui/dist-lib";
```
```tsx
import { Mail } from 'lucide-react'
import { Button, FeaturedInput, Select, Switch } from 'tansy-ui'
export function InviteForm() {
return (
<form className="grid max-w-sm gap-5">
<FeaturedInput label="Work email" type="email" startIcon={<Mail />} required />
<Select
label="Team"
options={[
{ value: 'design', label: 'Design' },
{ value: 'engineering', label: 'Engineering' },
]}
/>
<Switch label="Send a welcome email" defaultChecked />
<Button type="submit">Send invite</Button>
</form>
)
}
```
**Dark mode:** add the `dark` class to `<html>`.
## Theming
Tansy UI ships seven palettes: Classic Blue (default), Emerald, Violet, Amber, Crimson, Slate and Teal. Each defines full `primary`, `secondary`, `gray` and `zink` ramps plus semantic colours in `src/theme/palettes.ts`.
`applyPalette(element, name)` writes a palette as CSS custom properties on any element. Tailwind v4 reads those properties, so a palette applies to one subtree and several palettes can appear on the same page:
```ts
import { applyPalette } from './theme/applyPalette'
applyPalette(document.getElementById('settings')!, 'emerald')
```
Storybook's **Palette** toolbar and the landing page playground both use this function.
## Development
```bash
npm install
npm run dev # landing page at http://localhost:5173
npm run storybook # component workshop at http://localhost:6006
npm run lint
npm test # unit, keyboard and axe tests for every component
npm run build # landing page -> dist/
npm run build-storybook # workshop -> storybook-static/
npm run build:lib # library -> dist-lib/ (ES modules, types, tokens.css)
```
To check every story in a real browser (runtime errors and axe, including colour contrast):
```bash
npm run build-storybook
node scripts/check-stories.mjs --mode light
node scripts/check-stories.mjs --mode dark
python3 scripts/contact-sheet.py /tmp/tansy-story-check/light # screenshots to review
```
### Adding a component
Follow [`docs/CONVENTIONS.md`](docs/CONVENTIONS.md). In short:
1. Build it on Base UI where it has behaviour, in `src/components/`, with style maps in a sibling `*.tokens.ts`.
2. Use only the tokens (`bg-surface`, `text-fg`, `primary-*`, `danger-*` …), and check it in dark mode.
3. Add `Name.stories.tsx` with controls for every prop and a story for every state, and `Name.test.tsx` with keyboard and axe checks.
4. Export it from `src/index.ts`.
5. Run `npm test`, the story check in both modes, then `python3 scripts/gen_catalogue.py --patch` to refresh the landing page catalogue.
## Versioning
Tansy UI follows [Semantic Versioning](https://semver.org). While the version is `0.x`, a minor release may include breaking changes.
- `package.json` holds the version. The build injects it into the landing page and Storybook through `src/version.ts`, so it is never typed by hand.
- Every release gets an entry in [`CHANGELOG.md`](CHANGELOG.md) and an annotated git tag such as `v0.2.0`.
- Every deploy publishes `/version.json`, which records the version and commit that are live.
To cut a release:
```bash
# 1. Move the [Unreleased] notes in CHANGELOG.md under the new version, then:
npm version minor -m "Release v%s" # or patch / major; bumps package.json, commits and tags
git push origin main --follow-tags
python3 scripts/deploy.py # builds that commit and deploys it
```
## Project structure
```text
src/
├── brand/TansyMark.tsx # Palette-aware logo
├── components/ # Components, their tokens, stories and tests
├── data/catalogue.ts # Landing page catalogue (regenerated by scripts/gen_catalogue.py)
├── docs/ # Storybook Introduction pages (MDX)
├── lib/ # cn(), shared styles, useControllableState
├── styles/tokens.css # Design tokens (shipped as tansy-ui/tokens.css)
├── test/ # Vitest setup and the axe helper
├── theme/ # Palettes and applyPalette()
├── index.ts # Public API
├── version.ts # VERSION, injected from package.json
├── App.tsx # Landing page, built only from Tansy components
└── index.css # Tailwind entry and landing styles
.storybook/ # Storybook config, Tansy theme, light/dark and palette toolbars
docs/ # CONVENTIONS.md, ROADMAP.md
scripts/ # Deploy, catalogue, story check and contact sheets
public/ # tansy-mark.svg and favicon.svg
```
## Brand
The mark is a tansy flowerhead: six buttons in the palette's primary colour around a gold centre button.
- `src/brand/TansyMark.tsx` re-themes with the active palette. The gold centre stays fixed.
- `public/tansy-mark.svg` is the fixed Classic Blue version, used by Storybook.
- `public/favicon.svg` is the mark on a dark tile, so it stays visible in both light and dark browser tabs.
Typefaces: Schibsted Grotesk for headings, Instrument Sans for text and JetBrains Mono for code.
## Deployment
The build serves the landing page at `/` and Storybook at `/docs/`.
**Container.** The `Dockerfile` lints and builds both surfaces, then serves them from nginx with a `/healthz` endpoint:
```bash
docker build -t tansy-ui .
docker run --rm -p 8041:80 tansy-ui
curl http://127.0.0.1:8041/healthz
```
**cPanel.** `python3 scripts/deploy.py` builds, packages and uploads to a cPanel host, then removes files left over from earlier builds. See [`scripts/README.md`](scripts/README.md) for setup.