@jasonruesch/tokens 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +80 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# @jasonruesch/tokens
|
|
2
|
+
|
|
3
|
+
Design tokens for the design system, authored in [W3C DTCG](https://www.w3.org/community/design-tokens/)
|
|
4
|
+
JSON and compiled with [Style Dictionary](https://styledictionary.com/) into CSS
|
|
5
|
+
custom properties (`--ds-*`) and a typed TypeScript object.
|
|
6
|
+
|
|
7
|
+
Tokens are layered **primitive → semantic → component**:
|
|
8
|
+
|
|
9
|
+
- **Primitive** — raw values (color scales, dimensions, typography, shadow) on `:root`.
|
|
10
|
+
- **Semantic** — intent-based aliases (`bg`, `fg`, `accent`, `danger`, …) that
|
|
11
|
+
switch with `data-theme`.
|
|
12
|
+
- **Component** — component-scoped values that reference the semantic layer.
|
|
13
|
+
- **Brand** — per-brand overrides applied with `data-brand`.
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
npm install @jasonruesch/tokens
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
### CSS variables
|
|
24
|
+
|
|
25
|
+
Import the full cascade (primitives, light/dark themes, brand, components):
|
|
26
|
+
|
|
27
|
+
```css
|
|
28
|
+
@import "@jasonruesch/tokens/css";
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
…or import individual layers:
|
|
32
|
+
|
|
33
|
+
```css
|
|
34
|
+
@import "@jasonruesch/tokens/css/variables.css"; /* primitives → :root */
|
|
35
|
+
@import "@jasonruesch/tokens/css/theme-light.css"; /* [data-theme~="light"] */
|
|
36
|
+
@import "@jasonruesch/tokens/css/theme-dark.css"; /* [data-theme~="dark"] */
|
|
37
|
+
@import "@jasonruesch/tokens/css/brand-acme.css"; /* [data-brand="acme"] */
|
|
38
|
+
@import "@jasonruesch/tokens/css/components.css"; /* component layer → :root */
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Then reference the variables and switch theme/brand on any ancestor element — no
|
|
42
|
+
rebuild required:
|
|
43
|
+
|
|
44
|
+
```html
|
|
45
|
+
<html data-theme="dark" data-brand="acme">
|
|
46
|
+
<button style="background: var(--ds-color-accent-default); color: var(--ds-color-fg-on-accent)">
|
|
47
|
+
Save
|
|
48
|
+
</button>
|
|
49
|
+
</html>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### TypeScript / JavaScript
|
|
53
|
+
|
|
54
|
+
Resolved values (light theme as canonical) are also available as a typed object:
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
import { tokens, type TokenName } from "@jasonruesch/tokens";
|
|
58
|
+
|
|
59
|
+
tokens["color.accent.default"]; // "#2563eb"
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Exports
|
|
63
|
+
|
|
64
|
+
| Entry | Contents |
|
|
65
|
+
| -------------------------------- | ------------------------------------------------- |
|
|
66
|
+
| `@jasonruesch/tokens` | Typed `tokens` object + types (`dist/ts`) |
|
|
67
|
+
| `@jasonruesch/tokens/css` | Barrel importing every CSS layer in cascade order |
|
|
68
|
+
| `@jasonruesch/tokens/css/*` | Individual CSS layer files |
|
|
69
|
+
|
|
70
|
+
## Build
|
|
71
|
+
|
|
72
|
+
Tokens are authored in `tokens/` and compiled into `dist/` by `config.mjs`:
|
|
73
|
+
|
|
74
|
+
```sh
|
|
75
|
+
pnpm build # or: pnpm tokens:build
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## License
|
|
79
|
+
|
|
80
|
+
MIT
|