Package Tansy UI as @openkhalix/tansy-ui in a monorepo (v0.4.0)
Restructure the repo into npm workspaces so the component kit publishes as its own package, like MUI and shadcn/ui: - packages/ui: @openkhalix/tansy-ui (published), with components, stories, tests, tokens and the library build - packages/brand: private logo and catalogue data shared by both apps - apps/site: the landing page - apps/docs: Storybook The package: - MIT licence (copyright OpenKhalix) - per-component ES modules and type declarations - "use client" on component modules so they import into Next.js Server Components; helpers stay server-safe - tokens.css for Tailwind v4 apps, and a prebuilt styles.css for apps without Tailwind - lucide-react 1.x, whose types compile against current React 19 types The apps resolve the package through a "source" export condition, so they hot-reload component edits, while outside users get dist/. scripts/test-package.mjs packs the package and installs the tarball into Vite + Tailwind (strict types), plain React and Next.js apps; each must build and render correctly. Gitea workflows run CI on push and publish to npm when a vX.Y.Z tag matching the package version is pushed.
This commit is contained in:
1 parent
23e67006d3
commit
9255b255a6
214 files changed
+1521
-389
No files matched your search
@@ -1,186 +1,107 @@
|
||||
<p align="center">
|
||||
<img src="public/tansy-mark.svg" width="88" height="88" alt="Tansy UI logo" />
|
||||
<img src="packages/brand/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.
|
||||
A themeable, accessible React component kit by OpenKhalix.<br />
|
||||
<a href="https://ui.openkhalix.com">Website</a> ·
|
||||
<a href="https://ui.openkhalix.com/docs/">Storybook</a> ·
|
||||
<a href="packages/ui/README.md">Package README</a> ·
|
||||
<a href="packages/ui/CHANGELOG.md">Changelog</a>
|
||||
</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.
|
||||
Tansy UI is named after the tansy flower, also called *golden buttons*: many small, round heads that read
|
||||
as one bloom. It is published to npm as **`@openkhalix/tansy-ui`**:
|
||||
|
||||
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";
|
||||
```bash
|
||||
npm install @openkhalix/tansy-ui
|
||||
```
|
||||
|
||||
```tsx
|
||||
import { Mail } from 'lucide-react'
|
||||
import { Button, FeaturedInput, Select, Switch } from 'tansy-ui'
|
||||
See the [package README](packages/ui/README.md) for setup and usage.
|
||||
|
||||
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>
|
||||
)
|
||||
}
|
||||
```
|
||||
## Repository layout
|
||||
|
||||
**Dark mode:** add the `dark` class to `<html>`.
|
||||
This is an npm workspaces monorepo, laid out the way MUI and shadcn/ui lay out theirs:
|
||||
|
||||
## Theming
|
||||
| Path | Package | Published | What it is |
|
||||
|---|---|---|---|
|
||||
| [`packages/ui`](packages/ui) | `@openkhalix/tansy-ui` | yes | The components, their stories and tests, tokens, and the library build |
|
||||
| [`packages/brand`](packages/brand) | `@tansy/brand` | no | The Tansy mark and the component catalogue, shared by both apps |
|
||||
| [`apps/site`](apps/site) | `@tansy/site` | no | The landing page at ui.openkhalix.com |
|
||||
| [`apps/docs`](apps/docs) | `@tansy/docs` | no | Storybook at ui.openkhalix.com/docs |
|
||||
| [`docs`](docs) | | | [Conventions](docs/CONVENTIONS.md) and [roadmap](docs/ROADMAP.md) |
|
||||
| [`scripts`](scripts) | | | Deploy, story checks, package install tests, catalogue generator |
|
||||
|
||||
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`.
|
||||
The apps depend on the package through its real `exports`. In this repo they resolve its `source` export
|
||||
condition, so editing a component hot-reloads the landing page and Storybook without a rebuild. Outside
|
||||
users get the built files in `dist/`.
|
||||
|
||||
`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
|
||||
## Develop
|
||||
|
||||
```bash
|
||||
npm install
|
||||
npm run dev # landing page at http://localhost:5173
|
||||
npm run storybook # component workshop at http://localhost:6006
|
||||
npm run storybook # Storybook at http://localhost:6006
|
||||
npm run lint
|
||||
npm run typecheck
|
||||
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)
|
||||
npm run build # package, then landing page, then Storybook
|
||||
```
|
||||
|
||||
To check every story in a real browser (runtime errors and axe, including colour contrast):
|
||||
### Checks before a release
|
||||
|
||||
```bash
|
||||
npm run build-storybook
|
||||
node scripts/check-stories.mjs --mode light
|
||||
npm run build:docs
|
||||
node scripts/check-stories.mjs --mode light # every story in Chrome: errors and axe
|
||||
node scripts/check-stories.mjs --mode dark
|
||||
python3 scripts/contact-sheet.py /tmp/tansy-story-check/light # screenshots to review
|
||||
node scripts/check-stories.mjs --width 320 # nothing may scroll sideways on phones
|
||||
npm run test:package # packs the package and installs it into Vite + Tailwind,
|
||||
# plain React and Next.js apps; each must build and render
|
||||
```
|
||||
|
||||
### Adding a component
|
||||
Adding a component: follow [`docs/CONVENTIONS.md`](docs/CONVENTIONS.md), export it from
|
||||
`packages/ui/src/index.ts`, then run `python3 scripts/gen_catalogue.py --patch` after `npm run build:docs`
|
||||
to refresh the landing page catalogue.
|
||||
|
||||
Follow [`docs/CONVENTIONS.md`](docs/CONVENTIONS.md). In short:
|
||||
## Release
|
||||
|
||||
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.
|
||||
1. Move the **Unreleased** notes in [`packages/ui/CHANGELOG.md`](packages/ui/CHANGELOG.md) under the new
|
||||
version and set `version` in `packages/ui/package.json`.
|
||||
2. Run the checks above.
|
||||
3. Commit, tag and push: `git tag -a v0.4.0 -m "Tansy UI v0.4.0" && git push origin main --follow-tags`.
|
||||
4. The **Release** workflow (`.gitea/workflows/release.yml`) checks that the tag matches the package
|
||||
version, re-runs the checks and publishes to npm. It needs an `NPM_TOKEN` repository secret for an
|
||||
account in the `openkhalix` npm organisation.
|
||||
|
||||
## Versioning
|
||||
To publish by hand instead: `npm login`, then `npm publish -w @openkhalix/tansy-ui` (the package's
|
||||
`prepublishOnly` runs the type-check, tests and build first).
|
||||
|
||||
Tansy UI follows [Semantic Versioning](https://semver.org). While the version is `0.x`, a minor release may include breaking changes.
|
||||
## Deploy the website
|
||||
|
||||
- `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.
|
||||
The landing page is served at `/` and Storybook at `/docs/`.
|
||||
|
||||
To cut a release:
|
||||
- **cPanel:** `python3 scripts/deploy.py` builds a committed tree, uploads it and removes files left over
|
||||
from earlier builds. See [`scripts/README.md`](scripts/README.md).
|
||||
- **Container:** the `Dockerfile` runs the checks, builds both apps and serves them from nginx with a
|
||||
`/healthz` endpoint:
|
||||
|
||||
```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
|
||||
```
|
||||
```bash
|
||||
docker build -t tansy-ui .
|
||||
docker run --rm -p 8041:80 tansy-ui
|
||||
```
|
||||
|
||||
## Brand
|
||||
|
||||
The mark is a tansy flowerhead: six buttons in the palette's primary colour around a gold centre button.
|
||||
`packages/brand/src/TansyMark.tsx` re-themes with the active palette; `packages/brand/public/` holds the
|
||||
fixed-colour SVG and the favicon. Typefaces: Schibsted Grotesk, Instrument Sans and JetBrains Mono.
|
||||
|
||||
- `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.
|
||||
## Licence
|
||||
|
||||
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.
|
||||
[MIT](LICENSE) © OpenKhalix. Free to use, fork and ship in commercial products; keep the copyright
|
||||
notice in copies of the code. A visible credit ("UI by Tansy UI") is appreciated but not required.
|
||||
Contributions are welcome.
|
||||
Reference in new issue
Block a user