@tenphi/tasty 0.0.0-snapshot.2dc73be → 0.0.0-snapshot.2f5d166
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 +288 -250
- package/dist/_virtual/_rolldown/runtime.js +1 -2
- package/dist/chunks/cacheKey.d.ts +1 -0
- package/dist/chunks/cacheKey.js +17 -10
- package/dist/chunks/cacheKey.js.map +1 -1
- package/dist/chunks/definitions.d.ts +1 -1
- package/dist/chunks/definitions.js +2 -3
- package/dist/chunks/definitions.js.map +1 -1
- package/dist/chunks/index.d.ts +1 -0
- package/dist/chunks/renderChunk.d.ts +1 -0
- package/dist/chunks/renderChunk.js +32 -34
- package/dist/chunks/renderChunk.js.map +1 -1
- package/dist/compute-styles.d.ts +31 -0
- package/dist/compute-styles.js +335 -0
- package/dist/compute-styles.js.map +1 -0
- package/dist/config.d.ts +109 -30
- package/dist/config.js +142 -57
- package/dist/config.js.map +1 -1
- package/dist/core/index.d.ts +12 -11
- package/dist/core/index.js +10 -9
- package/dist/counter-style/index.js +51 -0
- package/dist/counter-style/index.js.map +1 -0
- package/dist/debug.d.ts +26 -141
- package/dist/debug.js +357 -637
- package/dist/debug.js.map +1 -1
- package/dist/font-face/index.js +63 -0
- package/dist/font-face/index.js.map +1 -0
- package/dist/hooks/index.d.ts +7 -0
- package/dist/hooks/useCounterStyle.d.ts +52 -0
- package/dist/hooks/useCounterStyle.js +43 -0
- package/dist/hooks/useCounterStyle.js.map +1 -0
- package/dist/hooks/useFontFace.d.ts +45 -0
- package/dist/hooks/useFontFace.js +68 -0
- package/dist/hooks/useFontFace.js.map +1 -0
- package/dist/hooks/useGlobalStyles.d.ts +18 -2
- package/dist/hooks/useGlobalStyles.js +50 -46
- package/dist/hooks/useGlobalStyles.js.map +1 -1
- package/dist/hooks/useKeyframes.d.ts +4 -2
- package/dist/hooks/useKeyframes.js +32 -57
- package/dist/hooks/useKeyframes.js.map +1 -1
- package/dist/hooks/useProperty.d.ts +4 -2
- package/dist/hooks/useProperty.js +29 -45
- package/dist/hooks/useProperty.js.map +1 -1
- package/dist/hooks/useRawCSS.d.ts +8 -44
- package/dist/hooks/useRawCSS.js +82 -27
- package/dist/hooks/useRawCSS.js.map +1 -1
- package/dist/hooks/useStyles.d.ts +4 -9
- package/dist/hooks/useStyles.js +7 -226
- package/dist/hooks/useStyles.js.map +1 -1
- package/dist/index.d.ts +15 -12
- package/dist/index.js +13 -10
- package/dist/injector/index.d.ts +36 -19
- package/dist/injector/index.js +42 -19
- package/dist/injector/index.js.map +1 -1
- package/dist/injector/injector.d.ts +48 -3
- package/dist/injector/injector.js +144 -16
- package/dist/injector/injector.js.map +1 -1
- package/dist/injector/sheet-manager.d.ts +9 -13
- package/dist/injector/sheet-manager.js +39 -70
- package/dist/injector/sheet-manager.js.map +1 -1
- package/dist/injector/types.d.ts +103 -19
- package/dist/keyframes/index.js +1 -1
- package/dist/parser/classify.js +6 -6
- package/dist/parser/classify.js.map +1 -1
- package/dist/parser/const.js +30 -3
- package/dist/parser/const.js.map +1 -1
- package/dist/parser/lru.js +1 -1
- package/dist/parser/lru.js.map +1 -1
- package/dist/parser/parser.js +2 -3
- package/dist/parser/parser.js.map +1 -1
- package/dist/parser/tokenizer.js +1 -1
- package/dist/parser/tokenizer.js.map +1 -1
- package/dist/parser/types.js +1 -1
- package/dist/parser/types.js.map +1 -1
- package/dist/pipeline/conditions.js +1 -1
- package/dist/pipeline/conditions.js.map +1 -1
- package/dist/pipeline/exclusive.js +1 -2
- package/dist/pipeline/exclusive.js.map +1 -1
- package/dist/pipeline/index.d.ts +3 -1
- package/dist/pipeline/index.js +80 -32
- package/dist/pipeline/index.js.map +1 -1
- package/dist/pipeline/materialize.js +329 -82
- package/dist/pipeline/materialize.js.map +1 -1
- package/dist/pipeline/parseStateKey.d.ts +1 -1
- package/dist/pipeline/parseStateKey.js +3 -8
- package/dist/pipeline/parseStateKey.js.map +1 -1
- package/dist/pipeline/simplify.js +1 -2
- package/dist/pipeline/simplify.js.map +1 -1
- package/dist/pipeline/warnings.js +1 -1
- package/dist/plugins/index.d.ts +2 -0
- package/dist/plugins/okhsl-plugin.js +3 -277
- package/dist/plugins/okhsl-plugin.js.map +1 -1
- package/dist/plugins/types.d.ts +9 -2
- package/dist/properties/index.js +3 -17
- package/dist/properties/index.js.map +1 -1
- package/dist/properties/property-type-resolver.js +5 -2
- package/dist/properties/property-type-resolver.js.map +1 -1
- package/dist/rsc-cache.js +70 -0
- package/dist/rsc-cache.js.map +1 -0
- package/dist/ssr/astro-client.d.ts +1 -0
- package/dist/ssr/astro-client.js +24 -0
- package/dist/ssr/astro-client.js.map +1 -0
- package/dist/ssr/astro-middleware.d.ts +15 -0
- package/dist/ssr/astro-middleware.js +19 -0
- package/dist/ssr/astro-middleware.js.map +1 -0
- package/dist/ssr/astro.d.ts +85 -8
- package/dist/ssr/astro.js +111 -22
- package/dist/ssr/astro.js.map +1 -1
- package/dist/ssr/async-storage.js +1 -2
- package/dist/ssr/async-storage.js.map +1 -1
- package/dist/ssr/collect-auto-properties.js +29 -11
- package/dist/ssr/collect-auto-properties.js.map +1 -1
- package/dist/ssr/collector.d.ts +17 -0
- package/dist/ssr/collector.js +60 -14
- package/dist/ssr/collector.js.map +1 -1
- package/dist/ssr/format-global-rules.js +1 -1
- package/dist/ssr/format-keyframes.js +1 -2
- package/dist/ssr/format-keyframes.js.map +1 -1
- package/dist/ssr/format-property.js +10 -9
- package/dist/ssr/format-property.js.map +1 -1
- package/dist/ssr/format-rules.js +8 -5
- package/dist/ssr/format-rules.js.map +1 -1
- package/dist/ssr/hydrate.js +1 -2
- package/dist/ssr/hydrate.js.map +1 -1
- package/dist/ssr/index.d.ts +2 -3
- package/dist/ssr/index.js +2 -4
- package/dist/ssr/index.js.map +1 -1
- package/dist/ssr/next.d.ts +1 -3
- package/dist/ssr/next.js +10 -7
- package/dist/ssr/next.js.map +1 -1
- package/dist/ssr/ssr-collector-ref.js +1 -1
- package/dist/states/index.js +13 -259
- package/dist/states/index.js.map +1 -1
- package/dist/static/index.js +1 -2
- 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/static/tastyStatic.js +1 -2
- package/dist/static/tastyStatic.js.map +1 -1
- package/dist/static/types.js +1 -1
- package/dist/styles/border.d.ts +1 -1
- package/dist/styles/border.js +30 -24
- package/dist/styles/border.js.map +1 -1
- package/dist/styles/color.d.ts +1 -1
- package/dist/styles/color.js +11 -8
- package/dist/styles/color.js.map +1 -1
- package/dist/styles/const.js +17 -0
- package/dist/styles/const.js.map +1 -0
- package/dist/styles/createStyle.js +28 -26
- package/dist/styles/createStyle.js.map +1 -1
- package/dist/styles/dimension.js +15 -3
- package/dist/styles/dimension.js.map +1 -1
- package/dist/styles/directional.js +133 -0
- package/dist/styles/directional.js.map +1 -0
- package/dist/styles/display.d.ts +3 -10
- package/dist/styles/display.js +45 -39
- package/dist/styles/display.js.map +1 -1
- package/dist/styles/fade.d.ts +1 -1
- package/dist/styles/fade.js +9 -5
- package/dist/styles/fade.js.map +1 -1
- package/dist/styles/fill.d.ts +2 -2
- package/dist/styles/fill.js +3 -4
- package/dist/styles/fill.js.map +1 -1
- package/dist/styles/flow.js +1 -1
- package/dist/styles/gap.d.ts +1 -1
- package/dist/styles/gap.js +4 -3
- package/dist/styles/gap.js.map +1 -1
- package/dist/styles/height.d.ts +1 -1
- package/dist/styles/height.js +1 -2
- package/dist/styles/height.js.map +1 -1
- package/dist/styles/index.d.ts +0 -1
- package/dist/styles/index.js +3 -4
- package/dist/styles/index.js.map +1 -1
- package/dist/styles/inset.d.ts +1 -29
- package/dist/styles/inset.js +19 -135
- package/dist/styles/inset.js.map +1 -1
- package/dist/styles/list.d.ts +5 -5
- package/dist/styles/list.js +4 -2
- package/dist/styles/list.js.map +1 -1
- package/dist/styles/margin.d.ts +1 -1
- package/dist/styles/margin.js +17 -89
- package/dist/styles/margin.js.map +1 -1
- package/dist/styles/outline.d.ts +1 -1
- package/dist/styles/outline.js +6 -16
- package/dist/styles/outline.js.map +1 -1
- package/dist/styles/padding.d.ts +1 -1
- package/dist/styles/padding.js +17 -89
- package/dist/styles/padding.js.map +1 -1
- package/dist/styles/placement.d.ts +37 -0
- package/dist/styles/placement.js +74 -0
- package/dist/styles/placement.js.map +1 -0
- package/dist/styles/predefined.d.ts +4 -4
- package/dist/styles/predefined.js +9 -10
- package/dist/styles/predefined.js.map +1 -1
- package/dist/styles/preset.d.ts +6 -1
- package/dist/styles/preset.js +54 -53
- package/dist/styles/preset.js.map +1 -1
- package/dist/styles/radius.d.ts +1 -3
- package/dist/styles/radius.js +38 -6
- package/dist/styles/radius.js.map +1 -1
- package/dist/styles/scrollMargin.d.ts +24 -0
- package/dist/styles/scrollMargin.js +32 -0
- package/dist/styles/scrollMargin.js.map +1 -0
- package/dist/styles/scrollbar.d.ts +1 -1
- package/dist/styles/scrollbar.js +8 -5
- package/dist/styles/scrollbar.js.map +1 -1
- package/dist/styles/shadow.d.ts +1 -1
- package/dist/styles/shadow.js +4 -3
- package/dist/styles/shadow.js.map +1 -1
- package/dist/styles/shared.js +17 -0
- package/dist/styles/shared.js.map +1 -0
- package/dist/styles/transition.d.ts +1 -1
- package/dist/styles/transition.js +5 -4
- package/dist/styles/transition.js.map +1 -1
- package/dist/styles/types.d.ts +84 -15
- package/dist/styles/width.d.ts +1 -1
- package/dist/styles/width.js +1 -2
- package/dist/styles/width.js.map +1 -1
- package/dist/tasty.d.ts +46 -893
- package/dist/tasty.js +96 -59
- package/dist/tasty.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/utils/cache-wrapper.js +4 -9
- package/dist/utils/cache-wrapper.js.map +1 -1
- package/dist/utils/case-converter.js +1 -1
- package/dist/utils/color-math.d.ts +46 -0
- package/dist/utils/color-math.js +749 -0
- package/dist/utils/color-math.js.map +1 -0
- package/dist/utils/color-space.d.ts +5 -0
- package/dist/utils/color-space.js +228 -0
- package/dist/utils/color-space.js.map +1 -0
- package/dist/utils/colors.js +3 -2
- package/dist/utils/colors.js.map +1 -1
- package/dist/utils/dotize.js +1 -1
- package/dist/utils/dotize.js.map +1 -1
- package/dist/utils/filter-base-props.d.ts +1 -1
- package/dist/utils/filter-base-props.js +1 -1
- package/dist/utils/filter-base-props.js.map +1 -1
- package/dist/utils/get-display-name.js +1 -1
- package/dist/utils/has-keys.js +13 -0
- package/dist/utils/has-keys.js.map +1 -0
- package/dist/utils/hash.js +14 -0
- package/dist/utils/hash.js.map +1 -0
- package/dist/utils/is-dev-env.js +1 -1
- package/dist/utils/is-dev-env.js.map +1 -1
- package/dist/utils/is-valid-element-type.js +1 -1
- package/dist/utils/merge-styles.js +1 -2
- package/dist/utils/merge-styles.js.map +1 -1
- package/dist/utils/mod-attrs.d.ts +0 -2
- package/dist/utils/mod-attrs.js +3 -4
- package/dist/utils/mod-attrs.js.map +1 -1
- package/dist/utils/process-tokens.d.ts +3 -17
- package/dist/utils/process-tokens.js +19 -107
- package/dist/utils/process-tokens.js.map +1 -1
- package/dist/utils/resolve-recipes.js +1 -2
- package/dist/utils/resolve-recipes.js.map +1 -1
- package/dist/utils/selector-transform.js +1 -1
- package/dist/utils/string.js +1 -1
- package/dist/utils/styles.d.ts +3 -81
- package/dist/utils/styles.js +29 -539
- package/dist/utils/styles.js.map +1 -1
- package/dist/utils/typography.d.ts +24 -13
- package/dist/utils/typography.js +15 -17
- package/dist/utils/typography.js.map +1 -1
- package/dist/utils/warnings.js +1 -1
- package/dist/zero/babel.d.ts +63 -8
- package/dist/zero/babel.js +163 -44
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/css-writer.js +1 -2
- package/dist/zero/css-writer.js.map +1 -1
- package/dist/zero/extractor.js +54 -3
- package/dist/zero/extractor.js.map +1 -1
- package/dist/zero/index.js +1 -2
- package/dist/zero/next.d.ts +28 -1
- package/dist/zero/next.js +70 -15
- package/dist/zero/next.js.map +1 -1
- package/docs/PIPELINE.md +519 -0
- package/docs/README.md +31 -0
- package/docs/adoption.md +296 -0
- package/docs/comparison.md +420 -0
- package/docs/configuration.md +127 -12
- package/docs/debug.md +152 -339
- package/docs/design-system.md +424 -0
- package/docs/{usage.md → dsl.md} +379 -386
- package/docs/getting-started.md +217 -0
- package/docs/injector.md +43 -27
- package/docs/methodology.md +616 -0
- package/docs/runtime.md +575 -0
- package/docs/ssr.md +144 -81
- package/docs/styles.md +48 -26
- package/docs/tasty-static.md +166 -22
- package/package.json +27 -12
- package/dist/ssr/context.d.ts +0 -8
- package/dist/ssr/context.js +0 -14
- package/dist/ssr/context.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/justify.d.ts +0 -15
- package/dist/styles/justify.js +0 -14
- package/dist/styles/justify.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/utils/hsl-to-rgb.js +0 -38
- package/dist/utils/hsl-to-rgb.js.map +0 -1
- package/dist/utils/okhsl-to-rgb.js +0 -296
- package/dist/utils/okhsl-to-rgb.js.map +0 -1
package/docs/{usage.md → dsl.md}
RENAMED
|
@@ -1,54 +1,208 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Style DSL Reference
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This is the Tasty style language reference — the value syntax, state mappings, tokens, units, extending semantics, and special declarations that apply to both runtime `tasty()` and build-time `tastyStatic()`.
|
|
4
4
|
|
|
5
|
-
For
|
|
5
|
+
For the runtime React API (`tasty()`, hooks, component props), see [Runtime API](runtime.md). For all enhanced style properties, see [Style Properties](styles.md). For global configuration, see [Configuration](configuration.md).
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
9
|
-
##
|
|
9
|
+
## Dictionary
|
|
10
|
+
|
|
11
|
+
### Style Mapping
|
|
12
|
+
|
|
13
|
+
Object where keys represent states and values are the styles to apply:
|
|
14
|
+
|
|
15
|
+
```jsx
|
|
16
|
+
fill: { '': '#white', hovered: '#gray.05', 'theme=danger': '#red' }
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
#### State Key Types
|
|
20
|
+
|
|
21
|
+
| Syntax | Example | Generated CSS |
|
|
22
|
+
|--------|---------|---------------|
|
|
23
|
+
| Boolean modifier | `hovered` | `[data-hovered]` |
|
|
24
|
+
| Value modifier | `theme=danger` | `[data-theme="danger"]` |
|
|
25
|
+
| Pseudo-class | `:hover` | `:hover` |
|
|
26
|
+
| Class selector | `.active` | `.active` |
|
|
27
|
+
| Attribute selector | `[aria-expanded="true"]` | `[aria-expanded="true"]` |
|
|
28
|
+
| Combined (AND) | `hovered & .active` | `[data-hovered].active` |
|
|
29
|
+
| Combined (OR) | `hovered \| focused` | `[data-hovered], [data-focused]` |
|
|
30
|
+
| Negated (NOT) | `!disabled` | `:not([data-disabled])` |
|
|
31
|
+
| Exclusive (XOR) | `hovered ^ focused` | `[data-hovered]:not([data-focused]), :not([data-hovered])[data-focused]` |
|
|
32
|
+
|
|
33
|
+
Operator precedence (highest to lowest): `!` (NOT) > `^` (XOR) > `|` (OR) > `&` (AND). Use parentheses to override: `hovered & (pressed ^ focused)`.
|
|
34
|
+
|
|
35
|
+
`^` (XOR) means "exactly one of" — `A ^ B` expands to `(A & !B) | (!A & B)`. This is useful for mutually exclusive states where exactly one should be active:
|
|
36
|
+
|
|
37
|
+
```jsx
|
|
38
|
+
fill: {
|
|
39
|
+
'': '#surface',
|
|
40
|
+
'hovered ^ focused': '#accent', // active when hovered OR focused, but not both
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Sub-element
|
|
45
|
+
|
|
46
|
+
Element styled using a capitalized key. Identified by `data-element` attribute:
|
|
47
|
+
|
|
48
|
+
```jsx
|
|
49
|
+
styles: { Title: { preset: 'h3' } }
|
|
50
|
+
// Targets: <div data-element="Title">
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
#### Selector Affix (`$`)
|
|
54
|
+
|
|
55
|
+
Control how a sub-element selector attaches to the root selector using the `$` property inside the sub-element's styles:
|
|
56
|
+
|
|
57
|
+
| Pattern | Result | Description |
|
|
58
|
+
|---------|--------|-------------|
|
|
59
|
+
| *(none)* | ` [el]` | Descendant (default) |
|
|
60
|
+
| `>` | `> [el]` | Direct child |
|
|
61
|
+
| `>Body>Row>` | `> [Body] > [Row] > [el]` | Chained elements |
|
|
62
|
+
| `h1` | ` h1` | Tag selector (no key injection) |
|
|
63
|
+
| `h1 >` | ` h1 > [el]` | Key is direct child of tag |
|
|
64
|
+
| `h1 *` | ` h1 *` | Any descendant of tag |
|
|
65
|
+
| `*` | ` *` | All descendants |
|
|
66
|
+
| `::before` | `::before` | Root pseudo (no key) |
|
|
67
|
+
| `@::before` | `[el]::before` | Pseudo on the sub-element |
|
|
68
|
+
| `>@:hover` | `> [el]:hover` | Pseudo-class on the sub-element |
|
|
69
|
+
| `>@.active` | `> [el].active` | Class on the sub-element |
|
|
70
|
+
|
|
71
|
+
Rules for key injection (`[data-element="..."]`):
|
|
72
|
+
|
|
73
|
+
- **Trailing combinator** (`>`, `+`, `~`) — key is injected after it
|
|
74
|
+
- **Uppercase element name** (`Body`, `Row`) — key is injected as descendant
|
|
75
|
+
- **HTML tag** (`h1`, `a`, `span`) — no key injection; the tag IS the selector
|
|
76
|
+
- **Universal selector** (`*`) — no key injection
|
|
77
|
+
- **Pseudo / class / attribute** — no key injection
|
|
78
|
+
|
|
79
|
+
The `@` placeholder marks exactly where `[data-element="..."]` is injected, allowing you to attach pseudo-classes, pseudo-elements, or class selectors directly to the sub-element instead of the root:
|
|
80
|
+
|
|
81
|
+
```jsx
|
|
82
|
+
const List = tasty({
|
|
83
|
+
styles: {
|
|
84
|
+
Item: {
|
|
85
|
+
$: '>@:last-child',
|
|
86
|
+
border: 'none',
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
// → .t0 > [data-element="Item"]:last-child { border: none }
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Color Token
|
|
94
|
+
|
|
95
|
+
Named color prefixed with `#` that maps to CSS custom properties. Supports opacity with `.N` suffix:
|
|
96
|
+
|
|
97
|
+
```jsx
|
|
98
|
+
fill: '#purple.5' // → var(--purple-color) with 50% opacity
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Modifier
|
|
102
|
+
|
|
103
|
+
State value via `mods` prop that generates `data-*` attributes:
|
|
104
|
+
|
|
105
|
+
```jsx
|
|
106
|
+
mods={{ hovered: true, theme: 'danger' }}
|
|
107
|
+
// → data-hovered="" data-theme="danger"
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Modifiers can also be exposed as top-level component props via `modProps` — see [Runtime — Mod Props](runtime.md#mod-props).
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## Color Tokens & Opacity
|
|
115
|
+
|
|
116
|
+
```jsx
|
|
117
|
+
color: '#purple', // Full opacity
|
|
118
|
+
color: '#purple.5', // 50% opacity
|
|
119
|
+
color: '#purple.05', // 5% opacity
|
|
120
|
+
fill: '#current', // → currentcolor
|
|
121
|
+
fill: '#current.5', // → color-mix(in oklab, currentcolor 50%, transparent)
|
|
122
|
+
color: '(#primary, #secondary)', // Fallback syntax
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## Built-in Units
|
|
128
|
+
|
|
129
|
+
| Unit | Description | Example | CSS Output |
|
|
130
|
+
|------|-------------|---------|------------|
|
|
131
|
+
| `x` | Gap multiplier | `2x` | `calc(var(--gap) * 2)` |
|
|
132
|
+
| `r` | Border radius | `1r` | `var(--radius)` |
|
|
133
|
+
| `cr` | Card border radius | `1cr` | `var(--card-radius)` |
|
|
134
|
+
| `bw` | Border width | `2bw` | `calc(var(--border-width) * 2)` |
|
|
135
|
+
| `ow` | Outline width | `1ow` | `var(--outline-width)` |
|
|
136
|
+
| `sf` | Stable fraction | `1sf` | `minmax(0, 1fr)` |
|
|
137
|
+
|
|
138
|
+
You can register additional custom units via [`configure()`](configuration.md#options).
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## Replace Tokens
|
|
10
143
|
|
|
11
|
-
|
|
144
|
+
Tokens defined via [`configure({ replaceTokens })`](configuration.md#replace-tokens-parse-time-substitution) are replaced at parse time and baked into the generated CSS:
|
|
12
145
|
|
|
13
146
|
```jsx
|
|
14
|
-
|
|
147
|
+
const Card = tasty({
|
|
148
|
+
styles: {
|
|
149
|
+
padding: '$card-padding',
|
|
150
|
+
fill: '#surface',
|
|
151
|
+
border: '1bw solid #accent',
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
## Recipes
|
|
15
159
|
|
|
16
|
-
|
|
160
|
+
Apply predefined style bundles (defined via [`configure({ recipes })`](configuration.md#recipes)) using the `recipe` style property:
|
|
161
|
+
|
|
162
|
+
```jsx
|
|
17
163
|
const Card = tasty({
|
|
18
|
-
as: 'div',
|
|
19
164
|
styles: {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
border: true,
|
|
23
|
-
radius: true,
|
|
165
|
+
recipe: 'card',
|
|
166
|
+
color: '#text',
|
|
24
167
|
},
|
|
25
|
-
styleProps: ['padding', 'fill'], // Expose styles as props
|
|
26
168
|
});
|
|
27
169
|
|
|
28
|
-
//
|
|
29
|
-
|
|
30
|
-
|
|
170
|
+
// Compose multiple recipes
|
|
171
|
+
const ElevatedCard = tasty({
|
|
172
|
+
styles: {
|
|
173
|
+
recipe: 'card elevated',
|
|
174
|
+
color: '#text',
|
|
175
|
+
},
|
|
176
|
+
});
|
|
31
177
|
```
|
|
32
178
|
|
|
33
|
-
|
|
179
|
+
**Post-merge recipes (`/` separator):**
|
|
34
180
|
|
|
35
|
-
|
|
181
|
+
Recipes listed after `/` are applied *after* component styles using `mergeStyles`:
|
|
36
182
|
|
|
37
183
|
```jsx
|
|
38
|
-
|
|
39
|
-
const PrimaryButton = tasty(Button, {
|
|
184
|
+
const Input = tasty({
|
|
40
185
|
styles: {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
padding: '2x 4x',
|
|
186
|
+
recipe: 'reset input / input-autofill',
|
|
187
|
+
preset: 't3',
|
|
44
188
|
},
|
|
45
189
|
});
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
Use `none` to skip base recipes and apply only post recipes:
|
|
46
193
|
|
|
47
|
-
|
|
48
|
-
|
|
194
|
+
```jsx
|
|
195
|
+
const Custom = tasty({
|
|
196
|
+
styles: {
|
|
197
|
+
recipe: 'none / disabled',
|
|
198
|
+
padding: '2x',
|
|
199
|
+
},
|
|
200
|
+
});
|
|
49
201
|
```
|
|
50
202
|
|
|
51
|
-
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
## Extending vs. Replacing State Maps
|
|
52
206
|
|
|
53
207
|
When a style property uses a state map, the merge behavior depends on whether the child provides a `''` (default) key:
|
|
54
208
|
|
|
@@ -102,7 +256,7 @@ fill: { pressed: null } // removes pressed from the result
|
|
|
102
256
|
fill: { disabled: false } // tombstone — no CSS for disabled, blocks recipe too
|
|
103
257
|
```
|
|
104
258
|
|
|
105
|
-
|
|
259
|
+
### Resetting Properties with `null` and `false`
|
|
106
260
|
|
|
107
261
|
```jsx
|
|
108
262
|
const SimpleButton = tasty(Button, {
|
|
@@ -119,229 +273,178 @@ const SimpleButton = tasty(Button, {
|
|
|
119
273
|
| `null` | Intentional unset — parent discarded | Yes |
|
|
120
274
|
| `false` | Tombstone — blocks everything | No |
|
|
121
275
|
|
|
122
|
-
### Essential Patterns
|
|
123
|
-
|
|
124
|
-
```jsx
|
|
125
|
-
// State-based styling
|
|
126
|
-
const InteractiveCard = tasty({
|
|
127
|
-
styles: {
|
|
128
|
-
fill: {
|
|
129
|
-
'': '#white',
|
|
130
|
-
'hovered': '#gray.05',
|
|
131
|
-
'pressed': '#gray.10',
|
|
132
|
-
},
|
|
133
|
-
},
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
// Using design tokens
|
|
137
|
-
const TokenCard = tasty({
|
|
138
|
-
styles: {
|
|
139
|
-
fill: '#surface', // Color token
|
|
140
|
-
color: '#text', // Color token
|
|
141
|
-
padding: '2x', // Custom unit (gap × 2)
|
|
142
|
-
radius: '1r', // Custom unit (border-radius)
|
|
143
|
-
border: '1bw solid #border', // Border width token
|
|
144
|
-
},
|
|
145
|
-
});
|
|
146
|
-
```
|
|
147
|
-
|
|
148
276
|
---
|
|
149
277
|
|
|
150
|
-
##
|
|
151
|
-
|
|
152
|
-
For tokens, recipes, custom units, style handlers, and other global settings, see **[Configuration](configuration.md)**.
|
|
278
|
+
## Advanced States (`@` prefix)
|
|
153
279
|
|
|
154
|
-
|
|
280
|
+
| Prefix | Purpose | Example |
|
|
281
|
+
|--------|---------|---------|
|
|
282
|
+
| `@media` | Media queries | `@media(w < 768px)` |
|
|
283
|
+
| `@(...)` | Container queries | `@(panel, w >= 300px)` |
|
|
284
|
+
| `@supports` | Feature/selector support | `@supports(display: grid)` |
|
|
285
|
+
| `@root` | Root element states | `@root(schema=dark)` |
|
|
286
|
+
| `@parent` | Parent/ancestor element states | `@parent(hovered)` |
|
|
287
|
+
| `@own` | Sub-element's own state | `@own(hovered)` |
|
|
288
|
+
| `@starting` | Entry animation | `@starting` |
|
|
289
|
+
| `:is()` | CSS `:is()` structural pseudo-class | `:is(fieldset > label)` |
|
|
290
|
+
| `:has()` | CSS `:has()` relational pseudo-class | `:has(> Icon)` |
|
|
291
|
+
| `:not()` | CSS `:not()` negation (prefer `!:is()`) | `:not(:first-child)` |
|
|
292
|
+
| `:where()` | CSS `:where()` (zero specificity) | `:where(Section)` |
|
|
155
293
|
|
|
156
|
-
|
|
294
|
+
### `@media(...)` — Media Queries
|
|
157
295
|
|
|
158
|
-
|
|
296
|
+
Media queries support dimension shorthands and custom unit expansion:
|
|
159
297
|
|
|
160
|
-
|
|
298
|
+
| Shorthand | Expands to |
|
|
299
|
+
|-----------|------------|
|
|
300
|
+
| `w` | `width` |
|
|
301
|
+
| `h` | `height` |
|
|
161
302
|
|
|
162
303
|
```jsx
|
|
163
|
-
fill: {
|
|
304
|
+
fill: {
|
|
305
|
+
'': '#surface',
|
|
306
|
+
'@media(w < 768px)': '#surface-mobile',
|
|
307
|
+
'@media(600px <= w < 1200px)': '#surface-tablet',
|
|
308
|
+
'@media(prefers-color-scheme: dark)': '#surface-dark',
|
|
309
|
+
}
|
|
164
310
|
```
|
|
165
311
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
|
169
|
-
|
|
170
|
-
|
|
|
171
|
-
|
|
|
172
|
-
|
|
|
173
|
-
|
|
|
174
|
-
| Attribute selector | `[aria-expanded="true"]` | `[aria-expanded="true"]` |
|
|
175
|
-
| Combined | `hovered & .active` | `[data-hovered].active` |
|
|
312
|
+
| Tasty syntax | CSS output |
|
|
313
|
+
|--------------|------------|
|
|
314
|
+
| `@media(w < 768px)` | `@media (width < 768px)` |
|
|
315
|
+
| `@media(600px <= w < 1200px)` | `@media (600px <= width < 1200px)` |
|
|
316
|
+
| `@media:print` | `@media print` |
|
|
317
|
+
| `@media:screen` | `@media screen` |
|
|
318
|
+
| `@media(prefers-color-scheme: dark)` | `@media (prefers-color-scheme: dark)` |
|
|
319
|
+
| `@media(prefers-reduced-motion)` | `@media (prefers-reduced-motion)` |
|
|
176
320
|
|
|
177
|
-
|
|
321
|
+
Custom units work inside media queries: `@media(w < 40x)` → `@media (width < calc(var(--gap) * 40))`.
|
|
178
322
|
|
|
179
|
-
|
|
323
|
+
In practice, define state aliases via `configure({ states })` and use `@mobile` instead of writing the full query in every component.
|
|
180
324
|
|
|
181
|
-
|
|
182
|
-
styles: { Title: { preset: 'h3' } }
|
|
183
|
-
// Targets: <div data-element="Title">
|
|
184
|
-
```
|
|
325
|
+
### `@(...)` — Container Queries
|
|
185
326
|
|
|
186
|
-
|
|
327
|
+
Container queries use the syntax `@(name, condition)` for named containers or `@(condition)` for the nearest ancestor container. Dimension shorthands (`w`, `h`, `is`, `bs`) are expanded the same way as `@media`.
|
|
187
328
|
|
|
188
|
-
|
|
329
|
+
| Shorthand | Expands to |
|
|
330
|
+
|-----------|------------|
|
|
331
|
+
| `w` | `width` |
|
|
332
|
+
| `h` | `height` |
|
|
333
|
+
| `is` | `inline-size` |
|
|
334
|
+
| `bs` | `block-size` |
|
|
189
335
|
|
|
190
336
|
```jsx
|
|
191
|
-
|
|
337
|
+
const Panel = tasty({
|
|
338
|
+
styles: {
|
|
339
|
+
flow: {
|
|
340
|
+
'': 'column',
|
|
341
|
+
'@(layout, w >= 600px)': 'row',
|
|
342
|
+
},
|
|
343
|
+
},
|
|
344
|
+
});
|
|
192
345
|
```
|
|
193
346
|
|
|
194
|
-
|
|
347
|
+
| Tasty syntax | CSS output |
|
|
348
|
+
|--------------|------------|
|
|
349
|
+
| `@(layout, w < 600px)` | `@container layout (width < 600px)` |
|
|
350
|
+
| `@(w < 600px)` | `@container (width < 600px)` |
|
|
351
|
+
| `@(layout, $variant=danger)` | `@container layout style(--variant: "danger")` |
|
|
352
|
+
| `@(layout, $compact)` | `@container layout style(--compact)` |
|
|
353
|
+
| `@(scroll-state(stuck: top))` | `@container scroll-state(stuck: top)` |
|
|
354
|
+
| `@(nav, scroll-state(stuck: top))` | `@container nav scroll-state(stuck: top)` |
|
|
195
355
|
|
|
196
|
-
|
|
356
|
+
Container style queries use `$prop` (boolean) or `$prop=value` syntax, which maps to CSS `style(--prop)` or `style(--prop: "value")`.
|
|
197
357
|
|
|
198
|
-
|
|
199
|
-
mods={{ hovered: true, theme: 'danger' }}
|
|
200
|
-
// → data-hovered="" data-theme="danger"
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
---
|
|
358
|
+
### `@supports(...)` — Feature Queries
|
|
204
359
|
|
|
205
|
-
|
|
360
|
+
Feature queries test CSS property support. Use `$` as the first argument to test selector support:
|
|
206
361
|
|
|
207
|
-
|
|
362
|
+
| Tasty syntax | CSS output |
|
|
363
|
+
|--------------|------------|
|
|
364
|
+
| `@supports(display: grid)` | `@supports (display: grid)` |
|
|
365
|
+
| `@supports($, :has(*))` | `@supports selector(:has(*))` |
|
|
366
|
+
| `!@supports(display: grid)` | `@supports (not (display: grid))` |
|
|
208
367
|
|
|
209
368
|
```jsx
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
// Extend existing component
|
|
217
|
-
const StyledButton = tasty(Button, {
|
|
218
|
-
styles: { /* additional styles */ },
|
|
219
|
-
});
|
|
369
|
+
display: {
|
|
370
|
+
'': 'flex',
|
|
371
|
+
'@supports(display: grid)': 'grid',
|
|
372
|
+
}
|
|
220
373
|
```
|
|
221
374
|
|
|
222
|
-
###
|
|
375
|
+
### `@root(...)` — Root Element States
|
|
223
376
|
|
|
224
|
-
|
|
377
|
+
Root states generate selectors on the `:root` element. They are useful for theme modes, feature flags, and other page-level conditions:
|
|
225
378
|
|
|
226
|
-
|
|
227
|
-
const FlexibleBox = tasty({
|
|
228
|
-
as: 'div',
|
|
229
|
-
styles: {
|
|
230
|
-
display: 'flex',
|
|
231
|
-
padding: '2x',
|
|
232
|
-
},
|
|
233
|
-
styleProps: ['gap', 'align', 'placeContent', 'fill'],
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
<FlexibleBox gap="2x" align="center" fill="#surface">
|
|
237
|
-
Content
|
|
238
|
-
</FlexibleBox>
|
|
239
|
-
```
|
|
240
|
-
|
|
241
|
-
### Color Tokens & Opacity
|
|
379
|
+
These docs use `data-schema` in examples. If your app standardizes on a different root attribute, keep the same pattern and swap the attribute name consistently in your aliases and selectors.
|
|
242
380
|
|
|
243
381
|
```jsx
|
|
244
|
-
color:
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
color: '(#primary, #secondary)', // Fallback syntax
|
|
382
|
+
color: {
|
|
383
|
+
'': '#text',
|
|
384
|
+
'@root(schema=dark)': '#text-on-dark',
|
|
385
|
+
'@root(.premium-user)': '#gold',
|
|
386
|
+
}
|
|
250
387
|
```
|
|
251
388
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
|
255
|
-
|
|
256
|
-
| `
|
|
257
|
-
| `
|
|
258
|
-
| `
|
|
259
|
-
| `bw` | Border width | `2bw` | `calc(var(--border-width) * 2)` |
|
|
260
|
-
| `ow` | Outline width | `1ow` | `var(--outline-width)` |
|
|
261
|
-
| `fs` | Font size | `1fs` | `var(--font-size)` |
|
|
262
|
-
| `lh` | Line height | `1lh` | `var(--line-height)` |
|
|
263
|
-
| `sf` | Stable fraction | `1sf` | `minmax(0, 1fr)` |
|
|
264
|
-
|
|
265
|
-
You can register additional custom units via [`configure()`](configuration.md#options).
|
|
266
|
-
|
|
267
|
-
### Predefined Tokens
|
|
389
|
+
| Tasty syntax | CSS selector |
|
|
390
|
+
|--------------|-------------|
|
|
391
|
+
| `@root(schema=dark)` | `:root[data-schema="dark"]` |
|
|
392
|
+
| `@root(hovered)` | `:root[data-hovered]` |
|
|
393
|
+
| `@root(.premium-user)` | `:root.premium-user` |
|
|
394
|
+
| `@root([lang="en"])` | `:root[lang="en"]` |
|
|
395
|
+
| `!@root(schema=dark)` | `:root:not([data-schema="dark"])` |
|
|
268
396
|
|
|
269
|
-
|
|
397
|
+
Root conditions are prepended to the component selector: `:root[data-schema="dark"] .t0.t0 { ... }`.
|
|
270
398
|
|
|
271
|
-
|
|
272
|
-
const Card = tasty({
|
|
273
|
-
styles: {
|
|
274
|
-
padding: '$card-padding',
|
|
275
|
-
fill: '#surface',
|
|
276
|
-
border: '1bw solid #accent',
|
|
277
|
-
},
|
|
278
|
-
});
|
|
279
|
-
```
|
|
399
|
+
### `@own(...)` — Sub-element's Own State
|
|
280
400
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
Apply predefined style bundles (defined via [`configure({ recipes })`](configuration.md#recipes)) using the `recipe` style property:
|
|
401
|
+
By default, state keys in sub-element styles refer to the root component's state context. Use `@own(...)` when the sub-element should react to its own state:
|
|
284
402
|
|
|
285
403
|
```jsx
|
|
286
|
-
const
|
|
404
|
+
const Nav = tasty({
|
|
287
405
|
styles: {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
//
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
recipe: 'card elevated',
|
|
297
|
-
color: '#text',
|
|
406
|
+
NavItem: {
|
|
407
|
+
color: {
|
|
408
|
+
'': '#text',
|
|
409
|
+
'@own(:hover)': '#primary',
|
|
410
|
+
'@own(:focus-visible)': '#primary',
|
|
411
|
+
'selected': '#primary', // root-level modifier
|
|
412
|
+
},
|
|
413
|
+
},
|
|
298
414
|
},
|
|
415
|
+
elements: { NavItem: 'a' },
|
|
299
416
|
});
|
|
300
417
|
```
|
|
301
418
|
|
|
302
|
-
|
|
419
|
+
| Tasty syntax (inside sub-element) | CSS output |
|
|
420
|
+
|-----------------------------------|------------|
|
|
421
|
+
| `@own(:hover)` | `:hover` on the sub-element selector |
|
|
422
|
+
| `@own(hovered)` | `[data-hovered]` on the sub-element selector |
|
|
423
|
+
| `@own(theme=dark)` | `[data-theme="dark"]` on the sub-element selector |
|
|
303
424
|
|
|
304
|
-
|
|
425
|
+
`@own()` is only valid inside sub-element styles. Using it on root styles emits a warning and is treated as a regular modifier.
|
|
305
426
|
|
|
306
|
-
|
|
307
|
-
const Input = tasty({
|
|
308
|
-
styles: {
|
|
309
|
-
recipe: 'reset input / input-autofill',
|
|
310
|
-
preset: 't3',
|
|
311
|
-
},
|
|
312
|
-
});
|
|
313
|
-
```
|
|
427
|
+
### `@starting` — Entry Animation
|
|
314
428
|
|
|
315
|
-
|
|
429
|
+
Wraps the rule in `@starting-style`, enabling CSS entry animations for elements as they appear in the DOM:
|
|
316
430
|
|
|
317
431
|
```jsx
|
|
318
|
-
const
|
|
432
|
+
const FadeIn = tasty({
|
|
319
433
|
styles: {
|
|
320
|
-
|
|
321
|
-
|
|
434
|
+
opacity: { '': '1', '@starting': '0' },
|
|
435
|
+
transform: { '': 'scale(1)', '@starting': 'scale(0.95)' },
|
|
436
|
+
transition: 'opacity 0.3s, translate 0.3s',
|
|
322
437
|
},
|
|
323
438
|
});
|
|
324
439
|
```
|
|
325
440
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
|
329
|
-
|--------|---------|---------|
|
|
330
|
-
| `@media` | Media queries | `@media(w < 768px)` |
|
|
331
|
-
| `@(...)` | Container queries | `@(panel, w >= 300px)` |
|
|
332
|
-
| `@supports` | Feature/selector support | `@supports(display: grid)` |
|
|
333
|
-
| `@root` | Root element states | `@root(theme=dark)` |
|
|
334
|
-
| `@parent` | Parent/ancestor element states | `@parent(hovered)` |
|
|
335
|
-
| `@own` | Sub-element's own state | `@own(hovered)` |
|
|
336
|
-
| `@starting` | Entry animation | `@starting` |
|
|
337
|
-
| `:is()` | CSS `:is()` structural pseudo-class | `:is(fieldset > label)` |
|
|
338
|
-
| `:has()` | CSS `:has()` relational pseudo-class | `:has(> Icon)` |
|
|
339
|
-
| `:not()` | CSS `:not()` negation (prefer `!:is()`) | `:not(:first-child)` |
|
|
340
|
-
| `:where()` | CSS `:where()` (zero specificity) | `:where(Section)` |
|
|
441
|
+
| Tasty syntax | CSS output |
|
|
442
|
+
|--------------|------------|
|
|
443
|
+
| `@starting` | `@starting-style { .t0.t0 { ... } }` |
|
|
341
444
|
|
|
342
|
-
|
|
445
|
+
### `@parent(...)` — Parent Element States
|
|
343
446
|
|
|
344
|
-
Style based on ancestor element attributes. Uses `:is([selector] *)` / `:not([selector] *)` for symmetric, composable parent checks. Boolean logic (`&`, `|`,
|
|
447
|
+
Style based on ancestor element attributes. Uses `:is([selector] *)` / `:not([selector] *)` for symmetric, composable parent checks. Boolean logic (`&`, `|`, `!`, `^`) is supported inside `@parent()`.
|
|
345
448
|
|
|
346
449
|
```jsx
|
|
347
450
|
const Highlight = tasty({
|
|
@@ -381,7 +484,7 @@ const Card = tasty({
|
|
|
381
484
|
// → .t0.t0:is([data-hovered] *) [data-element="Label"]
|
|
382
485
|
```
|
|
383
486
|
|
|
384
|
-
|
|
487
|
+
### `:is()`, `:has()` — CSS Structural Pseudo-classes
|
|
385
488
|
|
|
386
489
|
Use CSS structural pseudo-classes directly in state keys. Capitalized words become `[data-element="..."]` selectors; lowercase words are HTML tags. A trailing combinator (`>`, `+`, `~`) is auto-completed with `*`.
|
|
387
490
|
|
|
@@ -419,27 +522,22 @@ const Card = tasty({
|
|
|
419
522
|
| `!:has(> Icon)` | `:not(:has(> [data-element="Icon"]))` | Negation (use `!`) |
|
|
420
523
|
| `!:is(Panel)` | `:not([data-element="Panel"])` | Negation (use `!:is`) |
|
|
421
524
|
|
|
422
|
-
Combine with other states using boolean logic:
|
|
525
|
+
Combine with other states using boolean logic (`&`, `|`, `!`, `^`):
|
|
423
526
|
|
|
424
527
|
```jsx
|
|
425
|
-
':has(> Icon) & hovered' // structural + data attribute
|
|
426
|
-
'@parent(hovered) & :has(> Icon)' // parent check + structural
|
|
528
|
+
':has(> Icon) & hovered' // AND: structural + data attribute
|
|
529
|
+
'@parent(hovered) & :has(> Icon)' // AND: parent check + structural
|
|
427
530
|
':has(> Icon) | :has(> Button)' // OR: either sub-element present
|
|
531
|
+
':has(> Icon) ^ :has(> Button)' // XOR: exactly one present
|
|
428
532
|
```
|
|
429
533
|
|
|
430
534
|
> **Nesting limit:** The state key parser supports up to 2 levels of nested parentheses inside `:is()`, `:has()`, `:not()`, and `:where()` — e.g. `:has(Input:not(:disabled))` works, but 3+ levels like `:has(:is(:not(:hover)))` will not be tokenized correctly. This covers virtually all practical use cases.
|
|
431
535
|
|
|
432
536
|
---
|
|
433
537
|
|
|
434
|
-
##
|
|
538
|
+
## Keyframes
|
|
435
539
|
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
---
|
|
439
|
-
|
|
440
|
-
## Advanced Features
|
|
441
|
-
|
|
442
|
-
### Keyframes
|
|
540
|
+
Define animations inline using the `@keyframes` key in styles:
|
|
443
541
|
|
|
444
542
|
```jsx
|
|
445
543
|
const Pulse = tasty({
|
|
@@ -455,7 +553,9 @@ const Pulse = tasty({
|
|
|
455
553
|
});
|
|
456
554
|
```
|
|
457
555
|
|
|
458
|
-
|
|
556
|
+
---
|
|
557
|
+
|
|
558
|
+
## Properties (`@property`)
|
|
459
559
|
|
|
460
560
|
CSS cannot transition or animate custom properties unless the browser knows their type. Tasty solves this automatically — when you assign a concrete value to a custom property, the type is inferred and a CSS `@property` rule is registered behind the scenes:
|
|
461
561
|
|
|
@@ -480,216 +580,109 @@ Use explicit `@properties` when you need non-default settings like `inherits: fa
|
|
|
480
580
|
},
|
|
481
581
|
```
|
|
482
582
|
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
```jsx
|
|
486
|
-
const Button = tasty({
|
|
487
|
-
styles: {
|
|
488
|
-
padding: '2x 4x',
|
|
489
|
-
border: true,
|
|
490
|
-
},
|
|
491
|
-
variants: {
|
|
492
|
-
default: { fill: '#blue', color: '#white' },
|
|
493
|
-
danger: { fill: '#red', color: '#white' },
|
|
494
|
-
outline: { fill: 'transparent', color: '#blue', border: '1bw solid #blue' },
|
|
495
|
-
},
|
|
496
|
-
});
|
|
497
|
-
|
|
498
|
-
<Button variant="danger">Delete</Button>
|
|
499
|
-
```
|
|
583
|
+
---
|
|
500
584
|
|
|
501
|
-
|
|
585
|
+
## Font Face (`@fontFace`)
|
|
502
586
|
|
|
503
|
-
|
|
587
|
+
Register custom fonts directly inside a `styles` object. Keys are font-family names, values are descriptor objects (or arrays of them for multiple weights/styles).
|
|
504
588
|
|
|
505
|
-
```
|
|
506
|
-
const
|
|
589
|
+
```ts
|
|
590
|
+
const Heading = tasty({
|
|
507
591
|
styles: {
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
},
|
|
514
|
-
variants: {
|
|
515
|
-
primary: {
|
|
516
|
-
border: { '': '#white.2', pressed: '#primary-text', disabled: '#clear' },
|
|
517
|
-
fill: { '': '#white #primary', hovered: '#white #primary-text' },
|
|
518
|
-
},
|
|
519
|
-
secondary: {
|
|
520
|
-
border: { '': '#primary.15', pressed: '#primary.3' },
|
|
521
|
-
fill: '#primary.10',
|
|
592
|
+
'@fontFace': {
|
|
593
|
+
'Brand Sans': {
|
|
594
|
+
src: 'url("/fonts/brand-sans.woff2") format("woff2")',
|
|
595
|
+
fontDisplay: 'swap',
|
|
596
|
+
},
|
|
522
597
|
},
|
|
598
|
+
fontFamily: '"Brand Sans", sans-serif',
|
|
523
599
|
},
|
|
524
600
|
});
|
|
525
|
-
|
|
526
|
-
// Both variants get 'type=primary': '#clear' appended to their border map
|
|
527
601
|
```
|
|
528
602
|
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
### Sub-element Styling
|
|
532
|
-
|
|
533
|
-
Sub-elements are inner parts of a compound component, styled via capitalized keys in `styles` and identified by `data-element` attributes in the DOM.
|
|
534
|
-
|
|
535
|
-
> **Best Practice:** 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.
|
|
536
|
-
|
|
537
|
-
```jsx
|
|
538
|
-
const Card = tasty({
|
|
539
|
-
styles: {
|
|
540
|
-
padding: '4x',
|
|
541
|
-
Title: { preset: 'h3', color: '#primary' },
|
|
542
|
-
Content: { color: '#text' },
|
|
543
|
-
},
|
|
544
|
-
elements: {
|
|
545
|
-
Title: 'h3',
|
|
546
|
-
Content: 'div',
|
|
547
|
-
},
|
|
548
|
-
});
|
|
549
|
-
|
|
550
|
-
// Sub-components automatically get data-element attributes
|
|
551
|
-
<Card>
|
|
552
|
-
<Card.Title>Card Title</Card.Title>
|
|
553
|
-
<Card.Content>Card content</Card.Content>
|
|
554
|
-
</Card>
|
|
555
|
-
```
|
|
603
|
+
### Multiple weights
|
|
556
604
|
|
|
557
|
-
|
|
605
|
+
Supply an array to register several variants of the same family:
|
|
558
606
|
|
|
559
|
-
```
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
607
|
+
```ts
|
|
608
|
+
'@fontFace': {
|
|
609
|
+
'Brand Sans': [
|
|
610
|
+
{ src: 'url("/fonts/brand-regular.woff2") format("woff2")', fontWeight: 400, fontDisplay: 'swap' },
|
|
611
|
+
{ src: 'url("/fonts/brand-bold.woff2") format("woff2")', fontWeight: 700, fontDisplay: 'swap' },
|
|
612
|
+
],
|
|
563
613
|
}
|
|
564
614
|
```
|
|
565
615
|
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
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:
|
|
569
|
-
|
|
570
|
-
```jsx
|
|
571
|
-
const Card = tasty({
|
|
572
|
-
styles: {
|
|
573
|
-
padding: '4x',
|
|
574
|
-
Title: { preset: 'h3', color: '#primary' },
|
|
575
|
-
},
|
|
576
|
-
});
|
|
616
|
+
### Supported descriptors
|
|
577
617
|
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
618
|
+
| Descriptor | CSS property | Type |
|
|
619
|
+
|---|---|---|
|
|
620
|
+
| `src` (required) | `src` | `string` |
|
|
621
|
+
| `fontWeight` | `font-weight` | `string \| number` |
|
|
622
|
+
| `fontStyle` | `font-style` | `string` |
|
|
623
|
+
| `fontStretch` | `font-stretch` | `string` |
|
|
624
|
+
| `fontDisplay` | `font-display` | `'auto' \| 'block' \| 'swap' \| 'fallback' \| 'optional'` |
|
|
625
|
+
| `unicodeRange` | `unicode-range` | `string` |
|
|
626
|
+
| `ascentOverride` | `ascent-override` | `string` |
|
|
627
|
+
| `descentOverride` | `descent-override` | `string` |
|
|
628
|
+
| `lineGapOverride` | `line-gap-override` | `string` |
|
|
629
|
+
| `sizeAdjust` | `size-adjust` | `string` |
|
|
630
|
+
| `fontFeatureSettings` | `font-feature-settings` | `string` |
|
|
631
|
+
| `fontVariationSettings` | `font-variation-settings` | `string` |
|
|
582
632
|
|
|
583
|
-
|
|
633
|
+
> Font-face rules are permanent — they are injected once and never cleaned up, matching how browsers handle `@font-face`.
|
|
584
634
|
|
|
585
|
-
|
|
635
|
+
---
|
|
586
636
|
|
|
587
|
-
|
|
588
|
-
|---------|--------|-------------|
|
|
589
|
-
| *(none)* | ` [el]` | Descendant (default) |
|
|
590
|
-
| `>` | `> [el]` | Direct child |
|
|
591
|
-
| `>Body>Row>` | `> [Body] > [Row] > [el]` | Chained elements |
|
|
592
|
-
| `::before` | `::before` | Root pseudo (no key) |
|
|
593
|
-
| `@::before` | `[el]::before` | Pseudo on the sub-element |
|
|
594
|
-
| `>@:hover` | `> [el]:hover` | Pseudo-class on the sub-element |
|
|
595
|
-
| `>@.active` | `> [el].active` | Class on the sub-element |
|
|
637
|
+
## Counter Style (`@counterStyle`)
|
|
596
638
|
|
|
597
|
-
|
|
639
|
+
Define custom list markers via the CSS `@counter-style` at-rule. Keys are counter-style names, values are descriptor objects.
|
|
598
640
|
|
|
599
|
-
```
|
|
600
|
-
const
|
|
641
|
+
```ts
|
|
642
|
+
const EmojiList = tasty({
|
|
643
|
+
tag: 'ol',
|
|
601
644
|
styles: {
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
645
|
+
'@counterStyle': {
|
|
646
|
+
thumbs: {
|
|
647
|
+
system: 'cyclic',
|
|
648
|
+
symbols: '"👍"',
|
|
649
|
+
suffix: '" "',
|
|
650
|
+
},
|
|
605
651
|
},
|
|
652
|
+
listStyleType: 'thumbs',
|
|
606
653
|
},
|
|
607
654
|
});
|
|
608
|
-
// → .t0 > [data-element="Item"]:last-child { border: none }
|
|
609
655
|
```
|
|
610
656
|
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
## Hooks
|
|
614
|
-
|
|
615
|
-
### useStyles
|
|
657
|
+
### Supported descriptors
|
|
616
658
|
|
|
617
|
-
|
|
618
|
-
|
|
659
|
+
| Descriptor | CSS property | Type |
|
|
660
|
+
|---|---|---|
|
|
661
|
+
| `system` (required) | `system` | `'cyclic' \| 'numeric' \| 'alphabetic' \| 'symbolic' \| 'additive' \| 'fixed' \| string` |
|
|
662
|
+
| `symbols` | `symbols` | `string` |
|
|
663
|
+
| `additiveSymbols` | `additive-symbols` | `string` |
|
|
664
|
+
| `prefix` | `prefix` | `string` |
|
|
665
|
+
| `suffix` | `suffix` | `string` |
|
|
666
|
+
| `negative` | `negative` | `string` |
|
|
667
|
+
| `range` | `range` | `string` |
|
|
668
|
+
| `pad` | `pad` | `string` |
|
|
669
|
+
| `fallback` | `fallback` | `string` |
|
|
670
|
+
| `speakAs` | `speak-as` | `string` |
|
|
619
671
|
|
|
620
|
-
|
|
621
|
-
const { className } = useStyles({
|
|
622
|
-
padding: '2x',
|
|
623
|
-
fill: '#surface',
|
|
624
|
-
radius: '1r',
|
|
625
|
-
});
|
|
626
|
-
|
|
627
|
-
return <div className={className}>Styled content</div>;
|
|
628
|
-
}
|
|
629
|
-
```
|
|
630
|
-
|
|
631
|
-
### useGlobalStyles
|
|
632
|
-
|
|
633
|
-
```tsx
|
|
634
|
-
import { useGlobalStyles } from '@tenphi/tasty';
|
|
635
|
-
|
|
636
|
-
function ThemeStyles() {
|
|
637
|
-
useGlobalStyles('.card', {
|
|
638
|
-
padding: '4x',
|
|
639
|
-
fill: '#surface',
|
|
640
|
-
radius: '1r',
|
|
641
|
-
});
|
|
642
|
-
|
|
643
|
-
return null;
|
|
644
|
-
}
|
|
645
|
-
```
|
|
646
|
-
|
|
647
|
-
### useRawCSS
|
|
648
|
-
|
|
649
|
-
```tsx
|
|
650
|
-
import { useRawCSS } from '@tenphi/tasty';
|
|
651
|
-
|
|
652
|
-
function GlobalReset() {
|
|
653
|
-
useRawCSS(`
|
|
654
|
-
body { margin: 0; padding: 0; }
|
|
655
|
-
`);
|
|
656
|
-
|
|
657
|
-
return null;
|
|
658
|
-
}
|
|
659
|
-
```
|
|
660
|
-
|
|
661
|
-
### useMergeStyles
|
|
662
|
-
|
|
663
|
-
```tsx
|
|
664
|
-
import { useMergeStyles } from '@tenphi/tasty';
|
|
665
|
-
|
|
666
|
-
function MyTabs({ styles, tabListStyles, prefixStyles }) {
|
|
667
|
-
const mergedStyles = useMergeStyles(styles, {
|
|
668
|
-
TabList: tabListStyles,
|
|
669
|
-
Prefix: prefixStyles,
|
|
670
|
-
});
|
|
671
|
-
|
|
672
|
-
return <TabsElement styles={mergedStyles} />;
|
|
673
|
-
}
|
|
674
|
-
```
|
|
672
|
+
> Counter-style rules are permanent — they are injected once and never cleaned up, matching how browsers handle `@counter-style`.
|
|
675
673
|
|
|
676
674
|
---
|
|
677
675
|
|
|
678
|
-
##
|
|
676
|
+
## Style Properties
|
|
679
677
|
|
|
680
|
-
|
|
678
|
+
For a complete reference of all enhanced style properties — syntax, values, modifiers, and recommendations — see **[Style Properties Reference](styles.md)**.
|
|
681
679
|
|
|
682
|
-
|
|
683
|
-
- Use design tokens and custom units (`#text`, `2x`, `1r`)
|
|
684
|
-
- Use semantic transition names (`theme 0.3s`)
|
|
685
|
-
- Use `elements` prop to declare typed sub-components for compound components
|
|
686
|
-
- Use `styleProps` for component APIs
|
|
687
|
-
- Use `tokens` prop for dynamic values
|
|
680
|
+
---
|
|
688
681
|
|
|
689
|
-
|
|
682
|
+
## Learn more
|
|
690
683
|
|
|
691
|
-
-
|
|
692
|
-
-
|
|
693
|
-
-
|
|
694
|
-
-
|
|
695
|
-
-
|
|
684
|
+
- **[Runtime API](runtime.md)** — `tasty()` factory, component props, variants, sub-elements, style functions
|
|
685
|
+
- **[Methodology](methodology.md)** — Recommended patterns: root + sub-elements, styleProps, tokens, wrapping
|
|
686
|
+
- **[Configuration](configuration.md)** — Tokens, recipes, custom units, style handlers, TypeScript extensions
|
|
687
|
+
- **[Style Properties](styles.md)** — Complete reference for all enhanced style properties
|
|
688
|
+
- **[Zero Runtime (tastyStatic)](tasty-static.md)** — Build-time static styling with Babel plugin
|