@tenphi/tasty 0.0.0-snapshot.e4609d6 → 0.0.0-snapshot.e4e4347
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 +436 -394
- package/dist/babel-types-BKDTT4--.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-5d8WlQbq.js +60 -0
- package/dist/chunks/build-config-5d8WlQbq.js.map +1 -0
- package/dist/{collector-BpkjNQDo.js → chunks/collector-CjCak4iE.js} +25 -119
- package/dist/chunks/collector-CjCak4iE.js.map +1 -0
- package/dist/chunks/config-engine-uOFYZidB.js +272 -0
- package/dist/chunks/config-engine-uOFYZidB.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-ubrHP97m.js +910 -0
- package/dist/chunks/css-definitions-ubrHP97m.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-CJ31U_WE.js +502 -0
- package/dist/chunks/debug-CJ31U_WE.js.map +1 -0
- package/dist/chunks/dsl-DYSJc1-T.js +1383 -0
- package/dist/chunks/dsl-DYSJc1-T.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-CyyCI02N.js +689 -0
- package/dist/chunks/react-runtime-CyyCI02N.js.map +1 -0
- package/dist/chunks/runtime-engine-BQmOu5-W.js +2432 -0
- package/dist/chunks/runtime-engine-BQmOu5-W.js.map +1 -0
- package/dist/chunks/runtime-state-DEsyUMU-.js +152 -0
- package/dist/chunks/runtime-state-DEsyUMU-.js.map +1 -0
- package/dist/{merge-styles-B0lMso5W.js → chunks/shared-utils-y-HjvPN4.js} +60 -55
- package/dist/chunks/shared-utils-y-HjvPN4.js.map +1 -0
- package/dist/chunks/style-engine-BX2LshDZ.js +5466 -0
- package/dist/chunks/style-engine-BX2LshDZ.js.map +1 -0
- package/dist/{css-writer-BHjTF0YN.js → chunks/zero-engine-Dw0P4yGM.js} +65 -145
- package/dist/chunks/zero-engine-Dw0P4yGM.js.map +1 -0
- package/dist/{collector-D8o4Wdq-.d.ts → collector-CTU-nl0g.d.ts} +23 -4
- package/dist/{config-De8L9NWM.d.ts → config-CcxqSZI2.d.ts} +274 -78
- package/dist/core/index.d.ts +5 -5
- package/dist/core/index.js +9 -6
- package/dist/hydrate-CRyjjAyl.d.ts +22 -0
- package/dist/{index-DzGxoeyN.d.ts → index-xtey-KDu.d.ts} +350 -253
- package/dist/index.d.ts +5 -5
- package/dist/index.js +11 -867
- package/dist/{merge-styles-DLm4wdnb.d.ts → merge-styles-DSkVc6CD.d.ts} +2 -3
- package/dist/ssr/astro-client.d.ts +1 -1
- package/dist/ssr/astro-client.js +1 -14
- package/dist/ssr/astro-client.js.map +1 -1
- 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 +3 -2
- package/dist/ssr/astro-middleware-static.js +0 -11
- package/dist/ssr/astro-middleware-static.js.map +1 -1
- package/dist/ssr/astro-middleware.d.ts +3 -2
- package/dist/ssr/astro-middleware.js +0 -12
- package/dist/ssr/astro-middleware.js.map +1 -1
- package/dist/ssr/astro.d.ts +40 -6
- package/dist/ssr/astro.js +157 -93
- package/dist/ssr/astro.js.map +1 -1
- package/dist/ssr/client.d.ts +2 -0
- package/dist/ssr/client.js +2 -0
- package/dist/ssr/index.d.ts +5 -25
- package/dist/ssr/index.js +5 -5
- package/dist/ssr/index.js.map +1 -1
- 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 +9 -8
- package/dist/ssr/next.js +29 -43
- package/dist/ssr/next.js.map +1 -1
- package/dist/static/index.d.ts +8 -9
- package/dist/static/index.js +4 -22
- package/dist/static/index.js.map +1 -1
- package/dist/static/inject.d.ts +1 -2
- package/dist/{index-KUYya3x7.d.ts → types-DJEM_BOJ.d.ts} +741 -590
- package/dist/zero/babel.d.ts +67 -2
- package/dist/zero/babel.js +77 -140
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/index.d.ts +62 -8
- package/dist/zero/index.js +24 -2
- package/dist/zero/index.js.map +1 -0
- package/dist/zero/next.d.ts +4 -5
- package/dist/zero/next.js +3 -38
- package/dist/zero/next.js.map +1 -1
- package/docs/README.md +16 -8
- package/docs/adoption.md +69 -36
- package/docs/ai-agents.md +118 -86
- package/docs/comparison.md +77 -47
- package/docs/configuration.md +434 -108
- package/docs/debug.md +21 -8
- package/docs/design-system.md +152 -31
- package/docs/dsl.md +483 -211
- package/docs/getting-started.md +130 -50
- package/docs/injector.md +117 -68
- package/docs/methodology.md +81 -50
- package/docs/migration-v3.md +52 -52
- package/docs/pipeline.md +54 -30
- package/docs/plugins.md +59 -75
- package/docs/react-api.md +135 -53
- package/docs/runtime-benchmarks.md +388 -0
- package/docs/ssr.md +285 -101
- package/docs/styles.md +128 -33
- package/docs/tasty-static.md +272 -135
- package/package.json +119 -34
- package/dist/async-storage-DKK-wTD4.js +0 -44
- package/dist/async-storage-DKK-wTD4.js.map +0 -1
- package/dist/babel-R2qT7yLN.d.ts +0 -83
- package/dist/collector-BpkjNQDo.js.map +0 -1
- package/dist/config-DOCuTykY.js +0 -12315
- package/dist/config-DOCuTykY.js.map +0 -1
- package/dist/context-CA8YKeMn.js +0 -24
- package/dist/context-CA8YKeMn.js.map +0 -1
- package/dist/core-p6iTbQnn.js +0 -1550
- package/dist/core-p6iTbQnn.js.map +0 -1
- package/dist/css-writer-BHjTF0YN.js.map +0 -1
- package/dist/format-global-rules-DklyaXv-.js +0 -22
- package/dist/format-global-rules-DklyaXv-.js.map +0 -1
- package/dist/format-rules-Cb0YIjyS.js +0 -143
- package/dist/format-rules-Cb0YIjyS.js.map +0 -1
- package/dist/hydrate-xnaB3SDm.js +0 -37
- package/dist/hydrate-xnaB3SDm.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/keyframes-DiXjNoBZ.js +0 -424
- package/dist/keyframes-DiXjNoBZ.js.map +0 -1
- package/dist/merge-styles-B0lMso5W.js.map +0 -1
- package/dist/resolve-recipes-C9nAuwgR.js +0 -144
- package/dist/resolve-recipes-C9nAuwgR.js.map +0 -1
package/docs/react-api.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# React API
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Use `tasty()` to turn state-aware style definitions into normal React components, extend existing Tasty components, and expose typed styling APIs to consumers.
|
|
4
|
+
|
|
5
|
+
Every Tasty style function — `tasty()` components, `computeStyles()`, `useStyles()`, `useGlobalStyles()`, `useRawCSS()`, `useKeyframes()`, `useProperty()`, `useFontFace()`, `useCounterStyle()`, and `useFunction()` — works in React Server Components with no `'use client'` directive. All of them except `useStyles()` are hook-free. `useStyles()` reads the `TastyRegistry` collector from React context on the client, so it is a real hook there; outside React, call `computeStyles()` instead. For state maps, tokens, units, and extension semantics, see [Style DSL](dsl.md). For global configuration, see [Configuration](configuration.md). For the broader docs map, see the [Docs Hub](README.md).
|
|
4
6
|
|
|
5
7
|
> **Note:** This file was previously named `runtime.md`. All functionality documented here works in both server and client contexts — "runtime" referred to style computation during React rendering, not to client-side JavaScript.
|
|
6
8
|
|
|
@@ -42,6 +44,30 @@ const PrimaryButton = tasty(Button, {
|
|
|
42
44
|
|
|
43
45
|
Style maps merge intelligently — see [Style DSL — Extending vs. Replacing State Maps](dsl.md#extending-vs-replacing-state-maps) for extend mode, replace mode, `@inherit`, `null`, and `false` tombstones.
|
|
44
46
|
|
|
47
|
+
The extension form takes the same component options as `tasty({ … })`:
|
|
48
|
+
|
|
49
|
+
```jsx
|
|
50
|
+
const ActionCard = tasty(Card, {
|
|
51
|
+
styles: { fill: { '': '#surface', isRaised: '#surface-raised' } },
|
|
52
|
+
styleProps: ['gap'] as const, // gap="2x" becomes a style
|
|
53
|
+
modProps: ['isRaised'] as const, // isRaised becomes a mod (data-is-raised)
|
|
54
|
+
tokenProps: ['accentColor'] as const, // accentColor sets the #accent token
|
|
55
|
+
variants: {
|
|
56
|
+
plain: { border: 0 },
|
|
57
|
+
framed: { border: '2bw #accent' },
|
|
58
|
+
},
|
|
59
|
+
variant: 'framed', // applied when no variant prop is passed
|
|
60
|
+
elements: { Footer: 'footer' },
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
<ActionCard gap="2x" isRaised accentColor="#purple">
|
|
64
|
+
<ActionCard.Title>Kept from Card</ActionCard.Title>
|
|
65
|
+
<ActionCard.Footer>Added here</ActionCard.Footer>
|
|
66
|
+
</ActionCard>;
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
The extension turns its own `styleProps`, `modProps`, and `tokenProps` into the `styles`, `mods`, and `tokens` it passes to the base, which renders them as usual: mods as `data-*` attributes, tokens as inline custom properties. Its `variants` merge over its `styles`, and the `variant` prop is still forwarded, so it selects the base's own variants too and accepts either set's names. Both sets share that one prop, so a name only one of them defines leaves the other at its fallback: if `Card` had an `accent` variant, `variant="accent"` would apply it together with `framed`, and `variant="plain"` would leave `Card` on its default. For two independent choices, give one of them its own prop, such as a `modProps` value list. `elements` adds sub-components, and the base's are kept: `ActionCard.Title` is `Card.Title`. The returned component is typed with all of these props and sub-components.
|
|
70
|
+
|
|
45
71
|
`tasty(Component, ...)` always wraps `Component` and forwards every prop to it, so `Component` must be Tasty-aware (i.e. it accepts `styles`, `mods`, `qa`, etc. and renders them through its own Tasty pipeline). To apply styles to a third-party component or a string DOM tag via `className`, use the options-only form with `as`:
|
|
46
72
|
|
|
47
73
|
```jsx
|
|
@@ -58,13 +84,17 @@ const Link = tasty({
|
|
|
58
84
|
|
|
59
85
|
const Span = tasty({
|
|
60
86
|
as: 'span',
|
|
61
|
-
styles: {
|
|
87
|
+
styles: { preset: 'strong' },
|
|
62
88
|
});
|
|
63
89
|
|
|
64
|
-
<Link href="/blog" padding="1x">
|
|
90
|
+
<Link href="/blog" padding="1x">
|
|
91
|
+
Blog
|
|
92
|
+
</Link>;
|
|
65
93
|
```
|
|
66
94
|
|
|
67
|
-
The wrapped component only needs to forward `className` (and ideally `style`/`ref`). Tasty
|
|
95
|
+
The wrapped component only needs to forward `className` (and ideally `style`/`ref`). Tasty's own props (`styles`, `mods`, `tokens`, `qa`, `qaVal`, `theme`, `element`, the `is*` props) and the props you declared with `styleProps`, `modProps`, or `tokenProps` are consumed by Tasty; mods, `qa`, `qaVal`, `theme`, and `element` reach the DOM only as `data-*` attributes.
|
|
96
|
+
|
|
97
|
+
Props forwarded to the `as` component keep their declared types and requiredness. For example, a component with `position: 'top-right' | 'bottom-left'` accepts those values through `tasty({ as: Component })`; CSS positioning can still be set through `styles.position`. A prop explicitly listed in `styleProps` is consumed as a style value instead. The always-available base style props below are also consumed by Tasty, so keep component-specific prop names separate from those reserved names.
|
|
68
98
|
|
|
69
99
|
---
|
|
70
100
|
|
|
@@ -84,7 +114,7 @@ const FlexibleBox = tasty({
|
|
|
84
114
|
|
|
85
115
|
<FlexibleBox gap="2x" align="center" fill="#surface">
|
|
86
116
|
Content
|
|
87
|
-
</FlexibleBox
|
|
117
|
+
</FlexibleBox>;
|
|
88
118
|
```
|
|
89
119
|
|
|
90
120
|
Style props accept state maps, so responsive values work through the same API:
|
|
@@ -106,14 +136,14 @@ A small set of style properties — `display`, `font`, `preset`, `hide`, `whiteS
|
|
|
106
136
|
|
|
107
137
|
## `Element`
|
|
108
138
|
|
|
109
|
-
`Element` is the unstyled base component exported from the main entry — equivalent to `tasty({})` (a `div` with no default styles). It accepts
|
|
139
|
+
`Element` is the unstyled base component exported from the main entry — equivalent to `tasty({})` (a `div` with no default styles). It accepts the props every Tasty component has (`as`, `styles`, `mods`, `tokens`, `qa`, `theme`, the `is*` props) plus the [always-available style props](#always-available-style-props), and is useful as a generic box or as a building block for layout primitives. Other style names, such as `padding`, are not props on it: create a component with `styleProps` for those, or pass them through `styles`.
|
|
110
140
|
|
|
111
141
|
```jsx
|
|
112
142
|
import { Element } from '@tenphi/tasty';
|
|
113
143
|
|
|
114
|
-
<Element as="section"
|
|
144
|
+
<Element as="section" display="grid" preset="t2" styles={{ padding: '4x' }}>
|
|
115
145
|
Content
|
|
116
|
-
</Element
|
|
146
|
+
</Element>;
|
|
117
147
|
```
|
|
118
148
|
|
|
119
149
|
> Note: `Element` shadows the global DOM `Element` type when imported from `@tenphi/tasty`. In files that need the DOM type, alias the import: `import { Element as TastyElement } from '@tenphi/tasty'`.
|
|
@@ -138,6 +168,7 @@ List modifier key names. Types default to `ModValue` (`boolean | string | number
|
|
|
138
168
|
|
|
139
169
|
```jsx
|
|
140
170
|
const Button = tasty({
|
|
171
|
+
as: 'button',
|
|
141
172
|
modProps: ['isLoading', 'isSelected'] as const,
|
|
142
173
|
styles: {
|
|
143
174
|
fill: { '': '#surface', isLoading: '#surface.5' },
|
|
@@ -155,10 +186,11 @@ Map modifier names to type descriptors for precise TypeScript types:
|
|
|
155
186
|
|
|
156
187
|
```tsx
|
|
157
188
|
const Button = tasty({
|
|
189
|
+
as: 'button',
|
|
158
190
|
modProps: {
|
|
159
|
-
isLoading: Boolean,
|
|
160
|
-
isSelected: Boolean,
|
|
161
|
-
size: ['small', 'medium', 'large'] as const,
|
|
191
|
+
isLoading: Boolean, // isLoading?: boolean
|
|
192
|
+
isSelected: Boolean, // isSelected?: boolean
|
|
193
|
+
size: ['small', 'medium', 'large'] as const, // size?: 'small' | 'medium' | 'large'
|
|
162
194
|
},
|
|
163
195
|
styles: {
|
|
164
196
|
padding: { '': '2x 4x', 'size=small': '1x 2x', 'size=large': '3x 6x' },
|
|
@@ -166,18 +198,20 @@ const Button = tasty({
|
|
|
166
198
|
},
|
|
167
199
|
});
|
|
168
200
|
|
|
169
|
-
<Button isLoading size="large">
|
|
201
|
+
<Button isLoading size="large">
|
|
202
|
+
Submit
|
|
203
|
+
</Button>;
|
|
170
204
|
// Renders: <button data-is-loading="" data-size="large">Submit</button>
|
|
171
205
|
```
|
|
172
206
|
|
|
173
207
|
Available type descriptors:
|
|
174
208
|
|
|
175
|
-
| Descriptor
|
|
176
|
-
|
|
177
|
-
| `Boolean`
|
|
178
|
-
| `String`
|
|
179
|
-
| `Number`
|
|
180
|
-
| `['a', 'b'] as const` | `'a' \| 'b'`
|
|
209
|
+
| Descriptor | TypeScript type | Example |
|
|
210
|
+
| --------------------- | --------------- | ----------------------------------- |
|
|
211
|
+
| `Boolean` | `boolean` | `isLoading: Boolean` |
|
|
212
|
+
| `String` | `string` | `label: String` |
|
|
213
|
+
| `Number` | `number` | `count: Number` |
|
|
214
|
+
| `['a', 'b'] as const` | `'a' \| 'b'` | `size: ['sm', 'md', 'lg'] as const` |
|
|
181
215
|
|
|
182
216
|
### Merge with `mods`
|
|
183
217
|
|
|
@@ -190,11 +224,11 @@ Mod props and the `mods` object can be used together. Mod props take precedence:
|
|
|
190
224
|
|
|
191
225
|
### When to use `modProps` vs `mods`
|
|
192
226
|
|
|
193
|
-
| Use case
|
|
194
|
-
|
|
227
|
+
| Use case | Recommendation |
|
|
228
|
+
| -------------------------------------------- | -------------------------------------------------------- |
|
|
195
229
|
| Component has a fixed set of known modifiers | `modProps` — cleaner API, better TypeScript autocomplete |
|
|
196
|
-
| Component needs arbitrary/dynamic modifiers
|
|
197
|
-
| Both fixed and dynamic
|
|
230
|
+
| Component needs arbitrary/dynamic modifiers | `mods` — open-ended `Record<string, ModValue>` |
|
|
231
|
+
| Both fixed and dynamic | Combine: `modProps` for known keys, `mods` for ad-hoc |
|
|
198
232
|
|
|
199
233
|
For architecture guidance on when to use modifiers vs `styleProps`, see [Methodology — modProps and mods](methodology.md#modprops-and-mods).
|
|
200
234
|
|
|
@@ -224,7 +258,7 @@ const ProgressBar = tasty({
|
|
|
224
258
|
|
|
225
259
|
<ProgressBar progress="75%" accentColor="#purple" />
|
|
226
260
|
// 'progress' → $progress → --progress
|
|
227
|
-
// 'accentColor' → #accent → --accent-color
|
|
261
|
+
// 'accentColor' → #accent → --accent-color
|
|
228
262
|
```
|
|
229
263
|
|
|
230
264
|
### Object form
|
|
@@ -240,7 +274,7 @@ const Card = tasty({
|
|
|
240
274
|
styles: { padding: '$card-size', fill: '#card-accent' },
|
|
241
275
|
});
|
|
242
276
|
|
|
243
|
-
<Card size="4x" color="#purple"
|
|
277
|
+
<Card size="4x" color="#purple" />;
|
|
244
278
|
```
|
|
245
279
|
|
|
246
280
|
### Merge with `tokens`
|
|
@@ -259,11 +293,11 @@ const Bar = tasty({
|
|
|
259
293
|
|
|
260
294
|
### When to use `tokenProps` vs `tokens`
|
|
261
295
|
|
|
262
|
-
| Use case
|
|
263
|
-
|
|
264
|
-
| Component has a fixed set of known token keys
|
|
265
|
-
| Component needs arbitrary/dynamic token values | `tokens` — open-ended `Record<string, TokenValue>`
|
|
266
|
-
| Both fixed and dynamic
|
|
296
|
+
| Use case | Recommendation |
|
|
297
|
+
| ---------------------------------------------- | ---------------------------------------------------------- |
|
|
298
|
+
| Component has a fixed set of known token keys | `tokenProps` — cleaner API, better TypeScript autocomplete |
|
|
299
|
+
| Component needs arbitrary/dynamic token values | `tokens` — open-ended `Record<string, TokenValue>` |
|
|
300
|
+
| Both fixed and dynamic | Combine: `tokenProps` for known keys, `tokens` for ad-hoc |
|
|
267
301
|
|
|
268
302
|
For architecture guidance, see [Methodology — tokenProps](methodology.md#tokenprops).
|
|
269
303
|
|
|
@@ -282,11 +316,29 @@ const Button = tasty({
|
|
|
282
316
|
variants: {
|
|
283
317
|
default: { fill: '#blue', color: '#white' },
|
|
284
318
|
danger: { fill: '#red', color: '#white' },
|
|
285
|
-
outline: { fill: '
|
|
319
|
+
outline: { fill: '#clear', color: '#blue', border: '1bw solid #blue' },
|
|
320
|
+
},
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
<Button variant="danger">Delete</Button>;
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
With `variant` omitted, or set to a key `variants` does not define, the `default` variant applies; without a `default` key only the base `styles` apply. `variant` is typed from the variant keys.
|
|
327
|
+
|
|
328
|
+
To fall back to another variant instead, name it in the `variant` option:
|
|
329
|
+
|
|
330
|
+
```jsx
|
|
331
|
+
const Button = tasty({
|
|
332
|
+
styles: { padding: '2x 4x' },
|
|
333
|
+
variants: {
|
|
334
|
+
primary: { fill: '#blue', color: '#white' },
|
|
335
|
+
danger: { fill: '#red', color: '#white' },
|
|
286
336
|
},
|
|
337
|
+
variant: 'primary',
|
|
287
338
|
});
|
|
288
339
|
|
|
289
|
-
<Button
|
|
340
|
+
<Button>Save</Button>; // primary
|
|
341
|
+
<Button variant="danger">Delete</Button>;
|
|
290
342
|
```
|
|
291
343
|
|
|
292
344
|
### Extending Variants with Base State Maps
|
|
@@ -342,7 +394,7 @@ const Card = tasty({
|
|
|
342
394
|
<Card>
|
|
343
395
|
<Card.Title>Card Title</Card.Title>
|
|
344
396
|
<Card.Content>Card content</Card.Content>
|
|
345
|
-
</Card
|
|
397
|
+
</Card>;
|
|
346
398
|
```
|
|
347
399
|
|
|
348
400
|
Each entry in `elements` can be a tag name string or a config object:
|
|
@@ -368,7 +420,7 @@ const Card = tasty({
|
|
|
368
420
|
|
|
369
421
|
<Card>
|
|
370
422
|
<div data-element="Title">Card Title</div>
|
|
371
|
-
</Card
|
|
423
|
+
</Card>;
|
|
372
424
|
```
|
|
373
425
|
|
|
374
426
|
### Selector Affix (`$`)
|
|
@@ -393,19 +445,19 @@ const { className } = computeStyles({
|
|
|
393
445
|
});
|
|
394
446
|
```
|
|
395
447
|
|
|
396
|
-
On the client, CSS is injected synchronously into the DOM (idempotent via the injector cache). On the server, CSS
|
|
448
|
+
On the client, CSS is injected synchronously into the DOM (idempotent via the injector cache). On the server with an SSR collector (from `runWithCollector()` or `TastyRegistry`), the CSS goes to the collector. With neither a collector nor a `document` — a React Server Component — nothing is injected: the CSS comes back as `css`, and you render it in a `style` tag yourself, as `tasty()` components do. This is the same function that `tasty()` components use internally.
|
|
397
449
|
|
|
398
450
|
---
|
|
399
451
|
|
|
400
452
|
## Style Functions
|
|
401
453
|
|
|
402
|
-
All style functions below
|
|
454
|
+
All style functions below work in client components, SSR with a `ServerStyleCollector`, and React Server Components. All except `useStyles()` are plain functions, not React hooks; they keep the `use` prefix for backward compatibility.
|
|
403
455
|
|
|
404
|
-
In server-only contexts
|
|
456
|
+
In server-only contexts, components that use only Tasty style functions ship no Tasty styling runtime. Astro without `client:*` directives produces no client JavaScript; server-only Next.js RSC follows the same Tasty architecture, while final output depends on the application deployment. Tasty never forces the `'use client'` boundary — that decision belongs to your component when it needs React interactivity (state, effects, event handlers).
|
|
405
457
|
|
|
406
458
|
### useStyles
|
|
407
459
|
|
|
408
|
-
Generate a className from a style object.
|
|
460
|
+
Generate a className from a style object. A thin wrapper around `computeStyles()` that also picks up the `TastyRegistry` collector through React context. That makes it a hook on the client: call it inside a component, and use `computeStyles()` outside React. It also works in a Server Component, where it skips the context lookup; like the other style functions there, it cannot emit CSS itself, so the next `tasty()` element in the tree emits it.
|
|
409
461
|
|
|
410
462
|
```tsx
|
|
411
463
|
import { useStyles } from '@tenphi/tasty';
|
|
@@ -439,6 +491,13 @@ function ThemeStyles() {
|
|
|
439
491
|
}
|
|
440
492
|
```
|
|
441
493
|
|
|
494
|
+
The selector can be a list (`'.uni-checkbox, uni-checkbox'`) — every item gets
|
|
495
|
+
the states and sub-elements, with no `:is()` wrapping needed. Root states
|
|
496
|
+
(`@root(...)`) on a selector that is the root itself (`:root`, `html`) apply to
|
|
497
|
+
that element. Local `@keyframes` are injected with the rules, under the same
|
|
498
|
+
resolved names `tasty()` components use, and `@starting` states emit
|
|
499
|
+
`@starting-style`.
|
|
500
|
+
|
|
442
501
|
A slot — the `id`, or the selector when no `id` is given — holds exactly one
|
|
443
502
|
injection **per `root`**. So:
|
|
444
503
|
|
|
@@ -467,6 +526,8 @@ function GlobalReset() {
|
|
|
467
526
|
An `id` slot holds one injection per `root`. Without an `id` the CSS is deduped
|
|
468
527
|
by content and permanent — there is nothing to replace it with later.
|
|
469
528
|
|
|
529
|
+
It also accepts a factory and deps — `useRawCSS(() => css, [deps], { id })` — and skips the factory while the deps for that `id` are unchanged.
|
|
530
|
+
|
|
470
531
|
### useKeyframes
|
|
471
532
|
|
|
472
533
|
Inject `@keyframes` rules and return the generated animation name:
|
|
@@ -480,7 +541,7 @@ function Spinner() {
|
|
|
480
541
|
from: { transform: 'rotate(0deg)' },
|
|
481
542
|
to: { transform: 'rotate(360deg)' },
|
|
482
543
|
},
|
|
483
|
-
{ name: 'spin' }
|
|
544
|
+
{ name: 'spin' },
|
|
484
545
|
);
|
|
485
546
|
|
|
486
547
|
return <div style={{ animation: `${spin} 1s linear infinite` }} />;
|
|
@@ -497,10 +558,14 @@ function Pulse({ scale }: { scale: number }) {
|
|
|
497
558
|
'100%': { transform: `scale(${scale})` },
|
|
498
559
|
}),
|
|
499
560
|
[scale],
|
|
500
|
-
{ name: 'pulse' }
|
|
561
|
+
{ name: 'pulse' },
|
|
501
562
|
);
|
|
502
563
|
|
|
503
|
-
return
|
|
564
|
+
return (
|
|
565
|
+
<div
|
|
566
|
+
style={{ animation: `${pulse} 500ms ease-in-out alternate infinite` }}
|
|
567
|
+
/>
|
|
568
|
+
);
|
|
504
569
|
}
|
|
505
570
|
```
|
|
506
571
|
|
|
@@ -556,15 +621,27 @@ For multiple weights/styles, pass an array:
|
|
|
556
621
|
|
|
557
622
|
```tsx
|
|
558
623
|
useFontFace('Brand Sans', [
|
|
559
|
-
{
|
|
560
|
-
|
|
624
|
+
{
|
|
625
|
+
src: 'url("/fonts/brand-regular.woff2") format("woff2")',
|
|
626
|
+
fontWeight: 400,
|
|
627
|
+
fontDisplay: 'swap',
|
|
628
|
+
},
|
|
629
|
+
{
|
|
630
|
+
src: 'url("/fonts/brand-bold.woff2") format("woff2")',
|
|
631
|
+
fontWeight: 700,
|
|
632
|
+
fontDisplay: 'swap',
|
|
633
|
+
},
|
|
561
634
|
]);
|
|
562
635
|
```
|
|
563
636
|
|
|
564
637
|
Signature:
|
|
565
638
|
|
|
566
639
|
```ts
|
|
567
|
-
function useFontFace(
|
|
640
|
+
function useFontFace(
|
|
641
|
+
family: string,
|
|
642
|
+
input: FontFaceInput,
|
|
643
|
+
options?: { root?: Document | ShadowRoot },
|
|
644
|
+
): void;
|
|
568
645
|
```
|
|
569
646
|
|
|
570
647
|
### useCounterStyle
|
|
@@ -575,11 +652,14 @@ Inject a `@counter-style` rule and get back the counter style name. Permanent
|
|
|
575
652
|
import { useCounterStyle } from '@tenphi/tasty';
|
|
576
653
|
|
|
577
654
|
function EmojiList() {
|
|
578
|
-
const styleName = useCounterStyle(
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
655
|
+
const styleName = useCounterStyle(
|
|
656
|
+
{
|
|
657
|
+
system: 'cyclic',
|
|
658
|
+
symbols: '"👍"',
|
|
659
|
+
suffix: '" "',
|
|
660
|
+
},
|
|
661
|
+
{ name: 'thumbs' },
|
|
662
|
+
);
|
|
583
663
|
|
|
584
664
|
return (
|
|
585
665
|
<ol style={{ listStyleType: styleName }}>
|
|
@@ -606,7 +686,7 @@ Register a CSS `@function` (custom function). Permanent — no cleanup on unmoun
|
|
|
606
686
|
```tsx
|
|
607
687
|
import { tasty, useFunction } from '@tenphi/tasty';
|
|
608
688
|
|
|
609
|
-
const Box = tasty({ styles: {
|
|
689
|
+
const Box = tasty({ styles: { margin: '$$negative(10px) top' } });
|
|
610
690
|
|
|
611
691
|
function Layout() {
|
|
612
692
|
useFunction('$$negative', { args: ['$value'], result: '(-1 * $value)' });
|
|
@@ -621,8 +701,8 @@ Inside a `tasty()` component you call functions with the same `$$name(...)` suga
|
|
|
621
701
|
```tsx
|
|
622
702
|
const Box = tasty({
|
|
623
703
|
styles: {
|
|
624
|
-
'@function': {
|
|
625
|
-
|
|
704
|
+
'@function': { $$negative: { args: ['$value'], result: '(-1 * $value)' } },
|
|
705
|
+
margin: '$$negative(10px) top',
|
|
626
706
|
},
|
|
627
707
|
});
|
|
628
708
|
```
|
|
@@ -643,9 +723,10 @@ See the [Functions section of the DSL reference](dsl.md#functions-function) for
|
|
|
643
723
|
|
|
644
724
|
- Styles are not updating: make sure `configure()` runs before first render, and verify the generated class name or global rule with [Debug Utilities](debug.md).
|
|
645
725
|
- SSR output looks wrong: check the [SSR guide](ssr.md) for collector setup. All style functions discover the SSR collector via `AsyncLocalStorage` or the global getter registered by `TastyRegistry`.
|
|
726
|
+
- "Server rendering without a style collector" in development: the server render has no request scope, so each `tasty()` element inlines its own CSS and configured globals are not emitted. Add `tastyIntegration()` (Astro), `TastyRegistry` (Next.js), or `runWithCollector()` — see the [SSR guide](ssr.md).
|
|
646
727
|
- Animation/custom property issues: prefer `useKeyframes()` and `useProperty()` over raw CSS when you want Tasty to manage injection and SSR collection for you.
|
|
647
728
|
- For dynamic styles that change over the component lifecycle, use the `id` option in `useGlobalStyles()` and `useRawCSS()` to enable update tracking.
|
|
648
|
-
- RSC inline mode: CSS accumulated by standalone style functions (`useGlobalStyles`, `useRawCSS`, etc.) is flushed into inline `<style>` tags by the next `tasty()` component in the render tree. If your page uses only standalone style functions without any `tasty()` component, the CSS will not be emitted. Ensure at least one `tasty()` component is present in each RSC render tree.
|
|
729
|
+
- RSC inline mode: CSS accumulated by standalone style functions (`useStyles`, `useGlobalStyles`, `useRawCSS`, etc.) is flushed into inline `<style>` tags by the next `tasty()` component in the render tree. If your page uses only standalone style functions without any `tasty()` component, the CSS will not be emitted. Ensure at least one `tasty()` component is present in each RSC render tree.
|
|
649
730
|
|
|
650
731
|
---
|
|
651
732
|
|
|
@@ -654,7 +735,8 @@ See the [Functions section of the DSL reference](dsl.md#functions-function) for
|
|
|
654
735
|
- **[Style DSL](dsl.md)** — State maps, tokens, units, extending semantics, keyframes, @property
|
|
655
736
|
- **[Methodology](methodology.md)** — Recommended patterns: root + sub-elements, styleProps, tokens, wrapping
|
|
656
737
|
- **[Configuration](configuration.md)** — Tokens, recipes, custom units, style handlers, TypeScript extensions
|
|
738
|
+
- **[Configuration → TypeScript](configuration.md#typescript)** — How props are typed and how to register your names
|
|
657
739
|
- **[Style Properties](styles.md)** — Complete reference for all enhanced style properties
|
|
658
|
-
- **[
|
|
740
|
+
- **[Build-Time Extraction (`tastyStatic`)](tasty-static.md)** — Static styling with the Babel plugin
|
|
659
741
|
- **[Server-Side Rendering](ssr.md)** — SSR setup for Next.js, Astro, and generic frameworks
|
|
660
742
|
- **[Debug Utilities](debug.md)** — Inspect injected CSS, cache state, and active styles at runtime
|