@tenphi/tasty 0.0.0-snapshot.db103fd → 0.0.0-snapshot.db2ef70
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 +441 -362
- 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/chunks/collector-Cb8ah2JF.js +210 -0
- 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/{debug.js → chunks/debug-D2Pu7Xhy.js} +196 -147
- 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/{utils/merge-styles.js → chunks/shared-utils-y-HjvPN4.js} +60 -56
- 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/chunks/zero-engine-DcwaCvFs.js +310 -0
- package/dist/chunks/zero-engine-DcwaCvFs.js.map +1 -0
- package/dist/collector-D2OT6I2G.d.ts +164 -0
- package/dist/config-C4ftFxgI.d.ts +1367 -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-DxQNRj50.d.ts +1964 -0
- package/dist/index.d.ts +5 -50
- package/dist/index.js +11 -35
- package/dist/{utils/merge-styles.d.ts → merge-styles-D39qBtox.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 +110 -12
- package/dist/ssr/astro.js +205 -48
- 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 +17 -5
- package/dist/ssr/index.js +6 -7
- 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 +13 -12
- package/dist/ssr/next.js +38 -47
- package/dist/ssr/next.js.map +1 -1
- package/dist/static/index.d.ts +90 -5
- package/dist/static/index.js +31 -3
- package/dist/static/index.js.map +1 -0
- package/dist/static/inject.d.ts +1 -2
- package/dist/static/inject.js.map +1 -1
- package/dist/types-CYQIhUg1.d.ts +1569 -0
- package/dist/zero/babel.d.ts +12 -121
- package/dist/zero/babel.js +126 -149
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/index.d.ts +136 -3
- package/dist/zero/index.js +25 -3
- 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 +23 -12
- package/docs/adoption.md +72 -37
- package/docs/ai-agents.md +259 -0
- package/docs/comparison.md +83 -54
- package/docs/configuration.md +712 -81
- package/docs/debug.md +39 -24
- package/docs/design-system.md +174 -41
- package/docs/dsl.md +733 -195
- package/docs/getting-started.md +132 -52
- package/docs/injector.md +197 -90
- package/docs/methodology.md +154 -48
- package/docs/migration-v3.md +285 -0
- package/docs/pipeline.md +768 -0
- package/docs/plugins.md +333 -0
- package/docs/react-api.md +746 -0
- package/docs/runtime-benchmarks.md +388 -0
- package/docs/ssr.md +403 -151
- package/docs/styles.md +248 -49
- package/docs/tasty-static.md +298 -118
- package/package.json +152 -40
- package/tasty.config.ts +7 -0
- package/dist/_virtual/_rolldown/runtime.js +0 -7
- package/dist/chunks/cacheKey.d.ts +0 -1
- package/dist/chunks/cacheKey.js +0 -77
- package/dist/chunks/cacheKey.js.map +0 -1
- package/dist/chunks/definitions.d.ts +0 -37
- package/dist/chunks/definitions.js +0 -258
- package/dist/chunks/definitions.js.map +0 -1
- package/dist/chunks/index.d.ts +0 -1
- package/dist/chunks/renderChunk.d.ts +0 -1
- package/dist/chunks/renderChunk.js +0 -59
- package/dist/chunks/renderChunk.js.map +0 -1
- package/dist/config.d.ts +0 -366
- package/dist/config.js +0 -503
- package/dist/config.js.map +0 -1
- package/dist/counter-style/index.js +0 -51
- package/dist/counter-style/index.js.map +0 -1
- package/dist/debug.d.ts +0 -89
- package/dist/debug.js.map +0 -1
- package/dist/font-face/index.js +0 -63
- package/dist/font-face/index.js.map +0 -1
- package/dist/hooks/index.d.ts +0 -7
- package/dist/hooks/resolve-ssr-collector.js +0 -14
- package/dist/hooks/resolve-ssr-collector.js.map +0 -1
- package/dist/hooks/useCounterStyle.d.ts +0 -50
- package/dist/hooks/useCounterStyle.js +0 -46
- package/dist/hooks/useCounterStyle.js.map +0 -1
- package/dist/hooks/useFontFace.d.ts +0 -43
- package/dist/hooks/useFontFace.js +0 -70
- package/dist/hooks/useFontFace.js.map +0 -1
- package/dist/hooks/useGlobalStyles.d.ts +0 -30
- package/dist/hooks/useGlobalStyles.js +0 -78
- package/dist/hooks/useGlobalStyles.js.map +0 -1
- package/dist/hooks/useKeyframes.d.ts +0 -56
- package/dist/hooks/useKeyframes.js +0 -64
- package/dist/hooks/useKeyframes.js.map +0 -1
- package/dist/hooks/useProperty.d.ts +0 -79
- package/dist/hooks/useProperty.js +0 -109
- package/dist/hooks/useProperty.js.map +0 -1
- package/dist/hooks/useRawCSS.d.ts +0 -53
- package/dist/hooks/useRawCSS.js +0 -35
- package/dist/hooks/useRawCSS.js.map +0 -1
- package/dist/hooks/useStyles.d.ts +0 -45
- package/dist/hooks/useStyles.js +0 -237
- package/dist/hooks/useStyles.js.map +0 -1
- package/dist/injector/index.d.ts +0 -183
- package/dist/injector/index.js +0 -179
- package/dist/injector/index.js.map +0 -1
- package/dist/injector/injector.d.ts +0 -166
- package/dist/injector/injector.js +0 -464
- package/dist/injector/injector.js.map +0 -1
- package/dist/injector/sheet-manager.d.ts +0 -136
- package/dist/injector/sheet-manager.js +0 -733
- package/dist/injector/sheet-manager.js.map +0 -1
- package/dist/injector/types.d.ts +0 -204
- 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 -49
- 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 -115
- 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 -406
- package/dist/pipeline/conditions.js.map +0 -1
- package/dist/pipeline/exclusive.js +0 -230
- package/dist/pipeline/exclusive.js.map +0 -1
- package/dist/pipeline/index.d.ts +0 -55
- package/dist/pipeline/index.js +0 -708
- package/dist/pipeline/index.js.map +0 -1
- package/dist/pipeline/materialize.js +0 -1103
- package/dist/pipeline/materialize.js.map +0 -1
- package/dist/pipeline/parseStateKey.d.ts +0 -15
- package/dist/pipeline/parseStateKey.js +0 -446
- package/dist/pipeline/parseStateKey.js.map +0 -1
- package/dist/pipeline/simplify.js +0 -515
- package/dist/pipeline/simplify.js.map +0 -1
- package/dist/pipeline/warnings.js +0 -18
- package/dist/pipeline/warnings.js.map +0 -1
- package/dist/plugins/index.d.ts +0 -2
- package/dist/plugins/okhsl-plugin.d.ts +0 -35
- package/dist/plugins/okhsl-plugin.js +0 -97
- package/dist/plugins/okhsl-plugin.js.map +0 -1
- package/dist/plugins/types.d.ts +0 -76
- package/dist/properties/index.js +0 -222
- package/dist/properties/index.js.map +0 -1
- package/dist/properties/property-type-resolver.d.ts +0 -24
- package/dist/properties/property-type-resolver.js +0 -90
- package/dist/properties/property-type-resolver.js.map +0 -1
- package/dist/ssr/async-storage.d.ts +0 -17
- package/dist/ssr/async-storage.js +0 -34
- package/dist/ssr/async-storage.js.map +0 -1
- package/dist/ssr/collect-auto-properties.js +0 -39
- package/dist/ssr/collect-auto-properties.js.map +0 -1
- package/dist/ssr/collector.d.ts +0 -102
- package/dist/ssr/collector.js +0 -226
- package/dist/ssr/collector.js.map +0 -1
- package/dist/ssr/context.d.ts +0 -8
- package/dist/ssr/context.js +0 -13
- package/dist/ssr/context.js.map +0 -1
- package/dist/ssr/format-global-rules.js +0 -22
- package/dist/ssr/format-global-rules.js.map +0 -1
- package/dist/ssr/format-keyframes.js +0 -69
- package/dist/ssr/format-keyframes.js.map +0 -1
- package/dist/ssr/format-property.js +0 -49
- package/dist/ssr/format-property.js.map +0 -1
- package/dist/ssr/format-rules.js +0 -73
- package/dist/ssr/format-rules.js.map +0 -1
- package/dist/ssr/hydrate.d.ts +0 -22
- package/dist/ssr/hydrate.js +0 -49
- package/dist/ssr/hydrate.js.map +0 -1
- package/dist/ssr/ssr-collector-ref.js +0 -12
- package/dist/ssr/ssr-collector-ref.js.map +0 -1
- package/dist/states/index.d.ts +0 -49
- package/dist/states/index.js +0 -170
- package/dist/states/index.js.map +0 -1
- package/dist/static/tastyStatic.d.ts +0 -46
- package/dist/static/tastyStatic.js +0 -30
- 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 -113
- package/dist/styles/border.js.map +0 -1
- package/dist/styles/color.d.ts +0 -14
- package/dist/styles/color.js +0 -26
- package/dist/styles/color.js.map +0 -1
- package/dist/styles/createStyle.js +0 -79
- package/dist/styles/createStyle.js.map +0 -1
- package/dist/styles/dimension.js +0 -96
- package/dist/styles/dimension.js.map +0 -1
- package/dist/styles/display.d.ts +0 -37
- package/dist/styles/display.js +0 -66
- package/dist/styles/display.js.map +0 -1
- package/dist/styles/fade.d.ts +0 -15
- package/dist/styles/fade.js +0 -57
- package/dist/styles/fade.js.map +0 -1
- package/dist/styles/fill.d.ts +0 -42
- 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 -36
- package/dist/styles/gap.js.map +0 -1
- package/dist/styles/height.d.ts +0 -17
- package/dist/styles/height.js +0 -19
- package/dist/styles/height.js.map +0 -1
- package/dist/styles/index.d.ts +0 -1
- package/dist/styles/index.js +0 -8
- package/dist/styles/index.js.map +0 -1
- package/dist/styles/inset.d.ts +0 -52
- package/dist/styles/inset.js +0 -149
- 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 -103
- package/dist/styles/margin.js.map +0 -1
- package/dist/styles/outline.d.ts +0 -29
- package/dist/styles/outline.js +0 -64
- package/dist/styles/outline.js.map +0 -1
- package/dist/styles/padding.d.ts +0 -24
- package/dist/styles/padding.js +0 -103
- package/dist/styles/padding.js.map +0 -1
- package/dist/styles/predefined.d.ts +0 -71
- package/dist/styles/predefined.js +0 -237
- package/dist/styles/predefined.js.map +0 -1
- package/dist/styles/preset.d.ts +0 -52
- package/dist/styles/preset.js +0 -126
- package/dist/styles/preset.js.map +0 -1
- package/dist/styles/radius.d.ts +0 -12
- package/dist/styles/radius.js +0 -71
- package/dist/styles/radius.js.map +0 -1
- package/dist/styles/scrollbar.d.ts +0 -25
- package/dist/styles/scrollbar.js +0 -46
- package/dist/styles/scrollbar.js.map +0 -1
- package/dist/styles/shadow.d.ts +0 -14
- package/dist/styles/shadow.js +0 -23
- package/dist/styles/shadow.js.map +0 -1
- package/dist/styles/transition.d.ts +0 -14
- package/dist/styles/transition.js +0 -157
- package/dist/styles/transition.js.map +0 -1
- package/dist/styles/types.d.ts +0 -549
- package/dist/styles/width.d.ts +0 -17
- package/dist/styles/width.js +0 -19
- package/dist/styles/width.js.map +0 -1
- package/dist/tasty.d.ts +0 -119
- package/dist/tasty.js +0 -231
- package/dist/tasty.js.map +0 -1
- package/dist/types.d.ts +0 -184
- package/dist/utils/cache-wrapper.js +0 -21
- 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/color-math.d.ts +0 -46
- package/dist/utils/color-math.js +0 -749
- package/dist/utils/color-math.js.map +0 -1
- package/dist/utils/color-space.d.ts +0 -5
- package/dist/utils/color-space.js +0 -228
- package/dist/utils/color-space.js.map +0 -1
- package/dist/utils/colors.d.ts +0 -5
- package/dist/utils/colors.js +0 -10
- 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/has-keys.js +0 -13
- package/dist/utils/has-keys.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 -6
- package/dist/utils/mod-attrs.js +0 -20
- package/dist/utils/mod-attrs.js.map +0 -1
- package/dist/utils/process-tokens.d.ts +0 -21
- package/dist/utils/process-tokens.js +0 -90
- 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 -146
- package/dist/utils/resolve-recipes.js.map +0 -1
- package/dist/utils/selector-transform.js +0 -32
- package/dist/utils/selector-transform.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 -99
- package/dist/utils/styles.js +0 -220
- package/dist/utils/styles.js.map +0 -1
- package/dist/utils/typography.d.ts +0 -47
- package/dist/utils/typography.js +0 -51
- 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 -73
- package/dist/zero/css-writer.js.map +0 -1
- package/dist/zero/extractor.d.ts +0 -24
- package/dist/zero/extractor.js +0 -266
- package/dist/zero/extractor.js.map +0 -1
- package/docs/PIPELINE.md +0 -519
- package/docs/runtime.md +0 -485
|
@@ -0,0 +1,746 @@
|
|
|
1
|
+
# React API
|
|
2
|
+
|
|
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).
|
|
6
|
+
|
|
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.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Component Creation
|
|
12
|
+
|
|
13
|
+
### Create a new component
|
|
14
|
+
|
|
15
|
+
```jsx
|
|
16
|
+
import { tasty } from '@tenphi/tasty';
|
|
17
|
+
|
|
18
|
+
const Card = tasty({
|
|
19
|
+
as: 'div',
|
|
20
|
+
styles: {
|
|
21
|
+
padding: '4x',
|
|
22
|
+
fill: '#white',
|
|
23
|
+
border: true,
|
|
24
|
+
radius: true,
|
|
25
|
+
},
|
|
26
|
+
styleProps: ['padding', 'fill'],
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
<Card>Hello World</Card>
|
|
30
|
+
<Card padding="6x" fill="#gray.05">Custom Card</Card>
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Extend an existing component
|
|
34
|
+
|
|
35
|
+
```jsx
|
|
36
|
+
const PrimaryButton = tasty(Button, {
|
|
37
|
+
styles: {
|
|
38
|
+
fill: '#purple',
|
|
39
|
+
color: '#white',
|
|
40
|
+
padding: '2x 4x',
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
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.
|
|
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
|
+
|
|
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`:
|
|
72
|
+
|
|
73
|
+
```jsx
|
|
74
|
+
import NextLink from 'next/link';
|
|
75
|
+
|
|
76
|
+
const Link = tasty({
|
|
77
|
+
as: NextLink,
|
|
78
|
+
styles: {
|
|
79
|
+
color: { '': '#accent-text', ':hover': '#text' },
|
|
80
|
+
textDecoration: 'underline',
|
|
81
|
+
},
|
|
82
|
+
styleProps: ['padding'],
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const Span = tasty({
|
|
86
|
+
as: 'span',
|
|
87
|
+
styles: { preset: 'strong' },
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
<Link href="/blog" padding="1x">
|
|
91
|
+
Blog
|
|
92
|
+
</Link>;
|
|
93
|
+
```
|
|
94
|
+
|
|
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.
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## Style Props
|
|
102
|
+
|
|
103
|
+
Use `styleProps` to expose style properties as direct component props:
|
|
104
|
+
|
|
105
|
+
```jsx
|
|
106
|
+
const FlexibleBox = tasty({
|
|
107
|
+
as: 'div',
|
|
108
|
+
styles: {
|
|
109
|
+
display: 'flex',
|
|
110
|
+
padding: '2x',
|
|
111
|
+
},
|
|
112
|
+
styleProps: ['gap', 'align', 'placeContent', 'fill'],
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
<FlexibleBox gap="2x" align="center" fill="#surface">
|
|
116
|
+
Content
|
|
117
|
+
</FlexibleBox>;
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Style props accept state maps, so responsive values work through the same API:
|
|
121
|
+
|
|
122
|
+
```jsx
|
|
123
|
+
<FlexibleBox
|
|
124
|
+
gap={{ '': '2x', '@tablet': '4x' }}
|
|
125
|
+
fill={{ '': '#surface', '@dark': '#surface-dark' }}
|
|
126
|
+
>
|
|
127
|
+
```
|
|
128
|
+
|
|
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).
|
|
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
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## Mod Props
|
|
154
|
+
|
|
155
|
+
Use `modProps` to expose modifier keys as direct component props instead of requiring the `mods` object:
|
|
156
|
+
|
|
157
|
+
```jsx
|
|
158
|
+
// Before: mods object
|
|
159
|
+
<Button mods={{ isLoading: true, size: 'large' }}>Submit</Button>
|
|
160
|
+
|
|
161
|
+
// After: mod props
|
|
162
|
+
<Button isLoading size="large">Submit</Button>
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Array form
|
|
166
|
+
|
|
167
|
+
List modifier key names. Types default to `ModValue` (`boolean | string | number | undefined | null`):
|
|
168
|
+
|
|
169
|
+
```jsx
|
|
170
|
+
const Button = tasty({
|
|
171
|
+
as: 'button',
|
|
172
|
+
modProps: ['isLoading', 'isSelected'] as const,
|
|
173
|
+
styles: {
|
|
174
|
+
fill: { '': '#surface', isLoading: '#surface.5' },
|
|
175
|
+
border: { '': '1bw solid #outline', isSelected: '2bw solid #primary' },
|
|
176
|
+
},
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
<Button isLoading isSelected>Submit</Button>
|
|
180
|
+
// Renders: <button data-is-loading="" data-is-selected="">Submit</button>
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Object form (typed)
|
|
184
|
+
|
|
185
|
+
Map modifier names to type descriptors for precise TypeScript types:
|
|
186
|
+
|
|
187
|
+
```tsx
|
|
188
|
+
const Button = tasty({
|
|
189
|
+
as: 'button',
|
|
190
|
+
modProps: {
|
|
191
|
+
isLoading: Boolean, // isLoading?: boolean
|
|
192
|
+
isSelected: Boolean, // isSelected?: boolean
|
|
193
|
+
size: ['small', 'medium', 'large'] as const, // size?: 'small' | 'medium' | 'large'
|
|
194
|
+
},
|
|
195
|
+
styles: {
|
|
196
|
+
padding: { '': '2x 4x', 'size=small': '1x 2x', 'size=large': '3x 6x' },
|
|
197
|
+
fill: { '': '#surface', isLoading: '#surface.5' },
|
|
198
|
+
},
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
<Button isLoading size="large">
|
|
202
|
+
Submit
|
|
203
|
+
</Button>;
|
|
204
|
+
// Renders: <button data-is-loading="" data-size="large">Submit</button>
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Available type descriptors:
|
|
208
|
+
|
|
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` |
|
|
215
|
+
|
|
216
|
+
### Merge with `mods`
|
|
217
|
+
|
|
218
|
+
Mod props and the `mods` object can be used together. Mod props take precedence:
|
|
219
|
+
|
|
220
|
+
```jsx
|
|
221
|
+
<Button mods={{ isLoading: false, extra: true }} isLoading>
|
|
222
|
+
// isLoading=true wins (from mod prop), extra=true preserved from mods
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### When to use `modProps` vs `mods`
|
|
226
|
+
|
|
227
|
+
| Use case | Recommendation |
|
|
228
|
+
| -------------------------------------------- | -------------------------------------------------------- |
|
|
229
|
+
| Component has a fixed set of known modifiers | `modProps` — cleaner API, better TypeScript autocomplete |
|
|
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 |
|
|
232
|
+
|
|
233
|
+
For architecture guidance on when to use modifiers vs `styleProps`, see [Methodology — modProps and mods](methodology.md#modprops-and-mods).
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
## Token Props
|
|
238
|
+
|
|
239
|
+
Use `tokenProps` to expose token keys as direct component props instead of requiring the `tokens` object:
|
|
240
|
+
|
|
241
|
+
```jsx
|
|
242
|
+
// Before: tokens object
|
|
243
|
+
<ProgressBar tokens={{ $progress: '75%', '#accent': '#purple' }} />
|
|
244
|
+
|
|
245
|
+
// After: token props
|
|
246
|
+
<ProgressBar progress="75%" accentColor="#purple" />
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### Array form
|
|
250
|
+
|
|
251
|
+
List prop names. Names ending in `Color` map to `#` color tokens; everything else maps to `$` custom property tokens:
|
|
252
|
+
|
|
253
|
+
```jsx
|
|
254
|
+
const ProgressBar = tasty({
|
|
255
|
+
tokenProps: ['progress', 'accentColor'] as const,
|
|
256
|
+
styles: { width: '$progress', fill: '#accent' },
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
<ProgressBar progress="75%" accentColor="#purple" />
|
|
260
|
+
// 'progress' → $progress → --progress
|
|
261
|
+
// 'accentColor' → #accent → --accent-color
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
### Object form
|
|
265
|
+
|
|
266
|
+
Map prop names to explicit `$`/`#`-prefixed token keys:
|
|
267
|
+
|
|
268
|
+
```tsx
|
|
269
|
+
const Card = tasty({
|
|
270
|
+
tokenProps: {
|
|
271
|
+
size: '$card-size',
|
|
272
|
+
color: '#card-accent',
|
|
273
|
+
},
|
|
274
|
+
styles: { padding: '$card-size', fill: '#card-accent' },
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
<Card size="4x" color="#purple" />;
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
### Merge with `tokens`
|
|
281
|
+
|
|
282
|
+
Token props and the `tokens` prop can be used together. Token props take precedence over `tokens`, which takes precedence over default `tokens` in `tasty({...})`:
|
|
283
|
+
|
|
284
|
+
```jsx
|
|
285
|
+
const Bar = tasty({
|
|
286
|
+
tokenProps: ['progress'] as const,
|
|
287
|
+
tokens: { $progress: '0%' }, // default
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
<Bar tokens={{ $progress: '50%' }} progress="90%" />
|
|
291
|
+
// progress="90%" wins (from token prop)
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
### When to use `tokenProps` vs `tokens`
|
|
295
|
+
|
|
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 |
|
|
301
|
+
|
|
302
|
+
For architecture guidance, see [Methodology — tokenProps](methodology.md#tokenprops).
|
|
303
|
+
|
|
304
|
+
---
|
|
305
|
+
|
|
306
|
+
## Variants
|
|
307
|
+
|
|
308
|
+
Define named style variations. Only CSS for variants actually used at runtime is injected:
|
|
309
|
+
|
|
310
|
+
```jsx
|
|
311
|
+
const Button = tasty({
|
|
312
|
+
styles: {
|
|
313
|
+
padding: '2x 4x',
|
|
314
|
+
border: true,
|
|
315
|
+
},
|
|
316
|
+
variants: {
|
|
317
|
+
default: { fill: '#blue', color: '#white' },
|
|
318
|
+
danger: { fill: '#red', color: '#white' },
|
|
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' },
|
|
336
|
+
},
|
|
337
|
+
variant: 'primary',
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
<Button>Save</Button>; // primary
|
|
341
|
+
<Button variant="danger">Delete</Button>;
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
### Extending Variants with Base State Maps
|
|
345
|
+
|
|
346
|
+
When base `styles` contain an extend-mode state map (an object **without** a `''` key), it is applied **after** the variant merge. This lets you add or override states across all variants without repeating yourself:
|
|
347
|
+
|
|
348
|
+
```jsx
|
|
349
|
+
const Badge = tasty({
|
|
350
|
+
styles: {
|
|
351
|
+
padding: '1x 2x',
|
|
352
|
+
border: {
|
|
353
|
+
'type=primary': '#clear',
|
|
354
|
+
},
|
|
355
|
+
},
|
|
356
|
+
variants: {
|
|
357
|
+
primary: {
|
|
358
|
+
border: { '': '#white.2', pressed: '#primary-text', disabled: '#clear' },
|
|
359
|
+
fill: { '': '#primary', hovered: '#primary-text' },
|
|
360
|
+
},
|
|
361
|
+
secondary: {
|
|
362
|
+
border: { '': '#primary.15', pressed: '#primary.3' },
|
|
363
|
+
fill: '#primary.10',
|
|
364
|
+
},
|
|
365
|
+
},
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
// Both variants get 'type=primary': '#clear' appended to their border map
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
Properties that are **not** extend-mode (simple values, state maps with `''`, `null`, `false`, selectors, sub-elements) merge with variants as before — the variant can fully replace them.
|
|
372
|
+
|
|
373
|
+
---
|
|
374
|
+
|
|
375
|
+
## Sub-element Styling
|
|
376
|
+
|
|
377
|
+
Sub-elements are inner parts of a compound component, styled via capitalized keys in `styles` and identified by `data-element` attributes in the DOM.
|
|
378
|
+
|
|
379
|
+
> Use the `elements` prop to declare sub-element components. This gives you typed, reusable sub-components (`Card.Title`, `Card.Content`) instead of manually writing `data-element` attributes.
|
|
380
|
+
|
|
381
|
+
```jsx
|
|
382
|
+
const Card = tasty({
|
|
383
|
+
styles: {
|
|
384
|
+
padding: '4x',
|
|
385
|
+
Title: { preset: 'h3', color: '#primary' },
|
|
386
|
+
Content: { color: '#text' },
|
|
387
|
+
},
|
|
388
|
+
elements: {
|
|
389
|
+
Title: 'h3',
|
|
390
|
+
Content: 'div',
|
|
391
|
+
},
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
<Card>
|
|
395
|
+
<Card.Title>Card Title</Card.Title>
|
|
396
|
+
<Card.Content>Card content</Card.Content>
|
|
397
|
+
</Card>;
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
Each entry in `elements` can be a tag name string or a config object:
|
|
401
|
+
|
|
402
|
+
```jsx
|
|
403
|
+
elements: {
|
|
404
|
+
Title: 'h3', // shorthand: tag name only
|
|
405
|
+
Icon: { as: 'span', qa: 'card-icon' }, // full form: tag + QA attribute
|
|
406
|
+
}
|
|
407
|
+
```
|
|
408
|
+
|
|
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.
|
|
410
|
+
|
|
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:
|
|
412
|
+
|
|
413
|
+
```jsx
|
|
414
|
+
const Card = tasty({
|
|
415
|
+
styles: {
|
|
416
|
+
padding: '4x',
|
|
417
|
+
Title: { preset: 'h3', color: '#primary' },
|
|
418
|
+
},
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
<Card>
|
|
422
|
+
<div data-element="Title">Card Title</div>
|
|
423
|
+
</Card>;
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
### Selector Affix (`$`)
|
|
427
|
+
|
|
428
|
+
The `$` property inside a sub-element's styles controls how its selector attaches to the root selector — combinators, HTML tags, pseudo-elements, the `@` placeholder, and more. For the full reference table and injection rules, see [DSL — Selector Affix](dsl.md#selector-affix-).
|
|
429
|
+
|
|
430
|
+
For the mental model behind sub-elements — how they share root state context and how this differs from BEM — see [Methodology — Component architecture](methodology.md#component-architecture-root--sub-elements).
|
|
431
|
+
|
|
432
|
+
---
|
|
433
|
+
|
|
434
|
+
## computeStyles
|
|
435
|
+
|
|
436
|
+
Hook-free, synchronous style computation. Can be used anywhere — including React Server Components, plain functions, and non-React code:
|
|
437
|
+
|
|
438
|
+
```tsx
|
|
439
|
+
import { computeStyles } from '@tenphi/tasty';
|
|
440
|
+
|
|
441
|
+
const { className } = computeStyles({
|
|
442
|
+
padding: '2x',
|
|
443
|
+
fill: '#surface',
|
|
444
|
+
radius: '1r',
|
|
445
|
+
});
|
|
446
|
+
```
|
|
447
|
+
|
|
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.
|
|
449
|
+
|
|
450
|
+
---
|
|
451
|
+
|
|
452
|
+
## Style Functions
|
|
453
|
+
|
|
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.
|
|
455
|
+
|
|
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).
|
|
457
|
+
|
|
458
|
+
### useStyles
|
|
459
|
+
|
|
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.
|
|
461
|
+
|
|
462
|
+
```tsx
|
|
463
|
+
import { useStyles } from '@tenphi/tasty';
|
|
464
|
+
|
|
465
|
+
function MyComponent() {
|
|
466
|
+
const { className } = useStyles({
|
|
467
|
+
padding: '2x',
|
|
468
|
+
fill: '#surface',
|
|
469
|
+
radius: '1r',
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
return <div className={className}>Styled content</div>;
|
|
473
|
+
}
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
### useGlobalStyles
|
|
477
|
+
|
|
478
|
+
Inject global styles for a CSS selector. Accepts an optional third argument with an `id` for update tracking — when the styles change, the previous injection is disposed and the new one is injected:
|
|
479
|
+
|
|
480
|
+
```tsx
|
|
481
|
+
import { useGlobalStyles } from '@tenphi/tasty';
|
|
482
|
+
|
|
483
|
+
function ThemeStyles() {
|
|
484
|
+
useGlobalStyles('.card', {
|
|
485
|
+
padding: '4x',
|
|
486
|
+
fill: '#surface',
|
|
487
|
+
radius: '1r',
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
return null;
|
|
491
|
+
}
|
|
492
|
+
```
|
|
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
|
+
|
|
514
|
+
### useRawCSS
|
|
515
|
+
|
|
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:
|
|
517
|
+
|
|
518
|
+
```tsx
|
|
519
|
+
import { useRawCSS } from '@tenphi/tasty';
|
|
520
|
+
|
|
521
|
+
function GlobalReset() {
|
|
522
|
+
useRawCSS(`
|
|
523
|
+
body { margin: 0; padding: 0; }
|
|
524
|
+
`);
|
|
525
|
+
|
|
526
|
+
return null;
|
|
527
|
+
}
|
|
528
|
+
```
|
|
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
|
+
|
|
535
|
+
### useKeyframes
|
|
536
|
+
|
|
537
|
+
Inject `@keyframes` rules and return the generated animation name:
|
|
538
|
+
|
|
539
|
+
```tsx
|
|
540
|
+
import { useKeyframes } from '@tenphi/tasty';
|
|
541
|
+
|
|
542
|
+
function Spinner() {
|
|
543
|
+
const spin = useKeyframes(
|
|
544
|
+
{
|
|
545
|
+
from: { transform: 'rotate(0deg)' },
|
|
546
|
+
to: { transform: 'rotate(360deg)' },
|
|
547
|
+
},
|
|
548
|
+
{ name: 'spin' },
|
|
549
|
+
);
|
|
550
|
+
|
|
551
|
+
return <div style={{ animation: `${spin} 1s linear infinite` }} />;
|
|
552
|
+
}
|
|
553
|
+
```
|
|
554
|
+
|
|
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:
|
|
556
|
+
|
|
557
|
+
```tsx
|
|
558
|
+
function Pulse({ scale }: { scale: number }) {
|
|
559
|
+
const pulse = useKeyframes(
|
|
560
|
+
() => ({
|
|
561
|
+
'0%': { transform: 'scale(1)' },
|
|
562
|
+
'100%': { transform: `scale(${scale})` },
|
|
563
|
+
}),
|
|
564
|
+
[scale],
|
|
565
|
+
{ name: 'pulse' },
|
|
566
|
+
);
|
|
567
|
+
|
|
568
|
+
return (
|
|
569
|
+
<div
|
|
570
|
+
style={{ animation: `${pulse} 500ms ease-in-out alternate infinite` }}
|
|
571
|
+
/>
|
|
572
|
+
);
|
|
573
|
+
}
|
|
574
|
+
```
|
|
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
|
+
|
|
582
|
+
### useProperty
|
|
583
|
+
|
|
584
|
+
Register a CSS `@property` rule so a custom property can animate smoothly:
|
|
585
|
+
|
|
586
|
+
```tsx
|
|
587
|
+
import { useProperty } from '@tenphi/tasty';
|
|
588
|
+
|
|
589
|
+
function Spinner() {
|
|
590
|
+
useProperty('$rotation', {
|
|
591
|
+
syntax: '<angle>',
|
|
592
|
+
inherits: false,
|
|
593
|
+
initialValue: '0deg',
|
|
594
|
+
});
|
|
595
|
+
|
|
596
|
+
return <div style={{ transform: 'rotate(var(--rotation))' }} />;
|
|
597
|
+
}
|
|
598
|
+
```
|
|
599
|
+
|
|
600
|
+
`useProperty()` accepts Tasty token syntax for the property name:
|
|
601
|
+
|
|
602
|
+
- `$name` defines `--name`
|
|
603
|
+
- `#name` defines `--name-color` and auto-infers `<color>`
|
|
604
|
+
- `--name` is also supported for existing CSS variables
|
|
605
|
+
|
|
606
|
+
### useFontFace
|
|
607
|
+
|
|
608
|
+
Inject `@font-face` rules for custom fonts. Permanent — no cleanup on unmount. Deduplicates by content.
|
|
609
|
+
|
|
610
|
+
```tsx
|
|
611
|
+
import { useFontFace } from '@tenphi/tasty';
|
|
612
|
+
|
|
613
|
+
function App() {
|
|
614
|
+
useFontFace('Brand Sans', {
|
|
615
|
+
src: 'url("/fonts/brand-sans.woff2") format("woff2")',
|
|
616
|
+
fontWeight: '400 700',
|
|
617
|
+
fontDisplay: 'swap',
|
|
618
|
+
});
|
|
619
|
+
|
|
620
|
+
return <div style={{ fontFamily: '"Brand Sans", sans-serif' }}>Hello</div>;
|
|
621
|
+
}
|
|
622
|
+
```
|
|
623
|
+
|
|
624
|
+
For multiple weights/styles, pass an array:
|
|
625
|
+
|
|
626
|
+
```tsx
|
|
627
|
+
useFontFace('Brand Sans', [
|
|
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
|
+
},
|
|
638
|
+
]);
|
|
639
|
+
```
|
|
640
|
+
|
|
641
|
+
Signature:
|
|
642
|
+
|
|
643
|
+
```ts
|
|
644
|
+
function useFontFace(
|
|
645
|
+
family: string,
|
|
646
|
+
input: FontFaceInput,
|
|
647
|
+
options?: { root?: Document | ShadowRoot },
|
|
648
|
+
): void;
|
|
649
|
+
```
|
|
650
|
+
|
|
651
|
+
### useCounterStyle
|
|
652
|
+
|
|
653
|
+
Inject a `@counter-style` rule and get back the counter style name. Permanent — no cleanup on unmount. Deduplicates by name.
|
|
654
|
+
|
|
655
|
+
```tsx
|
|
656
|
+
import { useCounterStyle } from '@tenphi/tasty';
|
|
657
|
+
|
|
658
|
+
function EmojiList() {
|
|
659
|
+
const styleName = useCounterStyle(
|
|
660
|
+
{
|
|
661
|
+
system: 'cyclic',
|
|
662
|
+
symbols: '"👍"',
|
|
663
|
+
suffix: '" "',
|
|
664
|
+
},
|
|
665
|
+
{ name: 'thumbs' },
|
|
666
|
+
);
|
|
667
|
+
|
|
668
|
+
return (
|
|
669
|
+
<ol style={{ listStyleType: styleName }}>
|
|
670
|
+
<li>First</li>
|
|
671
|
+
<li>Second</li>
|
|
672
|
+
</ol>
|
|
673
|
+
);
|
|
674
|
+
}
|
|
675
|
+
```
|
|
676
|
+
|
|
677
|
+
Signature:
|
|
678
|
+
|
|
679
|
+
```ts
|
|
680
|
+
function useCounterStyle(
|
|
681
|
+
descriptors: CounterStyleDescriptors,
|
|
682
|
+
options?: { name?: string; root?: Document | ShadowRoot },
|
|
683
|
+
): string;
|
|
684
|
+
```
|
|
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
|
+
|
|
726
|
+
### Troubleshooting
|
|
727
|
+
|
|
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).
|
|
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).
|
|
731
|
+
- Animation/custom property issues: prefer `useKeyframes()` and `useProperty()` over raw CSS when you want Tasty to manage injection and SSR collection for you.
|
|
732
|
+
- For dynamic styles that change over the component lifecycle, use the `id` option in `useGlobalStyles()` and `useRawCSS()` to enable update tracking.
|
|
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.
|
|
734
|
+
|
|
735
|
+
---
|
|
736
|
+
|
|
737
|
+
## Learn more
|
|
738
|
+
|
|
739
|
+
- **[Style DSL](dsl.md)** — State maps, tokens, units, extending semantics, keyframes, @property
|
|
740
|
+
- **[Methodology](methodology.md)** — Recommended patterns: root + sub-elements, styleProps, tokens, wrapping
|
|
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
|
|
743
|
+
- **[Style Properties](styles.md)** — Complete reference for all enhanced style properties
|
|
744
|
+
- **[Build-Time Extraction (`tastyStatic`)](tasty-static.md)** — Static styling with the Babel plugin
|
|
745
|
+
- **[Server-Side Rendering](ssr.md)** — SSR setup for Next.js, Astro, and generic frameworks
|
|
746
|
+
- **[Debug Utilities](debug.md)** — Inspect injected CSS, cache state, and active styles at runtime
|