@tenphi/tasty 0.0.0-snapshot.fafcbfe → 0.0.0-snapshot.fc19da9
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 +497 -266
- package/dist/babel-types-DpUCD2L_.d.ts +18 -0
- package/dist/chunks/async-storage-f9j9JRtq.js +37 -0
- package/dist/chunks/async-storage-f9j9JRtq.js.map +1 -0
- package/dist/chunks/build-config-BDLYGmKn.js +60 -0
- package/dist/chunks/build-config-BDLYGmKn.js.map +1 -0
- package/dist/chunks/collector-DqcB0UUT.js +210 -0
- package/dist/chunks/collector-DqcB0UUT.js.map +1 -0
- package/dist/chunks/config-engine-CGIMO2PV.js +272 -0
- package/dist/chunks/config-engine-CGIMO2PV.js.map +1 -0
- package/dist/chunks/config-file-DlZXJMj8.js +25 -0
- package/dist/chunks/config-file-DlZXJMj8.js.map +1 -0
- package/dist/chunks/css-definitions-BibU6ZnP.js +904 -0
- package/dist/chunks/css-definitions-BibU6ZnP.js.map +1 -0
- package/dist/chunks/css-resources-P7IBUUZs.js +142 -0
- package/dist/chunks/css-resources-P7IBUUZs.js.map +1 -0
- package/dist/chunks/debug-BzYPQ0H2.js +502 -0
- package/dist/chunks/debug-BzYPQ0H2.js.map +1 -0
- package/dist/chunks/dsl-DRhFWQzo.js +1378 -0
- package/dist/chunks/dsl-DRhFWQzo.js.map +1 -0
- package/dist/chunks/hydration-TRcz5vnk.js +41 -0
- package/dist/chunks/hydration-TRcz5vnk.js.map +1 -0
- package/dist/chunks/react-runtime-B2e-Wha-.js +689 -0
- package/dist/chunks/react-runtime-B2e-Wha-.js.map +1 -0
- package/dist/chunks/runtime-engine-yeyCAx2e.js +2431 -0
- package/dist/chunks/runtime-engine-yeyCAx2e.js.map +1 -0
- package/dist/chunks/runtime-state-C0u1jp-Q.js +141 -0
- package/dist/chunks/runtime-state-C0u1jp-Q.js.map +1 -0
- package/dist/{utils/merge-styles.js → chunks/shared-utils-y-HjvPN4.js} +61 -58
- package/dist/chunks/shared-utils-y-HjvPN4.js.map +1 -0
- package/dist/chunks/style-engine-D35rvcdB.js +5420 -0
- package/dist/chunks/style-engine-D35rvcdB.js.map +1 -0
- package/dist/chunks/zero-engine-DpkieEPZ.js +310 -0
- package/dist/chunks/zero-engine-DpkieEPZ.js.map +1 -0
- package/dist/collector-D4POJ53X.d.ts +164 -0
- package/dist/config-DvPUj4cw.d.ts +1364 -0
- package/dist/core/index.d.ts +5 -33
- package/dist/core/index.js +9 -26
- package/dist/hydrate-CRyjjAyl.d.ts +22 -0
- package/dist/index-DC4q-xDq.d.ts +1946 -0
- package/dist/index.d.ts +5 -40
- package/dist/index.js +11 -33
- package/dist/{utils/merge-styles.d.ts → merge-styles-Jb5iZ-Jf.d.ts} +3 -4
- package/dist/ssr/astro-client.d.ts +1 -0
- package/dist/ssr/astro-client.js +6 -0
- package/dist/ssr/astro-client.js.map +1 -0
- package/dist/ssr/astro-middleware-extract-static.d.ts +10 -0
- package/dist/ssr/astro-middleware-extract-static.js +9 -0
- package/dist/ssr/astro-middleware-extract-static.js.map +1 -0
- package/dist/ssr/astro-middleware-extract.d.ts +10 -0
- package/dist/ssr/astro-middleware-extract.js +9 -0
- package/dist/ssr/astro-middleware-extract.js.map +1 -0
- package/dist/ssr/astro-middleware-static.d.ts +17 -0
- package/dist/ssr/astro-middleware-static.js +7 -0
- package/dist/ssr/astro-middleware-static.js.map +1 -0
- package/dist/ssr/astro-middleware.d.ts +18 -0
- package/dist/ssr/astro-middleware.js +7 -0
- package/dist/ssr/astro-middleware.js.map +1 -0
- package/dist/ssr/astro.d.ts +127 -0
- package/dist/ssr/astro.js +221 -0
- package/dist/ssr/astro.js.map +1 -0
- package/dist/ssr/client.d.ts +2 -0
- package/dist/ssr/client.js +2 -0
- package/dist/ssr/index.d.ts +17 -0
- package/dist/ssr/index.js +10 -0
- package/dist/ssr/index.js.map +1 -0
- package/dist/ssr/next-config.d.ts +64 -0
- package/dist/ssr/next-config.js +123 -0
- package/dist/ssr/next-config.js.map +1 -0
- package/dist/ssr/next.d.ts +46 -0
- package/dist/ssr/next.js +60 -0
- package/dist/ssr/next.js.map +1 -0
- package/dist/static/index.d.ts +90 -5
- package/dist/static/index.js +31 -4
- package/dist/static/index.js.map +1 -0
- package/dist/static/inject.d.ts +4 -0
- package/dist/static/inject.js +17 -0
- package/dist/static/inject.js.map +1 -0
- package/dist/types-ZbF2_6LV.d.ts +1567 -0
- package/dist/zero/babel.d.ts +49 -90
- package/dist/zero/babel.js +252 -119
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/index.d.ts +117 -3
- package/dist/zero/index.js +23 -3
- package/dist/zero/index.js.map +1 -0
- package/dist/zero/next.d.ts +58 -33
- package/dist/zero/next.js +89 -59
- package/dist/zero/next.js.map +1 -1
- package/docs/README.md +42 -0
- package/docs/adoption.md +331 -0
- package/docs/ai-agents.md +252 -0
- package/docs/comparison.md +449 -0
- package/docs/configuration.md +943 -0
- package/docs/debug.md +333 -0
- package/docs/design-system.md +557 -0
- package/docs/dsl.md +1093 -0
- package/docs/getting-started.md +297 -0
- package/docs/injector.md +633 -0
- package/docs/methodology.md +673 -0
- package/docs/migration-v3.md +285 -0
- package/docs/pipeline.md +768 -0
- package/docs/plugins.md +333 -0
- package/docs/react-api.md +703 -0
- package/docs/runtime-benchmarks.md +388 -0
- package/docs/ssr.md +630 -0
- package/docs/styles.md +725 -0
- package/docs/tasty-static.md +659 -0
- package/package.json +238 -50
- package/tasty.config.ts +6 -0
- package/dist/_virtual/_rolldown/runtime.js +0 -8
- package/dist/chunks/cacheKey.js +0 -70
- package/dist/chunks/cacheKey.js.map +0 -1
- package/dist/chunks/definitions.d.ts +0 -37
- package/dist/chunks/definitions.js +0 -260
- package/dist/chunks/definitions.js.map +0 -1
- package/dist/chunks/renderChunk.js +0 -61
- package/dist/chunks/renderChunk.js.map +0 -1
- package/dist/config.d.ts +0 -280
- package/dist/config.js +0 -403
- package/dist/config.js.map +0 -1
- package/dist/debug.d.ts +0 -204
- package/dist/debug.js +0 -733
- package/dist/debug.js.map +0 -1
- package/dist/hooks/useGlobalStyles.d.ts +0 -27
- package/dist/hooks/useGlobalStyles.js +0 -56
- package/dist/hooks/useGlobalStyles.js.map +0 -1
- package/dist/hooks/useKeyframes.d.ts +0 -56
- package/dist/hooks/useKeyframes.js +0 -54
- package/dist/hooks/useKeyframes.js.map +0 -1
- package/dist/hooks/useProperty.d.ts +0 -79
- package/dist/hooks/useProperty.js +0 -91
- package/dist/hooks/useProperty.js.map +0 -1
- package/dist/hooks/useRawCSS.d.ts +0 -53
- package/dist/hooks/useRawCSS.js +0 -28
- package/dist/hooks/useRawCSS.js.map +0 -1
- package/dist/hooks/useStyles.d.ts +0 -40
- package/dist/hooks/useStyles.js +0 -169
- package/dist/hooks/useStyles.js.map +0 -1
- package/dist/injector/index.d.ts +0 -157
- package/dist/injector/index.js +0 -154
- package/dist/injector/index.js.map +0 -1
- package/dist/injector/injector.d.ts +0 -139
- package/dist/injector/injector.js +0 -404
- package/dist/injector/injector.js.map +0 -1
- package/dist/injector/sheet-manager.d.ts +0 -127
- package/dist/injector/sheet-manager.js +0 -714
- package/dist/injector/sheet-manager.js.map +0 -1
- package/dist/injector/types.d.ts +0 -135
- package/dist/keyframes/index.js +0 -206
- package/dist/keyframes/index.js.map +0 -1
- package/dist/parser/classify.js +0 -319
- package/dist/parser/classify.js.map +0 -1
- package/dist/parser/const.js +0 -33
- package/dist/parser/const.js.map +0 -1
- package/dist/parser/lru.js +0 -109
- package/dist/parser/lru.js.map +0 -1
- package/dist/parser/parser.d.ts +0 -25
- package/dist/parser/parser.js +0 -116
- package/dist/parser/parser.js.map +0 -1
- package/dist/parser/tokenizer.js +0 -69
- package/dist/parser/tokenizer.js.map +0 -1
- package/dist/parser/types.d.ts +0 -51
- package/dist/parser/types.js +0 -46
- package/dist/parser/types.js.map +0 -1
- package/dist/pipeline/conditions.d.ts +0 -134
- package/dist/pipeline/conditions.js +0 -400
- package/dist/pipeline/conditions.js.map +0 -1
- package/dist/pipeline/exclusive.js +0 -231
- package/dist/pipeline/exclusive.js.map +0 -1
- package/dist/pipeline/index.d.ts +0 -53
- package/dist/pipeline/index.js +0 -641
- package/dist/pipeline/index.js.map +0 -1
- package/dist/pipeline/materialize.js +0 -908
- package/dist/pipeline/materialize.js.map +0 -1
- package/dist/pipeline/parseStateKey.d.ts +0 -15
- package/dist/pipeline/parseStateKey.js +0 -430
- package/dist/pipeline/parseStateKey.js.map +0 -1
- package/dist/pipeline/simplify.js +0 -557
- package/dist/pipeline/simplify.js.map +0 -1
- package/dist/plugins/okhsl-plugin.d.ts +0 -35
- package/dist/plugins/okhsl-plugin.js +0 -371
- package/dist/plugins/okhsl-plugin.js.map +0 -1
- package/dist/plugins/types.d.ts +0 -69
- package/dist/properties/index.js +0 -158
- package/dist/properties/index.js.map +0 -1
- package/dist/states/index.d.ts +0 -49
- package/dist/states/index.js +0 -416
- package/dist/states/index.js.map +0 -1
- package/dist/static/tastyStatic.d.ts +0 -46
- package/dist/static/tastyStatic.js +0 -31
- package/dist/static/tastyStatic.js.map +0 -1
- package/dist/static/types.d.ts +0 -49
- package/dist/static/types.js +0 -24
- package/dist/static/types.js.map +0 -1
- package/dist/styles/align.d.ts +0 -15
- package/dist/styles/align.js +0 -14
- package/dist/styles/align.js.map +0 -1
- package/dist/styles/border.d.ts +0 -25
- package/dist/styles/border.js +0 -114
- package/dist/styles/border.js.map +0 -1
- package/dist/styles/color.d.ts +0 -14
- package/dist/styles/color.js +0 -23
- package/dist/styles/color.js.map +0 -1
- package/dist/styles/createStyle.js +0 -77
- package/dist/styles/createStyle.js.map +0 -1
- package/dist/styles/dimension.js +0 -97
- package/dist/styles/dimension.js.map +0 -1
- package/dist/styles/display.d.ts +0 -37
- package/dist/styles/display.js +0 -67
- package/dist/styles/display.js.map +0 -1
- package/dist/styles/fade.d.ts +0 -15
- package/dist/styles/fade.js +0 -58
- package/dist/styles/fade.js.map +0 -1
- package/dist/styles/fill.d.ts +0 -44
- package/dist/styles/fill.js +0 -51
- package/dist/styles/fill.js.map +0 -1
- package/dist/styles/flow.d.ts +0 -16
- package/dist/styles/flow.js +0 -12
- package/dist/styles/flow.js.map +0 -1
- package/dist/styles/gap.d.ts +0 -31
- package/dist/styles/gap.js +0 -37
- package/dist/styles/gap.js.map +0 -1
- package/dist/styles/height.d.ts +0 -17
- package/dist/styles/height.js +0 -20
- package/dist/styles/height.js.map +0 -1
- package/dist/styles/index.d.ts +0 -2
- package/dist/styles/index.js +0 -9
- package/dist/styles/index.js.map +0 -1
- package/dist/styles/inset.d.ts +0 -52
- package/dist/styles/inset.js +0 -150
- package/dist/styles/inset.js.map +0 -1
- package/dist/styles/justify.d.ts +0 -15
- package/dist/styles/justify.js +0 -14
- package/dist/styles/justify.js.map +0 -1
- package/dist/styles/list.d.ts +0 -16
- package/dist/styles/list.js +0 -98
- package/dist/styles/list.js.map +0 -1
- package/dist/styles/margin.d.ts +0 -24
- package/dist/styles/margin.js +0 -104
- package/dist/styles/margin.js.map +0 -1
- package/dist/styles/outline.d.ts +0 -29
- package/dist/styles/outline.js +0 -65
- package/dist/styles/outline.js.map +0 -1
- package/dist/styles/padding.d.ts +0 -24
- package/dist/styles/padding.js +0 -104
- package/dist/styles/padding.js.map +0 -1
- package/dist/styles/predefined.d.ts +0 -73
- package/dist/styles/predefined.js +0 -241
- package/dist/styles/predefined.js.map +0 -1
- package/dist/styles/preset.d.ts +0 -47
- package/dist/styles/preset.js +0 -126
- package/dist/styles/preset.js.map +0 -1
- package/dist/styles/radius.d.ts +0 -14
- package/dist/styles/radius.js +0 -51
- package/dist/styles/radius.js.map +0 -1
- package/dist/styles/scrollbar.d.ts +0 -21
- package/dist/styles/scrollbar.js +0 -105
- package/dist/styles/scrollbar.js.map +0 -1
- package/dist/styles/shadow.d.ts +0 -14
- package/dist/styles/shadow.js +0 -24
- package/dist/styles/shadow.js.map +0 -1
- package/dist/styles/styledScrollbar.d.ts +0 -47
- package/dist/styles/styledScrollbar.js +0 -38
- package/dist/styles/styledScrollbar.js.map +0 -1
- package/dist/styles/transition.d.ts +0 -14
- package/dist/styles/transition.js +0 -158
- package/dist/styles/transition.js.map +0 -1
- package/dist/styles/types.d.ts +0 -498
- package/dist/styles/width.d.ts +0 -17
- package/dist/styles/width.js +0 -20
- package/dist/styles/width.js.map +0 -1
- package/dist/tasty.d.ts +0 -982
- package/dist/tasty.js +0 -191
- package/dist/tasty.js.map +0 -1
- package/dist/tokens/typography.d.ts +0 -19
- package/dist/tokens/typography.js +0 -237
- package/dist/tokens/typography.js.map +0 -1
- package/dist/types.d.ts +0 -184
- package/dist/utils/cache-wrapper.js +0 -26
- package/dist/utils/cache-wrapper.js.map +0 -1
- package/dist/utils/case-converter.js +0 -8
- package/dist/utils/case-converter.js.map +0 -1
- package/dist/utils/colors.d.ts +0 -5
- package/dist/utils/colors.js +0 -9
- package/dist/utils/colors.js.map +0 -1
- package/dist/utils/css-types.d.ts +0 -7
- package/dist/utils/dotize.d.ts +0 -26
- package/dist/utils/dotize.js +0 -122
- package/dist/utils/dotize.js.map +0 -1
- package/dist/utils/filter-base-props.d.ts +0 -15
- package/dist/utils/filter-base-props.js +0 -45
- package/dist/utils/filter-base-props.js.map +0 -1
- package/dist/utils/get-display-name.d.ts +0 -7
- package/dist/utils/get-display-name.js +0 -10
- package/dist/utils/get-display-name.js.map +0 -1
- package/dist/utils/hsl-to-rgb.js +0 -38
- package/dist/utils/hsl-to-rgb.js.map +0 -1
- package/dist/utils/is-dev-env.js +0 -19
- package/dist/utils/is-dev-env.js.map +0 -1
- package/dist/utils/is-valid-element-type.js +0 -15
- package/dist/utils/is-valid-element-type.js.map +0 -1
- package/dist/utils/merge-styles.js.map +0 -1
- package/dist/utils/mod-attrs.d.ts +0 -8
- package/dist/utils/mod-attrs.js +0 -21
- package/dist/utils/mod-attrs.js.map +0 -1
- package/dist/utils/okhsl-to-rgb.js +0 -296
- package/dist/utils/okhsl-to-rgb.js.map +0 -1
- package/dist/utils/process-tokens.d.ts +0 -31
- package/dist/utils/process-tokens.js +0 -171
- package/dist/utils/process-tokens.js.map +0 -1
- package/dist/utils/resolve-recipes.d.ts +0 -17
- package/dist/utils/resolve-recipes.js +0 -147
- package/dist/utils/resolve-recipes.js.map +0 -1
- package/dist/utils/string.js +0 -8
- package/dist/utils/string.js.map +0 -1
- package/dist/utils/styles.d.ts +0 -183
- package/dist/utils/styles.js +0 -585
- package/dist/utils/styles.js.map +0 -1
- package/dist/utils/typography.d.ts +0 -36
- package/dist/utils/typography.js +0 -53
- package/dist/utils/typography.js.map +0 -1
- package/dist/utils/warnings.d.ts +0 -16
- package/dist/utils/warnings.js +0 -16
- package/dist/utils/warnings.js.map +0 -1
- package/dist/zero/css-writer.d.ts +0 -45
- package/dist/zero/css-writer.js +0 -74
- package/dist/zero/css-writer.js.map +0 -1
- package/dist/zero/extractor.d.ts +0 -24
- package/dist/zero/extractor.js +0 -150
- package/dist/zero/extractor.js.map +0 -1
|
@@ -0,0 +1,557 @@
|
|
|
1
|
+
# Building a Design System
|
|
2
|
+
|
|
3
|
+
This guide shows how to build shared React components whose styles stay predictable as states, variants, themes, and responsive rules accumulate. You will define tokens, state aliases, recipes, primitive APIs, and compound components with sub-elements.
|
|
4
|
+
|
|
5
|
+
It assumes you have already decided to adopt Tasty. The goal is not only to centralize values, but to give your design system one state model and a governed component-facing styling API. For evaluation criteria and incremental rollout, see the [Adoption Guide](adoption.md). For the recommended component architecture, see [Methodology](methodology.md).
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Designing your token vocabulary
|
|
10
|
+
|
|
11
|
+
Tokens are the foundation of a design system. In Tasty, tokens are defined via `configure({ tokens })` and referenced in styles with `#name` (colors) or `$name` (values). See [Configuration — Design Tokens](configuration.md#design-tokens) for the API.
|
|
12
|
+
|
|
13
|
+
### Color tokens
|
|
14
|
+
|
|
15
|
+
Adopt a semantic naming convention that maps intent, not visual appearance. Define tokens via `configure({ tokens })`:
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import { configure } from '@tenphi/tasty';
|
|
19
|
+
|
|
20
|
+
configure({
|
|
21
|
+
tokens: {
|
|
22
|
+
// Surfaces
|
|
23
|
+
'#surface': '#fff',
|
|
24
|
+
'#surface-hover': '#f5f5f5',
|
|
25
|
+
'#surface-pressed': '#ebebeb',
|
|
26
|
+
|
|
27
|
+
// Primary action
|
|
28
|
+
'#primary': 'oklch(55% 0.25 265)',
|
|
29
|
+
'#primary-hover': 'oklch(50% 0.25 265)',
|
|
30
|
+
'#primary-pressed': 'oklch(45% 0.25 265)',
|
|
31
|
+
'#on-primary': '#fff',
|
|
32
|
+
|
|
33
|
+
// Semantic
|
|
34
|
+
'#danger': 'oklch(55% 0.22 25)',
|
|
35
|
+
'#danger-hover': 'oklch(50% 0.22 25)',
|
|
36
|
+
'#on-danger': '#fff',
|
|
37
|
+
|
|
38
|
+
// Text
|
|
39
|
+
'#text': '#111',
|
|
40
|
+
'#text-secondary': '#666',
|
|
41
|
+
|
|
42
|
+
// Borders
|
|
43
|
+
'#border': '#e0e0e0',
|
|
44
|
+
|
|
45
|
+
// Spacing and shape scale
|
|
46
|
+
$gap: '8px',
|
|
47
|
+
$radius: '4px',
|
|
48
|
+
'$border-width': '1px',
|
|
49
|
+
'$outline-width': '2px',
|
|
50
|
+
},
|
|
51
|
+
// Built-in units compile to fixed values by default. Pointing them at the
|
|
52
|
+
// tokens above lets a theme or density mode change the scale at runtime.
|
|
53
|
+
units: {
|
|
54
|
+
x: 'var(--gap)', // 2x → calc(2 * var(--gap))
|
|
55
|
+
r: 'var(--radius)',
|
|
56
|
+
bw: 'var(--border-width)',
|
|
57
|
+
ow: 'var(--outline-width)',
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Leave out the `units` block to keep the built-in fixed scale (`x` = `8px`, `r` = `6px`, `bw` = `1px`, `ow` = `3px`), or set fixed values there instead (`units: { x: '8px', r: '4px' }`). Always define the token a unit points at: `--gap` is registered with an initial value of `4px`, which would silently halve the default step. Boolean shorthands follow the same scale: `radius: true` is `1r`, `border: true` is `1bw`, and `outline: true` is `1ow`. See [Built-in Units](dsl.md#built-in-units).
|
|
63
|
+
|
|
64
|
+
Tokens are injected as CSS custom properties on `:root` when the first style is rendered. They support state maps for theme-aware values:
|
|
65
|
+
|
|
66
|
+
```tsx
|
|
67
|
+
configure({
|
|
68
|
+
tokens: {
|
|
69
|
+
'#primary': {
|
|
70
|
+
'': 'oklch(55% 0.25 265)',
|
|
71
|
+
'@dark': 'oklch(75% 0.2 265)',
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
The `#on-*` convention names the text color that sits on top of a fill — `#on-primary` is the text color on a `#primary` background. This makes state maps self-documenting: `fill: '#primary'` and `color: '#on-primary'` clearly belong together.
|
|
78
|
+
|
|
79
|
+
To generate the whole palette instead of hand-picking values, use [Glaze](https://github.com/tenphi/glaze): it builds light, dark, and high-contrast variants from one hue in the OKHST color space, solves WCAG and APCA contrast, and exports Tasty tokens you can pass straight to `configure({ tokens: theme.tasty() })`.
|
|
80
|
+
|
|
81
|
+
### Replace tokens for value aliases
|
|
82
|
+
|
|
83
|
+
`configure({ replaceTokens })` replaces tokens with literal values at parse time, baking them into the generated CSS. Use it for value aliases that should be inlined during style generation:
|
|
84
|
+
|
|
85
|
+
```tsx
|
|
86
|
+
configure({
|
|
87
|
+
replaceTokens: {
|
|
88
|
+
'$card-padding': '4x',
|
|
89
|
+
'$input-height': '5x',
|
|
90
|
+
'$sidebar-width': '280px',
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Typography presets
|
|
96
|
+
|
|
97
|
+
Pass typography presets directly to `configure()` — they are converted to tokens automatically:
|
|
98
|
+
|
|
99
|
+
```tsx
|
|
100
|
+
import { configure } from '@tenphi/tasty';
|
|
101
|
+
|
|
102
|
+
configure({
|
|
103
|
+
presets: {
|
|
104
|
+
h1: {
|
|
105
|
+
fontSize: '2rem',
|
|
106
|
+
lineHeight: '1.2',
|
|
107
|
+
letterSpacing: '-0.02em',
|
|
108
|
+
fontWeight: 700,
|
|
109
|
+
},
|
|
110
|
+
t2: {
|
|
111
|
+
fontSize: '0.875rem',
|
|
112
|
+
lineHeight: '1.5',
|
|
113
|
+
letterSpacing: 'normal',
|
|
114
|
+
fontWeight: 400,
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Preset values support state maps for responsive or theme-aware typography:
|
|
121
|
+
|
|
122
|
+
```tsx
|
|
123
|
+
configure({
|
|
124
|
+
presets: {
|
|
125
|
+
t2: {
|
|
126
|
+
fontSize: '0.875rem',
|
|
127
|
+
lineHeight: '1.5',
|
|
128
|
+
fontWeight: { '': 400, '@dark': 300 },
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Then use `preset: 'h1'` or `preset: 't2'` in any component's styles.
|
|
135
|
+
|
|
136
|
+
> You can also call `generateTypographyTokens()` manually and spread the result into `tokens` for more control — `presets` is just a shorthand.
|
|
137
|
+
|
|
138
|
+
### Registering brand fonts
|
|
139
|
+
|
|
140
|
+
Register your design system's custom fonts via `configure({ fontFaces })` so every component can reference them:
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
configure({
|
|
144
|
+
fontFaces: {
|
|
145
|
+
'Brand Sans': [
|
|
146
|
+
{
|
|
147
|
+
src: 'url("/fonts/brand-regular.woff2") format("woff2")',
|
|
148
|
+
fontWeight: 400,
|
|
149
|
+
fontDisplay: 'swap',
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
src: 'url("/fonts/brand-bold.woff2") format("woff2")',
|
|
153
|
+
fontWeight: 700,
|
|
154
|
+
fontDisplay: 'swap',
|
|
155
|
+
},
|
|
156
|
+
],
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
See [Font Face](configuration.md#font-face) for the full configuration reference.
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
## Defining state aliases
|
|
166
|
+
|
|
167
|
+
State aliases let you write `@mobile` instead of `@media(w < 768px)` in every component. Define them once in `configure()`:
|
|
168
|
+
|
|
169
|
+
```tsx
|
|
170
|
+
configure({
|
|
171
|
+
states: {
|
|
172
|
+
'@mobile': '@media(w < 768px)',
|
|
173
|
+
'@tablet': '@media(768px <= w < 1024px)',
|
|
174
|
+
'@desktop': '@media(w >= 1024px)',
|
|
175
|
+
'@dark':
|
|
176
|
+
'@root(schema=dark) | (!@root(schema) & @media(prefers-color-scheme: dark))',
|
|
177
|
+
'@reduced-motion': '@media(prefers-reduced-motion: reduce)',
|
|
178
|
+
},
|
|
179
|
+
});
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Every component can now use these without repeating the query logic:
|
|
183
|
+
|
|
184
|
+
```tsx
|
|
185
|
+
const Card = tasty({
|
|
186
|
+
styles: {
|
|
187
|
+
padding: { '': '4x', '@mobile': '2x' },
|
|
188
|
+
flow: { '': 'row', '@mobile': 'column' },
|
|
189
|
+
radius: { '': '1r', '@mobile': '0' },
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
Theme switching belongs in tokens (`'#surface': { '': '#fff', '@dark': '#1c1c1e' }`) rather than in component state maps, so components stay theme-agnostic.
|
|
195
|
+
|
|
196
|
+
Without aliases, the same component would need the full media query expression inlined in every state map — across every property, in every component. Aliases eliminate that duplication.
|
|
197
|
+
|
|
198
|
+
---
|
|
199
|
+
|
|
200
|
+
## Creating recipes
|
|
201
|
+
|
|
202
|
+
Recipes are named style bundles for patterns that repeat across components. Define them in `configure()`:
|
|
203
|
+
|
|
204
|
+
```tsx
|
|
205
|
+
configure({
|
|
206
|
+
recipes: {
|
|
207
|
+
card: {
|
|
208
|
+
padding: '4x',
|
|
209
|
+
fill: '#surface',
|
|
210
|
+
radius: '1r',
|
|
211
|
+
border: true,
|
|
212
|
+
},
|
|
213
|
+
elevated: {
|
|
214
|
+
shadow: '0 2x 4x #shadow',
|
|
215
|
+
},
|
|
216
|
+
'input-reset': {
|
|
217
|
+
border: 'none',
|
|
218
|
+
outline: 'none',
|
|
219
|
+
fill: '#clear',
|
|
220
|
+
font: true,
|
|
221
|
+
preset: 't3',
|
|
222
|
+
},
|
|
223
|
+
interactive: {
|
|
224
|
+
cursor: { '': 'pointer', disabled: 'not-allowed' },
|
|
225
|
+
opacity: { '': '1', disabled: '.5' },
|
|
226
|
+
transition: 'theme',
|
|
227
|
+
},
|
|
228
|
+
},
|
|
229
|
+
});
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
Components reference recipes by name. This keeps component definitions lean while ensuring consistency:
|
|
233
|
+
|
|
234
|
+
```tsx
|
|
235
|
+
const ProfileCard = tasty({
|
|
236
|
+
styles: {
|
|
237
|
+
recipe: 'card elevated',
|
|
238
|
+
color: '#text',
|
|
239
|
+
Title: { preset: 'h3', color: '#primary' },
|
|
240
|
+
},
|
|
241
|
+
elements: { Title: 'h2' },
|
|
242
|
+
});
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
Use the `/` separator when a recipe should be applied _after_ local styles (post-merge), so recipe states take priority:
|
|
246
|
+
|
|
247
|
+
```tsx
|
|
248
|
+
const Input = tasty({
|
|
249
|
+
styles: {
|
|
250
|
+
recipe: 'input-reset / interactive',
|
|
251
|
+
padding: '1.5x 2x',
|
|
252
|
+
border: '1bw solid #border',
|
|
253
|
+
},
|
|
254
|
+
});
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
See [Configuration — Recipes](configuration.md#recipes) for the API and [Style DSL — Recipes](dsl.md#recipes) for composition patterns.
|
|
258
|
+
|
|
259
|
+
---
|
|
260
|
+
|
|
261
|
+
## Building primitive components
|
|
262
|
+
|
|
263
|
+
Primitives are the layout and utility components that product engineers compose. They expose a controlled set of style props and have minimal opinions about appearance.
|
|
264
|
+
|
|
265
|
+
### Layout primitives
|
|
266
|
+
|
|
267
|
+
```tsx
|
|
268
|
+
import { tasty, FLOW_STYLES, POSITION_STYLES } from '@tenphi/tasty';
|
|
269
|
+
|
|
270
|
+
const Space = tasty({
|
|
271
|
+
as: 'div',
|
|
272
|
+
styles: {
|
|
273
|
+
display: 'flex',
|
|
274
|
+
flow: 'column',
|
|
275
|
+
gap: '1x',
|
|
276
|
+
},
|
|
277
|
+
styleProps: FLOW_STYLES,
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
const Box = tasty({
|
|
281
|
+
as: 'div',
|
|
282
|
+
styles: {
|
|
283
|
+
display: 'block',
|
|
284
|
+
},
|
|
285
|
+
styleProps: [...FLOW_STYLES, ...POSITION_STYLES, 'padding', 'fill', 'radius'],
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
const Grid = tasty({
|
|
289
|
+
as: 'div',
|
|
290
|
+
styles: {
|
|
291
|
+
display: 'grid',
|
|
292
|
+
gap: '1x',
|
|
293
|
+
},
|
|
294
|
+
styleProps: FLOW_STYLES, // includes gridColumns, gridRows, gridAreas
|
|
295
|
+
});
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
Product engineers use these to compose layouts without writing CSS:
|
|
299
|
+
|
|
300
|
+
```tsx
|
|
301
|
+
<Space flow="row" gap="2x" placeItems="center">
|
|
302
|
+
<Title>Dashboard</Title>
|
|
303
|
+
<Button placeSelf="end">Add Item</Button>
|
|
304
|
+
</Space>
|
|
305
|
+
|
|
306
|
+
<Grid gridColumns={{ '': '1fr', '@tablet': '1fr 1fr', '@desktop': '1fr 1fr 1fr' }} gap="3x">
|
|
307
|
+
<Card>...</Card>
|
|
308
|
+
<Card>...</Card>
|
|
309
|
+
<Card>...</Card>
|
|
310
|
+
</Grid>
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
### Interactive components with variants
|
|
314
|
+
|
|
315
|
+
Variants are named looks that replace each other. Combine them with `modProps` for states that stack, such as size or loading:
|
|
316
|
+
|
|
317
|
+
```tsx
|
|
318
|
+
const Button = tasty({
|
|
319
|
+
as: 'button',
|
|
320
|
+
modProps: { size: ['sm', 'md', 'lg'] as const },
|
|
321
|
+
styles: {
|
|
322
|
+
recipe: 'interactive',
|
|
323
|
+
padding: { '': '1.5x 3x', 'size=sm': '1x 2x', 'size=lg': '2x 4x' },
|
|
324
|
+
radius: '1r',
|
|
325
|
+
},
|
|
326
|
+
variants: {
|
|
327
|
+
default: {
|
|
328
|
+
fill: {
|
|
329
|
+
'': '#primary',
|
|
330
|
+
':hover': '#primary-hover',
|
|
331
|
+
disabled: '#surface',
|
|
332
|
+
},
|
|
333
|
+
color: '#on-primary',
|
|
334
|
+
},
|
|
335
|
+
danger: {
|
|
336
|
+
fill: { '': '#danger', ':hover': '#danger-hover', disabled: '#surface' },
|
|
337
|
+
color: '#on-danger',
|
|
338
|
+
},
|
|
339
|
+
},
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
<Button variant="danger" size="lg">
|
|
343
|
+
Delete
|
|
344
|
+
</Button>;
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
`variant` is typed from the keys, the `default` variant applies when no `variant` prop is passed, and only the variants that actually render emit CSS. See [React API — Variants](react-api.md#variants).
|
|
348
|
+
|
|
349
|
+
### Which styleProps to expose
|
|
350
|
+
|
|
351
|
+
Match the prop set to the component's role:
|
|
352
|
+
|
|
353
|
+
| Component category | Recommended styleProps |
|
|
354
|
+
| ------------------------------------------ | --------------------------------------------------------------------------------------------------- |
|
|
355
|
+
| Layout containers (`Space`, `Box`, `Grid`) | `FLOW_STYLES` — flow, gap, align/justify/place, grid templates (add `padding` or `fill` explicitly) |
|
|
356
|
+
| Positioned elements (`Button`, `Badge`) | `POSITION_STYLES` — placeSelf, gridArea, order |
|
|
357
|
+
| Text elements | `['color', ...TEXT_STYLES]` (`preset` is always available) |
|
|
358
|
+
| Compound components | Typically none — styling happens via sub-elements and wrapping |
|
|
359
|
+
|
|
360
|
+
`BASE_STYLES` (`display`, `font`, `preset`, `hide`, `whiteSpace`, `opacity`, `transition`) are accepted as props on every component without being listed. Exposing too many props weakens the design system's constraints. See [Methodology — styleProps as the public API](methodology.md#styleprops-as-the-public-api) for the rationale.
|
|
361
|
+
|
|
362
|
+
---
|
|
363
|
+
|
|
364
|
+
## Building compound components
|
|
365
|
+
|
|
366
|
+
Compound components have inner parts — a card has a title, content, and footer; a dialog has a header, body, and actions. Tasty models these as sub-elements.
|
|
367
|
+
|
|
368
|
+
```tsx
|
|
369
|
+
const Card = tasty({
|
|
370
|
+
styles: {
|
|
371
|
+
recipe: 'card',
|
|
372
|
+
flow: 'column',
|
|
373
|
+
gap: '2x',
|
|
374
|
+
|
|
375
|
+
Title: {
|
|
376
|
+
preset: 'h3',
|
|
377
|
+
color: '#primary',
|
|
378
|
+
},
|
|
379
|
+
Content: {
|
|
380
|
+
preset: 't2',
|
|
381
|
+
color: '#text',
|
|
382
|
+
},
|
|
383
|
+
Footer: {
|
|
384
|
+
display: 'flex',
|
|
385
|
+
flow: 'row',
|
|
386
|
+
gap: '1x',
|
|
387
|
+
justify: 'flex-end',
|
|
388
|
+
padding: '2x top',
|
|
389
|
+
border: '1bw solid #border top',
|
|
390
|
+
},
|
|
391
|
+
},
|
|
392
|
+
elements: {
|
|
393
|
+
Title: 'h2',
|
|
394
|
+
Content: 'div',
|
|
395
|
+
Footer: 'div',
|
|
396
|
+
},
|
|
397
|
+
});
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
Usage:
|
|
401
|
+
|
|
402
|
+
```tsx
|
|
403
|
+
<Card>
|
|
404
|
+
<Card.Title>Monthly Revenue</Card.Title>
|
|
405
|
+
<Card.Content>$1.2M — up 12% from last month.</Card.Content>
|
|
406
|
+
<Card.Footer>
|
|
407
|
+
<Button>Details</Button>
|
|
408
|
+
</Card.Footer>
|
|
409
|
+
</Card>
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
Sub-elements share the root component's state context by default. A `disabled` modifier on `<Card>` affects `Title`, `Content`, and `Footer` styles automatically — no prop drilling. For the full mental model, see [Methodology — Component architecture](methodology.md#component-architecture-root--sub-elements).
|
|
413
|
+
|
|
414
|
+
For sub-element syntax details (selector affix `$`, `@own()`, `elements` config), see [React API — Sub-element Styling](react-api.md#sub-element-styling).
|
|
415
|
+
|
|
416
|
+
---
|
|
417
|
+
|
|
418
|
+
## Defining the override contract
|
|
419
|
+
|
|
420
|
+
A design system works best when the rules for customization are explicit. Tasty gives product engineers four sanctioned ways to customize a component, and a few to discourage:
|
|
421
|
+
|
|
422
|
+
### What product engineers can do
|
|
423
|
+
|
|
424
|
+
1. **Use styleProps** — adjust layout, spacing, positioning through the props the component exposes:
|
|
425
|
+
|
|
426
|
+
```tsx
|
|
427
|
+
<Space flow="row" gap="3x" placeItems="center">
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
2. **Use modProps** — control component states through typed props instead of `mods`:
|
|
431
|
+
|
|
432
|
+
```tsx
|
|
433
|
+
<Button isLoading size="large">
|
|
434
|
+
Submit
|
|
435
|
+
</Button>
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
3. **Pass tokens** — inject runtime values through the `tokens` prop for per-instance customization:
|
|
439
|
+
|
|
440
|
+
```tsx
|
|
441
|
+
<ProgressBar tokens={{ $progress: `${percent}%` }} />
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
4. **Create styled wrappers** — extend a component's styles with `tasty(Base, { styles })`:
|
|
445
|
+
|
|
446
|
+
```tsx
|
|
447
|
+
const DangerButton = tasty(Button, {
|
|
448
|
+
styles: {
|
|
449
|
+
fill: {
|
|
450
|
+
'': '#danger',
|
|
451
|
+
':hover': '#danger-hover',
|
|
452
|
+
':active': '#danger-pressed',
|
|
453
|
+
disabled: '@inherit', // a map with '' replaces the parent's; keep its disabled branch
|
|
454
|
+
},
|
|
455
|
+
color: '#on-danger',
|
|
456
|
+
},
|
|
457
|
+
});
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
### What to discourage
|
|
461
|
+
|
|
462
|
+
- **Direct `styles` prop** — bypasses the component's intended API; prefer styled wrappers
|
|
463
|
+
- **`style` prop** — React inline styles that bypass Tasty entirely; reserve for third-party integration only
|
|
464
|
+
- **Overriding internal sub-elements** — if product engineers need to restyle sub-elements, the DS component should expose that through its own API (additional props or variants), not through raw `styles` overrides
|
|
465
|
+
|
|
466
|
+
See [Methodology — styles prop vs style prop](methodology.md#styles-prop-vs-style-prop) and [Methodology — Wrapping and extension](methodology.md#wrapping-and-extension) for the full rationale.
|
|
467
|
+
|
|
468
|
+
---
|
|
469
|
+
|
|
470
|
+
## Guardrails: linting and types
|
|
471
|
+
|
|
472
|
+
A vocabulary only holds if mistakes surface early. Register the same names you pass to `configure()` with the ESLint plugin and with TypeScript:
|
|
473
|
+
|
|
474
|
+
```ts
|
|
475
|
+
// tasty.config.ts — read by @tenphi/eslint-plugin-tasty
|
|
476
|
+
export default {
|
|
477
|
+
tokens: ['#surface', '#text', '#primary', '#danger', '$gap', '$radius'],
|
|
478
|
+
states: ['@mobile', '@tablet', '@desktop', '@dark', '@reduced-motion'],
|
|
479
|
+
presets: ['h1', 'h2', 'h3', 't2', 't3'],
|
|
480
|
+
recipes: ['card', 'elevated', 'input-reset', 'interactive'],
|
|
481
|
+
importSources: ['@my-org/ds'], // where product code imports tasty() from
|
|
482
|
+
};
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
```js
|
|
486
|
+
// eslint.config.js
|
|
487
|
+
import tasty from '@tenphi/eslint-plugin-tasty';
|
|
488
|
+
|
|
489
|
+
export default [tasty.configs.recommended]; // or tasty.configs.strict
|
|
490
|
+
```
|
|
491
|
+
|
|
492
|
+
```ts
|
|
493
|
+
// tasty.d.ts
|
|
494
|
+
import '@tenphi/tasty';
|
|
495
|
+
|
|
496
|
+
declare module '@tenphi/tasty' {
|
|
497
|
+
interface TastyNamedColors {
|
|
498
|
+
surface: true;
|
|
499
|
+
text: true;
|
|
500
|
+
primary: true;
|
|
501
|
+
danger: true;
|
|
502
|
+
}
|
|
503
|
+
interface TastyPresetNames {
|
|
504
|
+
h1: true;
|
|
505
|
+
h2: true;
|
|
506
|
+
h3: true;
|
|
507
|
+
t2: true;
|
|
508
|
+
t3: true;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
```
|
|
512
|
+
|
|
513
|
+
Unknown colors, presets, and recipes then fail lint (`valid-color-token`, `valid-preset`, `valid-recipe`), and `strict` adds checks for unknown `$` tokens and state aliases (`valid-custom-property`, `no-unknown-state-alias`). The same names autocomplete in editors. Deriving both lists from the same token and recipe modules that `config.ts` imports keeps all three in sync.
|
|
514
|
+
|
|
515
|
+
---
|
|
516
|
+
|
|
517
|
+
## Project structure
|
|
518
|
+
|
|
519
|
+
A recommended structure for a design system built on Tasty:
|
|
520
|
+
|
|
521
|
+
```
|
|
522
|
+
ds/
|
|
523
|
+
config.ts # configure() — tokens, units, states, recipes
|
|
524
|
+
tasty.config.ts # Names the ESLint plugin validates against
|
|
525
|
+
tasty.d.ts # TypeScript augmentation for autocomplete
|
|
526
|
+
primitives/
|
|
527
|
+
Space.tsx # Layout: flex container with FLOW_STYLES
|
|
528
|
+
Box.tsx # Generic container
|
|
529
|
+
Grid.tsx # Grid container
|
|
530
|
+
Text.tsx # Text element with preset + color
|
|
531
|
+
components/
|
|
532
|
+
Button.tsx # Interactive component with variants
|
|
533
|
+
Card.tsx # Compound component with sub-elements
|
|
534
|
+
Input.tsx # Form input with recipes
|
|
535
|
+
Dialog.tsx # Overlay compound component
|
|
536
|
+
recipes/
|
|
537
|
+
index.ts # Recipe definitions (imported by config.ts)
|
|
538
|
+
tokens/
|
|
539
|
+
colors.ts # Color token definitions
|
|
540
|
+
typography.ts # Typography presets for configure({ presets })
|
|
541
|
+
units.ts # Spacing and shape scale for configure({ units })
|
|
542
|
+
index.ts # Public API: re-exports components + configure
|
|
543
|
+
```
|
|
544
|
+
|
|
545
|
+
The key principle: `config.ts` imports tokens and recipes, calls `configure()`, and is imported at the app entry point before any component renders. Components import only from `@tenphi/tasty` — they reference tokens and recipes by name, not by import.
|
|
546
|
+
|
|
547
|
+
---
|
|
548
|
+
|
|
549
|
+
## Learn more
|
|
550
|
+
|
|
551
|
+
- **[Methodology](methodology.md)** — The recommended patterns for structuring Tasty components
|
|
552
|
+
- **[Getting Started](getting-started.md)** — Installation, first component, tooling setup
|
|
553
|
+
- **[Style DSL](dsl.md)** — State maps, tokens, units, extending semantics, keyframes, @property
|
|
554
|
+
- **[React API](react-api.md)** — `tasty()` factory, component props, variants, sub-elements, style functions
|
|
555
|
+
- **[Configuration](configuration.md)** — Full `configure()` API: tokens, recipes, custom units, style handlers
|
|
556
|
+
- **[Adoption Guide](adoption.md)** — Who should adopt Tasty, incremental phases, what changes for product engineers
|
|
557
|
+
- **[Style Properties](styles.md)** — Complete reference for all enhanced style properties
|