@tenphi/tasty 0.0.0-snapshot.056b911

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.
Files changed (332) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +635 -0
  3. package/dist/_virtual/_rolldown/runtime.js +7 -0
  4. package/dist/chunks/cacheKey.d.ts +1 -0
  5. package/dist/chunks/cacheKey.js +77 -0
  6. package/dist/chunks/cacheKey.js.map +1 -0
  7. package/dist/chunks/definitions.d.ts +37 -0
  8. package/dist/chunks/definitions.js +258 -0
  9. package/dist/chunks/definitions.js.map +1 -0
  10. package/dist/chunks/index.d.ts +1 -0
  11. package/dist/chunks/renderChunk.d.ts +1 -0
  12. package/dist/chunks/renderChunk.js +59 -0
  13. package/dist/chunks/renderChunk.js.map +1 -0
  14. package/dist/compute-styles.d.ts +31 -0
  15. package/dist/compute-styles.js +335 -0
  16. package/dist/compute-styles.js.map +1 -0
  17. package/dist/config.d.ts +409 -0
  18. package/dist/config.js +584 -0
  19. package/dist/config.js.map +1 -0
  20. package/dist/core/index.d.ts +34 -0
  21. package/dist/core/index.js +27 -0
  22. package/dist/counter-style/index.js +51 -0
  23. package/dist/counter-style/index.js.map +1 -0
  24. package/dist/debug.d.ts +89 -0
  25. package/dist/debug.js +453 -0
  26. package/dist/debug.js.map +1 -0
  27. package/dist/font-face/index.js +63 -0
  28. package/dist/font-face/index.js.map +1 -0
  29. package/dist/hooks/index.d.ts +7 -0
  30. package/dist/hooks/useCounterStyle.d.ts +36 -0
  31. package/dist/hooks/useCounterStyle.js +64 -0
  32. package/dist/hooks/useCounterStyle.js.map +1 -0
  33. package/dist/hooks/useFontFace.d.ts +45 -0
  34. package/dist/hooks/useFontFace.js +66 -0
  35. package/dist/hooks/useFontFace.js.map +1 -0
  36. package/dist/hooks/useGlobalStyles.d.ts +46 -0
  37. package/dist/hooks/useGlobalStyles.js +88 -0
  38. package/dist/hooks/useGlobalStyles.js.map +1 -0
  39. package/dist/hooks/useKeyframes.d.ts +58 -0
  40. package/dist/hooks/useKeyframes.js +54 -0
  41. package/dist/hooks/useKeyframes.js.map +1 -0
  42. package/dist/hooks/useProperty.d.ts +81 -0
  43. package/dist/hooks/useProperty.js +96 -0
  44. package/dist/hooks/useProperty.js.map +1 -0
  45. package/dist/hooks/useRawCSS.d.ts +22 -0
  46. package/dist/hooks/useRawCSS.js +103 -0
  47. package/dist/hooks/useRawCSS.js.map +1 -0
  48. package/dist/hooks/useStyles.d.ts +40 -0
  49. package/dist/hooks/useStyles.js +31 -0
  50. package/dist/hooks/useStyles.js.map +1 -0
  51. package/dist/index.d.ts +51 -0
  52. package/dist/index.js +36 -0
  53. package/dist/injector/index.d.ts +182 -0
  54. package/dist/injector/index.js +185 -0
  55. package/dist/injector/index.js.map +1 -0
  56. package/dist/injector/injector.d.ts +193 -0
  57. package/dist/injector/injector.js +564 -0
  58. package/dist/injector/injector.js.map +1 -0
  59. package/dist/injector/sheet-manager.d.ts +132 -0
  60. package/dist/injector/sheet-manager.js +698 -0
  61. package/dist/injector/sheet-manager.js.map +1 -0
  62. package/dist/injector/types.d.ts +228 -0
  63. package/dist/keyframes/index.js +206 -0
  64. package/dist/keyframes/index.js.map +1 -0
  65. package/dist/parser/classify.js +319 -0
  66. package/dist/parser/classify.js.map +1 -0
  67. package/dist/parser/const.js +60 -0
  68. package/dist/parser/const.js.map +1 -0
  69. package/dist/parser/lru.js +109 -0
  70. package/dist/parser/lru.js.map +1 -0
  71. package/dist/parser/parser.d.ts +25 -0
  72. package/dist/parser/parser.js +115 -0
  73. package/dist/parser/parser.js.map +1 -0
  74. package/dist/parser/tokenizer.js +69 -0
  75. package/dist/parser/tokenizer.js.map +1 -0
  76. package/dist/parser/types.d.ts +51 -0
  77. package/dist/parser/types.js +46 -0
  78. package/dist/parser/types.js.map +1 -0
  79. package/dist/pipeline/conditions.d.ts +134 -0
  80. package/dist/pipeline/conditions.js +406 -0
  81. package/dist/pipeline/conditions.js.map +1 -0
  82. package/dist/pipeline/exclusive.js +230 -0
  83. package/dist/pipeline/exclusive.js.map +1 -0
  84. package/dist/pipeline/index.d.ts +55 -0
  85. package/dist/pipeline/index.js +708 -0
  86. package/dist/pipeline/index.js.map +1 -0
  87. package/dist/pipeline/materialize.js +1103 -0
  88. package/dist/pipeline/materialize.js.map +1 -0
  89. package/dist/pipeline/parseStateKey.d.ts +15 -0
  90. package/dist/pipeline/parseStateKey.js +446 -0
  91. package/dist/pipeline/parseStateKey.js.map +1 -0
  92. package/dist/pipeline/simplify.js +515 -0
  93. package/dist/pipeline/simplify.js.map +1 -0
  94. package/dist/pipeline/warnings.js +18 -0
  95. package/dist/pipeline/warnings.js.map +1 -0
  96. package/dist/plugins/index.d.ts +2 -0
  97. package/dist/plugins/okhsl-plugin.d.ts +35 -0
  98. package/dist/plugins/okhsl-plugin.js +97 -0
  99. package/dist/plugins/okhsl-plugin.js.map +1 -0
  100. package/dist/plugins/types.d.ts +87 -0
  101. package/dist/properties/index.js +222 -0
  102. package/dist/properties/index.js.map +1 -0
  103. package/dist/properties/property-type-resolver.d.ts +24 -0
  104. package/dist/properties/property-type-resolver.js +90 -0
  105. package/dist/properties/property-type-resolver.js.map +1 -0
  106. package/dist/rsc-cache.js +81 -0
  107. package/dist/rsc-cache.js.map +1 -0
  108. package/dist/ssr/astro-client.d.ts +1 -0
  109. package/dist/ssr/astro-client.js +24 -0
  110. package/dist/ssr/astro-client.js.map +1 -0
  111. package/dist/ssr/astro-middleware.d.ts +15 -0
  112. package/dist/ssr/astro-middleware.js +19 -0
  113. package/dist/ssr/astro-middleware.js.map +1 -0
  114. package/dist/ssr/astro.d.ts +106 -0
  115. package/dist/ssr/astro.js +149 -0
  116. package/dist/ssr/astro.js.map +1 -0
  117. package/dist/ssr/async-storage.d.ts +17 -0
  118. package/dist/ssr/async-storage.js +44 -0
  119. package/dist/ssr/async-storage.js.map +1 -0
  120. package/dist/ssr/collect-auto-properties.js +58 -0
  121. package/dist/ssr/collect-auto-properties.js.map +1 -0
  122. package/dist/ssr/collector.d.ts +102 -0
  123. package/dist/ssr/collector.js +227 -0
  124. package/dist/ssr/collector.js.map +1 -0
  125. package/dist/ssr/context.js +16 -0
  126. package/dist/ssr/context.js.map +1 -0
  127. package/dist/ssr/format-global-rules.js +22 -0
  128. package/dist/ssr/format-global-rules.js.map +1 -0
  129. package/dist/ssr/format-keyframes.js +69 -0
  130. package/dist/ssr/format-keyframes.js.map +1 -0
  131. package/dist/ssr/format-property.js +49 -0
  132. package/dist/ssr/format-property.js.map +1 -0
  133. package/dist/ssr/format-rules.js +73 -0
  134. package/dist/ssr/format-rules.js.map +1 -0
  135. package/dist/ssr/hydrate.d.ts +22 -0
  136. package/dist/ssr/hydrate.js +49 -0
  137. package/dist/ssr/hydrate.js.map +1 -0
  138. package/dist/ssr/index.d.ts +4 -0
  139. package/dist/ssr/index.js +10 -0
  140. package/dist/ssr/index.js.map +1 -0
  141. package/dist/ssr/next.d.ts +45 -0
  142. package/dist/ssr/next.js +75 -0
  143. package/dist/ssr/next.js.map +1 -0
  144. package/dist/ssr/ssr-collector-ref.js +29 -0
  145. package/dist/ssr/ssr-collector-ref.js.map +1 -0
  146. package/dist/states/index.d.ts +49 -0
  147. package/dist/states/index.js +170 -0
  148. package/dist/states/index.js.map +1 -0
  149. package/dist/static/index.d.ts +5 -0
  150. package/dist/static/index.js +4 -0
  151. package/dist/static/inject.d.ts +5 -0
  152. package/dist/static/inject.js +17 -0
  153. package/dist/static/inject.js.map +1 -0
  154. package/dist/static/tastyStatic.d.ts +46 -0
  155. package/dist/static/tastyStatic.js +30 -0
  156. package/dist/static/tastyStatic.js.map +1 -0
  157. package/dist/static/types.d.ts +49 -0
  158. package/dist/static/types.js +24 -0
  159. package/dist/static/types.js.map +1 -0
  160. package/dist/styles/border.d.ts +25 -0
  161. package/dist/styles/border.js +120 -0
  162. package/dist/styles/border.js.map +1 -0
  163. package/dist/styles/color.d.ts +14 -0
  164. package/dist/styles/color.js +26 -0
  165. package/dist/styles/color.js.map +1 -0
  166. package/dist/styles/const.js +17 -0
  167. package/dist/styles/const.js.map +1 -0
  168. package/dist/styles/createStyle.js +79 -0
  169. package/dist/styles/createStyle.js.map +1 -0
  170. package/dist/styles/dimension.js +109 -0
  171. package/dist/styles/dimension.js.map +1 -0
  172. package/dist/styles/directional.js +133 -0
  173. package/dist/styles/directional.js.map +1 -0
  174. package/dist/styles/display.d.ts +30 -0
  175. package/dist/styles/display.js +73 -0
  176. package/dist/styles/display.js.map +1 -0
  177. package/dist/styles/fade.d.ts +15 -0
  178. package/dist/styles/fade.js +62 -0
  179. package/dist/styles/fade.js.map +1 -0
  180. package/dist/styles/fill.d.ts +42 -0
  181. package/dist/styles/fill.js +51 -0
  182. package/dist/styles/fill.js.map +1 -0
  183. package/dist/styles/flow.d.ts +16 -0
  184. package/dist/styles/flow.js +12 -0
  185. package/dist/styles/flow.js.map +1 -0
  186. package/dist/styles/gap.d.ts +31 -0
  187. package/dist/styles/gap.js +38 -0
  188. package/dist/styles/gap.js.map +1 -0
  189. package/dist/styles/height.d.ts +17 -0
  190. package/dist/styles/height.js +19 -0
  191. package/dist/styles/height.js.map +1 -0
  192. package/dist/styles/index.d.ts +1 -0
  193. package/dist/styles/index.js +8 -0
  194. package/dist/styles/index.js.map +1 -0
  195. package/dist/styles/inset.d.ts +24 -0
  196. package/dist/styles/inset.js +34 -0
  197. package/dist/styles/inset.js.map +1 -0
  198. package/dist/styles/list.d.ts +16 -0
  199. package/dist/styles/list.js +100 -0
  200. package/dist/styles/list.js.map +1 -0
  201. package/dist/styles/margin.d.ts +24 -0
  202. package/dist/styles/margin.js +32 -0
  203. package/dist/styles/margin.js.map +1 -0
  204. package/dist/styles/outline.d.ts +29 -0
  205. package/dist/styles/outline.js +55 -0
  206. package/dist/styles/outline.js.map +1 -0
  207. package/dist/styles/padding.d.ts +24 -0
  208. package/dist/styles/padding.js +32 -0
  209. package/dist/styles/padding.js.map +1 -0
  210. package/dist/styles/placement.d.ts +37 -0
  211. package/dist/styles/placement.js +74 -0
  212. package/dist/styles/placement.js.map +1 -0
  213. package/dist/styles/predefined.d.ts +71 -0
  214. package/dist/styles/predefined.js +237 -0
  215. package/dist/styles/predefined.js.map +1 -0
  216. package/dist/styles/preset.d.ts +52 -0
  217. package/dist/styles/preset.js +127 -0
  218. package/dist/styles/preset.js.map +1 -0
  219. package/dist/styles/radius.d.ts +12 -0
  220. package/dist/styles/radius.js +83 -0
  221. package/dist/styles/radius.js.map +1 -0
  222. package/dist/styles/scrollMargin.d.ts +24 -0
  223. package/dist/styles/scrollMargin.js +32 -0
  224. package/dist/styles/scrollMargin.js.map +1 -0
  225. package/dist/styles/scrollbar.d.ts +25 -0
  226. package/dist/styles/scrollbar.js +51 -0
  227. package/dist/styles/scrollbar.js.map +1 -0
  228. package/dist/styles/shadow.d.ts +14 -0
  229. package/dist/styles/shadow.js +25 -0
  230. package/dist/styles/shadow.js.map +1 -0
  231. package/dist/styles/shared.js +17 -0
  232. package/dist/styles/shared.js.map +1 -0
  233. package/dist/styles/transition.d.ts +14 -0
  234. package/dist/styles/transition.js +159 -0
  235. package/dist/styles/transition.js.map +1 -0
  236. package/dist/styles/types.d.ts +564 -0
  237. package/dist/styles/width.d.ts +17 -0
  238. package/dist/styles/width.js +19 -0
  239. package/dist/styles/width.js.map +1 -0
  240. package/dist/tasty.d.ts +134 -0
  241. package/dist/tasty.js +243 -0
  242. package/dist/tasty.js.map +1 -0
  243. package/dist/types.d.ts +184 -0
  244. package/dist/utils/cache-wrapper.js +21 -0
  245. package/dist/utils/cache-wrapper.js.map +1 -0
  246. package/dist/utils/case-converter.js +8 -0
  247. package/dist/utils/case-converter.js.map +1 -0
  248. package/dist/utils/color-math.d.ts +46 -0
  249. package/dist/utils/color-math.js +749 -0
  250. package/dist/utils/color-math.js.map +1 -0
  251. package/dist/utils/color-space.d.ts +5 -0
  252. package/dist/utils/color-space.js +228 -0
  253. package/dist/utils/color-space.js.map +1 -0
  254. package/dist/utils/colors.d.ts +5 -0
  255. package/dist/utils/colors.js +10 -0
  256. package/dist/utils/colors.js.map +1 -0
  257. package/dist/utils/css-types.d.ts +7 -0
  258. package/dist/utils/deps-equal.js +15 -0
  259. package/dist/utils/deps-equal.js.map +1 -0
  260. package/dist/utils/dotize.d.ts +26 -0
  261. package/dist/utils/dotize.js +122 -0
  262. package/dist/utils/dotize.js.map +1 -0
  263. package/dist/utils/filter-base-props.d.ts +15 -0
  264. package/dist/utils/filter-base-props.js +45 -0
  265. package/dist/utils/filter-base-props.js.map +1 -0
  266. package/dist/utils/get-display-name.d.ts +7 -0
  267. package/dist/utils/get-display-name.js +10 -0
  268. package/dist/utils/get-display-name.js.map +1 -0
  269. package/dist/utils/has-keys.js +13 -0
  270. package/dist/utils/has-keys.js.map +1 -0
  271. package/dist/utils/hash.js +14 -0
  272. package/dist/utils/hash.js.map +1 -0
  273. package/dist/utils/is-dev-env.js +19 -0
  274. package/dist/utils/is-dev-env.js.map +1 -0
  275. package/dist/utils/is-valid-element-type.js +15 -0
  276. package/dist/utils/is-valid-element-type.js.map +1 -0
  277. package/dist/utils/merge-styles.d.ts +7 -0
  278. package/dist/utils/merge-styles.js +145 -0
  279. package/dist/utils/merge-styles.js.map +1 -0
  280. package/dist/utils/mod-attrs.d.ts +6 -0
  281. package/dist/utils/mod-attrs.js +20 -0
  282. package/dist/utils/mod-attrs.js.map +1 -0
  283. package/dist/utils/process-tokens.d.ts +17 -0
  284. package/dist/utils/process-tokens.js +83 -0
  285. package/dist/utils/process-tokens.js.map +1 -0
  286. package/dist/utils/resolve-recipes.d.ts +17 -0
  287. package/dist/utils/resolve-recipes.js +146 -0
  288. package/dist/utils/resolve-recipes.js.map +1 -0
  289. package/dist/utils/selector-transform.js +32 -0
  290. package/dist/utils/selector-transform.js.map +1 -0
  291. package/dist/utils/string.js +8 -0
  292. package/dist/utils/string.js.map +1 -0
  293. package/dist/utils/styles.d.ts +99 -0
  294. package/dist/utils/styles.js +220 -0
  295. package/dist/utils/styles.js.map +1 -0
  296. package/dist/utils/typography.d.ts +58 -0
  297. package/dist/utils/typography.js +51 -0
  298. package/dist/utils/typography.js.map +1 -0
  299. package/dist/utils/warnings.d.ts +16 -0
  300. package/dist/utils/warnings.js +16 -0
  301. package/dist/utils/warnings.js.map +1 -0
  302. package/dist/zero/babel.d.ts +195 -0
  303. package/dist/zero/babel.js +456 -0
  304. package/dist/zero/babel.js.map +1 -0
  305. package/dist/zero/css-writer.d.ts +45 -0
  306. package/dist/zero/css-writer.js +73 -0
  307. package/dist/zero/css-writer.js.map +1 -0
  308. package/dist/zero/extractor.d.ts +24 -0
  309. package/dist/zero/extractor.js +266 -0
  310. package/dist/zero/extractor.js.map +1 -0
  311. package/dist/zero/index.d.ts +3 -0
  312. package/dist/zero/index.js +3 -0
  313. package/dist/zero/next.d.ts +86 -0
  314. package/dist/zero/next.js +143 -0
  315. package/dist/zero/next.js.map +1 -0
  316. package/docs/PIPELINE.md +519 -0
  317. package/docs/README.md +31 -0
  318. package/docs/adoption.md +298 -0
  319. package/docs/comparison.md +419 -0
  320. package/docs/configuration.md +389 -0
  321. package/docs/debug.md +318 -0
  322. package/docs/design-system.md +436 -0
  323. package/docs/dsl.md +688 -0
  324. package/docs/getting-started.md +217 -0
  325. package/docs/injector.md +544 -0
  326. package/docs/methodology.md +616 -0
  327. package/docs/react-api.md +557 -0
  328. package/docs/ssr.md +440 -0
  329. package/docs/styles.md +596 -0
  330. package/docs/tasty-static.md +532 -0
  331. package/package.json +221 -0
  332. package/tasty.config.ts +14 -0
