@luxalgo/vela-ui 0.0.0-stage → 0.2.0

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 (269) hide show
  1. package/CHANGELOG.md +91 -0
  2. package/LICENSE +201 -0
  3. package/NOTICE +28 -0
  4. package/README.md +86 -3
  5. package/cli/engine.mjs +282 -0
  6. package/cli/index.mjs +154 -0
  7. package/dist/badge.d.ts +26 -0
  8. package/dist/badge.js +44 -0
  9. package/dist/bar-chart.d.ts +40 -0
  10. package/dist/bar-chart.js +105 -0
  11. package/dist/button.d.ts +55 -0
  12. package/dist/button.js +11 -0
  13. package/dist/calendar.d.ts +24 -0
  14. package/dist/calendar.js +1 -0
  15. package/dist/callout-bubble.d.ts +103 -0
  16. package/dist/callout-bubble.js +177 -0
  17. package/dist/chart.d.ts +30 -0
  18. package/dist/chart.js +1 -0
  19. package/dist/checkbox.d.ts +60 -0
  20. package/dist/checkbox.js +12 -0
  21. package/dist/chunk-2GQIZM5Z.js +28 -0
  22. package/dist/chunk-3Q32K4PE.js +85 -0
  23. package/dist/chunk-6QCILIT2.js +52 -0
  24. package/dist/chunk-7VMN7NKJ.js +133 -0
  25. package/dist/chunk-A2FJ7Y7D.js +55 -0
  26. package/dist/chunk-A72NWYNP.js +26 -0
  27. package/dist/chunk-B5ZSRUDQ.js +227 -0
  28. package/dist/chunk-BXMWQIBO.js +66 -0
  29. package/dist/chunk-C3ICYMI3.js +25 -0
  30. package/dist/chunk-CC3DDNFC.js +117 -0
  31. package/dist/chunk-E2FE6V2N.js +81 -0
  32. package/dist/chunk-FN2BUFNM.js +10 -0
  33. package/dist/chunk-FVH6L7FM.js +18 -0
  34. package/dist/chunk-G7IQLY3A.js +183 -0
  35. package/dist/chunk-GVRX3UAV.js +82 -0
  36. package/dist/chunk-J2QJATCD.js +12 -0
  37. package/dist/chunk-LZWZV2ZS.js +18 -0
  38. package/dist/chunk-MJ4RUGX7.js +403 -0
  39. package/dist/chunk-MMTMOV6R.js +31 -0
  40. package/dist/chunk-P4MTEMT7.js +23 -0
  41. package/dist/chunk-Q6WTDVH6.js +31 -0
  42. package/dist/chunk-S7USVSYP.js +50 -0
  43. package/dist/chunk-TAKSIV57.js +90 -0
  44. package/dist/chunk-U3EH42YY.js +72 -0
  45. package/dist/chunk-V2Q4MRMS.js +573 -0
  46. package/dist/chunk-VMCR3S2A.js +22 -0
  47. package/dist/chunk-WBGSYCV2.js +101 -0
  48. package/dist/chunk-WGULXRWD.js +351 -0
  49. package/dist/chunk-WXH3EFV5.js +219 -0
  50. package/dist/chunk-X66RJAIS.js +14 -0
  51. package/dist/chunk-XBEL4K33.js +142 -0
  52. package/dist/chunk-Z5PINFQO.js +280 -0
  53. package/dist/collapsible.d.ts +49 -0
  54. package/dist/collapsible.js +106 -0
  55. package/dist/color-picker.d.ts +103 -0
  56. package/dist/color-picker.js +19 -0
  57. package/dist/color.d.ts +24 -0
  58. package/dist/color.js +1 -0
  59. package/dist/context-menu.d.ts +72 -0
  60. package/dist/context-menu.js +161 -0
  61. package/dist/css.d.ts +17 -0
  62. package/dist/css.js +4 -0
  63. package/dist/data-table.d.ts +40 -0
  64. package/dist/data-table.js +88 -0
  65. package/dist/date-picker.d.ts +90 -0
  66. package/dist/date-picker.js +257 -0
  67. package/dist/define-D5u3F5Dj.d.ts +21 -0
  68. package/dist/dialog.d.ts +89 -0
  69. package/dist/dialog.js +258 -0
  70. package/dist/dispose.d.ts +9 -0
  71. package/dist/dispose.js +2 -0
  72. package/dist/donut.d.ts +27 -0
  73. package/dist/donut.js +67 -0
  74. package/dist/drawer.d.ts +119 -0
  75. package/dist/drawer.js +326 -0
  76. package/dist/dropdown-menu.d.ts +114 -0
  77. package/dist/dropdown-menu.js +18 -0
  78. package/dist/empty.d.ts +21 -0
  79. package/dist/empty.js +38 -0
  80. package/dist/field.d.ts +147 -0
  81. package/dist/field.js +328 -0
  82. package/dist/glyph-select.d.ts +57 -0
  83. package/dist/glyph-select.js +17 -0
  84. package/dist/h-Bl37qUis.d.ts +24 -0
  85. package/dist/headless.d.ts +6 -0
  86. package/dist/headless.js +9 -0
  87. package/dist/hover-card.d.ts +43 -0
  88. package/dist/hover-card.js +97 -0
  89. package/dist/i18n.d.ts +20 -0
  90. package/dist/i18n.js +1 -0
  91. package/dist/icons.d.ts +20 -0
  92. package/dist/icons.js +2 -0
  93. package/dist/index.d.ts +51 -0
  94. package/dist/index.js +13 -0
  95. package/dist/input-group.d.ts +57 -0
  96. package/dist/input-group.js +87 -0
  97. package/dist/input.d.ts +54 -0
  98. package/dist/input.js +9 -0
  99. package/dist/item.d.ts +72 -0
  100. package/dist/item.js +131 -0
  101. package/dist/kbd.d.ts +19 -0
  102. package/dist/kbd.js +8 -0
  103. package/dist/kit-text.d.ts +8 -0
  104. package/dist/kit-text.js +2 -0
  105. package/dist/line-chart.d.ts +32 -0
  106. package/dist/line-chart.js +120 -0
  107. package/dist/manifest.json +4508 -0
  108. package/dist/month-grid.d.ts +45 -0
  109. package/dist/month-grid.js +157 -0
  110. package/dist/number-input.d.ts +99 -0
  111. package/dist/number-input.js +14 -0
  112. package/dist/page.d.ts +7 -0
  113. package/dist/page.js +1 -0
  114. package/dist/palette.d.ts +55 -0
  115. package/dist/palette.js +1 -0
  116. package/dist/placement.d.ts +98 -0
  117. package/dist/placement.js +1 -0
  118. package/dist/popover.d.ts +107 -0
  119. package/dist/popover.js +15 -0
  120. package/dist/scatter-chart.d.ts +32 -0
  121. package/dist/scatter-chart.js +121 -0
  122. package/dist/select.d.ts +112 -0
  123. package/dist/select.js +19 -0
  124. package/dist/slider.d.ts +46 -0
  125. package/dist/slider.js +111 -0
  126. package/dist/sort-button.d.ts +41 -0
  127. package/dist/sort-button.js +88 -0
  128. package/dist/sparkline.d.ts +22 -0
  129. package/dist/sparkline.js +72 -0
  130. package/dist/stat.d.ts +29 -0
  131. package/dist/stat.js +41 -0
  132. package/dist/styles.d.ts +22 -0
  133. package/dist/styles.js +2 -0
  134. package/dist/surface-events.d.ts +17 -0
  135. package/dist/surface-events.js +1 -0
  136. package/dist/surface-exit.d.ts +25 -0
  137. package/dist/surface-exit.js +1 -0
  138. package/dist/switch.d.ts +54 -0
  139. package/dist/switch.js +92 -0
  140. package/dist/t.d.ts +89 -0
  141. package/dist/t.js +1 -0
  142. package/dist/tabs.d.ts +65 -0
  143. package/dist/tabs.js +155 -0
  144. package/dist/text-area.d.ts +54 -0
  145. package/dist/text-area.js +9 -0
  146. package/dist/theme.d.ts +199 -0
  147. package/dist/theme.js +8 -0
  148. package/dist/theme.schema.json +1994 -0
  149. package/dist/themes/dark.css +3 -0
  150. package/dist/themes/light.css +3 -0
  151. package/dist/toggle-group.d.ts +56 -0
  152. package/dist/toggle-group.js +130 -0
  153. package/dist/tokens.d.ts +16 -0
  154. package/dist/tokens.js +3 -0
  155. package/dist/tooltip.d.ts +47 -0
  156. package/dist/tooltip.js +74 -0
  157. package/dist/variants-B4stUBnY.d.ts +16 -0
  158. package/dist/zag.d.ts +19 -0
  159. package/dist/zag.js +2 -0
  160. package/docs/theming.md +217 -0
  161. package/docs/what-to-change.md +20 -0
  162. package/docs/writing-a-component.md +250 -0
  163. package/llms.txt +71 -0
  164. package/package.json +90 -6
  165. package/registry/badge.ts +119 -0
  166. package/registry/bar-chart.ts +215 -0
  167. package/registry/button.ts +379 -0
  168. package/registry/callout-bubble.ts +347 -0
  169. package/registry/checkbox.ts +234 -0
  170. package/registry/collapsible.ts +271 -0
  171. package/registry/color-picker.ts +582 -0
  172. package/registry/context-menu.ts +208 -0
  173. package/registry/data-table.ts +215 -0
  174. package/registry/date-picker.ts +483 -0
  175. package/registry/dialog.ts +535 -0
  176. package/registry/donut.ts +145 -0
  177. package/registry/drawer.ts +636 -0
  178. package/registry/dropdown-menu.ts +762 -0
  179. package/registry/empty.ts +91 -0
  180. package/registry/field.ts +585 -0
  181. package/registry/glyph-select.ts +268 -0
  182. package/registry/hover-card.ts +222 -0
  183. package/registry/input-group.ts +229 -0
  184. package/registry/input.ts +181 -0
  185. package/registry/item.ts +376 -0
  186. package/registry/kbd.ts +64 -0
  187. package/registry/line-chart.ts +218 -0
  188. package/registry/month-grid.ts +328 -0
  189. package/registry/number-input.ts +443 -0
  190. package/registry/popover.ts +368 -0
  191. package/registry/scatter-chart.ts +221 -0
  192. package/registry/select.ts +620 -0
  193. package/registry/slider.ts +259 -0
  194. package/registry/sort-button.ts +189 -0
  195. package/registry/sparkline.ts +114 -0
  196. package/registry/stat.ts +96 -0
  197. package/registry/switch.ts +205 -0
  198. package/registry/tabs.ts +426 -0
  199. package/registry/text-area.ts +186 -0
  200. package/registry/toggle-group.ts +295 -0
  201. package/registry/tooltip.ts +156 -0
  202. package/skills/theming-vela-ui/SKILL.md +137 -0
  203. package/skills/using-vela-ui-components/SKILL.md +137 -0
  204. package/skills/writing-vela-ui-components/SKILL.md +163 -0
  205. package/src/components/badge.ts +119 -0
  206. package/src/components/bar-chart.ts +215 -0
  207. package/src/components/button.ts +379 -0
  208. package/src/components/callout-bubble.ts +347 -0
  209. package/src/components/checkbox.ts +234 -0
  210. package/src/components/collapsible.ts +271 -0
  211. package/src/components/color-picker.ts +582 -0
  212. package/src/components/context-menu.ts +208 -0
  213. package/src/components/data-table.ts +215 -0
  214. package/src/components/date-picker.ts +483 -0
  215. package/src/components/dialog.ts +535 -0
  216. package/src/components/donut.ts +145 -0
  217. package/src/components/drawer.ts +636 -0
  218. package/src/components/dropdown-menu.ts +762 -0
  219. package/src/components/empty.ts +91 -0
  220. package/src/components/field.ts +585 -0
  221. package/src/components/glyph-select.ts +268 -0
  222. package/src/components/hover-card.ts +222 -0
  223. package/src/components/input-group.ts +229 -0
  224. package/src/components/input.ts +181 -0
  225. package/src/components/item.ts +376 -0
  226. package/src/components/kbd.ts +64 -0
  227. package/src/components/line-chart.ts +218 -0
  228. package/src/components/month-grid.ts +328 -0
  229. package/src/components/number-input.ts +443 -0
  230. package/src/components/popover.ts +368 -0
  231. package/src/components/scatter-chart.ts +221 -0
  232. package/src/components/select.ts +620 -0
  233. package/src/components/slider.ts +259 -0
  234. package/src/components/sort-button.ts +189 -0
  235. package/src/components/sparkline.ts +114 -0
  236. package/src/components/stat.ts +96 -0
  237. package/src/components/switch.ts +205 -0
  238. package/src/components/tabs.ts +426 -0
  239. package/src/components/text-area.ts +186 -0
  240. package/src/components/toggle-group.ts +295 -0
  241. package/src/components/tooltip.ts +156 -0
  242. package/src/index.ts +24 -0
  243. package/src/lib/calendar.ts +117 -0
  244. package/src/lib/chart.ts +72 -0
  245. package/src/lib/color.ts +89 -0
  246. package/src/lib/component-index.ts +151 -0
  247. package/src/lib/css.ts +48 -0
  248. package/src/lib/define.ts +45 -0
  249. package/src/lib/dispose.ts +36 -0
  250. package/src/lib/h.ts +55 -0
  251. package/src/lib/headless.ts +16 -0
  252. package/src/lib/i18n.ts +30 -0
  253. package/src/lib/icons.ts +237 -0
  254. package/src/lib/kit-text.ts +26 -0
  255. package/src/lib/page.ts +24 -0
  256. package/src/lib/palette.ts +81 -0
  257. package/src/lib/placement.ts +188 -0
  258. package/src/lib/scope.ts +135 -0
  259. package/src/lib/styles.ts +53 -0
  260. package/src/lib/surface-events.ts +31 -0
  261. package/src/lib/surface-exit.ts +87 -0
  262. package/src/lib/t.ts +68 -0
  263. package/src/lib/theme.ts +664 -0
  264. package/src/lib/tokens.ts +111 -0
  265. package/src/lib/variants.ts +32 -0
  266. package/src/lib/zag.ts +46 -0
  267. package/stylelint/index.mjs +60 -0
  268. package/stylelint/lint.mjs +81 -0
  269. package/stylelint/plugin.mjs +115 -0
