@tenphi/tasty 0.0.0-snapshot.2f41cf6 → 0.0.0-snapshot.2f4e31d
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 +440 -372
- package/dist/babel-types-Dc5zghyE.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-D9Iq8QQm.js +60 -0
- package/dist/chunks/build-config-D9Iq8QQm.js.map +1 -0
- package/dist/{collector-BMEQCkCn.js → chunks/collector-Cb8ah2JF.js} +68 -101
- package/dist/chunks/collector-Cb8ah2JF.js.map +1 -0
- package/dist/chunks/config-engine-CMYFZYQh.js +272 -0
- package/dist/chunks/config-engine-CMYFZYQh.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-B4aWBkH3.js +910 -0
- package/dist/chunks/css-definitions-B4aWBkH3.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-D2Pu7Xhy.js +502 -0
- package/dist/chunks/debug-D2Pu7Xhy.js.map +1 -0
- package/dist/chunks/dsl-CsFl9LGn.js +1458 -0
- package/dist/chunks/dsl-CsFl9LGn.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-DHiopXCu.js +691 -0
- package/dist/chunks/react-runtime-DHiopXCu.js.map +1 -0
- package/dist/chunks/runtime-engine-NGCofNXy.js +2435 -0
- package/dist/chunks/runtime-engine-NGCofNXy.js.map +1 -0
- package/dist/chunks/runtime-state-lZjMbvwV.js +152 -0
- package/dist/chunks/runtime-state-lZjMbvwV.js.map +1 -0
- package/dist/{merge-styles-3il_ClCF.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-DnkV_4Jg.js +5602 -0
- package/dist/chunks/style-engine-DnkV_4Jg.js.map +1 -0
- package/dist/{css-writer-BSv8PrEX.js → chunks/zero-engine-DcwaCvFs.js} +95 -136
- package/dist/chunks/zero-engine-DcwaCvFs.js.map +1 -0
- package/dist/{collector-osfWTeRd.d.ts → collector-D2OT6I2G.d.ts} +64 -8
- package/dist/{config-BoZDUHW5.d.ts → config-C4ftFxgI.d.ts} +514 -92
- 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-D-OA_O6i.d.ts → index-DxQNRj50.d.ts} +718 -502
- package/dist/index.d.ts +5 -5
- package/dist/index.js +11 -732
- package/dist/{merge-styles-BMWcH6MF.d.ts → merge-styles-D39qBtox.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 +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 +11 -8
- package/dist/ssr/astro-middleware.js +2 -14
- package/dist/ssr/astro-middleware.js.map +1 -1
- package/dist/ssr/astro.d.ts +40 -10
- package/dist/ssr/astro.js +163 -91
- 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 -32
- package/dist/ssr/index.js +6 -6
- 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 -9
- package/dist/ssr/next.js +29 -44
- 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/static/inject.js.map +1 -1
- package/dist/{index-tcHuMPFt.d.ts → types-CYQIhUg1.d.ts} +883 -600
- package/dist/zero/babel.d.ts +12 -20
- package/dist/zero/babel.js +97 -156
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/index.d.ts +76 -7
- package/dist/zero/index.js +25 -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 +20 -9
- package/docs/adoption.md +69 -36
- package/docs/ai-agents.md +259 -0
- package/docs/comparison.md +77 -47
- package/docs/configuration.md +617 -98
- package/docs/debug.md +28 -15
- package/docs/design-system.md +154 -33
- package/docs/dsl.md +715 -194
- package/docs/getting-started.md +130 -50
- package/docs/injector.md +160 -69
- package/docs/methodology.md +82 -51
- package/docs/migration-v3.md +285 -0
- package/docs/pipeline.md +102 -33
- package/docs/plugins.md +333 -0
- package/docs/react-api.md +215 -50
- package/docs/runtime-benchmarks.md +388 -0
- package/docs/ssr.md +310 -118
- package/docs/styles.md +225 -42
- package/docs/tasty-static.md +289 -136
- package/package.json +141 -45
- package/tasty.config.ts +6 -0
- package/dist/async-storage-B7_o6FKt.js +0 -44
- package/dist/async-storage-B7_o6FKt.js.map +0 -1
- package/dist/collector-BMEQCkCn.js.map +0 -1
- package/dist/config-eiremPHv.js +0 -10559
- package/dist/config-eiremPHv.js.map +0 -1
- package/dist/context-CkSg-kDT.js +0 -24
- package/dist/context-CkSg-kDT.js.map +0 -1
- package/dist/core-Dm9EkOA_.js +0 -1598
- package/dist/core-Dm9EkOA_.js.map +0 -1
- package/dist/css-writer-BSv8PrEX.js.map +0 -1
- package/dist/format-global-rules-Dbc_1tc3.js +0 -22
- package/dist/format-global-rules-Dbc_1tc3.js.map +0 -1
- package/dist/format-rules-DcFFQceU.js +0 -143
- package/dist/format-rules-DcFFQceU.js.map +0 -1
- package/dist/hydrate-B6SjFHhj.js +0 -45
- package/dist/hydrate-B6SjFHhj.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/keyframes-DJ8Geo4L.js +0 -595
- package/dist/keyframes-DJ8Geo4L.js.map +0 -1
- package/dist/merge-styles-3il_ClCF.js.map +0 -1
- package/dist/resolve-recipes-B3MSkfFQ.js +0 -144
- package/dist/resolve-recipes-B3MSkfFQ.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:
|
|
@@ -98,6 +128,26 @@ Style props accept state maps, so responsive values work through the same API:
|
|
|
98
128
|
|
|
99
129
|
For predefined style prop lists (`FLOW_STYLES`, `POSITION_STYLES`, `DIMENSION_STYLES`, etc.) and guidance on which props to expose per component category, see [Methodology — styleProps as the public API](methodology.md#styleprops-as-the-public-api).
|
|
100
130
|
|
|
131
|
+
### Always-available style props
|
|
132
|
+
|
|
133
|
+
A small set of style properties — `display`, `font`, `preset`, `hide`, `whiteSpace`, `opacity`, and `transition` — are always harvested as style props on every `tasty()` component, even when `styleProps` is omitted. This means you can pass `<Card display="grid" />` or `<Text preset="h1" />` without declaring them. When you do declare `styleProps`, these base props are unioned with your list (not replaced).
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## `Element`
|
|
138
|
+
|
|
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`.
|
|
140
|
+
|
|
141
|
+
```jsx
|
|
142
|
+
import { Element } from '@tenphi/tasty';
|
|
143
|
+
|
|
144
|
+
<Element as="section" display="grid" preset="t2" styles={{ padding: '4x' }}>
|
|
145
|
+
Content
|
|
146
|
+
</Element>;
|
|
147
|
+
```
|
|
148
|
+
|
|
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'`.
|
|
150
|
+
|
|
101
151
|
---
|
|
102
152
|
|
|
103
153
|
## Mod Props
|
|
@@ -118,6 +168,7 @@ List modifier key names. Types default to `ModValue` (`boolean | string | number
|
|
|
118
168
|
|
|
119
169
|
```jsx
|
|
120
170
|
const Button = tasty({
|
|
171
|
+
as: 'button',
|
|
121
172
|
modProps: ['isLoading', 'isSelected'] as const,
|
|
122
173
|
styles: {
|
|
123
174
|
fill: { '': '#surface', isLoading: '#surface.5' },
|
|
@@ -135,10 +186,11 @@ Map modifier names to type descriptors for precise TypeScript types:
|
|
|
135
186
|
|
|
136
187
|
```tsx
|
|
137
188
|
const Button = tasty({
|
|
189
|
+
as: 'button',
|
|
138
190
|
modProps: {
|
|
139
|
-
isLoading: Boolean,
|
|
140
|
-
isSelected: Boolean,
|
|
141
|
-
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'
|
|
142
194
|
},
|
|
143
195
|
styles: {
|
|
144
196
|
padding: { '': '2x 4x', 'size=small': '1x 2x', 'size=large': '3x 6x' },
|
|
@@ -146,18 +198,20 @@ const Button = tasty({
|
|
|
146
198
|
},
|
|
147
199
|
});
|
|
148
200
|
|
|
149
|
-
<Button isLoading size="large">
|
|
201
|
+
<Button isLoading size="large">
|
|
202
|
+
Submit
|
|
203
|
+
</Button>;
|
|
150
204
|
// Renders: <button data-is-loading="" data-size="large">Submit</button>
|
|
151
205
|
```
|
|
152
206
|
|
|
153
207
|
Available type descriptors:
|
|
154
208
|
|
|
155
|
-
| Descriptor
|
|
156
|
-
|
|
157
|
-
| `Boolean`
|
|
158
|
-
| `String`
|
|
159
|
-
| `Number`
|
|
160
|
-
| `['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` |
|
|
161
215
|
|
|
162
216
|
### Merge with `mods`
|
|
163
217
|
|
|
@@ -170,11 +224,11 @@ Mod props and the `mods` object can be used together. Mod props take precedence:
|
|
|
170
224
|
|
|
171
225
|
### When to use `modProps` vs `mods`
|
|
172
226
|
|
|
173
|
-
| Use case
|
|
174
|
-
|
|
227
|
+
| Use case | Recommendation |
|
|
228
|
+
| -------------------------------------------- | -------------------------------------------------------- |
|
|
175
229
|
| Component has a fixed set of known modifiers | `modProps` — cleaner API, better TypeScript autocomplete |
|
|
176
|
-
| Component needs arbitrary/dynamic modifiers
|
|
177
|
-
| 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 |
|
|
178
232
|
|
|
179
233
|
For architecture guidance on when to use modifiers vs `styleProps`, see [Methodology — modProps and mods](methodology.md#modprops-and-mods).
|
|
180
234
|
|
|
@@ -204,7 +258,7 @@ const ProgressBar = tasty({
|
|
|
204
258
|
|
|
205
259
|
<ProgressBar progress="75%" accentColor="#purple" />
|
|
206
260
|
// 'progress' → $progress → --progress
|
|
207
|
-
// 'accentColor' → #accent → --accent-color
|
|
261
|
+
// 'accentColor' → #accent → --accent-color
|
|
208
262
|
```
|
|
209
263
|
|
|
210
264
|
### Object form
|
|
@@ -220,7 +274,7 @@ const Card = tasty({
|
|
|
220
274
|
styles: { padding: '$card-size', fill: '#card-accent' },
|
|
221
275
|
});
|
|
222
276
|
|
|
223
|
-
<Card size="4x" color="#purple"
|
|
277
|
+
<Card size="4x" color="#purple" />;
|
|
224
278
|
```
|
|
225
279
|
|
|
226
280
|
### Merge with `tokens`
|
|
@@ -239,11 +293,11 @@ const Bar = tasty({
|
|
|
239
293
|
|
|
240
294
|
### When to use `tokenProps` vs `tokens`
|
|
241
295
|
|
|
242
|
-
| Use case
|
|
243
|
-
|
|
244
|
-
| Component has a fixed set of known token keys
|
|
245
|
-
| Component needs arbitrary/dynamic token values | `tokens` — open-ended `Record<string, TokenValue>`
|
|
246
|
-
| 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 |
|
|
247
301
|
|
|
248
302
|
For architecture guidance, see [Methodology — tokenProps](methodology.md#tokenprops).
|
|
249
303
|
|
|
@@ -262,11 +316,29 @@ const Button = tasty({
|
|
|
262
316
|
variants: {
|
|
263
317
|
default: { fill: '#blue', color: '#white' },
|
|
264
318
|
danger: { fill: '#red', color: '#white' },
|
|
265
|
-
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' },
|
|
266
336
|
},
|
|
337
|
+
variant: 'primary',
|
|
267
338
|
});
|
|
268
339
|
|
|
269
|
-
<Button
|
|
340
|
+
<Button>Save</Button>; // primary
|
|
341
|
+
<Button variant="danger">Delete</Button>;
|
|
270
342
|
```
|
|
271
343
|
|
|
272
344
|
### Extending Variants with Base State Maps
|
|
@@ -284,7 +356,7 @@ const Badge = tasty({
|
|
|
284
356
|
variants: {
|
|
285
357
|
primary: {
|
|
286
358
|
border: { '': '#white.2', pressed: '#primary-text', disabled: '#clear' },
|
|
287
|
-
fill: { '': '#
|
|
359
|
+
fill: { '': '#primary', hovered: '#primary-text' },
|
|
288
360
|
},
|
|
289
361
|
secondary: {
|
|
290
362
|
border: { '': '#primary.15', pressed: '#primary.3' },
|
|
@@ -322,7 +394,7 @@ const Card = tasty({
|
|
|
322
394
|
<Card>
|
|
323
395
|
<Card.Title>Card Title</Card.Title>
|
|
324
396
|
<Card.Content>Card content</Card.Content>
|
|
325
|
-
</Card
|
|
397
|
+
</Card>;
|
|
326
398
|
```
|
|
327
399
|
|
|
328
400
|
Each entry in `elements` can be a tag name string or a config object:
|
|
@@ -334,7 +406,7 @@ elements: {
|
|
|
334
406
|
}
|
|
335
407
|
```
|
|
336
408
|
|
|
337
|
-
The sub-components produced by `elements` support `mods`, `tokens`, `isDisabled`, `isHidden`, and `isChecked` props — the same modifier interface as the root component.
|
|
409
|
+
The sub-components produced by `elements` support `mods`, `tokens`, `theme`, `isDisabled`, `isHidden`, and `isChecked` props — the same modifier interface as the root component. As on the root, `theme` renders as `data-theme`, and an explicit `data-theme` wins over it.
|
|
338
410
|
|
|
339
411
|
If you don't need sub-components (e.g., the inner elements are already rendered by a third-party library), you can still style them by key alone — just omit `elements` and apply `data-element` manually:
|
|
340
412
|
|
|
@@ -348,7 +420,7 @@ const Card = tasty({
|
|
|
348
420
|
|
|
349
421
|
<Card>
|
|
350
422
|
<div data-element="Title">Card Title</div>
|
|
351
|
-
</Card
|
|
423
|
+
</Card>;
|
|
352
424
|
```
|
|
353
425
|
|
|
354
426
|
### Selector Affix (`$`)
|
|
@@ -373,19 +445,19 @@ const { className } = computeStyles({
|
|
|
373
445
|
});
|
|
374
446
|
```
|
|
375
447
|
|
|
376
|
-
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.
|
|
377
449
|
|
|
378
450
|
---
|
|
379
451
|
|
|
380
452
|
## Style Functions
|
|
381
453
|
|
|
382
|
-
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.
|
|
383
455
|
|
|
384
|
-
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).
|
|
385
457
|
|
|
386
458
|
### useStyles
|
|
387
459
|
|
|
388
|
-
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.
|
|
389
461
|
|
|
390
462
|
```tsx
|
|
391
463
|
import { useStyles } from '@tenphi/tasty';
|
|
@@ -419,6 +491,26 @@ function ThemeStyles() {
|
|
|
419
491
|
}
|
|
420
492
|
```
|
|
421
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. A selector that ends in a pseudo-element takes its states on the
|
|
498
|
+
pseudo-element (`'.card::before'` with `:hover` gives
|
|
499
|
+
`.card::before:where(:hover)`) and `@parent()` on the element before it.
|
|
500
|
+
Attribute and modifier states, which a pseudo-element can't have, are ignored
|
|
501
|
+
with a warning. Local `@keyframes` are injected with the rules,
|
|
502
|
+
under the same resolved names `tasty()` components use, and `@starting` states
|
|
503
|
+
emit `@starting-style`.
|
|
504
|
+
|
|
505
|
+
A slot — the `id`, or the selector when no `id` is given — holds exactly one
|
|
506
|
+
injection **per `root`**. So:
|
|
507
|
+
|
|
508
|
+
- Changing the styles replaces the previous CSS rather than adding to it.
|
|
509
|
+
- Passing styles that produce no CSS (for example `{}`) clears the slot.
|
|
510
|
+
- The same selector used in two shadow roots keeps a separate injection in each.
|
|
511
|
+
- Two independent call sites that share a selector share a slot, and the last
|
|
512
|
+
render wins. Give them distinct `id`s if they should coexist.
|
|
513
|
+
|
|
422
514
|
### useRawCSS
|
|
423
515
|
|
|
424
516
|
Inject raw CSS strings. Accepts an optional `id` in the options for update tracking — when the CSS changes for the same id, the previous injection is replaced:
|
|
@@ -435,6 +527,11 @@ function GlobalReset() {
|
|
|
435
527
|
}
|
|
436
528
|
```
|
|
437
529
|
|
|
530
|
+
An `id` slot holds one injection per `root`. Without an `id` the CSS is deduped
|
|
531
|
+
by content and permanent — there is nothing to replace it with later.
|
|
532
|
+
|
|
533
|
+
It also accepts a factory and deps — `useRawCSS(() => css, [deps], { id })` — and skips the factory while the deps for that `id` are unchanged.
|
|
534
|
+
|
|
438
535
|
### useKeyframes
|
|
439
536
|
|
|
440
537
|
Inject `@keyframes` rules and return the generated animation name:
|
|
@@ -448,14 +545,14 @@ function Spinner() {
|
|
|
448
545
|
from: { transform: 'rotate(0deg)' },
|
|
449
546
|
to: { transform: 'rotate(360deg)' },
|
|
450
547
|
},
|
|
451
|
-
{ name: 'spin' }
|
|
548
|
+
{ name: 'spin' },
|
|
452
549
|
);
|
|
453
550
|
|
|
454
551
|
return <div style={{ animation: `${spin} 1s linear infinite` }} />;
|
|
455
552
|
}
|
|
456
553
|
```
|
|
457
554
|
|
|
458
|
-
`useKeyframes()` also supports a factory function.
|
|
555
|
+
`useKeyframes()` also supports a factory function. Without a `name` the factory runs on every invocation and deduplication is handled internally by content hash; with a `name`, matching deps skip the factory entirely:
|
|
459
556
|
|
|
460
557
|
```tsx
|
|
461
558
|
function Pulse({ scale }: { scale: number }) {
|
|
@@ -464,13 +561,24 @@ function Pulse({ scale }: { scale: number }) {
|
|
|
464
561
|
'0%': { transform: 'scale(1)' },
|
|
465
562
|
'100%': { transform: `scale(${scale})` },
|
|
466
563
|
}),
|
|
467
|
-
[scale]
|
|
564
|
+
[scale],
|
|
565
|
+
{ name: 'pulse' },
|
|
468
566
|
);
|
|
469
567
|
|
|
470
|
-
return
|
|
568
|
+
return (
|
|
569
|
+
<div
|
|
570
|
+
style={{ animation: `${pulse} 500ms ease-in-out alternate infinite` }}
|
|
571
|
+
/>
|
|
572
|
+
);
|
|
471
573
|
}
|
|
472
574
|
```
|
|
473
575
|
|
|
576
|
+
Passing `name` claims a slot owned by that one call site, per `root` — much like
|
|
577
|
+
`id` in `useGlobalStyles()` and `useRawCSS()`. When the steps change the previous
|
|
578
|
+
`@keyframes` rule is disposed and the name is reused, so the rules don't
|
|
579
|
+
accumulate and the returned name stays stable. Anonymous keyframes are permanent
|
|
580
|
+
and shared by content.
|
|
581
|
+
|
|
474
582
|
### useProperty
|
|
475
583
|
|
|
476
584
|
Register a CSS `@property` rule so a custom property can animate smoothly:
|
|
@@ -517,15 +625,27 @@ For multiple weights/styles, pass an array:
|
|
|
517
625
|
|
|
518
626
|
```tsx
|
|
519
627
|
useFontFace('Brand Sans', [
|
|
520
|
-
{
|
|
521
|
-
|
|
628
|
+
{
|
|
629
|
+
src: 'url("/fonts/brand-regular.woff2") format("woff2")',
|
|
630
|
+
fontWeight: 400,
|
|
631
|
+
fontDisplay: 'swap',
|
|
632
|
+
},
|
|
633
|
+
{
|
|
634
|
+
src: 'url("/fonts/brand-bold.woff2") format("woff2")',
|
|
635
|
+
fontWeight: 700,
|
|
636
|
+
fontDisplay: 'swap',
|
|
637
|
+
},
|
|
522
638
|
]);
|
|
523
639
|
```
|
|
524
640
|
|
|
525
641
|
Signature:
|
|
526
642
|
|
|
527
643
|
```ts
|
|
528
|
-
function useFontFace(
|
|
644
|
+
function useFontFace(
|
|
645
|
+
family: string,
|
|
646
|
+
input: FontFaceInput,
|
|
647
|
+
options?: { root?: Document | ShadowRoot },
|
|
648
|
+
): void;
|
|
529
649
|
```
|
|
530
650
|
|
|
531
651
|
### useCounterStyle
|
|
@@ -536,11 +656,14 @@ Inject a `@counter-style` rule and get back the counter style name. Permanent
|
|
|
536
656
|
import { useCounterStyle } from '@tenphi/tasty';
|
|
537
657
|
|
|
538
658
|
function EmojiList() {
|
|
539
|
-
const styleName = useCounterStyle(
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
659
|
+
const styleName = useCounterStyle(
|
|
660
|
+
{
|
|
661
|
+
system: 'cyclic',
|
|
662
|
+
symbols: '"👍"',
|
|
663
|
+
suffix: '" "',
|
|
664
|
+
},
|
|
665
|
+
{ name: 'thumbs' },
|
|
666
|
+
);
|
|
544
667
|
|
|
545
668
|
return (
|
|
546
669
|
<ol style={{ listStyleType: styleName }}>
|
|
@@ -560,13 +683,54 @@ function useCounterStyle(
|
|
|
560
683
|
): string;
|
|
561
684
|
```
|
|
562
685
|
|
|
686
|
+
### useFunction
|
|
687
|
+
|
|
688
|
+
Register a CSS `@function` (custom function). Permanent — no cleanup on unmount. Deduplicates by function name. The function name accepts `$$name` (matching the call site `$$name(...)`), `$name`, or `--name`.
|
|
689
|
+
|
|
690
|
+
```tsx
|
|
691
|
+
import { tasty, useFunction } from '@tenphi/tasty';
|
|
692
|
+
|
|
693
|
+
const Box = tasty({ styles: { margin: '$$negative(10px) top' } });
|
|
694
|
+
|
|
695
|
+
function Layout() {
|
|
696
|
+
useFunction('$$negative', { args: ['$value'], result: '(-1 * $value)' });
|
|
697
|
+
return <Box />;
|
|
698
|
+
}
|
|
699
|
+
```
|
|
700
|
+
|
|
701
|
+
Call the function through the Tasty DSL rather than a raw `style` prop. An inline `style` value reaches the browser unparsed, so the `$$name(...)` sugar is never expanded — and under `configure({ polyfills: { functions: true } })` it silently does nothing, because the polyfill rewrites calls at parse time.
|
|
702
|
+
|
|
703
|
+
Inside a `tasty()` component you call functions with the same `$$name(...)` sugar:
|
|
704
|
+
|
|
705
|
+
```tsx
|
|
706
|
+
const Box = tasty({
|
|
707
|
+
styles: {
|
|
708
|
+
'@function': { $$negative: { args: ['$value'], result: '(-1 * $value)' } },
|
|
709
|
+
margin: '$$negative(10px) top',
|
|
710
|
+
},
|
|
711
|
+
});
|
|
712
|
+
```
|
|
713
|
+
|
|
714
|
+
Signature:
|
|
715
|
+
|
|
716
|
+
```ts
|
|
717
|
+
function useFunction(
|
|
718
|
+
name: string,
|
|
719
|
+
definition: FunctionDefinition,
|
|
720
|
+
options?: { root?: Document | ShadowRoot },
|
|
721
|
+
): void;
|
|
722
|
+
```
|
|
723
|
+
|
|
724
|
+
See the [Functions section of the DSL reference](dsl.md#functions-function) for the full descriptor shape, token conventions, and value-sugar support. `@function` is an experimental CSS feature — unsupported browsers safely ignore the native rule, or enable the [`polyfills.functions`](configuration.md#polyfills) inline polyfill for full cross-browser support.
|
|
725
|
+
|
|
563
726
|
### Troubleshooting
|
|
564
727
|
|
|
565
728
|
- 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).
|
|
566
729
|
- 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`.
|
|
730
|
+
- "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).
|
|
567
731
|
- Animation/custom property issues: prefer `useKeyframes()` and `useProperty()` over raw CSS when you want Tasty to manage injection and SSR collection for you.
|
|
568
732
|
- For dynamic styles that change over the component lifecycle, use the `id` option in `useGlobalStyles()` and `useRawCSS()` to enable update tracking.
|
|
569
|
-
- 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.
|
|
733
|
+
- 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.
|
|
570
734
|
|
|
571
735
|
---
|
|
572
736
|
|
|
@@ -575,7 +739,8 @@ function useCounterStyle(
|
|
|
575
739
|
- **[Style DSL](dsl.md)** — State maps, tokens, units, extending semantics, keyframes, @property
|
|
576
740
|
- **[Methodology](methodology.md)** — Recommended patterns: root + sub-elements, styleProps, tokens, wrapping
|
|
577
741
|
- **[Configuration](configuration.md)** — Tokens, recipes, custom units, style handlers, TypeScript extensions
|
|
742
|
+
- **[Configuration → TypeScript](configuration.md#typescript)** — How props are typed and how to register your names
|
|
578
743
|
- **[Style Properties](styles.md)** — Complete reference for all enhanced style properties
|
|
579
|
-
- **[
|
|
744
|
+
- **[Build-Time Extraction (`tastyStatic`)](tasty-static.md)** — Static styling with the Babel plugin
|
|
580
745
|
- **[Server-Side Rendering](ssr.md)** — SSR setup for Next.js, Astro, and generic frameworks
|
|
581
746
|
- **[Debug Utilities](debug.md)** — Inspect injected CSS, cache state, and active styles at runtime
|