@tenphi/tasty 0.0.0-snapshot.fafcbfe → 0.0.0-snapshot.fdb16ea
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 +397 -185
- package/dist/async-storage-DKK-wTD4.js +44 -0
- package/dist/async-storage-DKK-wTD4.js.map +1 -0
- package/dist/babel-CMYf4JZ2.d.ts +83 -0
- package/dist/collector-Ctn5s74s.d.ts +145 -0
- package/dist/collector-DMSR6ANK.js +304 -0
- package/dist/collector-DMSR6ANK.js.map +1 -0
- package/dist/config-B23gZrfP.js +12317 -0
- package/dist/config-B23gZrfP.js.map +1 -0
- package/dist/config-CZx8_DCu.d.ts +1296 -0
- package/dist/context-CA8YKeMn.js +24 -0
- package/dist/context-CA8YKeMn.js.map +1 -0
- package/dist/core/index.d.ts +5 -33
- package/dist/core/index.js +6 -26
- package/dist/core-B1tyn69d.js +1573 -0
- package/dist/core-B1tyn69d.js.map +1 -0
- package/dist/css-writer-CvAxkR6S.js +390 -0
- package/dist/css-writer-CvAxkR6S.js.map +1 -0
- package/dist/format-global-rules-DklyaXv-.js +22 -0
- package/dist/format-global-rules-DklyaXv-.js.map +1 -0
- package/dist/format-rules-BCTWVvcS.js +130 -0
- package/dist/format-rules-BCTWVvcS.js.map +1 -0
- package/dist/hydrate-BCPvkJj3.js +37 -0
- package/dist/hydrate-BCPvkJj3.js.map +1 -0
- package/dist/index-B3o0aCYV.d.ts +1538 -0
- package/dist/index-CsvB0EXZ.d.ts +1909 -0
- package/dist/index.d.ts +5 -40
- package/dist/index.js +921 -32
- package/dist/index.js.map +1 -0
- package/dist/keyframes-Dxdx3KOo.js +493 -0
- package/dist/keyframes-Dxdx3KOo.js.map +1 -0
- package/dist/{utils/merge-styles.js → merge-styles-C-uwpoNW.js} +4 -6
- package/dist/merge-styles-C-uwpoNW.js.map +1 -0
- package/dist/{utils/merge-styles.d.ts → merge-styles-DJTSfz_M.d.ts} +3 -3
- package/dist/{utils/resolve-recipes.js → resolve-recipes-BuOvSEa2.js} +5 -8
- package/dist/resolve-recipes-BuOvSEa2.js.map +1 -0
- package/dist/ssr/astro-client.d.ts +1 -0
- package/dist/ssr/astro-client.js +19 -0
- package/dist/ssr/astro-client.js.map +1 -0
- package/dist/ssr/astro-middleware-static.d.ts +16 -0
- package/dist/ssr/astro-middleware-static.js +18 -0
- package/dist/ssr/astro-middleware-static.js.map +1 -0
- package/dist/ssr/astro-middleware.d.ts +17 -0
- package/dist/ssr/astro-middleware.js +19 -0
- package/dist/ssr/astro-middleware.js.map +1 -0
- package/dist/ssr/astro.d.ts +93 -0
- package/dist/ssr/astro.js +157 -0
- package/dist/ssr/astro.js.map +1 -0
- package/dist/ssr/index.d.ts +37 -0
- package/dist/ssr/index.js +10 -0
- package/dist/ssr/index.js.map +1 -0
- package/dist/ssr/next.d.ts +45 -0
- package/dist/ssr/next.js +74 -0
- package/dist/ssr/next.js.map +1 -0
- package/dist/static/index.d.ts +91 -5
- package/dist/static/index.js +49 -4
- package/dist/static/index.js.map +1 -0
- package/dist/static/inject.d.ts +5 -0
- package/dist/static/inject.js +17 -0
- package/dist/static/inject.js.map +1 -0
- package/dist/zero/babel.d.ts +2 -108
- package/dist/zero/babel.js +235 -39
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/index.d.ts +81 -3
- package/dist/zero/index.js +2 -4
- package/dist/zero/next.d.ts +56 -30
- package/dist/zero/next.js +106 -41
- package/dist/zero/next.js.map +1 -1
- package/docs/README.md +39 -0
- package/docs/adoption.md +323 -0
- package/docs/ai-agents.md +224 -0
- package/docs/comparison.md +448 -0
- package/docs/configuration.md +823 -0
- package/docs/debug.md +322 -0
- package/docs/design-system.md +455 -0
- package/docs/dsl.md +1021 -0
- package/docs/getting-started.md +238 -0
- package/docs/injector.md +614 -0
- package/docs/methodology.md +648 -0
- package/docs/migration-v3.md +285 -0
- package/docs/pipeline.md +741 -0
- package/docs/plugins.md +353 -0
- package/docs/react-api.md +681 -0
- package/docs/runtime-benchmarks.md +216 -0
- package/docs/ssr.md +451 -0
- package/docs/styles.md +645 -0
- package/docs/tasty-static.md +582 -0
- package/package.json +149 -40
- package/tasty.config.ts +6 -0
- package/dist/_virtual/_rolldown/runtime.js +0 -8
- package/dist/chunks/cacheKey.js +0 -70
- package/dist/chunks/cacheKey.js.map +0 -1
- package/dist/chunks/definitions.d.ts +0 -37
- package/dist/chunks/definitions.js +0 -260
- package/dist/chunks/definitions.js.map +0 -1
- package/dist/chunks/renderChunk.js +0 -61
- package/dist/chunks/renderChunk.js.map +0 -1
- package/dist/config.d.ts +0 -280
- package/dist/config.js +0 -403
- package/dist/config.js.map +0 -1
- package/dist/debug.d.ts +0 -204
- package/dist/debug.js +0 -733
- package/dist/debug.js.map +0 -1
- package/dist/hooks/useGlobalStyles.d.ts +0 -27
- package/dist/hooks/useGlobalStyles.js +0 -56
- package/dist/hooks/useGlobalStyles.js.map +0 -1
- package/dist/hooks/useKeyframes.d.ts +0 -56
- package/dist/hooks/useKeyframes.js +0 -54
- package/dist/hooks/useKeyframes.js.map +0 -1
- package/dist/hooks/useProperty.d.ts +0 -79
- package/dist/hooks/useProperty.js +0 -91
- package/dist/hooks/useProperty.js.map +0 -1
- package/dist/hooks/useRawCSS.d.ts +0 -53
- package/dist/hooks/useRawCSS.js +0 -28
- package/dist/hooks/useRawCSS.js.map +0 -1
- package/dist/hooks/useStyles.d.ts +0 -40
- package/dist/hooks/useStyles.js +0 -169
- package/dist/hooks/useStyles.js.map +0 -1
- package/dist/injector/index.d.ts +0 -157
- package/dist/injector/index.js +0 -154
- package/dist/injector/index.js.map +0 -1
- package/dist/injector/injector.d.ts +0 -139
- package/dist/injector/injector.js +0 -404
- package/dist/injector/injector.js.map +0 -1
- package/dist/injector/sheet-manager.d.ts +0 -127
- package/dist/injector/sheet-manager.js +0 -714
- package/dist/injector/sheet-manager.js.map +0 -1
- package/dist/injector/types.d.ts +0 -135
- package/dist/keyframes/index.js +0 -206
- package/dist/keyframes/index.js.map +0 -1
- package/dist/parser/classify.js +0 -319
- package/dist/parser/classify.js.map +0 -1
- package/dist/parser/const.js +0 -33
- package/dist/parser/const.js.map +0 -1
- package/dist/parser/lru.js +0 -109
- package/dist/parser/lru.js.map +0 -1
- package/dist/parser/parser.d.ts +0 -25
- package/dist/parser/parser.js +0 -116
- package/dist/parser/parser.js.map +0 -1
- package/dist/parser/tokenizer.js +0 -69
- package/dist/parser/tokenizer.js.map +0 -1
- package/dist/parser/types.d.ts +0 -51
- package/dist/parser/types.js +0 -46
- package/dist/parser/types.js.map +0 -1
- package/dist/pipeline/conditions.d.ts +0 -134
- package/dist/pipeline/conditions.js +0 -400
- package/dist/pipeline/conditions.js.map +0 -1
- package/dist/pipeline/exclusive.js +0 -231
- package/dist/pipeline/exclusive.js.map +0 -1
- package/dist/pipeline/index.d.ts +0 -53
- package/dist/pipeline/index.js +0 -641
- package/dist/pipeline/index.js.map +0 -1
- package/dist/pipeline/materialize.js +0 -908
- package/dist/pipeline/materialize.js.map +0 -1
- package/dist/pipeline/parseStateKey.d.ts +0 -15
- package/dist/pipeline/parseStateKey.js +0 -430
- package/dist/pipeline/parseStateKey.js.map +0 -1
- package/dist/pipeline/simplify.js +0 -557
- package/dist/pipeline/simplify.js.map +0 -1
- package/dist/plugins/okhsl-plugin.d.ts +0 -35
- package/dist/plugins/okhsl-plugin.js +0 -371
- package/dist/plugins/okhsl-plugin.js.map +0 -1
- package/dist/plugins/types.d.ts +0 -69
- package/dist/properties/index.js +0 -158
- package/dist/properties/index.js.map +0 -1
- package/dist/states/index.d.ts +0 -49
- package/dist/states/index.js +0 -416
- package/dist/states/index.js.map +0 -1
- package/dist/static/tastyStatic.d.ts +0 -46
- package/dist/static/tastyStatic.js +0 -31
- package/dist/static/tastyStatic.js.map +0 -1
- package/dist/static/types.d.ts +0 -49
- package/dist/static/types.js +0 -24
- package/dist/static/types.js.map +0 -1
- package/dist/styles/align.d.ts +0 -15
- package/dist/styles/align.js +0 -14
- package/dist/styles/align.js.map +0 -1
- package/dist/styles/border.d.ts +0 -25
- package/dist/styles/border.js +0 -114
- package/dist/styles/border.js.map +0 -1
- package/dist/styles/color.d.ts +0 -14
- package/dist/styles/color.js +0 -23
- package/dist/styles/color.js.map +0 -1
- package/dist/styles/createStyle.js +0 -77
- package/dist/styles/createStyle.js.map +0 -1
- package/dist/styles/dimension.js +0 -97
- package/dist/styles/dimension.js.map +0 -1
- package/dist/styles/display.d.ts +0 -37
- package/dist/styles/display.js +0 -67
- package/dist/styles/display.js.map +0 -1
- package/dist/styles/fade.d.ts +0 -15
- package/dist/styles/fade.js +0 -58
- package/dist/styles/fade.js.map +0 -1
- package/dist/styles/fill.d.ts +0 -44
- package/dist/styles/fill.js +0 -51
- package/dist/styles/fill.js.map +0 -1
- package/dist/styles/flow.d.ts +0 -16
- package/dist/styles/flow.js +0 -12
- package/dist/styles/flow.js.map +0 -1
- package/dist/styles/gap.d.ts +0 -31
- package/dist/styles/gap.js +0 -37
- package/dist/styles/gap.js.map +0 -1
- package/dist/styles/height.d.ts +0 -17
- package/dist/styles/height.js +0 -20
- package/dist/styles/height.js.map +0 -1
- package/dist/styles/index.d.ts +0 -2
- package/dist/styles/index.js +0 -9
- package/dist/styles/index.js.map +0 -1
- package/dist/styles/inset.d.ts +0 -52
- package/dist/styles/inset.js +0 -150
- package/dist/styles/inset.js.map +0 -1
- package/dist/styles/justify.d.ts +0 -15
- package/dist/styles/justify.js +0 -14
- package/dist/styles/justify.js.map +0 -1
- package/dist/styles/list.d.ts +0 -16
- package/dist/styles/list.js +0 -98
- package/dist/styles/list.js.map +0 -1
- package/dist/styles/margin.d.ts +0 -24
- package/dist/styles/margin.js +0 -104
- package/dist/styles/margin.js.map +0 -1
- package/dist/styles/outline.d.ts +0 -29
- package/dist/styles/outline.js +0 -65
- package/dist/styles/outline.js.map +0 -1
- package/dist/styles/padding.d.ts +0 -24
- package/dist/styles/padding.js +0 -104
- package/dist/styles/padding.js.map +0 -1
- package/dist/styles/predefined.d.ts +0 -73
- package/dist/styles/predefined.js +0 -241
- package/dist/styles/predefined.js.map +0 -1
- package/dist/styles/preset.d.ts +0 -47
- package/dist/styles/preset.js +0 -126
- package/dist/styles/preset.js.map +0 -1
- package/dist/styles/radius.d.ts +0 -14
- package/dist/styles/radius.js +0 -51
- package/dist/styles/radius.js.map +0 -1
- package/dist/styles/scrollbar.d.ts +0 -21
- package/dist/styles/scrollbar.js +0 -105
- package/dist/styles/scrollbar.js.map +0 -1
- package/dist/styles/shadow.d.ts +0 -14
- package/dist/styles/shadow.js +0 -24
- package/dist/styles/shadow.js.map +0 -1
- package/dist/styles/styledScrollbar.d.ts +0 -47
- package/dist/styles/styledScrollbar.js +0 -38
- package/dist/styles/styledScrollbar.js.map +0 -1
- package/dist/styles/transition.d.ts +0 -14
- package/dist/styles/transition.js +0 -158
- package/dist/styles/transition.js.map +0 -1
- package/dist/styles/types.d.ts +0 -498
- package/dist/styles/width.d.ts +0 -17
- package/dist/styles/width.js +0 -20
- package/dist/styles/width.js.map +0 -1
- package/dist/tasty.d.ts +0 -982
- package/dist/tasty.js +0 -191
- package/dist/tasty.js.map +0 -1
- package/dist/tokens/typography.d.ts +0 -19
- package/dist/tokens/typography.js +0 -237
- package/dist/tokens/typography.js.map +0 -1
- package/dist/types.d.ts +0 -184
- package/dist/utils/cache-wrapper.js +0 -26
- package/dist/utils/cache-wrapper.js.map +0 -1
- package/dist/utils/case-converter.js +0 -8
- package/dist/utils/case-converter.js.map +0 -1
- package/dist/utils/colors.d.ts +0 -5
- package/dist/utils/colors.js +0 -9
- package/dist/utils/colors.js.map +0 -1
- package/dist/utils/css-types.d.ts +0 -7
- package/dist/utils/dotize.d.ts +0 -26
- package/dist/utils/dotize.js +0 -122
- package/dist/utils/dotize.js.map +0 -1
- package/dist/utils/filter-base-props.d.ts +0 -15
- package/dist/utils/filter-base-props.js +0 -45
- package/dist/utils/filter-base-props.js.map +0 -1
- package/dist/utils/get-display-name.d.ts +0 -7
- package/dist/utils/get-display-name.js +0 -10
- package/dist/utils/get-display-name.js.map +0 -1
- package/dist/utils/hsl-to-rgb.js +0 -38
- package/dist/utils/hsl-to-rgb.js.map +0 -1
- package/dist/utils/is-dev-env.js +0 -19
- package/dist/utils/is-dev-env.js.map +0 -1
- package/dist/utils/is-valid-element-type.js +0 -15
- package/dist/utils/is-valid-element-type.js.map +0 -1
- package/dist/utils/merge-styles.js.map +0 -1
- package/dist/utils/mod-attrs.d.ts +0 -8
- package/dist/utils/mod-attrs.js +0 -21
- package/dist/utils/mod-attrs.js.map +0 -1
- package/dist/utils/okhsl-to-rgb.js +0 -296
- package/dist/utils/okhsl-to-rgb.js.map +0 -1
- package/dist/utils/process-tokens.d.ts +0 -31
- package/dist/utils/process-tokens.js +0 -171
- package/dist/utils/process-tokens.js.map +0 -1
- package/dist/utils/resolve-recipes.d.ts +0 -17
- package/dist/utils/resolve-recipes.js.map +0 -1
- package/dist/utils/string.js +0 -8
- package/dist/utils/string.js.map +0 -1
- package/dist/utils/styles.d.ts +0 -183
- package/dist/utils/styles.js +0 -585
- package/dist/utils/styles.js.map +0 -1
- package/dist/utils/typography.d.ts +0 -36
- package/dist/utils/typography.js +0 -53
- package/dist/utils/typography.js.map +0 -1
- package/dist/utils/warnings.d.ts +0 -16
- package/dist/utils/warnings.js +0 -16
- package/dist/utils/warnings.js.map +0 -1
- package/dist/zero/css-writer.d.ts +0 -45
- package/dist/zero/css-writer.js +0 -74
- package/dist/zero/css-writer.js.map +0 -1
- package/dist/zero/extractor.d.ts +0 -24
- package/dist/zero/extractor.js +0 -150
- package/dist/zero/extractor.js.map +0 -1
|
@@ -0,0 +1,681 @@
|
|
|
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
|
+
All Tasty style functions — `tasty()` components, `useStyles()`, `useGlobalStyles()`, `useRawCSS()`, `useKeyframes()`, `useProperty()`, `useFontFace()`, `useCounterStyle()`, and `useFunction()` — are hook-free and compatible with React Server Components. No `'use client'` directive is needed. 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
|
+
`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`:
|
|
48
|
+
|
|
49
|
+
```jsx
|
|
50
|
+
import NextLink from 'next/link';
|
|
51
|
+
|
|
52
|
+
const Link = tasty({
|
|
53
|
+
as: NextLink,
|
|
54
|
+
styles: {
|
|
55
|
+
color: { '': '#accent-text', ':hover': '#text' },
|
|
56
|
+
textDecoration: 'underline',
|
|
57
|
+
},
|
|
58
|
+
styleProps: ['padding'],
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const Span = tasty({
|
|
62
|
+
as: 'span',
|
|
63
|
+
styles: { preset: 'strong' },
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
<Link href="/blog" padding="1x">
|
|
67
|
+
Blog
|
|
68
|
+
</Link>;
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
The wrapped component only needs to forward `className` (and ideally `style`/`ref`). Tasty-specific props (`qa`, `qaVal`, `mods`, `tokens`, `styleProps`, `modProps`, `tokenProps`) are consumed by Tasty and never leak to the DOM.
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## Style Props
|
|
76
|
+
|
|
77
|
+
Use `styleProps` to expose style properties as direct component props:
|
|
78
|
+
|
|
79
|
+
```jsx
|
|
80
|
+
const FlexibleBox = tasty({
|
|
81
|
+
as: 'div',
|
|
82
|
+
styles: {
|
|
83
|
+
display: 'flex',
|
|
84
|
+
padding: '2x',
|
|
85
|
+
},
|
|
86
|
+
styleProps: ['gap', 'align', 'placeContent', 'fill'],
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
<FlexibleBox gap="2x" align="center" fill="#surface">
|
|
90
|
+
Content
|
|
91
|
+
</FlexibleBox>;
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Style props accept state maps, so responsive values work through the same API:
|
|
95
|
+
|
|
96
|
+
```jsx
|
|
97
|
+
<FlexibleBox
|
|
98
|
+
gap={{ '': '2x', '@tablet': '4x' }}
|
|
99
|
+
fill={{ '': '#surface', '@dark': '#surface-dark' }}
|
|
100
|
+
>
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
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).
|
|
104
|
+
|
|
105
|
+
### Always-available style props
|
|
106
|
+
|
|
107
|
+
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).
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## `Element`
|
|
112
|
+
|
|
113
|
+
`Element` is the unstyled base component exported from the main entry — equivalent to `tasty({})` (a `div` with no default styles). It accepts all Tasty props (`styles`, `styleProps`, `mods`, `tokens`, `as`, `qa`, `theme`, the `is*` props, etc.) and is useful as a generic styled box or as a building block for layout primitives.
|
|
114
|
+
|
|
115
|
+
```jsx
|
|
116
|
+
import { Element } from '@tenphi/tasty';
|
|
117
|
+
|
|
118
|
+
<Element as="section" padding="4x" fill="#surface">
|
|
119
|
+
Content
|
|
120
|
+
</Element>;
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
> 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'`.
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## Mod Props
|
|
128
|
+
|
|
129
|
+
Use `modProps` to expose modifier keys as direct component props instead of requiring the `mods` object:
|
|
130
|
+
|
|
131
|
+
```jsx
|
|
132
|
+
// Before: mods object
|
|
133
|
+
<Button mods={{ isLoading: true, size: 'large' }}>Submit</Button>
|
|
134
|
+
|
|
135
|
+
// After: mod props
|
|
136
|
+
<Button isLoading size="large">Submit</Button>
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Array form
|
|
140
|
+
|
|
141
|
+
List modifier key names. Types default to `ModValue` (`boolean | string | number | undefined | null`):
|
|
142
|
+
|
|
143
|
+
```jsx
|
|
144
|
+
const Button = tasty({
|
|
145
|
+
modProps: ['isLoading', 'isSelected'] as const,
|
|
146
|
+
styles: {
|
|
147
|
+
fill: { '': '#surface', isLoading: '#surface.5' },
|
|
148
|
+
border: { '': '1bw solid #outline', isSelected: '2bw solid #primary' },
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
<Button isLoading isSelected>Submit</Button>
|
|
153
|
+
// Renders: <button data-is-loading="" data-is-selected="">Submit</button>
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Object form (typed)
|
|
157
|
+
|
|
158
|
+
Map modifier names to type descriptors for precise TypeScript types:
|
|
159
|
+
|
|
160
|
+
```tsx
|
|
161
|
+
const Button = tasty({
|
|
162
|
+
modProps: {
|
|
163
|
+
isLoading: Boolean, // isLoading?: boolean
|
|
164
|
+
isSelected: Boolean, // isSelected?: boolean
|
|
165
|
+
size: ['small', 'medium', 'large'] as const, // size?: 'small' | 'medium' | 'large'
|
|
166
|
+
},
|
|
167
|
+
styles: {
|
|
168
|
+
padding: { '': '2x 4x', 'size=small': '1x 2x', 'size=large': '3x 6x' },
|
|
169
|
+
fill: { '': '#surface', isLoading: '#surface.5' },
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
<Button isLoading size="large">
|
|
174
|
+
Submit
|
|
175
|
+
</Button>;
|
|
176
|
+
// Renders: <button data-is-loading="" data-size="large">Submit</button>
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Available type descriptors:
|
|
180
|
+
|
|
181
|
+
| Descriptor | TypeScript type | Example |
|
|
182
|
+
| --------------------- | --------------- | ----------------------------------- |
|
|
183
|
+
| `Boolean` | `boolean` | `isLoading: Boolean` |
|
|
184
|
+
| `String` | `string` | `label: String` |
|
|
185
|
+
| `Number` | `number` | `count: Number` |
|
|
186
|
+
| `['a', 'b'] as const` | `'a' \| 'b'` | `size: ['sm', 'md', 'lg'] as const` |
|
|
187
|
+
|
|
188
|
+
### Merge with `mods`
|
|
189
|
+
|
|
190
|
+
Mod props and the `mods` object can be used together. Mod props take precedence:
|
|
191
|
+
|
|
192
|
+
```jsx
|
|
193
|
+
<Button mods={{ isLoading: false, extra: true }} isLoading>
|
|
194
|
+
// isLoading=true wins (from mod prop), extra=true preserved from mods
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### When to use `modProps` vs `mods`
|
|
198
|
+
|
|
199
|
+
| Use case | Recommendation |
|
|
200
|
+
| -------------------------------------------- | -------------------------------------------------------- |
|
|
201
|
+
| Component has a fixed set of known modifiers | `modProps` — cleaner API, better TypeScript autocomplete |
|
|
202
|
+
| Component needs arbitrary/dynamic modifiers | `mods` — open-ended `Record<string, ModValue>` |
|
|
203
|
+
| Both fixed and dynamic | Combine: `modProps` for known keys, `mods` for ad-hoc |
|
|
204
|
+
|
|
205
|
+
For architecture guidance on when to use modifiers vs `styleProps`, see [Methodology — modProps and mods](methodology.md#modprops-and-mods).
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
## Token Props
|
|
210
|
+
|
|
211
|
+
Use `tokenProps` to expose token keys as direct component props instead of requiring the `tokens` object:
|
|
212
|
+
|
|
213
|
+
```jsx
|
|
214
|
+
// Before: tokens object
|
|
215
|
+
<ProgressBar tokens={{ $progress: '75%', '#accent': '#purple' }} />
|
|
216
|
+
|
|
217
|
+
// After: token props
|
|
218
|
+
<ProgressBar progress="75%" accentColor="#purple" />
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### Array form
|
|
222
|
+
|
|
223
|
+
List prop names. Names ending in `Color` map to `#` color tokens; everything else maps to `$` custom property tokens:
|
|
224
|
+
|
|
225
|
+
```jsx
|
|
226
|
+
const ProgressBar = tasty({
|
|
227
|
+
tokenProps: ['progress', 'accentColor'] as const,
|
|
228
|
+
styles: { width: '$progress', fill: '#accent' },
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
<ProgressBar progress="75%" accentColor="#purple" />
|
|
232
|
+
// 'progress' → $progress → --progress
|
|
233
|
+
// 'accentColor' → #accent → --accent-color
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### Object form
|
|
237
|
+
|
|
238
|
+
Map prop names to explicit `$`/`#`-prefixed token keys:
|
|
239
|
+
|
|
240
|
+
```tsx
|
|
241
|
+
const Card = tasty({
|
|
242
|
+
tokenProps: {
|
|
243
|
+
size: '$card-size',
|
|
244
|
+
color: '#card-accent',
|
|
245
|
+
},
|
|
246
|
+
styles: { padding: '$card-size', fill: '#card-accent' },
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
<Card size="4x" color="#purple" />;
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
### Merge with `tokens`
|
|
253
|
+
|
|
254
|
+
Token props and the `tokens` prop can be used together. Token props take precedence over `tokens`, which takes precedence over default `tokens` in `tasty({...})`:
|
|
255
|
+
|
|
256
|
+
```jsx
|
|
257
|
+
const Bar = tasty({
|
|
258
|
+
tokenProps: ['progress'] as const,
|
|
259
|
+
tokens: { $progress: '0%' }, // default
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
<Bar tokens={{ $progress: '50%' }} progress="90%" />
|
|
263
|
+
// progress="90%" wins (from token prop)
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
### When to use `tokenProps` vs `tokens`
|
|
267
|
+
|
|
268
|
+
| Use case | Recommendation |
|
|
269
|
+
| ---------------------------------------------- | ---------------------------------------------------------- |
|
|
270
|
+
| Component has a fixed set of known token keys | `tokenProps` — cleaner API, better TypeScript autocomplete |
|
|
271
|
+
| Component needs arbitrary/dynamic token values | `tokens` — open-ended `Record<string, TokenValue>` |
|
|
272
|
+
| Both fixed and dynamic | Combine: `tokenProps` for known keys, `tokens` for ad-hoc |
|
|
273
|
+
|
|
274
|
+
For architecture guidance, see [Methodology — tokenProps](methodology.md#tokenprops).
|
|
275
|
+
|
|
276
|
+
---
|
|
277
|
+
|
|
278
|
+
## Variants
|
|
279
|
+
|
|
280
|
+
Define named style variations. Only CSS for variants actually used at runtime is injected:
|
|
281
|
+
|
|
282
|
+
```jsx
|
|
283
|
+
const Button = tasty({
|
|
284
|
+
styles: {
|
|
285
|
+
padding: '2x 4x',
|
|
286
|
+
border: true,
|
|
287
|
+
},
|
|
288
|
+
variants: {
|
|
289
|
+
default: { fill: '#blue', color: '#white' },
|
|
290
|
+
danger: { fill: '#red', color: '#white' },
|
|
291
|
+
outline: { fill: '#clear', color: '#blue', border: '1bw solid #blue' },
|
|
292
|
+
},
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
<Button variant="danger">Delete</Button>;
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
### Extending Variants with Base State Maps
|
|
299
|
+
|
|
300
|
+
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:
|
|
301
|
+
|
|
302
|
+
```jsx
|
|
303
|
+
const Badge = tasty({
|
|
304
|
+
styles: {
|
|
305
|
+
padding: '1x 2x',
|
|
306
|
+
border: {
|
|
307
|
+
'type=primary': '#clear',
|
|
308
|
+
},
|
|
309
|
+
},
|
|
310
|
+
variants: {
|
|
311
|
+
primary: {
|
|
312
|
+
border: { '': '#white.2', pressed: '#primary-text', disabled: '#clear' },
|
|
313
|
+
fill: { '': '#white #primary', hovered: '#white #primary-text' },
|
|
314
|
+
},
|
|
315
|
+
secondary: {
|
|
316
|
+
border: { '': '#primary.15', pressed: '#primary.3' },
|
|
317
|
+
fill: '#primary.10',
|
|
318
|
+
},
|
|
319
|
+
},
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
// Both variants get 'type=primary': '#clear' appended to their border map
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
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.
|
|
326
|
+
|
|
327
|
+
---
|
|
328
|
+
|
|
329
|
+
## Sub-element Styling
|
|
330
|
+
|
|
331
|
+
Sub-elements are inner parts of a compound component, styled via capitalized keys in `styles` and identified by `data-element` attributes in the DOM.
|
|
332
|
+
|
|
333
|
+
> 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.
|
|
334
|
+
|
|
335
|
+
```jsx
|
|
336
|
+
const Card = tasty({
|
|
337
|
+
styles: {
|
|
338
|
+
padding: '4x',
|
|
339
|
+
Title: { preset: 'h3', color: '#primary' },
|
|
340
|
+
Content: { color: '#text' },
|
|
341
|
+
},
|
|
342
|
+
elements: {
|
|
343
|
+
Title: 'h3',
|
|
344
|
+
Content: 'div',
|
|
345
|
+
},
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
<Card>
|
|
349
|
+
<Card.Title>Card Title</Card.Title>
|
|
350
|
+
<Card.Content>Card content</Card.Content>
|
|
351
|
+
</Card>;
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
Each entry in `elements` can be a tag name string or a config object:
|
|
355
|
+
|
|
356
|
+
```jsx
|
|
357
|
+
elements: {
|
|
358
|
+
Title: 'h3', // shorthand: tag name only
|
|
359
|
+
Icon: { as: 'span', qa: 'card-icon' }, // full form: tag + QA attribute
|
|
360
|
+
}
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
The sub-components produced by `elements` support `mods`, `tokens`, `isDisabled`, `isHidden`, and `isChecked` props — the same modifier interface as the root component.
|
|
364
|
+
|
|
365
|
+
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:
|
|
366
|
+
|
|
367
|
+
```jsx
|
|
368
|
+
const Card = tasty({
|
|
369
|
+
styles: {
|
|
370
|
+
padding: '4x',
|
|
371
|
+
Title: { preset: 'h3', color: '#primary' },
|
|
372
|
+
},
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
<Card>
|
|
376
|
+
<div data-element="Title">Card Title</div>
|
|
377
|
+
</Card>;
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
### Selector Affix (`$`)
|
|
381
|
+
|
|
382
|
+
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-).
|
|
383
|
+
|
|
384
|
+
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).
|
|
385
|
+
|
|
386
|
+
---
|
|
387
|
+
|
|
388
|
+
## computeStyles
|
|
389
|
+
|
|
390
|
+
Hook-free, synchronous style computation. Can be used anywhere — including React Server Components, plain functions, and non-React code:
|
|
391
|
+
|
|
392
|
+
```tsx
|
|
393
|
+
import { computeStyles } from '@tenphi/tasty';
|
|
394
|
+
|
|
395
|
+
const { className } = computeStyles({
|
|
396
|
+
padding: '2x',
|
|
397
|
+
fill: '#surface',
|
|
398
|
+
radius: '1r',
|
|
399
|
+
});
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
On the client, CSS is injected synchronously into the DOM (idempotent via the injector cache). On the server, CSS is collected via the SSR collector if one is available. This is the same function that `tasty()` components use internally.
|
|
403
|
+
|
|
404
|
+
---
|
|
405
|
+
|
|
406
|
+
## Style Functions
|
|
407
|
+
|
|
408
|
+
All style functions below are plain functions (not React hooks) and can be used in any environment: client components, SSR with a `ServerStyleCollector`, and React Server Components. They retain their `use` prefix for backward compatibility, but do not use any React hooks internally.
|
|
409
|
+
|
|
410
|
+
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).
|
|
411
|
+
|
|
412
|
+
### useStyles
|
|
413
|
+
|
|
414
|
+
Generate a className from a style object. Thin wrapper around `computeStyles()`:
|
|
415
|
+
|
|
416
|
+
```tsx
|
|
417
|
+
import { useStyles } from '@tenphi/tasty';
|
|
418
|
+
|
|
419
|
+
function MyComponent() {
|
|
420
|
+
const { className } = useStyles({
|
|
421
|
+
padding: '2x',
|
|
422
|
+
fill: '#surface',
|
|
423
|
+
radius: '1r',
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
return <div className={className}>Styled content</div>;
|
|
427
|
+
}
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
### useGlobalStyles
|
|
431
|
+
|
|
432
|
+
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:
|
|
433
|
+
|
|
434
|
+
```tsx
|
|
435
|
+
import { useGlobalStyles } from '@tenphi/tasty';
|
|
436
|
+
|
|
437
|
+
function ThemeStyles() {
|
|
438
|
+
useGlobalStyles('.card', {
|
|
439
|
+
padding: '4x',
|
|
440
|
+
fill: '#surface',
|
|
441
|
+
radius: '1r',
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
return null;
|
|
445
|
+
}
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
A slot — the `id`, or the selector when no `id` is given — holds exactly one
|
|
449
|
+
injection **per `root`**. So:
|
|
450
|
+
|
|
451
|
+
- Changing the styles replaces the previous CSS rather than adding to it.
|
|
452
|
+
- Passing styles that produce no CSS (for example `{}`) clears the slot.
|
|
453
|
+
- The same selector used in two shadow roots keeps a separate injection in each.
|
|
454
|
+
- Two independent call sites that share a selector share a slot, and the last
|
|
455
|
+
render wins. Give them distinct `id`s if they should coexist.
|
|
456
|
+
|
|
457
|
+
### useRawCSS
|
|
458
|
+
|
|
459
|
+
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:
|
|
460
|
+
|
|
461
|
+
```tsx
|
|
462
|
+
import { useRawCSS } from '@tenphi/tasty';
|
|
463
|
+
|
|
464
|
+
function GlobalReset() {
|
|
465
|
+
useRawCSS(`
|
|
466
|
+
body { margin: 0; padding: 0; }
|
|
467
|
+
`);
|
|
468
|
+
|
|
469
|
+
return null;
|
|
470
|
+
}
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
An `id` slot holds one injection per `root`. Without an `id` the CSS is deduped
|
|
474
|
+
by content and permanent — there is nothing to replace it with later.
|
|
475
|
+
|
|
476
|
+
### useKeyframes
|
|
477
|
+
|
|
478
|
+
Inject `@keyframes` rules and return the generated animation name:
|
|
479
|
+
|
|
480
|
+
```tsx
|
|
481
|
+
import { useKeyframes } from '@tenphi/tasty';
|
|
482
|
+
|
|
483
|
+
function Spinner() {
|
|
484
|
+
const spin = useKeyframes(
|
|
485
|
+
{
|
|
486
|
+
from: { transform: 'rotate(0deg)' },
|
|
487
|
+
to: { transform: 'rotate(360deg)' },
|
|
488
|
+
},
|
|
489
|
+
{ name: 'spin' },
|
|
490
|
+
);
|
|
491
|
+
|
|
492
|
+
return <div style={{ animation: `${spin} 1s linear infinite` }} />;
|
|
493
|
+
}
|
|
494
|
+
```
|
|
495
|
+
|
|
496
|
+
`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:
|
|
497
|
+
|
|
498
|
+
```tsx
|
|
499
|
+
function Pulse({ scale }: { scale: number }) {
|
|
500
|
+
const pulse = useKeyframes(
|
|
501
|
+
() => ({
|
|
502
|
+
'0%': { transform: 'scale(1)' },
|
|
503
|
+
'100%': { transform: `scale(${scale})` },
|
|
504
|
+
}),
|
|
505
|
+
[scale],
|
|
506
|
+
{ name: 'pulse' },
|
|
507
|
+
);
|
|
508
|
+
|
|
509
|
+
return (
|
|
510
|
+
<div
|
|
511
|
+
style={{ animation: `${pulse} 500ms ease-in-out alternate infinite` }}
|
|
512
|
+
/>
|
|
513
|
+
);
|
|
514
|
+
}
|
|
515
|
+
```
|
|
516
|
+
|
|
517
|
+
Passing `name` claims a slot owned by that one call site, per `root` — much like
|
|
518
|
+
`id` in `useGlobalStyles()` and `useRawCSS()`. When the steps change the previous
|
|
519
|
+
`@keyframes` rule is disposed and the name is reused, so the rules don't
|
|
520
|
+
accumulate and the returned name stays stable. Anonymous keyframes are permanent
|
|
521
|
+
and shared by content.
|
|
522
|
+
|
|
523
|
+
### useProperty
|
|
524
|
+
|
|
525
|
+
Register a CSS `@property` rule so a custom property can animate smoothly:
|
|
526
|
+
|
|
527
|
+
```tsx
|
|
528
|
+
import { useProperty } from '@tenphi/tasty';
|
|
529
|
+
|
|
530
|
+
function Spinner() {
|
|
531
|
+
useProperty('$rotation', {
|
|
532
|
+
syntax: '<angle>',
|
|
533
|
+
inherits: false,
|
|
534
|
+
initialValue: '0deg',
|
|
535
|
+
});
|
|
536
|
+
|
|
537
|
+
return <div style={{ transform: 'rotate(var(--rotation))' }} />;
|
|
538
|
+
}
|
|
539
|
+
```
|
|
540
|
+
|
|
541
|
+
`useProperty()` accepts Tasty token syntax for the property name:
|
|
542
|
+
|
|
543
|
+
- `$name` defines `--name`
|
|
544
|
+
- `#name` defines `--name-color` and auto-infers `<color>`
|
|
545
|
+
- `--name` is also supported for existing CSS variables
|
|
546
|
+
|
|
547
|
+
### useFontFace
|
|
548
|
+
|
|
549
|
+
Inject `@font-face` rules for custom fonts. Permanent — no cleanup on unmount. Deduplicates by content.
|
|
550
|
+
|
|
551
|
+
```tsx
|
|
552
|
+
import { useFontFace } from '@tenphi/tasty';
|
|
553
|
+
|
|
554
|
+
function App() {
|
|
555
|
+
useFontFace('Brand Sans', {
|
|
556
|
+
src: 'url("/fonts/brand-sans.woff2") format("woff2")',
|
|
557
|
+
fontWeight: '400 700',
|
|
558
|
+
fontDisplay: 'swap',
|
|
559
|
+
});
|
|
560
|
+
|
|
561
|
+
return <div style={{ fontFamily: '"Brand Sans", sans-serif' }}>Hello</div>;
|
|
562
|
+
}
|
|
563
|
+
```
|
|
564
|
+
|
|
565
|
+
For multiple weights/styles, pass an array:
|
|
566
|
+
|
|
567
|
+
```tsx
|
|
568
|
+
useFontFace('Brand Sans', [
|
|
569
|
+
{
|
|
570
|
+
src: 'url("/fonts/brand-regular.woff2") format("woff2")',
|
|
571
|
+
fontWeight: 400,
|
|
572
|
+
fontDisplay: 'swap',
|
|
573
|
+
},
|
|
574
|
+
{
|
|
575
|
+
src: 'url("/fonts/brand-bold.woff2") format("woff2")',
|
|
576
|
+
fontWeight: 700,
|
|
577
|
+
fontDisplay: 'swap',
|
|
578
|
+
},
|
|
579
|
+
]);
|
|
580
|
+
```
|
|
581
|
+
|
|
582
|
+
Signature:
|
|
583
|
+
|
|
584
|
+
```ts
|
|
585
|
+
function useFontFace(family: string, input: FontFaceInput): void;
|
|
586
|
+
```
|
|
587
|
+
|
|
588
|
+
### useCounterStyle
|
|
589
|
+
|
|
590
|
+
Inject a `@counter-style` rule and get back the counter style name. Permanent — no cleanup on unmount. Deduplicates by name.
|
|
591
|
+
|
|
592
|
+
```tsx
|
|
593
|
+
import { useCounterStyle } from '@tenphi/tasty';
|
|
594
|
+
|
|
595
|
+
function EmojiList() {
|
|
596
|
+
const styleName = useCounterStyle(
|
|
597
|
+
{
|
|
598
|
+
system: 'cyclic',
|
|
599
|
+
symbols: '"👍"',
|
|
600
|
+
suffix: '" "',
|
|
601
|
+
},
|
|
602
|
+
{ name: 'thumbs' },
|
|
603
|
+
);
|
|
604
|
+
|
|
605
|
+
return (
|
|
606
|
+
<ol style={{ listStyleType: styleName }}>
|
|
607
|
+
<li>First</li>
|
|
608
|
+
<li>Second</li>
|
|
609
|
+
</ol>
|
|
610
|
+
);
|
|
611
|
+
}
|
|
612
|
+
```
|
|
613
|
+
|
|
614
|
+
Signature:
|
|
615
|
+
|
|
616
|
+
```ts
|
|
617
|
+
function useCounterStyle(
|
|
618
|
+
descriptors: CounterStyleDescriptors,
|
|
619
|
+
options?: { name?: string; root?: Document | ShadowRoot },
|
|
620
|
+
): string;
|
|
621
|
+
```
|
|
622
|
+
|
|
623
|
+
### useFunction
|
|
624
|
+
|
|
625
|
+
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`.
|
|
626
|
+
|
|
627
|
+
```tsx
|
|
628
|
+
import { tasty, useFunction } from '@tenphi/tasty';
|
|
629
|
+
|
|
630
|
+
const Box = tasty({ styles: { margin: '$$negative(10px) top' } });
|
|
631
|
+
|
|
632
|
+
function Layout() {
|
|
633
|
+
useFunction('$$negative', { args: ['$value'], result: '(-1 * $value)' });
|
|
634
|
+
return <Box />;
|
|
635
|
+
}
|
|
636
|
+
```
|
|
637
|
+
|
|
638
|
+
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.
|
|
639
|
+
|
|
640
|
+
Inside a `tasty()` component you call functions with the same `$$name(...)` sugar:
|
|
641
|
+
|
|
642
|
+
```tsx
|
|
643
|
+
const Box = tasty({
|
|
644
|
+
styles: {
|
|
645
|
+
'@function': { $$negative: { args: ['$value'], result: '(-1 * $value)' } },
|
|
646
|
+
margin: '$$negative(10px) top',
|
|
647
|
+
},
|
|
648
|
+
});
|
|
649
|
+
```
|
|
650
|
+
|
|
651
|
+
Signature:
|
|
652
|
+
|
|
653
|
+
```ts
|
|
654
|
+
function useFunction(
|
|
655
|
+
name: string,
|
|
656
|
+
definition: FunctionDefinition,
|
|
657
|
+
options?: { root?: Document | ShadowRoot },
|
|
658
|
+
): void;
|
|
659
|
+
```
|
|
660
|
+
|
|
661
|
+
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.
|
|
662
|
+
|
|
663
|
+
### Troubleshooting
|
|
664
|
+
|
|
665
|
+
- 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).
|
|
666
|
+
- 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`.
|
|
667
|
+
- Animation/custom property issues: prefer `useKeyframes()` and `useProperty()` over raw CSS when you want Tasty to manage injection and SSR collection for you.
|
|
668
|
+
- For dynamic styles that change over the component lifecycle, use the `id` option in `useGlobalStyles()` and `useRawCSS()` to enable update tracking.
|
|
669
|
+
- 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.
|
|
670
|
+
|
|
671
|
+
---
|
|
672
|
+
|
|
673
|
+
## Learn more
|
|
674
|
+
|
|
675
|
+
- **[Style DSL](dsl.md)** — State maps, tokens, units, extending semantics, keyframes, @property
|
|
676
|
+
- **[Methodology](methodology.md)** — Recommended patterns: root + sub-elements, styleProps, tokens, wrapping
|
|
677
|
+
- **[Configuration](configuration.md)** — Tokens, recipes, custom units, style handlers, TypeScript extensions
|
|
678
|
+
- **[Style Properties](styles.md)** — Complete reference for all enhanced style properties
|
|
679
|
+
- **[Build-Time Extraction (`tastyStatic`)](tasty-static.md)** — Static styling with the Babel plugin
|
|
680
|
+
- **[Server-Side Rendering](ssr.md)** — SSR setup for Next.js, Astro, and generic frameworks
|
|
681
|
+
- **[Debug Utilities](debug.md)** — Inspect injected CSS, cache state, and active styles at runtime
|