@tini-work/tokens
v2.3.0
Published
Design token system for the tini component library. Provides OKLCH color scales, spacing, typography, radius, shadows, and motion tokens — output as CSS variables, a Tailwind preset, and typed TypeScript constants.
Readme
@tini-work/tokens
Design token system for the tini component library. Provides OKLCH color scales, spacing, typography, radius, shadows, and motion tokens — output as CSS variables, a Tailwind preset, and typed TypeScript constants.
Installation
npm install @tini-work/tokensExports
| Export | Description |
| ---------------------------- | ------------------------------------------------------------------------------------------ |
| @tini-work/tokens | Typed TS token constants (colors, spacing, typography, radius, shadow, motion) |
| @tini-work/tokens/tailwind | Tailwind v3 preset (tiniPreset) |
| @tini-work/tokens/css | CSS file with all custom properties (--primary, --background, etc.) |
Setup
Tailwind v4
Import the CSS directly — no preset needed:
@import "@tini-work/tokens/css";Tailwind v3
Add the preset to your config:
import { tiniPreset } from '@tini-work/tokens/tailwind'
export default {
presets: [tiniPreset],
}CSS variables only
@import "@tini-work/tokens/css";Then use tokens directly in your styles:
.my-element {
color: var(--foreground);
background: var(--background);
border-radius: var(--radius);
}Token Categories
| Category | Tokens |
| ------------ | ---------------------------------------------------------------------------------------------------------------------------------- |
| colors | OKLCH color scales (light + dark), semantic aliases (--primary, --background, --foreground, …), chart colors, severity scale |
| spacing | Spacing scale (maps to Tailwind spacing utilities) |
| typography | Font families, sizes, weights, line heights, letter spacing |
| radius | Border radius scale + base --radius variable |
| shadow | Box shadow scale (light + dark variants) |
| motion | Transition duration scale + easing curves + presets |
Dark mode
Dark mode is handled via a mode selector. By default, the CSS file emits overrides under both:
.dark { … }(compatibility with common Tailwind conventions)[data-mode="dark"] { … }(supports subtree theming)
<html class="dark">
<!-- all tokens automatically switch to dark values -->
</html>Themes (brand packs) and subtree theming
Themes are handled via a theme selector. The recommended API is:
[data-theme="<id>"] { … }(supports subtree theming)- Optional sugar:
.theme-<id> { … }
This allows global theming:
<!-- Intent: apply a brand theme to the whole app -->
<html data-theme="acme">
…
</html>And subtree theming (e.g. previews, embedded widgets, multi-tenant sections):
<!-- Intent: theme only a section without affecting the rest of the page -->
<section data-theme="acme">
…
</section>Dark mode composes with themes (orthogonal axes):
<!-- Intent: apply a brand theme + dark mode together -->
<html data-theme="acme" class="dark">
…
</html>TypeScript usage
import { colors, spacing, typography, radius, shadow, motion } from '@tini-work/tokens'
import type { Colors, Spacing, Typography, Radius, Shadow, Motion } from '@tini-work/tokens'Note: TypeScript exports represent the default token definitions. Multi-theme customization is intended to be CSS-first (override variables via selectors).
App semantic extensions (--app-*)
Consumer apps can define additional semantic variables under the reserved --app-* namespace.
/* Intent: app-specific semantics that compose from the design system contract */
:root {
--app-shell: var(--background);
--app-shell-foreground: var(--foreground);
}If you want Tailwind utilities for these, opt-in by mapping them in your own Tailwind config (the preset intentionally does not generate app-* keys).
Token pipeline
Tokens are defined in src/*.json and compiled by scripts/build-tokens.mjs into:
generated/tokens.ts— typed TypeScript constantsgenerated/tailwind-preset.ts— Tailwind v3 theme extensiongenerated/css-variables.css— CSS custom properties
Run the build manually:
pnpm --filter @tini-work/tokens build:tokens # regenerate from JSON sources
pnpm --filter @tini-work/tokens build # build:tokens + tsup (JS/DTS output)
pnpm --filter @tini-work/tokens validate:contrast # validate WCAG contrast ratiosLicense
MIT
