@tenphi/tasty 0.10.1 → 0.11.0
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 +79 -5
- package/dist/config.d.ts +32 -9
- package/dist/config.js +51 -10
- package/dist/config.js.map +1 -1
- package/dist/core/index.d.ts +3 -4
- package/dist/index.d.ts +3 -4
- package/dist/injector/injector.js +1 -7
- package/dist/injector/injector.js.map +1 -1
- package/dist/parser/classify.js.map +1 -1
- package/dist/plugins/types.d.ts +9 -2
- package/dist/ssr/collector.js +11 -1
- package/dist/ssr/collector.js.map +1 -1
- package/dist/styles/types.d.ts +14 -1
- package/dist/tasty.d.ts +6 -6
- package/dist/utils/typography.d.ts +24 -13
- package/dist/utils/typography.js +6 -16
- package/dist/utils/typography.js.map +1 -1
- package/dist/zero/babel.d.ts +10 -4
- package/dist/zero/babel.js +6 -1
- package/dist/zero/babel.js.map +1 -1
- package/docs/adoption.md +286 -0
- package/docs/comparison.md +413 -0
- package/docs/configuration.md +41 -10
- package/docs/debug.md +1 -1
- package/docs/design-system.md +401 -0
- package/docs/{usage.md → dsl.md} +254 -409
- package/docs/getting-started.md +201 -0
- package/docs/injector.md +2 -2
- package/docs/methodology.md +501 -0
- package/docs/runtime.md +291 -0
- package/docs/ssr.md +11 -1
- package/docs/styles.md +2 -2
- package/docs/tasty-static.md +25 -3
- package/package.json +7 -4
- package/dist/tokens/typography.d.ts +0 -19
- package/dist/tokens/typography.js +0 -237
- package/dist/tokens/typography.js.map +0 -1
package/docs/adoption.md
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
# Adoption Guide
|
|
2
|
+
|
|
3
|
+
Tasty is not a drop-in replacement for another styling library. It is a **substrate for building a design-system-defined styling language**. That means the adoption path is not "rewrite your classes" but "reshape your styling architecture."
|
|
4
|
+
|
|
5
|
+
This guide is for design-system maintainers and platform engineers evaluating Tasty or introducing it into an existing codebase.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Where Tasty sits in the stack
|
|
10
|
+
|
|
11
|
+
Tasty is not the surface your product engineers interact with directly. It sits one layer below:
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
Product code
|
|
15
|
+
└─ DS components (Button, Card, Layout, ...)
|
|
16
|
+
└─ Tasty engine (tasty(), configure(), hooks)
|
|
17
|
+
└─ CSS (mutually exclusive selectors, tokens, custom properties)
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
**What Tasty owns:**
|
|
21
|
+
- The DSL and value parser (tokens, custom units, auto-calc, color opacity)
|
|
22
|
+
- State compilation (mutually exclusive selectors from state maps)
|
|
23
|
+
- Style injection and deduplication (runtime or build-time)
|
|
24
|
+
- The `tasty()` component factory and hooks API
|
|
25
|
+
|
|
26
|
+
**What the DS team owns:**
|
|
27
|
+
- Token names and values (colors, spacing, typography)
|
|
28
|
+
- Custom units and their semantics
|
|
29
|
+
- State aliases (`@mobile`, `@dark`, `@compact`)
|
|
30
|
+
- Recipes (reusable style bundles)
|
|
31
|
+
- Which style props each component exposes
|
|
32
|
+
- Sub-element structure for compound components
|
|
33
|
+
- The override and extension rules product teams follow
|
|
34
|
+
|
|
35
|
+
Two teams using Tasty can end up with very different authoring models. That is by design.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Who should adopt Tasty
|
|
40
|
+
|
|
41
|
+
**Strong fit:**
|
|
42
|
+
- A design-system or platform team that wants to define a governed styling language
|
|
43
|
+
- Components with complex, intersecting states (hover + disabled + theme + breakpoint)
|
|
44
|
+
- Teams that need deterministic style resolution without cascade/specificity bugs
|
|
45
|
+
- Organizations where styling decisions should be centralized, not distributed
|
|
46
|
+
|
|
47
|
+
**Not the right fit:**
|
|
48
|
+
- Solo developers building a one-off app with minimal UI structure
|
|
49
|
+
- Teams that want a shared utility vocabulary and direct markup authoring (Tailwind is better here)
|
|
50
|
+
- Projects where low ceremony matters more than central governance
|
|
51
|
+
- Codebases where intersecting state complexity is low
|
|
52
|
+
|
|
53
|
+
For a detailed comparison with Tailwind, Panda CSS, vanilla-extract, StyleX, Stitches, and Emotion, see the [Comparison guide](comparison.md).
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## What you are expected to define
|
|
58
|
+
|
|
59
|
+
Tasty provides the engine. The DS team defines the language that runs on it. Here is what that typically involves:
|
|
60
|
+
|
|
61
|
+
| Layer | What you define | Where |
|
|
62
|
+
|-------|----------------|-------|
|
|
63
|
+
| **Tokens** | Color names, spacing scale, border widths, radii | `configure({ tokens })` |
|
|
64
|
+
| **Units** | Custom multiplier units (`x`, `r`, `bw`, or your own) | `configure({ units })` |
|
|
65
|
+
| **State aliases** | Responsive breakpoints, theme modes, feature flags | `configure({ states })` |
|
|
66
|
+
| **Recipes** | Reusable style bundles (card, elevated, input-reset) | `configure({ recipes })` |
|
|
67
|
+
| **Typography** | Preset definitions (h1-h6, t1-t4, etc.) | `configure({ tokens: generateTypographyTokens(...) })` |
|
|
68
|
+
| **Style props** | Which CSS properties each component exposes as React props | `styleProps` in each component |
|
|
69
|
+
| **Sub-elements** | Inner parts of compound components (Title, Icon, Content) | `elements` + capitalized keys in `styles` |
|
|
70
|
+
| **Override rules** | How product engineers extend or constrain components | Styled wrappers via `tasty(Base, { ... })` |
|
|
71
|
+
|
|
72
|
+
The same engine can power a minimal design system with a handful of tokens:
|
|
73
|
+
|
|
74
|
+
```tsx
|
|
75
|
+
configure({
|
|
76
|
+
tokens: { '#bg': '#white', '#text': '#111' },
|
|
77
|
+
states: { '@dark': '@root(theme=dark)' },
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
...or an enterprise-scale system with dozens of tokens, multiple state aliases, typography presets, recipes, and custom units. The scope is yours to decide.
|
|
82
|
+
|
|
83
|
+
Here is how the layers connect end-to-end. The DS team configures the engine, defines components, and product engineers consume them:
|
|
84
|
+
|
|
85
|
+
```tsx
|
|
86
|
+
// ds/config.ts — DS team defines the language
|
|
87
|
+
configure({
|
|
88
|
+
tokens: { '#primary': 'oklch(55% 0.25 265)', '#surface': '#fff', '#text': '#111' },
|
|
89
|
+
states: { '@mobile': '@media(w < 768px)', '@dark': '@root(schema=dark)' },
|
|
90
|
+
recipes: { card: { padding: '4x', fill: '#surface', radius: '1r', border: true } },
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// ds/components/Card.tsx — DS team builds components on top
|
|
94
|
+
const Card = tasty({
|
|
95
|
+
styles: {
|
|
96
|
+
recipe: 'card',
|
|
97
|
+
Title: { preset: 'h3', color: '#primary' },
|
|
98
|
+
Body: { preset: 't2', color: '#text' },
|
|
99
|
+
},
|
|
100
|
+
elements: { Title: 'h2', Body: 'div' },
|
|
101
|
+
styleProps: ['padding', 'fill'],
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// app/Dashboard.tsx — product engineer uses the component
|
|
105
|
+
<Card padding={{ '': '4x', '@mobile': '2x' }}>
|
|
106
|
+
<Card.Title>Monthly Revenue</Card.Title>
|
|
107
|
+
<Card.Body>$1.2M — up 12% from last month</Card.Body>
|
|
108
|
+
</Card>
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
See [Configuration](configuration.md) for the full `configure()` API.
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## Incremental adoption
|
|
116
|
+
|
|
117
|
+
You do not need to adopt everything at once. Tasty is designed to be introduced layer by layer.
|
|
118
|
+
|
|
119
|
+
### Phase 1 -- Tokens and units
|
|
120
|
+
|
|
121
|
+
Start by defining your design tokens and custom units. This is the lowest-risk step: it only configures the parser and does not require rewriting any components.
|
|
122
|
+
|
|
123
|
+
```tsx
|
|
124
|
+
import { configure } from '@tenphi/tasty';
|
|
125
|
+
|
|
126
|
+
configure({
|
|
127
|
+
tokens: {
|
|
128
|
+
'#primary': 'oklch(55% 0.25 265)',
|
|
129
|
+
'#surface': '#white',
|
|
130
|
+
'#text': '#111',
|
|
131
|
+
'$card-padding': '4x',
|
|
132
|
+
},
|
|
133
|
+
// Common units (x, r, bw, ow, cr) are built-in.
|
|
134
|
+
// A DS typically redefines them to use CSS custom properties
|
|
135
|
+
// so that the actual scale is controlled via CSS, not JS:
|
|
136
|
+
units: {
|
|
137
|
+
x: 'var(--gap)', // 2x → calc(var(--gap) * 2)
|
|
138
|
+
r: 'var(--radius)',
|
|
139
|
+
bw: 'var(--border-width)',
|
|
140
|
+
},
|
|
141
|
+
});
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Phase 2 -- State aliases and recipes
|
|
145
|
+
|
|
146
|
+
Define the state vocabulary your components will share. This is where you start encoding your team's conventions.
|
|
147
|
+
|
|
148
|
+
```tsx
|
|
149
|
+
configure({
|
|
150
|
+
states: {
|
|
151
|
+
'@mobile': '@media(w < 768px)',
|
|
152
|
+
'@tablet': '@media(w < 1024px)',
|
|
153
|
+
'@dark': '@root(schema=dark) | (!@root(schema) & @media(prefers-color-scheme: dark))',
|
|
154
|
+
},
|
|
155
|
+
recipes: {
|
|
156
|
+
card: { padding: '4x', fill: '#surface', radius: '1r', border: true },
|
|
157
|
+
elevated: { shadow: '0 2x 4x #shadow' },
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Phase 3 -- Migrate a few primitives
|
|
163
|
+
|
|
164
|
+
Pick 2-3 simple, widely used components (Box, Text, Button) and rewrite them with `tasty()`. Keep the public API identical so product code does not need to change.
|
|
165
|
+
|
|
166
|
+
```tsx
|
|
167
|
+
const Box = tasty({
|
|
168
|
+
as: 'div',
|
|
169
|
+
styles: {
|
|
170
|
+
display: 'flex',
|
|
171
|
+
flow: 'column',
|
|
172
|
+
gap: '1x',
|
|
173
|
+
},
|
|
174
|
+
styleProps: ['gap', 'flow', 'padding', 'fill'],
|
|
175
|
+
});
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
At this point you can validate the DSL, token workflow, and component authoring experience before committing further.
|
|
179
|
+
|
|
180
|
+
### Phase 4 -- Encode complex states
|
|
181
|
+
|
|
182
|
+
Move components with intersecting states (buttons with hover + disabled + theme variants, inputs with focus + error + readonly) to Tasty's state map syntax. This is where mutually exclusive selectors start paying off.
|
|
183
|
+
|
|
184
|
+
```tsx
|
|
185
|
+
const Button = tasty({
|
|
186
|
+
as: 'button',
|
|
187
|
+
styles: {
|
|
188
|
+
fill: {
|
|
189
|
+
'': '#primary',
|
|
190
|
+
':hover': '#primary-hover',
|
|
191
|
+
':active': '#primary-pressed',
|
|
192
|
+
// `disabled` is a data-attribute modifier → [data-disabled].
|
|
193
|
+
// Tasty auto-applies it from the native `disabled` attribute.
|
|
194
|
+
// `[disabled]` (attribute selector) also works here.
|
|
195
|
+
disabled: '#surface',
|
|
196
|
+
},
|
|
197
|
+
color: {
|
|
198
|
+
'': '#on-primary',
|
|
199
|
+
disabled: '#text.40',
|
|
200
|
+
},
|
|
201
|
+
cursor: {
|
|
202
|
+
'': 'pointer',
|
|
203
|
+
disabled: 'not-allowed',
|
|
204
|
+
},
|
|
205
|
+
transition: 'theme',
|
|
206
|
+
},
|
|
207
|
+
});
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### Phase 5 -- Standardize style props and sub-elements
|
|
211
|
+
|
|
212
|
+
Define which style props each component category exposes. Layout components get flow/gap/padding. Interactive components get positioning. Compound components declare sub-elements.
|
|
213
|
+
|
|
214
|
+
```tsx
|
|
215
|
+
const Card = tasty({
|
|
216
|
+
styles: {
|
|
217
|
+
recipe: 'card elevated',
|
|
218
|
+
Title: { preset: 'h3', color: '#primary' },
|
|
219
|
+
Content: { color: '#text', preset: 't2' },
|
|
220
|
+
},
|
|
221
|
+
elements: { Title: 'h2', Content: 'div' },
|
|
222
|
+
styleProps: ['padding', 'fill', 'radius'],
|
|
223
|
+
});
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### Phase 6 -- Expand to full DS coverage
|
|
227
|
+
|
|
228
|
+
Migrate the remaining components, add the [ESLint plugin](https://github.com/tenphi/eslint-plugin-tasty) to enforce style conventions at lint time, and consider [zero-runtime mode](tasty-static.md) for static or performance-critical pages.
|
|
229
|
+
|
|
230
|
+
---
|
|
231
|
+
|
|
232
|
+
## What changes for product engineers
|
|
233
|
+
|
|
234
|
+
When a DS is powered by Tasty, product engineers typically interact with **components, not Tasty itself**. Here is what changes from their perspective:
|
|
235
|
+
|
|
236
|
+
**They do not write CSS directly.** Styling decisions are embedded in the components the DS provides. Product code consumes components, tokens, and style props.
|
|
237
|
+
|
|
238
|
+
**Overrides use styled wrappers.** Instead of passing one-off `className` or `style` props, product engineers extend components:
|
|
239
|
+
|
|
240
|
+
```tsx
|
|
241
|
+
import { tasty } from '@tenphi/tasty';
|
|
242
|
+
import { Button } from 'my-ds';
|
|
243
|
+
|
|
244
|
+
// Replace mode: providing '' (default) key replaces the parent's fill entirely
|
|
245
|
+
const DangerButton = tasty(Button, {
|
|
246
|
+
styles: {
|
|
247
|
+
fill: { '': '#danger', ':hover': '#danger-hover' },
|
|
248
|
+
},
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
// Extend mode: omitting '' key preserves parent states and adds/overrides
|
|
252
|
+
const LoadingButton = tasty(Button, {
|
|
253
|
+
styles: {
|
|
254
|
+
fill: {
|
|
255
|
+
loading: '#yellow', // new state appended
|
|
256
|
+
disabled: '#gray.20', // existing state overridden in place
|
|
257
|
+
},
|
|
258
|
+
},
|
|
259
|
+
});
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
**Style props replace raw CSS.** Layout, spacing, and positioning are controlled through typed props on the components that expose them:
|
|
263
|
+
|
|
264
|
+
```tsx
|
|
265
|
+
<Space flow="row" gap="2x" placeItems="center">
|
|
266
|
+
<Title>Dashboard</Title>
|
|
267
|
+
<Button placeSelf="end">Add Item</Button>
|
|
268
|
+
</Space>
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
**No cascade/specificity concerns.** Tasty's mutually exclusive selectors mean extending a component cannot accidentally break another. Import order, class name collisions, and specificity arithmetic are non-issues.
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
275
|
+
## Learn more
|
|
276
|
+
|
|
277
|
+
- [README](../README.md) -- overview, quick start, and feature highlights
|
|
278
|
+
- [Getting Started](getting-started.md) -- installation, first component, tooling setup
|
|
279
|
+
- [Methodology](methodology.md) -- the recommended patterns for structuring Tasty components
|
|
280
|
+
- [Building a Design System](design-system.md) -- practical guide to building a DS layer with Tasty
|
|
281
|
+
- [Style DSL](dsl.md) -- state maps, tokens, units, extending semantics, keyframes, @property
|
|
282
|
+
- [Runtime API](runtime.md) -- `tasty()` factory, component props, variants, sub-elements, hooks
|
|
283
|
+
- [Configuration](configuration.md) -- tokens, recipes, custom units, style handlers, and TypeScript extensions
|
|
284
|
+
- [Style Properties](styles.md) -- complete reference for all enhanced style properties
|
|
285
|
+
- [Comparison](comparison.md) -- positioning and trade-offs vs. other styling systems
|
|
286
|
+
- [Zero Runtime (tastyStatic)](tasty-static.md) -- build-time static styling with Babel plugin
|