Files
tansy-ui/README.md
T
thekhalidsha 9d406d6d2a Tansy UI: a themeable React component kit
Tansy UI is a React component kit by OpenKhalix, named after the tansy
flower ("golden buttons"). It has two surfaces:

- A landing page built entirely from the kit's own components, with
  five featured parts, a palette-switching playground form, and links
  into Storybook
- A Storybook workshop with Tansy branding, a Welcome page, palette
  toolbar and accessibility checks

Includes 15 components with colocated tokens and stories, seven brand
palettes, a palette-aware logo, a Docker/nginx image, a scripted
cPanel deploy, and a generator that keeps the landing page catalogue
in sync with Storybook.
2026-09-28 17:09:57 +05:30

137 lines
5.2 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.2). Tansy UI is not published to npm yet. It is developed in this repository, with a landing page and a Storybook workshop as its showcase.
## Components
| Group | Components |
|---|---|
| Actions | `Button`, `LinkButton` |
| Forms | `Input`, `FeaturedInput`, `Select`, `Checkbox`, `Radio`, `Switch`, `TextArea` |
| Data entry | `TextField` |
| Feedback | `Alert`, `Spinner` |
| Display | `Badge` |
| Layout | `Card` (with `Card.Header`, `Card.Title`, `Card.Body`, `Card.Footer`) |
| Navigation | `Accordion` |
| Overlays | `Tooltip` |
Each component lives in `src/components/` with its style maps in a sibling `*.tokens.ts` and its stories in `*.stories.tsx`.
## Usage
```tsx
import { useState } from 'react'
import { Button } from './components/Button'
import { FeaturedInput } from './components/FeaturedInput'
import { Switch } from './components/Switch'
export function InviteForm() {
const [email, setEmail] = useState('')
return (
<form>
<FeaturedInput
label="Work email"
type="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
required
/>
<Switch label="Send a welcome email" defaultChecked />
<Button type="submit">Send invite</Button>
</form>
)
}
```
## 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 run build # landing page -> dist/
npm run build-storybook # workshop -> storybook-static/
```
### Adding a component
1. Add it under `src/components/`, with style maps in a sibling `*.tokens.ts`.
2. Add a colocated `ComponentName.stories.tsx` that covers every meaningful state.
3. Read colours from the palette ramps (`bg-primary-500`) so the palette switcher reaches it.
4. Run `npm run build-storybook && python3 scripts/gen_catalogue.py --patch` to refresh the landing page catalogue.
## Project structure
```text
src/
├── brand/TansyMark.tsx # Palette-aware logo
├── components/ # Components, their tokens and their stories
├── data/catalogue.ts # Landing page catalogue (regenerated by scripts/gen_catalogue.py)
├── theme/ # Palettes and applyPalette()
├── Welcome.mdx # Storybook welcome page
├── App.tsx # Landing page, built only from Tansy components
└── index.css # Tailwind entry, palette tokens, landing styles
.storybook/ # Storybook config, Tansy theme, fonts
public/ # tansy-mark.svg and favicon.svg
scripts/ # Deploy and catalogue scripts
```
## 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.