@thatch-health/slab-tokens 0.0.4 → 0.0.6
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 +78 -2
- package/dist/index.d.mts +1822 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +17454 -4
- package/dist/index.mjs.map +1 -1
- package/dist/tailwind-plugin.cjs +244 -53
- package/dist/tailwind-v4-plugin.css +878 -53
- package/package.json +8 -3
package/README.md
CHANGED
|
@@ -2,9 +2,85 @@
|
|
|
2
2
|
|
|
3
3
|
This package is the pipeline for importing Figma tokens defined in [Token Foundations](https://www.figma.com/design/AMVtHovyyMCo78skFvePV4/Token-Foundations?node-id=32-93&p=f&t=fLz0IYz5irefoKsl-11) and then outputing in appropriate formats for web, the marketing website, and slab design system itself. This package uses [Terrazzo](https://terrazzo.app/) to manage the conversion from the [Design Token Community Group](https://www.designtokens.org/) specification which is a universal token specification. The package itself exports a few endpoints for consumers to use:
|
|
4
4
|
|
|
5
|
+
- `@thatch-health/slab-tokens` - The `getToken` and `mergeToken` JavaScript API for querying token metadata
|
|
5
6
|
- `@thatch-health/slab-tokens/tokens-raw` - The raw JSON values of the DTCG specification downloaded from Figma
|
|
6
|
-
- `@thatch-health/slab-tokens/css` -
|
|
7
|
-
- `@thatch-health/slab-tokens/tailwind-v3-plugin` - A plugin for
|
|
7
|
+
- `@thatch-health/slab-tokens/css/app` - CSS custom properties output from Terrazzo (import in a root CSS file)
|
|
8
|
+
- `@thatch-health/slab-tokens/tailwind-v3-plugin` - A plugin for Tailwind v3 that maps CSS variables to utility classes
|
|
9
|
+
- `@thatch-health/slab-tokens/tailwind-v4-plugin` - A CSS plugin for Tailwind v4 that maps CSS variables to utility classes
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
Install the package:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm i @thatch-health/slab-tokens
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Import CSS
|
|
20
|
+
|
|
21
|
+
In a root `.css` file, import the token styles:
|
|
22
|
+
|
|
23
|
+
```css
|
|
24
|
+
@import "@thatch-health/slab-tokens/css/app";
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Tailwind v3
|
|
28
|
+
|
|
29
|
+
In your `tailwind.config.js`, import the plugin and add it to your plugins array:
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import slabPlugin from "@thatch-health/slab-tokens/tailwind-v3-plugin";
|
|
33
|
+
|
|
34
|
+
const config = {
|
|
35
|
+
plugins: [slabPlugin],
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export default config;
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Tailwind v4
|
|
42
|
+
|
|
43
|
+
In the CSS file where you import Tailwind, add both the CSS tokens and the v4 plugin:
|
|
44
|
+
|
|
45
|
+
```css
|
|
46
|
+
@import "tailwindcss";
|
|
47
|
+
@import "@thatch-health/slab-tokens/css/app";
|
|
48
|
+
@import "@thatch-health/slab-tokens/tailwind-v4-plugin";
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## `getToken` API
|
|
52
|
+
|
|
53
|
+
The package exposes a `getToken` function for querying token metadata programmatically. This is useful for MCP servers, documentation tooling, or any code that needs to discover which tokens apply to a given design intent.
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import { getToken } from "@thatch-health/slab-tokens";
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
`getToken` accepts an options object where **at least one field is required**. Multiple fields are ANDed together to narrow results.
|
|
60
|
+
|
|
61
|
+
| Option | Type | Description |
|
|
62
|
+
| ---------- | --------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
|
|
63
|
+
| `category` | `TokenCategory` | Filter by design intent: `"surface"`, `"action"`, `"form"`, `"typography"`, `"dimension"`, `"radius"`, `"gap"`, `"spacing"`, `"stroke"` |
|
|
64
|
+
| `scope` | `Scope` | Filter by broad token kind: `"color"`, `"spacing"`, or `"typography"` |
|
|
65
|
+
| `property` | `CSSProperty` | Filter by the CSS property the token applies to (e.g. `"background"`, `"padding"`, `"font-size"`) |
|
|
66
|
+
| `name` | `string` | Fuzzy-match on token name (e.g. `"action primary bg"` matches `"action.default.primary.bg"`) |
|
|
67
|
+
|
|
68
|
+
Each result is a `MergedToken` which includes the DTCG token fields plus a `$extensions["thatch.slab"]` entry describing the CSS variable, Tailwind class(es), and applicable CSS properties.
|
|
69
|
+
|
|
70
|
+
### Examples
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
// All action color tokens
|
|
74
|
+
getToken({ category: "action", scope: "color" });
|
|
75
|
+
|
|
76
|
+
// Tokens that set the background property on action components, filtered by name
|
|
77
|
+
getToken({ property: "background", category: "action", name: "default" });
|
|
78
|
+
// → ["action.default.ghost.bg", "action.default.primary.bg", ...]
|
|
79
|
+
|
|
80
|
+
// Fuzzy search by name
|
|
81
|
+
getToken({ name: "action.default.primary.bg" });
|
|
82
|
+
// → includes "action.default.primary.bg", "action.default.primary.bg-end", etc.
|
|
83
|
+
```
|
|
8
84
|
|
|
9
85
|
## Development
|
|
10
86
|
|