@@ -0,0 +1,250 @@
1
+ # Writing a component
2
+
3
+ Each component is **one file**, `src/components/<name>.ts`, published at
4
+ `@luxalgo/vela-ui/<name>`, holding its declaration, its variants, its CSS and its
5
+ `create<Name>` function. Overlays (menu, dialog, drawer, tooltip) and composite controls (tabs,
6
+ toggle group) run a [Zag.js](https://zagjs.com) state machine, which owns their keyboard
7
+ behavior and accessibility; form controls keep small vanilla state objects.
8
+
9
+ ## One file per component
10
+
11
+ Start one with `npm run new-component -- gauge` at the repo root: it writes the file in the
12
+ shape below, adds its declaration to the theme, and writes its test. A component file reads
13
+ top to bottom:
14
+
15
+ ```ts
16
+ // Gauge: … what it is and how it behaves, for the reader of the file.
17
+ import { css, defineStyles } from '../lib/css';
18
+ import { defineComponent } from '../lib/define';
19
+ import { h } from '../lib/h';
20
+ import { t } from '../lib/t';
21
+ import { variants, type VariantProps } from '../lib/variants';
22
+
23
+ // Its name, its parts (each part's data-slot) and its settings (custom properties a theme
24
+ // or a host's CSS can set, with their defaults).
25
+ export const gaugeDef = defineComponent({ name: 'gauge', parts: ['root', 'needle'], settings: { radius: t.radius.lg } });
26
+
27
+ // Its variants: the names type the props, the first value is the default.
28
+ export const gaugeVariants = variants({ size: ['md', 'sm'] });
29
+
30
+ export interface GaugeProps extends VariantProps<typeof gaugeVariants> {
31
+ value: number;
32
+ }
33
+
34
+ export interface GaugeHandle {
35
+ readonly el: HTMLElement;
36
+ setValue(value: number): void;
37
+ destroy(): void;
38
+ }
39
+
40
+ const injectStyles = defineStyles(
41
+ 'vela-ui-gauge',
42
+ css`
43
+ @layer vela.ui {
44
+ [data-slot='gauge'] {
45
+ border-radius: ${gaugeDef.vars.radius};
46
+ background: ${t.surface.sunken};
47
+
48
+ &[data-size='sm'] { … }
49
+ & > [data-slot='gauge-needle'] { color: ${t.accent}; }
50
+ }
51
+ }
52
+ `,
53
+ );
54
+
55
+ class GaugeImpl implements GaugeHandle { … } // methods shared across instances
56
+
57
+ export function createGauge(props: GaugeProps): GaugeHandle {
58
+ return new GaugeImpl(props);
59
+ }
60
+ ```
61
+
62
+ Then add the declaration to `ComponentDefs` in `src/lib/theme.ts`
63
+ (`gauge: typeof gaugeDef;`), which types the component's settings and parts in a theme. The
64
+ build fails while one is missing. The manifest (`dist/manifest.json`), the theme's JSON
65
+ Schema and `llms.txt` are generated from the file at build time, so there is nothing else to
66
+ list.
67
+
68
+ Released components keep their class (`new Checkbox(…)`, `new Tooltip(trigger, …)`) and their
69
+ controller (`checkboxController`, `tooltipController`) next to the `create…` function; the
70
+ class is the instance the function returns. New components start from the shape above.
71
+
72
+ ## A component of your own
73
+
74
+ The same shape works outside the kit, for a component a project writes: import the helpers
75
+ from the package root (`import { css, defineComponent, defineStyles, h, t, variants } from
76
+ '@luxalgo/vela-ui'`) and keep the rules below. Three things make it a full citizen:
77
+
78
+ - **Its CSS goes in `@layer vela.ui`**, like the kit's, not in `vela.custom`: a theme's part
79
+ CSS sits in `vela.custom`, and only from a later layer does it restyle the component.
80
+ - **Declare it before creating a theme that names it.** `defineComponent` records the
81
+ component for the page, and `checkTheme` (and `createTheme`'s warnings) then check the
82
+ theme's settings and parts for it, as they do the kit's.
83
+ - **Type it in themes** by merging its declaration into `ComponentDefs`, so a wrong setting
84
+ or part fails the typecheck:
85
+
86
+ ```ts
87
+ export const gaugeDef = defineComponent({ name: 'gauge', parts: ['root', 'needle'], settings: { radius: t.radius.lg } });
88
+
89
+ declare module '@luxalgo/vela-ui/theme' {
90
+ interface ComponentDefs {
91
+ gauge: typeof gaugeDef;
92
+ }
93
+ }
94
+
95
+ createTheme({ components: { gauge: { radius: '2px', css: { needle: css`color: ${t.accent};` } } } });
96
+ ```
97
+
98
+ ## Changing a component
99
+
100
+ A component's public contract is what hosts and themes build on: its props and its handle's
101
+ methods, its part names (the `data-slot` values), its variant and size values, the state
102
+ attributes its CSS keys on, and its settings. Inside the file, everything else is free to
103
+ change.
104
+
105
+ - **Keep the contract.** A change to how a component looks or behaves keeps those names. Add
106
+ a prop, a variant or a setting freely; give a new setting a default that keeps today's look,
107
+ so a theme that sets nothing renders as before.
108
+ - **Rename in two steps.** A renamed prop, part, variant or component keeps its old name
109
+ working for one release: the component accepts both (and says which is deprecated in the
110
+ prop's comment), and Vela's `src/ui/renamed.ts` keeps the old export names on
111
+ `@luxalgo/vela/ui`. The changelog names the old and the new, and the release after removes
112
+ the old one.
113
+ - **Prove it.** The component's test covers the change; `npm run lint` checks its CSS; the
114
+ gallery (`npm run playground`, then `/primitives.html`) shows every component in every
115
+ variant, beside the theme editor, so compare it before and after. The build regenerates the
116
+ manifest, the theme's JSON Schema and `llms.txt` from the file, so they follow on their
117
+ own.
118
+ - **Write it down.** A change users notice gets an entry in Vela's `CHANGELOG.md`, and a
119
+ breaking one says what to do instead.
120
+
121
+ ## The helpers (`src/lib/`)
122
+
123
+ - **`h(tag, props, ...children)`** builds an element, typed by its tag. `slot` writes the
124
+ `data-slot`, `data` the `data-*` attributes (`true` writes an empty value, `false` and
125
+ `null` nothing), `attrs`, `on` and `text` the rest. Class names are layout hooks, never the
126
+ styling contract.
127
+ - **`css`** marks a template as CSS (editors highlight it, stylelint checks it) and
128
+ **`defineStyles(id, text)`** returns the injector a component calls at creation, never at
129
+ import: it declares the layer order once per document or shadow root, then injects the
130
+ sheet, id-guarded. The sheet applies inside kit hosts, their floating layers and themed
131
+ hosts only: a `:where()` joins the first compound of each top-level selector, adding no
132
+ weight, so a page's own elements that carry the same `data-slot` names are never restyled.
133
+ Inject a component's CSS through it, never by hand.
134
+ - **`t`** reads the design tokens: `${t.radius.md}` prints `var(--vela-radius-md)`, and a
135
+ name that does not exist fails the typecheck. A test checks that `t` and the tokens the
136
+ theme writes match in both directions.
137
+ - **`variants(spec)`** turns `{ variant: [...], size: [...] }` into the `data-*` attributes
138
+ the CSS keys on, and types the props through `VariantProps`.
139
+ - **`defineComponent({ name, parts, settings })`** links a name to its CSS: `slot(part)` is
140
+ the part's `data-slot` (`name` for `root`, `name-part` otherwise), and `vars.<setting>`
141
+ prints `var(--vela-<name>-<setting>, <default>)`.
142
+ - **`addSlot(el, part)`** adds a part to an element's slot. A shell one component owns and
143
+ another builds on carries both, `data-slot="popover-content select-content"`, and CSS
144
+ matches either with `[data-slot~='…']`.
145
+
146
+ ## CSS rules
147
+
148
+ - Everything sits in **`@layer vela.ui`**, below unlayered CSS, so a page's own rule wins
149
+ without `!important` or a more specific selector. Selectors start with one of the
150
+ component's own parts (`[data-slot='gauge-needle']`), nest with `&`, and key on state
151
+ attributes (`data-state`, `data-selected`, `aria-expanded`), never on classes.
152
+ - A root that can be `hidden` takes its `display` under `:where(:not([hidden]))`: any
153
+ authored `display` beats the browser's `[hidden]` rule. A rule that depends on an ancestor
154
+ (the mobile layout) reads `&:is([data-layout='mobile'] *)`, which keeps the selector's
155
+ weight.
156
+ - Values come from `t` or the component's settings; durations from `t.dur`; directions are
157
+ logical (`padding-inline`, `inset-inline-end`, `text-align: start`).
158
+ - `npm run lint` (at the repo root) checks every template with stylelint and the postcss-lit
159
+ syntax, through the package's shared config (`@luxalgo/vela-ui/stylelint`, which Vela's
160
+ chrome, Pro and a host's own components extend with their own layer): the `vela/layer`,
161
+ `vela/slot-scope`, `vela/token-values` and `vela/no-raw-token-var` rules, no hex or named
162
+ colors, no class or id selectors, no `!important`, no
163
+ `box-sizing: content-box` (the kit's border-box reset is unlayered: size the full box
164
+ instead). A template the parser cannot read fails the run instead of going unchecked.
165
+ - The kit supports the browsers that brought `color-mix()`, which its tints use: Chrome and
166
+ Edge 111, Firefox 113, Safari 16.2. The build flattens the nesting for them (Lightning CSS),
167
+ as nesting came later; the tests and the playground run the nested source.
168
+ - Three rules stay outside the layer on purpose, each next to a comment saying why: the
169
+ kit's border-box reset, the field rows' dimmed state, and the reset of a dragged dialog's
170
+ offset in the mobile layout.
171
+
172
+ ## Zag machines
173
+
174
+ Wrap the machine in a controller function that maps the component's options to machine
175
+ props, with an explicit return interface (TypeScript cannot name Zag's inferred types
176
+ portably), then start it with `runMachine` and re-project the api's props on every
177
+ notification with `spreadProps`:
178
+
179
+ ```ts
180
+ export function tooltipController(opts: TooltipControllerOptions = {}): TooltipController {
181
+ return {
182
+ machine: tooltip.machine,
183
+ props: { id: nextUid('vela-tooltip'), /* map opts */ },
184
+ connect: (service) => tooltip.connect(service, normalizeProps),
185
+ };
186
+ }
187
+
188
+ // in the component class:
189
+ this.handle = runMachine(ctrl.machine, ctrl.props, (service) => {
190
+ const api = ctrl.connect(service);
191
+ spreadProps(trigger, api.getTriggerProps(), mid);
192
+ // …spread the other parts onto their elements
193
+ });
194
+ this.release = ownTeardown(trigger, () => this.handle.stop());
195
+
196
+ destroy(): void {
197
+ this.release();
198
+ }
199
+ ```
200
+
201
+ Tie the machine's teardown to the element with `ownTeardown`, and have `destroy()` call the
202
+ release: a host that discards a subtree with `disposeWithin` reaches controls whose handles it
203
+ never kept, and the release runs once whichever comes first. A component whose content holds
204
+ other controls (a dialog's panel, a popover's content) calls `disposeWithin` on it when it is
205
+ destroyed.
206
+
207
+ Form controls keep the value they show in a small state of their own (getters, `set*` /
208
+ `sync` that do not emit, and the one method that does), so a host refresh rewrites the
209
+ displayed value without firing `onChange`. The text fields are plain inputs; the checkbox, the
210
+ switch, the number field and the select's list run Zag machines underneath, which that state
211
+ drives (`setChecked`, `setValue`) without reporting.
212
+
213
+ ## Rules (learned the hard way)
214
+
215
+ - **Always pass a `machineId` to `spreadProps`** (the `mid` above). Two machines sharing one
216
+ element under the default scope wipe each other's listeners.
217
+ - **Zag trigger props overwrite the element's DOM `id`.** To compose several machines on one
218
+ trigger, share the id through the machines' `ids` prop (see the `triggerId` option on
219
+ Tooltip and DropdownMenu).
220
+ - **Dialog-like machines expect conditional rendering**: their props carry no `hidden`;
221
+ toggle visibility from `api.open` in your render (tooltip and menu props do carry it).
222
+ - **Never hard-code colors.** The tokens derive from the theme (`src/lib/tokens.ts`), and the
223
+ fixed brand and meaning colors live in `src/lib/palette.ts`. A test fails on a stray hex
224
+ literal.
225
+ - **Take icons from the registry** (`src/lib/icons.ts`) rather than inlining SVG: 16×16 at
226
+ stroke 1.2 for UI chrome, 24×24 at stroke 1.8 for drawing tools, always `currentColor`.
227
+ - **No imports from Vela.** The kit is used without the chart; what it needs lives in
228
+ `src/lib/`.
229
+ - **A machine must be stopped, not only removed.** Some machines register page-wide
230
+ listeners (the switch's focus-visible tracking is one) that keep running, and keep their
231
+ memory, after the element is gone. See `ownTeardown` above.
232
+ - **State other copies of the kit must see goes through `pageState`** (`src/lib/page.ts`),
233
+ not a module variable: a page can load the kit twice, and a registry, an id counter or an
234
+ "open popover" kept per copy splits in two. Caches each copy can rebuild stay local.
235
+ - Floating layers mount into the nearest `.vela-ui` host, which carries the theme; use the
236
+ `vela-ui-layer` class on portaled positioners. Popovers call `ensureUIHost` on show, so a
237
+ list portaled to the body still has the theme. A component built before its trigger is in
238
+ the DOM needs an explicit `host`: the `closest()` fallback portals to the body, outside the
239
+ theme.
240
+ - Keyboard-facing components report open and close through an `onOpenChange` option, so a
241
+ host can scope its keyboard shortcuts while they are open.
242
+ - A component that opens and closes a surface **announces it** with `announceSurface`
243
+ (`@luxalgo/vela-ui/surface-events`): open once the surface shows, close while it still
244
+ shows (before a fade-out, `hidden`, or removal), so the event bubbles to the host.
245
+ - After announcing the close, run the hide or removal through `holdForExit`
246
+ (`@luxalgo/vela-ui/surface-exit`), so hosts can animate it out by styling `data-closing`. It
247
+ completes synchronously when no exit animation starts; keep the returned handle to
248
+ `cancel()` it on a reopen and `finish()` it on teardown.
249
+ - The primitive's **root is one element**. Settings rows use `display: contents`, so a
250
+ fragment of sibling nodes would fall onto the pane grid as extra tracks.
package/llms.txt ADDED
@@ -0,0 +1,71 @@
1
+ # @luxalgo/vela-ui 0.2.0
2
+
3
+ > The component kit of Vela: one file per component, Zag state machines for behavior, CSS in
4
+ > cascade layers over design tokens, and one typed theme config.
5
+
6
+ Every component is a function, `create<Name>(props)`, imported from its own path, that returns
7
+ a handle with `el` (the element to append) and `destroy()`. Every part of a component carries
8
+ a `data-slot`; variants and sizes are `data-variant` and `data-size`. Mount components in a
9
+ kit host: `ensureUIHost(el, createTheme())` (`@luxalgo/vela-ui/theme`), or inside a Vela chart.
10
+
11
+ ## Skills (agent instructions in this package)
12
+
13
+ - [theming-vela-ui](skills/theming-vela-ui/SKILL.md): Themes and restyles Vela charts and @luxalgo/vela-ui components with createTheme - brand colors, light, dark and custom themes, design tokens, component settings, part-by-part CSS restyles, scrollbars, cascade layers and theme JSON files checked with checkTheme.
14
+ - [using-vela-ui-components](skills/using-vela-ui-components/SKILL.md): Builds interface pieces with @luxalgo/vela-ui, the component kit behind Vela charts - buttons, tabs, toggle groups, badges, dialogs, drawers, dropdown and context menus, tooltips, hover cards, popovers, collapsible sections, list rows, form controls (checkbox, switch, slider, input, select, number input, date and color pickers) and data components (data table, sort buttons, month grid, stat, sparkline, bar, line and scatter charts).
15
+ - [writing-vela-ui-components](skills/writing-vela-ui-components/SKILL.md): Writes new UI components with the @luxalgo/vela-ui authoring helpers (defineComponent, h, css, defineStyles, variants, t), customizes a kit component's markup or behavior by copying its source with "vela-ui add --source", and adds components to the kit itself.
16
+
17
+ Link them into a project's coding agent with `npx skills experimental_sync` once the package is
18
+ installed, or install them from the repository with `npx skills add LuxAlgo/Vela`.
19
+
20
+ ## Reference (in this package)
21
+
22
+ - [Components](dist/manifest.json): every component's import, props, variants, parts and
23
+ their slots, settings, the tokens it reads, the attributes its CSS styles by, an example.
24
+ - [Theme schema](dist/theme.schema.json): the JSON Schema of a theme written to a file.
25
+ - [Theming](docs/theming.md): createTheme, kit hosts, colors-only themes, the tokens, component
26
+ settings, part CSS and the cascade layers.
27
+ - [What to change, and where](docs/what-to-change.md): one table, a kind of change per row.
28
+ - [Writing a component](docs/writing-a-component.md): the one-file shape and its rules.
29
+ - Plain CSS themes: `dist/themes/dark.css`, `dist/themes/light.css`.
30
+ - Command line: `npx @luxalgo/vela-ui add <component>` prints its import, `--source` copies it
31
+ as a component of the project's own, `check` validates the project (see README.md).
32
+
33
+ ## Components
34
+
35
+ - createBadge (`@luxalgo/vela-ui/badge`): Badge: a short status label, or a round count.
36
+ - createBarChart (`@luxalgo/vela-ui/bar-chart`): BarChart: vertical bars around a zero line with a hover readout (daily P&L, a distribution), in the profit tone above zero and the loss tone below unless a bar names its own; optionally a value axis with gridlines and a title, slanted labels, and dashed markers.
37
+ - createButton (`@luxalgo/vela-ui/button`): Button: a <button> with optional icons and key caps before and after its text (`↵ Open`, `Esc Close` in a picker's footer).
38
+ - createCalloutBubble (`@luxalgo/vela-ui/callout-bubble`): CalloutBubble: a small tinted circle with a centered icon.
39
+ - createCheckbox (`@luxalgo/vela-ui/checkbox`): Checkbox: a square check toggle, filled with a check mark when on.
40
+ - createCollapsible (`@luxalgo/vela-ui/collapsible`): Collapsible: a section that shows or hides its content.
41
+ - createColorField (`@luxalgo/vela-ui/color-picker`): ColorPicker: a swatch grid (grays, then hue × shade), a recents row with a custom "+" chooser, and an opacity slider over a transparency checker; and ColorField, the swatch button that opens it on a popover.
42
+ - createContextMenu (`@luxalgo/vela-ui/context-menu`): ContextMenu: the dropdown menu's list, opened where the user asks for it instead of from a button: a right-click on the target, a long press on a touch screen, or the keyboard's context-menu key on a focused target.
43
+ - createDataTable (`@luxalgo/vela-ui/data-table`): DataTable: a sortable table with a sticky header in its own scroller (positions, orders, trades).
44
+ - createDatePicker (`@luxalgo/vela-ui/date-picker`): DatePicker: a month calendar with month and year panels behind its header.
45
+ - createDialog (`@luxalgo/vela-ui/dialog`): Dialog: a backdrop and a panel with a header and a body, over Zag's dialog machine (focus trap, dismissal, ARIA).
46
+ - createDonut (`@luxalgo/vela-ui/donut`): Donut: a ring split in segments with a figure in its middle (a win rate), and a legend of the segments beside it.
47
+ - createDrawer (`@luxalgo/vela-ui/drawer`): Drawer: a bottom sheet.
48
+ - createDropdownMenu (`@luxalgo/vela-ui/dropdown-menu`): DropdownMenu: MenuItemDescriptor[] projected into a floating list over Zag's menu machine (keyboard navigation, typeahead and dismissal belong to the machine).
49
+ - createEmpty (`@luxalgo/vela-ui/empty`): Empty: what a panel shows when it has nothing to list: an icon in a tile, a title, a line saying why or what to do, and an optional action (a button that fills it).
50
+ - FieldGridVariant (`@luxalgo/vela-ui/field`): Field: the label-and-control grid the settings dialogs lay their inputs out on: rows (a label and its control, an optional master toggle that dims the control, an optional info mark), full-width toggles, stacked and inline rows, section headings and separators, and a factory that builds a row's control from a descriptor.
51
+ - createGlyphSelect (`@luxalgo/vela-ui/glyph-select`): GlyphSelect: a trigger showing the current option's glyph, and a list of glyph options on a popover.
52
+ - createHoverCard (`@luxalgo/vela-ui/hover-card`): HoverCard: a card beside a control while the pointer rests on it, richer than a tooltip: a title with an icon tile and a shortcut drawn as keycaps, a description, rich content (figures, a sparkline) and a hint line.
53
+ - createInputGroup (`@luxalgo/vela-ui/input-group`): InputGroup: an input with addons inside its border: an icon, a short text or a button, at its start or end, or in a row above or below it (a search field with its magnifier, an amount with its unit).
54
+ - createInput (`@luxalgo/vela-ui/input`): Input: a one-line text input that commits on blur or Enter.
55
+ - createItem (`@luxalgo/vela-ui/item`): Item: one row of a list (a watchlist, a list of alerts, search results): media (an icon, a logo, an avatar, a star), a title over a description, then at its end the meta (figures, badges) and the actions (buttons).
56
+ - createKbd (`@luxalgo/vela-ui/kbd`): Kbd: one key of a shortcut, drawn as a keycap (`Alt`, `A`).
57
+ - createLineChart (`@luxalgo/vela-ui/line-chart`): LineChart: a compact area chart with a hover readout (equity curves, P&L over time): one line over a fading area, in the profit tone when its last point ends at or above the baseline and the loss tone below it, with optional axis labels under and beside the plot.
58
+ - createMonthGrid (`@luxalgo/vela-ui/month-grid`): MonthGrid: a month of day cells, each with a figure: a trading journal's P&L by day.
59
+ - createNumberInput (`@luxalgo/vela-ui/number-input`): NumberInput: a typed number field with optional steppers that show on hover and repeat while pressed.
60
+ - createPopover (`@luxalgo/vela-ui/popover`): Popover: a positioned floating shell.
61
+ - createScatterChart (`@luxalgo/vela-ui/scatter-chart`): ScatterChart: dots on two value axes with an optional dashed trend line and a hover readout (a trade's P&L against its length).
62
+ - createSelect (`@luxalgo/vela-ui/select`): Select: a trigger button and a themed option list on a popover, with an overlay scrollbar for long lists.
63
+ - createSlider (`@luxalgo/vela-ui/slider`): Slider: a value on a track, dragged by its thumb or moved with the arrow keys, Page Up/Down and Home/End, over Zag's slider machine.
64
+ - createSortButton (`@luxalgo/vela-ui/sort-button`): SortButton: the header of a column that sorts a list which is not a table (a watchlist's Last and Day %).
65
+ - createSparkline (`@luxalgo/vela-ui/sparkline`): Sparkline: a tiny line of values (a watchlist row's day, an equity curve in a card), in the profit tone when it ends at or above where it started (or its baseline) and the loss tone below, with an optional soft area under it and a dotted baseline (the previous close).
66
+ - createStat (`@luxalgo/vela-ui/stat`): Stat: a figure under its label (Net P&L, Win rate), with an optional line under it.
67
+ - createSwitch (`@luxalgo/vela-ui/switch`): Switch: a sliding on/off toggle, a track with a round thumb, for a setting that applies at once.
68
+ - createTabs (`@luxalgo/vela-ui/tabs`): Tabs: a tab list over Zag's tabs machine (WAI-ARIA tabs: roving focus, the arrow keys along the orientation, Home/End, automatic or manual activation).
69
+ - createTextArea (`@luxalgo/vela-ui/text-area`): TextArea: a multi-line text input that commits on blur, and can grow with its content up to a number of lines before it scrolls.
70
+ - createToggleGroup (`@luxalgo/vela-ui/toggle-group`): ToggleGroup: a few options side by side on one track, over Zag's toggle-group machine.
71
+ - createTooltip (`@luxalgo/vela-ui/tooltip`): Tooltip: a floating label over Zag's tooltip machine (floating-ui placement).
package/package.json CHANGED
@@ -1,6 +1,90 @@
1
- {
2
- "name": "@luxalgo/vela-ui",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
1
+ {
2
+ "name": "@luxalgo/vela-ui",
3
+ "version": "0.2.0",
4
+ "description": "The component kit of Vela: one file per component, Zag state machines for behavior, CSS in cascade layers over design tokens.",
5
+ "license": "Apache-2.0",
6
+ "author": "LuxAlgo",
7
+ "homepage": "https://velacharts.dev",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/luxalgo/vela.git",
11
+ "directory": "packages/vela-ui"
12
+ },
13
+ "type": "module",
14
+ "sideEffects": false,
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/index.d.ts",
18
+ "default": "./dist/index.js"
19
+ },
20
+ "./package.json": "./package.json",
21
+ "./themes/*.css": "./dist/themes/*.css",
22
+ "./manifest.json": "./dist/manifest.json",
23
+ "./theme.schema.json": "./dist/theme.schema.json",
24
+ "./cli": "./cli/engine.mjs",
25
+ "./stylelint": "./stylelint/index.mjs",
26
+ "./stylelint/lint": "./stylelint/lint.mjs",
27
+ "./*": {
28
+ "types": "./dist/*.d.ts",
29
+ "default": "./dist/*.js"
30
+ }
31
+ },
32
+ "bin": {
33
+ "vela-ui": "./cli/index.mjs"
34
+ },
35
+ "files": [
36
+ "dist",
37
+ "src",
38
+ "docs",
39
+ "cli",
40
+ "registry",
41
+ "stylelint",
42
+ "skills",
43
+ "llms.txt",
44
+ "CHANGELOG.md",
45
+ "LICENSE",
46
+ "NOTICE"
47
+ ],
48
+ "scripts": {
49
+ "build": "node scripts/component-index.mjs && tsup && node scripts/build-reference.mjs"
50
+ },
51
+ "peerDependencies": {
52
+ "postcss-lit": "^1.4.1",
53
+ "stylelint": "^18.0.0",
54
+ "stylelint-config-recommended": "^19.0.0"
55
+ },
56
+ "peerDependenciesMeta": {
57
+ "postcss-lit": {
58
+ "optional": true
59
+ },
60
+ "stylelint": {
61
+ "optional": true
62
+ },
63
+ "stylelint-config-recommended": {
64
+ "optional": true
65
+ }
66
+ },
67
+ "dependencies": {
68
+ "@zag-js/core": "^1.42.0",
69
+ "@zag-js/dialog": "^1.42.0",
70
+ "@zag-js/dom-query": "^1.42.0",
71
+ "@zag-js/listbox": "^1.42.0",
72
+ "@zag-js/menu": "^1.42.0",
73
+ "@zag-js/number-input": "^1.42.0",
74
+ "@zag-js/slider": "^1.42.0",
75
+ "@zag-js/switch": "^1.42.0",
76
+ "@zag-js/tabs": "^1.42.0",
77
+ "@zag-js/toggle-group": "^1.42.0",
78
+ "@zag-js/tooltip": "^1.42.0",
79
+ "@zag-js/types": "^1.42.0",
80
+ "@zag-js/vanilla": "^1.42.0"
81
+ },
82
+ "keywords": [
83
+ "ui components",
84
+ "design tokens",
85
+ "cascade layers",
86
+ "zag",
87
+ "vela",
88
+ "luxalgo"
89
+ ]
90
+ }
@@ -0,0 +1,119 @@
1
+ // Badge: a short status label, or a round count. `default` is filled with the selection color,
2
+ // `secondary` a neutral tint, `outline` bordered, `destructive` tinted with the danger color,
3
+ // `up` and `down` with the market colors.
4
+ import { css, defineStyles } from '@luxalgo/vela-ui';
5
+ import { defineComponent } from '@luxalgo/vela-ui';
6
+ import { h } from '@luxalgo/vela-ui';
7
+ import { t } from '@luxalgo/vela-ui';
8
+ import { variants, type VariantProps } from '@luxalgo/vela-ui';
9
+
10
+ export const badgeDef = defineComponent({
11
+ name: 'badge',
12
+ parts: ['root'],
13
+ settings: { radius: '5px' },
14
+ });
15
+
16
+ export const badgeVariants = variants({ variant: ['default', 'secondary', 'outline', 'destructive', 'up', 'down'] });
17
+
18
+ export type BadgeVariant = (typeof badgeVariants.spec.variant)[number];
19
+
20
+ export interface BadgeProps extends VariantProps<typeof badgeVariants> {
21
+ text: string;
22
+ /** A round count pill (`3`, `9+`) rather than a label. */
23
+ count?: boolean;
24
+ className?: string;
25
+ }
26
+
27
+ export interface BadgeHandle {
28
+ readonly el: HTMLSpanElement;
29
+ setText(text: string): void;
30
+ setVariant(variant: BadgeVariant): void;
31
+ destroy(): void;
32
+ }
33
+
34
+ export const BADGE_STYLE_ID = 'vela-ui-badge';
35
+
36
+ export const BADGE_CSS = css`
37
+ @layer vela.ui {
38
+ [data-slot='badge'] {
39
+ align-items: center;
40
+ gap: 4px;
41
+ box-sizing: border-box;
42
+ height: 20px;
43
+ padding: 0 6px;
44
+ border-radius: ${badgeDef.vars.radius};
45
+ border: 1px solid transparent;
46
+ font-size: 12px;
47
+ font-weight: 500;
48
+ line-height: 1;
49
+ white-space: nowrap;
50
+ font-variant-numeric: tabular-nums;
51
+ background: ${t.selected.bg};
52
+ color: ${t.selected.fg};
53
+
54
+ &:where(:not([hidden])) {
55
+ display: inline-flex;
56
+ }
57
+ &[data-count] {
58
+ min-width: 18px;
59
+ height: 18px;
60
+ padding: 0 5px;
61
+ justify-content: center;
62
+ border-radius: 999px;
63
+ font-size: 11px;
64
+ }
65
+ &[data-variant='secondary'] {
66
+ background: ${t.hover};
67
+ color: ${t.fg.muted};
68
+ }
69
+ &[data-variant='outline'] {
70
+ background: transparent;
71
+ border-color: ${t.border.strong};
72
+ color: ${t.fg};
73
+ }
74
+ &[data-variant='destructive'] {
75
+ background: color-mix(in srgb, ${t.danger} 18%, transparent);
76
+ color: ${t.danger};
77
+ }
78
+ &[data-variant='up'] {
79
+ background: color-mix(in srgb, ${t.up} 18%, transparent);
80
+ color: ${t.up};
81
+ }
82
+ &[data-variant='down'] {
83
+ background: color-mix(in srgb, ${t.down} 18%, transparent);
84
+ color: ${t.down};
85
+ }
86
+ }
87
+ }
88
+ `;
89
+
90
+ const injectStyles = defineStyles(BADGE_STYLE_ID, BADGE_CSS);
91
+
92
+ class BadgeImpl implements BadgeHandle {
93
+ readonly el: HTMLSpanElement;
94
+
95
+ constructor(props: BadgeProps) {
96
+ injectStyles(document);
97
+ this.el = h('span', {
98
+ className: props.className ? `vela-badge ${props.className}` : 'vela-badge',
99
+ slot: badgeDef.slot('root'),
100
+ attrs: badgeVariants(props),
101
+ data: { count: props.count === true },
102
+ text: props.text,
103
+ });
104
+ }
105
+
106
+ setText(text: string): void {
107
+ this.el.textContent = text;
108
+ }
109
+
110
+ setVariant(variant: BadgeVariant): void {
111
+ this.el.setAttribute('data-variant', variant);
112
+ }
113
+
114
+ destroy(): void {}
115
+ }
116
+
117
+ export function createBadge(props: BadgeProps): BadgeHandle {
118
+ return new BadgeImpl(props);
119
+ }