@@ -0,0 +1,616 @@
1
+ # Methodology
2
+
3
+ Tasty has opinions about how components should be structured. The patterns described here are not mandatory — Tasty works without them — but following them gets the most out of the engine: deterministic state resolution, cleaner component APIs, simpler overrides, and fewer surprises as the system grows.
4
+
5
+ ---
6
+
7
+ ## Component architecture: root + sub-elements
8
+
9
+ This model matters most for design-system authors and platform teams building reusable, stateful components. It turns Tasty's selector guarantees into a component architecture that stays predictable as states, variants, and compound parts accumulate.
10
+
11
+ ### The model
12
+
13
+ Every Tasty component has a **root element** and zero or more **sub-elements**. The root owns the state context. Sub-elements participate in the same context by default.
14
+
15
+ ```tsx
16
+ const Alert = tasty({
17
+ styles: {
18
+ padding: '3x',
19
+ fill: { '': '#surface', 'type=danger': '#danger.10' },
20
+ border: { '': '1bw solid #border', 'type=danger': '1bw solid #danger' },
21
+ radius: '1r',
22
+
23
+ Icon: {
24
+ color: { '': '#text-secondary', 'type=danger': '#danger' },
25
+ width: '3x',
26
+ height: '3x',
27
+ },
28
+ Message: {
29
+ preset: 't2',
30
+ color: '#text',
31
+ },
32
+ },
33
+ elements: { Icon: 'span', Message: 'div' },
34
+ });
35
+ ```
36
+
37
+ When `<Alert mods={{ type: 'danger' }}>` is rendered, the root gets `data-type="danger"` and **all** sub-elements react to it through their state maps. The `Icon` turns `#danger`, the border changes — from a single modifier on the root.
38
+
39
+ ### How this differs from BEM
40
+
41
+ BEM organizes CSS around blocks, elements, and modifiers. Each element applies its own modifier classes independently:
42
+
43
+ ```html
44
+ <!-- BEM: each element carries its own modifier -->
45
+ <div class="alert alert--danger">
46
+ <span class="alert__icon alert__icon--danger">!</span>
47
+ <div class="alert__message">Something went wrong</div>
48
+ </div>
49
+ ```
50
+
51
+ In BEM, `alert__icon--danger` is a separate class that must be applied to the icon element explicitly. The block modifier `alert--danger` does not automatically propagate to elements — each element needs its own modifier class, and the CSS for each element+modifier combination is written separately.
52
+
53
+ In Tasty, sub-elements inherit the root's state context automatically:
54
+
55
+ ```tsx
56
+ <Alert mods={{ type: 'danger' }}>
57
+ <Alert.Icon>!</Alert.Icon>
58
+ <Alert.Message>Something went wrong</Alert.Message>
59
+ </Alert>
60
+ ```
61
+
62
+ One `mods` prop on the root. No modifier classes on sub-elements. The CSS for `type=danger` is declared once per property, and every sub-element that references that state key reacts to it.
63
+
64
+ This is the fundamental design choice: **state flows from root to sub-elements**, not from each element independently.
65
+
66
+ ### When sub-elements need their own state
67
+
68
+ Use `@own(...)` when a sub-element should react to its own state rather than the root's:
69
+
70
+ ```tsx
71
+ const Nav = tasty({
72
+ styles: {
73
+ NavItem: {
74
+ color: {
75
+ '': '#text',
76
+ '@own(:hover)': '#primary',
77
+ '@own(:focus-visible)': '#primary',
78
+ 'selected': '#primary',
79
+ },
80
+ },
81
+ },
82
+ elements: { NavItem: 'a' },
83
+ });
84
+ ```
85
+
86
+ Here, `:hover` and `:focus-visible` belong to the individual `NavItem` being hovered, not the root `Nav`. But `selected` is still a root-level modifier — a parent component controls which item is selected.
87
+
88
+ The default (root state context) is the right choice most of the time. Use `@own()` only when the sub-element has interactive states that are independent of the root.
89
+
90
+ ---
91
+
92
+ ## styleProps as the public API
93
+
94
+ `styleProps` define which CSS properties a component exposes as typed React props. They are the primary mechanism for product engineers to customize a component without breaking its design constraints.
95
+
96
+ ```tsx
97
+ const Space = tasty({
98
+ as: 'div',
99
+ styles: { display: 'flex', flow: 'column', gap: '1x' },
100
+ styleProps: ['flow', 'gap', 'padding', 'fill', 'placeItems', 'placeContent'],
101
+ });
102
+
103
+ // Product engineer uses it:
104
+ <Space flow="row" gap="2x" padding="4x" placeItems="center">
105
+ ```
106
+
107
+ Style props accept state maps, so responsive values work through the same API:
108
+
109
+ ```tsx
110
+ <Space
111
+ flow={{ '': 'column', '@tablet': 'row' }}
112
+ gap={{ '': '2x', '@tablet': '4x' }}
113
+ >
114
+ ```
115
+
116
+ ### Choosing what to expose
117
+
118
+ Tasty exports predefined style prop lists that group properties by role. Use them instead of hand-picking arrays:
119
+
120
+ | Preset | Properties | Typical use |
121
+ |--------|-----------|-------------|
122
+ | `FLOW_STYLES` | flow, gap, columnGap, rowGap, align, justify, placeItems, placeContent, alignItems, alignContent, justifyItems, justifyContent, gridColumns, gridRows, gridTemplate, gridAreas | Layout containers (`Space`, `Grid`) |
123
+ | `POSITION_STYLES` | gridArea, gridColumn, gridRow, order, placeSelf, alignSelf, justifySelf, zIndex, margin, inset, position | Positioned elements (`Button`, `Badge`) |
124
+ | `DIMENSION_STYLES` | width, height, flexBasis, flexGrow, flexShrink, flex | Sized elements |
125
+ | `COLOR_STYLES` | color, fill, fade, image | Color-customizable elements |
126
+ | `BLOCK_STYLES` | padding, paddingInline, paddingBlock, overflow, scrollbar, textAlign, border, radius, shadow, outline | Block-level containers |
127
+ | `CONTAINER_STYLES` | All of the above combined (+ BASE_STYLES) | Fully flexible containers |
128
+ | `OUTER_STYLES` | POSITION_STYLES + DIMENSION_STYLES + block outer (border, radius, shadow, outline) | Components whose outer shell is customizable |
129
+ | `INNER_STYLES` | BASE_STYLES + COLOR_STYLES + block inner (padding, overflow, scrollbar) + FLOW_STYLES | Components whose inner layout is customizable |
130
+
131
+ ```tsx
132
+ import { tasty, FLOW_STYLES, POSITION_STYLES } from '@tenphi/tasty';
133
+
134
+ const Space = tasty({
135
+ as: 'div',
136
+ styles: { display: 'flex', flow: 'column', gap: '1x' },
137
+ styleProps: FLOW_STYLES,
138
+ });
139
+
140
+ const Button = tasty({
141
+ as: 'button',
142
+ styles: { padding: '1.5x 3x', fill: '#primary', radius: true },
143
+ styleProps: POSITION_STYLES,
144
+ });
145
+ ```
146
+
147
+ You can also combine presets or mix them with individual properties:
148
+
149
+ ```tsx
150
+ styleProps: [...FLOW_STYLES, ...DIMENSION_STYLES, 'fill'],
151
+ ```
152
+
153
+ Match the preset to the component's role:
154
+
155
+ - **Layout containers** (`Space`, `Box`, `Grid`) — `FLOW_STYLES`, optionally with `DIMENSION_STYLES`
156
+ - **Positioned elements** (`Button`, `Badge`) — `POSITION_STYLES`
157
+ - **Text elements** — custom: `['preset', 'color']`
158
+ - **Compound components** — typically none; styling happens via sub-elements and extension
159
+
160
+ ### The governance trade-off
161
+
162
+ Exposing every CSS property as a prop defeats the purpose of a design system. The more props a component exposes, the more ways product engineers can deviate from the intended design. A good rule of thumb: expose props that product engineers *need* to adjust for layout and composition, and keep visual identity (colors, borders, typography) controlled through the component definition, variants, or styled wrappers.
163
+
164
+ ---
165
+
166
+ ## modProps and mods
167
+
168
+ `modProps` expose modifier keys as top-level component props — the modifier equivalent of `styleProps`. Use them when a component has a fixed set of known state modifiers.
169
+
170
+ ```tsx
171
+ const Card = tasty({
172
+ modProps: {
173
+ isLoading: Boolean,
174
+ isSelected: Boolean,
175
+ },
176
+ styles: {
177
+ fill: { '': '#surface', isLoading: '#surface.5' },
178
+ border: { '': '1bw solid #outline', isSelected: '2bw solid #primary' },
179
+ },
180
+ });
181
+
182
+ // Clean prop API — no mods object needed
183
+ <Card isLoading isSelected>Content</Card>
184
+ ```
185
+
186
+ ### When to use which
187
+
188
+ | Pattern | Use when |
189
+ |---|---|
190
+ | `modProps` | The component has a fixed set of known boolean/string states that drive styles. Provides TypeScript autocomplete and a cleaner JSX API. |
191
+ | `mods` prop | The component needs arbitrary or dynamic modifiers that aren't known at definition time. |
192
+ | Both | Combine `modProps` for the known states and `mods` for ad-hoc overrides. Mod props take precedence. |
193
+ | `styleProps` | Exposing CSS properties (layout, sizing) for customization — different from modifiers. |
194
+
195
+ ### Typed modProps vs array form
196
+
197
+ The object form gives precise TypeScript types using JS constructors (`Boolean`, `String`, `Number`) or enum arrays:
198
+
199
+ ```tsx
200
+ const Button = tasty({
201
+ modProps: {
202
+ isLoading: Boolean,
203
+ size: ['small', 'medium', 'large'] as const,
204
+ },
205
+ // ...
206
+ });
207
+
208
+ // TypeScript knows: isLoading?: boolean, size?: 'small' | 'medium' | 'large'
209
+ ```
210
+
211
+ The array form is simpler but types all values as `ModValue`:
212
+
213
+ ```tsx
214
+ modProps: ['isLoading', 'isSelected'] as const,
215
+ ```
216
+
217
+ For the full API reference, see [Runtime — Mod Props](react-api.md#mod-props).
218
+
219
+ ---
220
+
221
+ ## tokens prop for dynamic values
222
+
223
+ Every Tasty component accepts a `tokens` prop that renders as inline CSS custom properties on the element. This is the mechanism for per-instance dynamic values.
224
+
225
+ ```tsx
226
+ const ProgressBar = tasty({
227
+ styles: {
228
+ width: '100%',
229
+ height: '1x',
230
+ fill: '#surface',
231
+ Bar: {
232
+ width: '$progress',
233
+ height: '100%',
234
+ fill: '#primary',
235
+ transition: 'width 0.3s',
236
+ },
237
+ },
238
+ elements: { Bar: 'div' },
239
+ });
240
+
241
+ // Usage: the progress value comes from a prop, not from styles
242
+ <ProgressBar tokens={{ '$progress': `${percent}%` }} />
243
+ ```
244
+
245
+ The `tokens` prop sets `style="--progress: 75%"` on the DOM element. The `$progress` reference in styles maps to `var(--progress)`, so the bar width updates without regenerating any CSS.
246
+
247
+ ### When to use tokens vs other mechanisms
248
+
249
+ | Need | Use |
250
+ |------|-----|
251
+ | Value changes per instance at render time (progress, user color, avatar size) | `tokens` prop (on component) |
252
+ | Value is constant across all instances (card padding, border radius) | `configure({ tokens })` for `:root` CSS custom properties |
253
+ | Value should be inlined at parse time (alias for another token) | `configure({ replaceTokens })` |
254
+ | Value changes based on component state (hover, disabled, breakpoint) | State map in `styles` |
255
+ | Value changes based on a variant (primary, danger, outline) | `variants` option |
256
+
257
+ Design tokens (via `configure({ tokens })`) are injected as CSS custom properties on `:root`. Replace tokens (via `configure({ replaceTokens })`) are resolved at parse time and baked into the generated CSS. The `tokens` prop on components is resolved at render time via inline CSS custom properties. Use design tokens for design-system constants, replace tokens for value aliases, and the `tokens` prop for truly dynamic per-instance values.
258
+
259
+ ### tokenProps
260
+
261
+ `tokenProps` expose token keys as top-level component props — the token equivalent of `styleProps` and `modProps`. Use them when a component has a fixed set of known dynamic token values.
262
+
263
+ #### Array form
264
+
265
+ Prop names are plain camelCase identifiers. Names ending in `Color` map to `#` color tokens; everything else maps to `$` custom property tokens:
266
+
267
+ ```tsx
268
+ const ProgressBar = tasty({
269
+ tokenProps: ['progress', 'accentColor'] as const,
270
+ styles: { width: '$progress', fill: '#accent' },
271
+ });
272
+
273
+ // Clean prop API — no tokens object needed
274
+ <ProgressBar progress="75%" accentColor="#purple" />
275
+
276
+ // Conversion:
277
+ // 'progress' → $progress → --progress
278
+ // 'accentColor' → #accent → --accent-color + --accent-color-oklch
279
+ ```
280
+
281
+ #### Object form
282
+
283
+ Keys are prop names; values are `$`/`#`-prefixed token keys. No suffix convention needed — the prefix in the value is explicit:
284
+
285
+ ```tsx
286
+ const Card = tasty({
287
+ tokenProps: {
288
+ size: '$card-size',
289
+ color: '#card-accent',
290
+ },
291
+ styles: { padding: '$card-size', fill: '#card-accent' },
292
+ });
293
+
294
+ <Card size="4x" color="#purple" />
295
+ ```
296
+
297
+ #### Merge order
298
+
299
+ When all three token sources are present, values merge with increasing priority:
300
+
301
+ 1. `tokens` option in `tasty({...})` — default tokens (lowest)
302
+ 2. `tokens` prop on the component instance — runtime overrides
303
+ 3. `tokenProps`-derived values — highest priority (explicit named props win)
304
+
305
+ The `tokens` prop remains available for ad-hoc or dynamic tokens alongside `tokenProps`.
306
+
307
+ ---
308
+
309
+ ## styles prop vs style prop
310
+
311
+ Tasty components accept both `styles` and `style`, but they serve very different purposes.
312
+
313
+ ### styles — Tasty extension mechanism
314
+
315
+ The `styles` prop is processed through the full Tasty pipeline. Tokens, custom units, state maps, sub-element keys — everything works:
316
+
317
+ ```tsx
318
+ <Card styles={{ padding: '6x', Title: { color: '#danger' } }} />
319
+ ```
320
+
321
+ However, **using `styles` directly is discouraged in design-system code.** The recommended pattern is to create a styled wrapper instead:
322
+
323
+ ```tsx
324
+ // Preferred: create a styled wrapper
325
+ const LargeCard = tasty(Card, {
326
+ styles: { padding: '6x', Title: { color: '#danger' } },
327
+ });
328
+
329
+ <LargeCard />
330
+ ```
331
+
332
+ Why? Styled wrappers are:
333
+
334
+ - **Faster** — styles are parsed and injected once at definition time, not on every render
335
+ - **Stable** — the style object is defined once, not recreated on every render
336
+ - **Composable** — another engineer can extend `LargeCard` further
337
+ - **Inspectable** — the component has a name in React DevTools
338
+ - **Lint-friendly** — the ESLint plugin's `no-styles-prop` rule flags direct usage
339
+
340
+ The `styles` prop exists as an escape hatch — for prototyping, one-off overrides during development, or cases where wrapping is impractical. It should not be the default way product engineers customize components.
341
+
342
+ ### style — React inline styles (escape hatch)
343
+
344
+ The `style` prop is standard React `CSSProperties`. It bypasses Tasty entirely — no tokens, no units, no state maps:
345
+
346
+ ```tsx
347
+ <Card style={{ marginTop: 16 }} />
348
+ ```
349
+
350
+ Reserve `style` for third-party library integration where you need to set CSS properties that Tasty does not control (e.g. a library that reads inline `style` for positioning). Never use `style` as a styling mechanism for your own components.
351
+
352
+ See [Best practices](#best-practices) below for the full list of do's and don'ts.
353
+
354
+ ---
355
+
356
+ ## Wrapping and extension
357
+
358
+ `tasty(Base, { styles })` is the primary extension mechanism. It creates a new component whose styles are merged with the base component's styles.
359
+
360
+ ```tsx
361
+ import { Button } from 'my-ds';
362
+
363
+ const DangerButton = tasty(Button, {
364
+ styles: {
365
+ fill: { '': '#danger', ':hover': '#danger-hover' },
366
+ color: '#danger-text',
367
+ },
368
+ });
369
+ ```
370
+
371
+ ### Extend mode vs replace mode
372
+
373
+ Merge behavior depends on whether the child provides a `''` (default) key in a state map:
374
+
375
+ - **No `''` key** — extend mode: parent states are preserved, child adds or overrides specific states
376
+ - **Has `''` key** — replace mode: child defines everything from scratch for that property
377
+
378
+ ```tsx
379
+ // Extend: adds `loading` state, overrides `disabled`, keeps parent's '' and ':hover'
380
+ tasty(Button, {
381
+ styles: {
382
+ fill: {
383
+ loading: '#yellow',
384
+ disabled: '#gray.20',
385
+ },
386
+ },
387
+ });
388
+
389
+ // Replace: provides '' key, so parent's fill states are dropped entirely
390
+ tasty(Button, {
391
+ styles: {
392
+ fill: {
393
+ '': '#danger',
394
+ ':hover': '#danger-hover',
395
+ },
396
+ },
397
+ });
398
+ ```
399
+
400
+ For full details on merge semantics, `@inherit`, `null`, and `false` tombstones, see [Style DSL — Extending vs. Replacing State Maps](dsl.md#extending-vs-replacing-state-maps).
401
+
402
+ ### When to use styleProps vs wrapping
403
+
404
+ If the component exposes the properties you need as `styleProps`, use them directly — that is what they are for:
405
+
406
+ ```tsx
407
+ // Card exposes padding and gap as styleProps — just use them
408
+ <Card padding="2x" gap="1x">
409
+ ```
410
+
411
+ Wrapping is for changes that go beyond what `styleProps` expose — overriding colors, adding state mappings, restyling sub-elements:
412
+
413
+ ```tsx
414
+ const DangerCard = tasty(Card, {
415
+ styles: {
416
+ border: '1bw solid #danger',
417
+ Title: { color: '#danger' },
418
+ },
419
+ });
420
+ ```
421
+
422
+ This is preferred over `<Card styles={{ border: '1bw solid #danger' }}>` because:
423
+
424
+ 1. Styles are parsed and injected once, not on every render
425
+ 2. `DangerCard` can be extended further by others
426
+ 3. It has a meaningful name in DevTools and code search
427
+ 4. The ESLint `no-styles-prop` rule encourages this pattern
428
+
429
+ ---
430
+
431
+ ## How configuration simplifies components
432
+
433
+ Tasty's `configure()` is not just setup — it directly reduces the complexity of every component in the system.
434
+
435
+ ### State aliases eliminate repetition
436
+
437
+ Without aliases, every component inlines the full query:
438
+
439
+ ```tsx
440
+ // Without aliases
441
+ padding: { '': '4x', '@media(w < 768px)': '2x' },
442
+ flow: { '': 'row', '@media(w < 768px)': 'column' },
443
+ ```
444
+
445
+ With aliases:
446
+
447
+ ```tsx
448
+ // With aliases
449
+ padding: { '': '4x', '@mobile': '2x' },
450
+ flow: { '': 'row', '@mobile': 'column' },
451
+ ```
452
+
453
+ The alias is defined once. If the breakpoint changes from `768px` to `640px`, you update one line in `configure()` and every component adjusts.
454
+
455
+ ### Recipes extract repeated patterns
456
+
457
+ Without recipes, every card-like component repeats the same base styles:
458
+
459
+ ```tsx
460
+ // Without recipes — repeated in Card, ProfileCard, SettingsPanel, ...
461
+ styles: {
462
+ padding: '4x',
463
+ fill: '#surface',
464
+ radius: '1r',
465
+ border: true,
466
+ // ...component-specific styles
467
+ }
468
+ ```
469
+
470
+ With recipes:
471
+
472
+ ```tsx
473
+ // With recipes
474
+ styles: {
475
+ recipe: 'card',
476
+ // ...component-specific styles only
477
+ }
478
+ ```
479
+
480
+ The recipe encapsulates the shared pattern. Change `card`'s radius from `1r` to `2r` and every component using it updates.
481
+
482
+ ### Design tokens enforce consistency
483
+
484
+ ```tsx
485
+ configure({
486
+ tokens: {
487
+ '$card-padding': '4x',
488
+ '$input-height': '5x',
489
+ },
490
+ });
491
+ ```
492
+
493
+ Components use `$card-padding` instead of hardcoding `4x`. If the DS team decides to change card padding, the token is the single source of truth. Tokens support state maps for theme-aware values. Token values are parsed through the Tasty DSL, so you can use units (`4x`), color syntax (`#purple`), and other DSL features in token definitions.
494
+
495
+ See [Configuration](configuration.md) for the full `configure()` API.
496
+
497
+ ---
498
+
499
+ ## Best practices
500
+
501
+ ### Do
502
+
503
+ - **Create styled wrappers** instead of passing `styles` directly — faster, composable, inspectable
504
+ - **Use design tokens and custom units** (`#text`, `2x`, `1r`) instead of raw CSS values
505
+ - **Use semantic transition names** (`transition: 'theme 0.3s'`) instead of listing CSS properties
506
+ - **Use `elements` prop** to declare typed sub-components for compound components
507
+ - **Use `styleProps`** to define what product engineers can customize
508
+ - **Use `modProps`** to expose known modifier states as clean component props
509
+ - **Use `tokenProps`** to expose known token keys as clean component props
510
+ - **Use `tokens` prop** for ad-hoc or dynamic per-instance token values (progress, user color)
511
+ - **Use modifiers** (`mods` or `modProps`) for state-driven style changes instead of runtime `styles` prop changes
512
+
513
+ ### Avoid
514
+
515
+ ### Using raw CSS values when tokens exist
516
+
517
+ ```tsx
518
+ // Bad: hardcoded color
519
+ fill: 'oklch(55% 0.25 265)',
520
+
521
+ // Good: token reference
522
+ fill: '#primary',
523
+ ```
524
+
525
+ Tokens ensure consistency across components and make theme changes a one-line update.
526
+
527
+ ### Using CSS property names when Tasty alternatives exist
528
+
529
+ ```tsx
530
+ // Bad: raw CSS properties
531
+ backgroundColor: '#fff',
532
+ borderRadius: '4px',
533
+ flexDirection: 'column',
534
+
535
+ // Good: Tasty shorthands
536
+ fill: '#surface',
537
+ radius: '1r',
538
+ flow: 'column',
539
+ ```
540
+
541
+ Tasty's enhanced properties provide concise syntax, better composability, and simpler overrides. See [recommended props](styles.md#recommended-props) for the full mapping.
542
+
543
+ ### Changing styles prop at runtime
544
+
545
+ ```tsx
546
+ // Bad: styles object changes every render
547
+ <Card styles={{ padding: isCompact ? '2x' : '4x' }} />
548
+
549
+ // Good: use modifiers via modProps
550
+ <Card isCompact={isCompact} />
551
+
552
+ // Or via mods object
553
+ <Card mods={{ isCompact }} />
554
+
555
+ // In the component definition:
556
+ const Card = tasty({
557
+ modProps: ['isCompact'] as const,
558
+ styles: {
559
+ padding: { '': '4x', isCompact: '2x' },
560
+ },
561
+ });
562
+ ```
563
+
564
+ Modifiers are compiled into exclusive selectors once. Changing `styles` at runtime forces Tasty to regenerate and re-inject CSS.
565
+
566
+ ### Overusing style prop
567
+
568
+ ```tsx
569
+ // Bad: bypassing Tasty for custom styling
570
+ <Button style={{ backgroundColor: 'red', padding: '12px 24px' }} />
571
+
572
+ // Good: create a styled wrapper
573
+ const DangerButton = tasty(Button, {
574
+ styles: { fill: '#danger', padding: '1.5x 3x' },
575
+ });
576
+ ```
577
+
578
+ The `style` prop bypasses tokens, units, and state maps. It should only be used for third-party library integration.
579
+
580
+ ### Skipping elements for compound components
581
+
582
+ ```tsx
583
+ // Less ideal: manual data-element attributes
584
+ <Card>
585
+ <div data-element="Title">Card Title</div>
586
+ <div data-element="Content">Card content</div>
587
+ </Card>
588
+
589
+ // Better: declare elements for typed sub-components
590
+ const Card = tasty({
591
+ styles: {
592
+ Title: { preset: 'h3', color: '#primary' },
593
+ Content: { preset: 't2', color: '#text' },
594
+ },
595
+ elements: { Title: 'h2', Content: 'div' },
596
+ });
597
+
598
+ <Card>
599
+ <Card.Title>Card Title</Card.Title>
600
+ <Card.Content>Card content</Card.Content>
601
+ </Card>
602
+ ```
603
+
604
+ The `elements` prop gives you typed sub-components with automatic `data-element` attributes, `mods` support, and better discoverability.
605
+
606
+ ---
607
+
608
+ ## Learn more
609
+
610
+ - **[Getting Started](getting-started.md)** — Installation, first component, tooling setup
611
+ - **[Building a Design System](design-system.md)** — Practical guide to building a DS layer with Tasty
612
+ - **[Style DSL](dsl.md)** — State maps, tokens, units, extending semantics, keyframes, @property
613
+ - **[React API](react-api.md)** — `tasty()` factory, component props, variants, sub-elements, style functions
614
+ - **[Configuration](configuration.md)** — Full `configure()` API: tokens, recipes, custom units, style handlers
615
+ - **[Style Properties](styles.md)** — Complete reference for all enhanced style properties
616
+ - **[Adoption Guide](adoption.md)** — Who should adopt Tasty, incremental phases, what changes for product engineers