@luxalgo/vela-ui 0.3.0 → 0.4.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 (167) hide show
  1. package/CHANGELOG.md +153 -132
  2. package/LICENSE +201 -201
  3. package/NOTICE +28 -28
  4. package/README.md +86 -86
  5. package/cli/engine.mjs +282 -282
  6. package/cli/index.mjs +154 -154
  7. package/dist/callout-bubble.js +2 -2
  8. package/dist/checkbox.js +2 -2
  9. package/dist/{chunk-KKS6NEGI.js → chunk-BWSOMG3G.js} +1 -1
  10. package/dist/chunk-GUIYFQ27.js +30 -0
  11. package/dist/{chunk-B2EZB5ZG.js → chunk-KUWTI2PE.js} +2 -2
  12. package/dist/{chunk-WWHNUKSZ.js → chunk-QGWAN3EP.js} +2 -2
  13. package/dist/{chunk-TBXUF5YX.js → chunk-RH53NQGE.js} +18 -4
  14. package/dist/{chunk-IOOYDSSK.js → chunk-SKFAYTDK.js} +1 -1
  15. package/dist/{chunk-OQXFQMZM.js → chunk-TGJNHUYV.js} +2 -2
  16. package/dist/{chunk-UEO6W37Z.js → chunk-VC7SVSDK.js} +1 -1
  17. package/dist/{chunk-OJ2SEMN6.js → chunk-YT2BSP7O.js} +1 -1
  18. package/dist/collapsible.js +1 -1
  19. package/dist/color-picker.js +4 -4
  20. package/dist/context-menu.js +3 -3
  21. package/dist/dialog.js +3 -3
  22. package/dist/donut.d.ts +1 -1
  23. package/dist/drawer.js +1 -1
  24. package/dist/dropdown-menu.js +3 -3
  25. package/dist/field.js +8 -8
  26. package/dist/{stat.d.ts → figure.d.ts} +9 -9
  27. package/dist/figure.js +41 -0
  28. package/dist/glyph-select.js +3 -3
  29. package/dist/index.d.ts +2 -2
  30. package/dist/index.js +1 -1
  31. package/dist/manifest.json +74 -74
  32. package/dist/number-input.js +2 -2
  33. package/dist/popover.js +2 -2
  34. package/dist/select.d.ts +1 -1
  35. package/dist/select.js +4 -4
  36. package/dist/slider.js +1 -1
  37. package/dist/sort-button.js +1 -1
  38. package/dist/switch.js +1 -1
  39. package/dist/tabs.js +1 -1
  40. package/dist/{theme-Ct-q58xz.d.ts → theme-TefB8vtl.d.ts} +2 -2
  41. package/dist/theme.d.ts +2 -2
  42. package/dist/theme.js +1 -1
  43. package/dist/theme.schema.json +30 -30
  44. package/dist/toast.d.ts +2 -2
  45. package/dist/toast.js +1 -1
  46. package/dist/toggle-group.js +1 -1
  47. package/dist/tooltip.js +1 -1
  48. package/dist/zag.d.ts +11 -2
  49. package/dist/zag.js +1 -1
  50. package/docs/theming.md +217 -217
  51. package/docs/what-to-change.md +20 -20
  52. package/docs/writing-a-component.md +250 -250
  53. package/llms.txt +3 -3
  54. package/package.json +90 -90
  55. package/registry/badge.ts +119 -119
  56. package/registry/bar-chart.ts +215 -215
  57. package/registry/button.ts +387 -387
  58. package/registry/callout-bubble.ts +347 -347
  59. package/registry/card.ts +379 -379
  60. package/registry/checkbox.ts +234 -234
  61. package/registry/collapsible.ts +271 -271
  62. package/registry/color-picker.ts +582 -582
  63. package/registry/context-menu.ts +208 -208
  64. package/registry/data-table.ts +215 -215
  65. package/registry/date-picker.ts +483 -483
  66. package/registry/dialog.ts +551 -551
  67. package/registry/donut.ts +145 -145
  68. package/registry/drawer.ts +636 -636
  69. package/registry/dropdown-menu.ts +762 -762
  70. package/registry/empty.ts +91 -91
  71. package/registry/field.ts +584 -584
  72. package/registry/{stat.ts → figure.ts} +96 -96
  73. package/registry/glyph-select.ts +268 -268
  74. package/registry/hover-card.ts +222 -222
  75. package/registry/input-group.ts +229 -229
  76. package/registry/input.ts +181 -181
  77. package/registry/item.ts +376 -376
  78. package/registry/kbd.ts +64 -64
  79. package/registry/line-chart.ts +218 -218
  80. package/registry/month-grid.ts +328 -328
  81. package/registry/number-input.ts +443 -443
  82. package/registry/popover.ts +368 -368
  83. package/registry/scatter-chart.ts +221 -221
  84. package/registry/select.ts +620 -620
  85. package/registry/slider.ts +259 -259
  86. package/registry/sort-button.ts +189 -189
  87. package/registry/sparkline.ts +114 -114
  88. package/registry/switch.ts +205 -205
  89. package/registry/tabs.ts +426 -426
  90. package/registry/text-area.ts +186 -186
  91. package/registry/toast.ts +965 -965
  92. package/registry/toggle-group.ts +295 -295
  93. package/registry/tooltip.ts +156 -156
  94. package/registry/treemap.ts +847 -847
  95. package/skills/theming-vela-ui/SKILL.md +137 -137
  96. package/skills/using-vela-ui-components/SKILL.md +139 -139
  97. package/skills/writing-vela-ui-components/SKILL.md +163 -163
  98. package/src/components/badge.ts +119 -119
  99. package/src/components/bar-chart.ts +215 -215
  100. package/src/components/button.ts +387 -387
  101. package/src/components/callout-bubble.ts +347 -347
  102. package/src/components/card.ts +379 -379
  103. package/src/components/checkbox.ts +234 -234
  104. package/src/components/collapsible.ts +271 -271
  105. package/src/components/color-picker.ts +582 -582
  106. package/src/components/context-menu.ts +208 -208
  107. package/src/components/data-table.ts +215 -215
  108. package/src/components/date-picker.ts +483 -483
  109. package/src/components/dialog.ts +551 -551
  110. package/src/components/donut.ts +145 -145
  111. package/src/components/drawer.ts +636 -636
  112. package/src/components/dropdown-menu.ts +762 -762
  113. package/src/components/empty.ts +91 -91
  114. package/src/components/field.ts +584 -584
  115. package/src/components/{stat.ts → figure.ts} +96 -96
  116. package/src/components/glyph-select.ts +268 -268
  117. package/src/components/hover-card.ts +222 -222
  118. package/src/components/input-group.ts +229 -229
  119. package/src/components/input.ts +181 -181
  120. package/src/components/item.ts +376 -376
  121. package/src/components/kbd.ts +64 -64
  122. package/src/components/line-chart.ts +218 -218
  123. package/src/components/month-grid.ts +328 -328
  124. package/src/components/number-input.ts +443 -443
  125. package/src/components/popover.ts +368 -368
  126. package/src/components/scatter-chart.ts +221 -221
  127. package/src/components/select.ts +620 -620
  128. package/src/components/slider.ts +259 -259
  129. package/src/components/sort-button.ts +189 -189
  130. package/src/components/sparkline.ts +114 -114
  131. package/src/components/switch.ts +205 -205
  132. package/src/components/tabs.ts +426 -426
  133. package/src/components/text-area.ts +186 -186
  134. package/src/components/toast.ts +965 -965
  135. package/src/components/toggle-group.ts +295 -295
  136. package/src/components/tooltip.ts +156 -156
  137. package/src/components/treemap.ts +847 -847
  138. package/src/index.ts +24 -24
  139. package/src/lib/calendar.ts +117 -117
  140. package/src/lib/chart.ts +72 -72
  141. package/src/lib/color.ts +89 -89
  142. package/src/lib/component-index.ts +163 -163
  143. package/src/lib/css.ts +48 -48
  144. package/src/lib/define.ts +45 -45
  145. package/src/lib/dispose.ts +36 -36
  146. package/src/lib/h.ts +55 -55
  147. package/src/lib/headless.ts +16 -16
  148. package/src/lib/i18n.ts +30 -30
  149. package/src/lib/icons.ts +244 -244
  150. package/src/lib/kit-text.ts +26 -26
  151. package/src/lib/page.ts +24 -24
  152. package/src/lib/palette.ts +81 -81
  153. package/src/lib/placement.ts +188 -188
  154. package/src/lib/scope.ts +135 -135
  155. package/src/lib/styles.ts +53 -53
  156. package/src/lib/surface-events.ts +31 -31
  157. package/src/lib/surface-exit.ts +87 -87
  158. package/src/lib/t.ts +68 -68
  159. package/src/lib/theme.ts +684 -670
  160. package/src/lib/tokens.ts +110 -110
  161. package/src/lib/variants.ts +32 -32
  162. package/src/lib/zag.ts +61 -46
  163. package/stylelint/index.mjs +60 -60
  164. package/stylelint/lint.mjs +81 -81
  165. package/stylelint/plugin.mjs +115 -115
  166. package/dist/chunk-P4MTEMT7.js +0 -23
  167. package/dist/stat.js +0 -41
package/docs/theming.md CHANGED
@@ -1,217 +1,217 @@
1
- # Theming
2
-
3
- A theme is data: the chart's colors and font, every design token, and the settings of each
4
- component. `createTheme` builds one from a few choices; applied to a host, it is written once
5
- per document (or shadow root) as a rule in the `vela.theme` cascade layer, keyed by the host's
6
- `data-vela-theme` attribute.
7
-
8
- ```ts
9
- import { createTheme, ensureUIHost } from '@luxalgo/vela-ui/theme';
10
-
11
- const theme = createTheme({
12
- base: 'dark', // 'dark' (default), 'light', or a chart theme's seven fields
13
- accent: '#7c3aed', // brand color; the ink on it is derived
14
- radius: 'sm', // none | sm | md | lg: scales every radius token
15
- font: 'Inter, sans-serif',
16
- tokens: { 'surface-elev': '#1b1c22' }, // any token, by name
17
- components: { button: { radius: '2px' } }, // a component's own settings
18
- });
19
-
20
- ensureUIHost(document.getElementById('app')!, theme);
21
- ```
22
-
23
- On a page of your own, `ensureUIHost(el, theme)` makes the element a kit host and themes it:
24
- the kit's base styles apply inside it, and menus, dialogs and tooltips opened from it mount
25
- there. `applyTheme(el, theme)` alone only themes an element, so a menu opened from it would
26
- mount outside, unthemed; use it to switch a host that is already one to another theme.
27
-
28
- In Vela, pass the theme as the chart's `theme` option or to `setTheme`, and offer it in the
29
- chart settings with `registerTheme({ id, label, theme })`.
30
-
31
- ## Themes from colors alone
32
-
33
- `colors` builds a whole theme from a few colors: grid and border derive from the background
34
- and the text, and light or dark is read from the background.
35
-
36
- ```ts
37
- const paper = createTheme({ colors: { background: '#fdf6e3', accent: '#268bd2' } });
38
- ```
39
-
40
- `up` and `down` are the candles' colors, and the `up`, `down`, `profit` and `loss` tokens
41
- follow them. In Vela they are the candles' defaults: a chart's own `upColor` and
42
- `downColor` options, and colors a user picks in its settings, win over them.
43
-
44
- A theme of colors only is plain JSON that cannot break the UI: users can save their own, an
45
- app can offer a picker, and an agent can write one. A theme file names the schema shipped in
46
- the package, so editors and CI check it:
47
-
48
- ```json
49
- {
50
- "$schema": "./node_modules/@luxalgo/vela-ui/dist/theme.schema.json",
51
- "colors": { "background": "#0f1117", "text": "#c9d1d9", "accent": "#7c3aed" }
52
- }
53
- ```
54
-
55
- ## The tokens
56
-
57
- Every token is a custom property, `--vela-<name>`; in a theme, `tokens` takes the name
58
- without the prefix, and in a component's CSS `t` reads it (`${t.fg.muted}`).
59
-
60
- | Group | Tokens | What they set |
61
- | --- | --- | --- |
62
- | Text | `fg`, `fg-muted`, `fg-faint`, `fg-bright`, `fg-on-fill` | body text, secondary text, placeholders and disabled text, emphasized text, ink on a saturated fill |
63
- | Surfaces | `bg`, `surface`, `surface-elev`, `surface-overlay`, `surface-sunken` | the chart's background, panels, menus and popovers (opaque, above the chart), recessed fields |
64
- | Lines | `border`, `border-strong`, `border-soft`, `border-faint`, `separator-hover-band`, `separator-hover-line` | borders, field borders, rules inside a panel, a divider under the pointer |
65
- | States | `hover`, `hover-strong`, `active`, `focus`, `focus-soft`, `selected-bg`, `selected-fg`, `highlight` | hover and pressed washes, the focus ring, the selected chip and its ink, favorites |
66
- | Brand and meaning | `accent`, `accent-bright`, `up`, `down`, `profit`, `loss`, `danger` | the brand color, the candles' colors, gains and losses, destructive actions |
67
- | Depth | `shadow`, `shadow-dialog`, `backdrop` | floating surfaces, dialogs, the dim behind a dialog |
68
- | Scrollbars | `scroll`, `scroll-size` | the thumb's color (the chart's border color by default) and the bar's width (5px) |
69
- | Scale | `space-1`…`space-4`, `radius-sm`, `radius-md`, `radius-lg`, `font`, `font-size-sm`, `font-size-md`, `font-size-lg`, `dur-fast`, `dur-med`, `ease`, `z-tooltip`, `z-menu`, `z-dialog`, `z-popover` | spacing, corners, type, motion and stacking, the same in every theme |
70
-
71
- The colors derive from the chart theme's seven fields, so a theme that sets only those
72
- (or only `colors`) still sets every token.
73
-
74
- ## Component settings
75
-
76
- Each component declares a few settings with defaults that point at shared tokens (the
77
- button's `radius` defaults to `radius-md`), so a theme that sets nothing looks exactly as
78
- before. Each is written as `--vela-<component>-<setting>`, so a host can also set one in
79
- its own CSS. The `components` field is typed from the declarations: a component or a setting
80
- that does not exist fails the typecheck. `dist/manifest.json` lists every component's
81
- settings.
82
-
83
- ## Restyling a component completely
84
-
85
- When settings are not enough, a component's `css` restyles its parts: shape, typography,
86
- borders, shadows, every variant and state. It is keyed by the parts the component declares:
87
-
88
- ```ts
89
- import { createTheme, css, t } from '@luxalgo/vela-ui';
90
-
91
- const theme = createTheme({
92
- components: {
93
- button: {
94
- radius: '999px',
95
- css: {
96
- root: css`
97
- text-transform: uppercase;
98
- box-shadow: ${t.shadow};
99
- &[data-variant='outline'] { border-width: 2px; }
100
- &:hover:not(:disabled) { transform: translateY(-1px); }
101
- `,
102
- icon: css`order: 1;`,
103
- },
104
- },
105
- },
106
- });
107
- ```
108
-
109
- - **The name and the part pick the element.** `components.button.css.icon` becomes a rule on
110
- `[data-slot~='button-icon']`; `&` is that part, so its variants and states follow it.
111
- - **Scoped to the theme.** Each part's rule sits under the theme's `data-vela-theme`, so two
112
- charts with two themes on one page each keep their own. Floating layers mount inside their
113
- themed host, so a select's list or a dialog's content is reached the same way.
114
- - **In the last layer.** It goes into `@layer vela.custom`, after every layer of the kit, so
115
- it wins without `!important`; a page's unlayered CSS still beats it.
116
- - **Flattened at run time**, one level: `&` rules, rules without `&` (descendants), and
117
- `@media`, `@supports` or `@container` around either. `@keyframes` and `@font-face` belong
118
- in the page's stylesheet; the part uses them by name.
119
- - **Written against the public contract**: the parts, `data-variant`, `data-size`, and the
120
- state attributes (`data-state`, `data-selected`, `data-disabled`). Class names are not part
121
- of it; `checkTheme` flags them, and `!important`. The shared stylelint config
122
- (`@luxalgo/vela-ui/stylelint`) checks CSS written with the `css` tag in a project too.
123
- - **Off for themes loaded from data.** CSS that was not written with the `css` tag (a saved
124
- JSON, a shared file, a generated theme) is left out unless the host passes
125
- `createTheme(input, { allowCss: true })`. CSS from someone else can restyle the page to
126
- mislead and can load remote images that leak what the page shows. Colors and settings carry
127
- no such risk.
128
-
129
- CSS changes how a component looks, not its markup or behavior.
130
-
131
- ## Checking a theme
132
-
133
- `checkTheme(input)` lists what a theme gets wrong: unknown tokens, a component, setting or
134
- part that does not exist (the kit's components, and those the page declared with
135
- `defineComponent`), colors the theme cannot derive from (it reads `#rrggbb` and `rgb()`),
136
- text with too little contrast on its background, ink with too little contrast on the accent,
137
- and part CSS that is left out or reaches past the component's contract. `createTheme` warns
138
- about each problem once. The typecheck catches the same names in TypeScript; this catches
139
- them in a theme loaded from JSON or written in plain JavaScript, where nothing else would.
140
-
141
- ## Cascade layers
142
-
143
- Every style the kit and Vela write sits in a cascade layer, declared once per document (or
144
- shadow root) in this order, lowest first:
145
-
146
- | Layer | Holds | Written by |
147
- | --- | --- | --- |
148
- | `vela.theme` | the tokens and the scale | `applyTheme`, or a built-in theme's CSS file |
149
- | `vela.ui` | the kit's components | each component, when it is first created |
150
- | `vela.chrome` | Vela's own chrome: toolbars, legends, the status line, dialog layouts | Vela |
151
- | `vela.pro` | Vela Pro's features | Vela Pro |
152
- | `vela.custom` | a theme's component `css` | `applyTheme` |
153
- | no layer | your page's CSS | you |
154
-
155
- A later layer wins over an earlier one whatever the selectors' weight, and CSS in no layer
156
- wins over all of them, so a page overrides any of it without `!important`. Layers a page
157
- declared before the first Vela stylesheet rank below Vela's. Write CSS that restyles
158
- components into `vela.custom` to sit above the kit and below your page's other CSS.
159
-
160
- A component of your own (built with the kit's helpers, or copied with `vela-ui add --source`)
161
- puts its base styles in `vela.ui`, like the kit's, so a theme's part CSS and your restyles
162
- reach it. In `vela.custom` its rules would tie with the theme's, and whichever stylesheet
163
- loaded last would win, usually the component's own.
164
-
165
- Unlayered CSS also reaches the kit when you did not mean it to: a global reset such as
166
- `button { background: none; }` or `input { border: 0; }` now restyles the kit's buttons and
167
- fields. Scope such rules away from Vela (`button:where(:not(.vela-ui *)) { … }`), or move them
168
- into a layer declared before Vela's (`@layer reset;` first in your stylesheet).
169
-
170
- The kit's CSS does not reach the other way: a component's styles apply inside kit hosts and
171
- the floating layers they open only, so a page's own components keep their look, even those
172
- that use the same part names (`data-slot="select-trigger"`).
173
-
174
- ## Overriding from a page's CSS
175
-
176
- The theme layer sits below every other style, so a page's own CSS overrides any token without
177
- `!important`. `[data-vela-theme]` reaches every themed host, chrome inside a chart included:
178
-
179
- ```css
180
- [data-vela-theme] { --vela-accent: #7c3aed; }
181
- ```
182
-
183
- ## Scrollbars
184
-
185
- Every scroller inside a kit host (`.vela-ui`) and its floating layers shows the same
186
- scrollbar: thin, a rounded thumb, no track and no arrows. `scroll` colors the thumb and
187
- `scroll-size` sets the bar's width; set them like any token:
188
-
189
- ```ts
190
- createTheme({ tokens: { scroll: '#3b3f4a', 'scroll-size': '8px' } });
191
- ```
192
-
193
- Chromium and Safari draw it from the `::-webkit-scrollbar` parts, Firefox from
194
- `scrollbar-width` and `scrollbar-color`. Setting `scrollbar-width` or `scrollbar-color` on an
195
- element switches Chromium back to its native bar, so a page that sets them on every element
196
- (`* { scrollbar-width: thin; }`) brings the native bar back inside the chart too. Leave the
197
- kit out of that rule, or reset it:
198
-
199
- ```css
200
- .vela-ui, .vela-ui * { scrollbar-width: auto; scrollbar-color: auto; }
201
- ```
202
-
203
- A scroller outside any kit host takes the same scrollbar with `overlayScrollbarCss(selector)`
204
- (`@luxalgo/vela-ui/styles`).
205
-
206
- ## Without JavaScript
207
-
208
- A page that uses the kit without building a theme can link a built-in theme as plain CSS; it
209
- sets every token on the page root:
210
-
211
- ```html
212
- <link rel="stylesheet" href="node_modules/@luxalgo/vela-ui/dist/themes/dark.css" />
213
- ```
214
-
215
- Bundlers resolve `@luxalgo/vela-ui/themes/dark.css` and `@luxalgo/vela-ui/themes/light.css`.
216
- The components still go in a kit host, which gives them their base styles: call
217
- `ensureUIHost(el)` without a theme on the element that holds them.
1
+ # Theming
2
+
3
+ A theme is data: the chart's colors and font, every design token, and the settings of each
4
+ component. `createTheme` builds one from a few choices; applied to a host, it is written once
5
+ per document (or shadow root) as a rule in the `vela.theme` cascade layer, keyed by the host's
6
+ `data-vela-theme` attribute.
7
+
8
+ ```ts
9
+ import { createTheme, ensureUIHost } from '@luxalgo/vela-ui/theme';
10
+
11
+ const theme = createTheme({
12
+ base: 'dark', // 'dark' (default), 'light', or a chart theme's seven fields
13
+ accent: '#7c3aed', // brand color; the ink on it is derived
14
+ radius: 'sm', // none | sm | md | lg: scales every radius token
15
+ font: 'Inter, sans-serif',
16
+ tokens: { 'surface-elev': '#1b1c22' }, // any token, by name
17
+ components: { button: { radius: '2px' } }, // a component's own settings
18
+ });
19
+
20
+ ensureUIHost(document.getElementById('app')!, theme);
21
+ ```
22
+
23
+ On a page of your own, `ensureUIHost(el, theme)` makes the element a kit host and themes it:
24
+ the kit's base styles apply inside it, and menus, dialogs and tooltips opened from it mount
25
+ there. `applyTheme(el, theme)` alone only themes an element, so a menu opened from it would
26
+ mount outside, unthemed; use it to switch a host that is already one to another theme.
27
+
28
+ In Vela, pass the theme as the chart's `theme` option or to `setTheme`, and offer it in the
29
+ chart settings with `registerTheme({ id, label, theme })`.
30
+
31
+ ## Themes from colors alone
32
+
33
+ `colors` builds a whole theme from a few colors: grid and border derive from the background
34
+ and the text, and light or dark is read from the background.
35
+
36
+ ```ts
37
+ const paper = createTheme({ colors: { background: '#fdf6e3', accent: '#268bd2' } });
38
+ ```
39
+
40
+ `up` and `down` are the candles' colors, and the `up`, `down`, `profit` and `loss` tokens
41
+ follow them. In Vela they are the candles' defaults: a chart's own `upColor` and
42
+ `downColor` options, and colors a user picks in its settings, win over them.
43
+
44
+ A theme of colors only is plain JSON that cannot break the UI: users can save their own, an
45
+ app can offer a picker, and an agent can write one. A theme file names the schema shipped in
46
+ the package, so editors and CI check it:
47
+
48
+ ```json
49
+ {
50
+ "$schema": "./node_modules/@luxalgo/vela-ui/dist/theme.schema.json",
51
+ "colors": { "background": "#0f1117", "text": "#c9d1d9", "accent": "#7c3aed" }
52
+ }
53
+ ```
54
+
55
+ ## The tokens
56
+
57
+ Every token is a custom property, `--vela-<name>`; in a theme, `tokens` takes the name
58
+ without the prefix, and in a component's CSS `t` reads it (`${t.fg.muted}`).
59
+
60
+ | Group | Tokens | What they set |
61
+ | --- | --- | --- |
62
+ | Text | `fg`, `fg-muted`, `fg-faint`, `fg-bright`, `fg-on-fill` | body text, secondary text, placeholders and disabled text, emphasized text, ink on a saturated fill |
63
+ | Surfaces | `bg`, `surface`, `surface-elev`, `surface-overlay`, `surface-sunken` | the chart's background, panels, menus and popovers (opaque, above the chart), recessed fields |
64
+ | Lines | `border`, `border-strong`, `border-soft`, `border-faint`, `separator-hover-band`, `separator-hover-line` | borders, field borders, rules inside a panel, a divider under the pointer |
65
+ | States | `hover`, `hover-strong`, `active`, `focus`, `focus-soft`, `selected-bg`, `selected-fg`, `highlight` | hover and pressed washes, the focus ring, the selected chip and its ink, favorites |
66
+ | Brand and meaning | `accent`, `accent-bright`, `up`, `down`, `profit`, `loss`, `danger` | the brand color, the candles' colors, gains and losses, destructive actions |
67
+ | Depth | `shadow`, `shadow-dialog`, `backdrop` | floating surfaces, dialogs, the dim behind a dialog |
68
+ | Scrollbars | `scroll`, `scroll-size` | the thumb's color (the chart's border color by default) and the bar's width (5px) |
69
+ | Scale | `space-1`…`space-4`, `radius-sm`, `radius-md`, `radius-lg`, `font`, `font-size-sm`, `font-size-md`, `font-size-lg`, `dur-fast`, `dur-med`, `ease`, `z-tooltip`, `z-menu`, `z-dialog`, `z-popover` | spacing, corners, type, motion and stacking, the same in every theme |
70
+
71
+ The colors derive from the chart theme's seven fields, so a theme that sets only those
72
+ (or only `colors`) still sets every token.
73
+
74
+ ## Component settings
75
+
76
+ Each component declares a few settings with defaults that point at shared tokens (the
77
+ button's `radius` defaults to `radius-md`), so a theme that sets nothing looks exactly as
78
+ before. Each is written as `--vela-<component>-<setting>`, so a host can also set one in
79
+ its own CSS. The `components` field is typed from the declarations: a component or a setting
80
+ that does not exist fails the typecheck. `dist/manifest.json` lists every component's
81
+ settings.
82
+
83
+ ## Restyling a component completely
84
+
85
+ When settings are not enough, a component's `css` restyles its parts: shape, typography,
86
+ borders, shadows, every variant and state. It is keyed by the parts the component declares:
87
+
88
+ ```ts
89
+ import { createTheme, css, t } from '@luxalgo/vela-ui';
90
+
91
+ const theme = createTheme({
92
+ components: {
93
+ button: {
94
+ radius: '999px',
95
+ css: {
96
+ root: css`
97
+ text-transform: uppercase;
98
+ box-shadow: ${t.shadow};
99
+ &[data-variant='outline'] { border-width: 2px; }
100
+ &:hover:not(:disabled) { transform: translateY(-1px); }
101
+ `,
102
+ icon: css`order: 1;`,
103
+ },
104
+ },
105
+ },
106
+ });
107
+ ```
108
+
109
+ - **The name and the part pick the element.** `components.button.css.icon` becomes a rule on
110
+ `[data-slot~='button-icon']`; `&` is that part, so its variants and states follow it.
111
+ - **Scoped to the theme.** Each part's rule sits under the theme's `data-vela-theme`, so two
112
+ charts with two themes on one page each keep their own. Floating layers mount inside their
113
+ themed host, so a select's list or a dialog's content is reached the same way.
114
+ - **In the last layer.** It goes into `@layer vela.custom`, after every layer of the kit, so
115
+ it wins without `!important`; a page's unlayered CSS still beats it.
116
+ - **Flattened at run time**, one level: `&` rules, rules without `&` (descendants), and
117
+ `@media`, `@supports` or `@container` around either. `@keyframes` and `@font-face` belong
118
+ in the page's stylesheet; the part uses them by name.
119
+ - **Written against the public contract**: the parts, `data-variant`, `data-size`, and the
120
+ state attributes (`data-state`, `data-selected`, `data-disabled`). Class names are not part
121
+ of it; `checkTheme` flags them, and `!important`. The shared stylelint config
122
+ (`@luxalgo/vela-ui/stylelint`) checks CSS written with the `css` tag in a project too.
123
+ - **Off for themes loaded from data.** CSS that was not written with the `css` tag (a saved
124
+ JSON, a shared file, a generated theme) is left out unless the host passes
125
+ `createTheme(input, { allowCss: true })`. CSS from someone else can restyle the page to
126
+ mislead and can load remote images that leak what the page shows. Colors and settings carry
127
+ no such risk.
128
+
129
+ CSS changes how a component looks, not its markup or behavior.
130
+
131
+ ## Checking a theme
132
+
133
+ `checkTheme(input)` lists what a theme gets wrong: unknown tokens, a component, setting or
134
+ part that does not exist (the kit's components, and those the page declared with
135
+ `defineComponent`), colors the theme cannot derive from (it reads `#rrggbb` and `rgb()`),
136
+ text with too little contrast on its background, ink with too little contrast on the accent,
137
+ and part CSS that is left out or reaches past the component's contract. `createTheme` warns
138
+ about each problem once. The typecheck catches the same names in TypeScript; this catches
139
+ them in a theme loaded from JSON or written in plain JavaScript, where nothing else would.
140
+
141
+ ## Cascade layers
142
+
143
+ Every style the kit and Vela write sits in a cascade layer, declared once per document (or
144
+ shadow root) in this order, lowest first:
145
+
146
+ | Layer | Holds | Written by |
147
+ | --- | --- | --- |
148
+ | `vela.theme` | the tokens and the scale | `applyTheme`, or a built-in theme's CSS file |
149
+ | `vela.ui` | the kit's components | each component, when it is first created |
150
+ | `vela.chrome` | Vela's own chrome: toolbars, legends, the status line, dialog layouts | Vela |
151
+ | `vela.pro` | Vela Pro's features | Vela Pro |
152
+ | `vela.custom` | a theme's component `css` | `applyTheme` |
153
+ | no layer | your page's CSS | you |
154
+
155
+ A later layer wins over an earlier one whatever the selectors' weight, and CSS in no layer
156
+ wins over all of them, so a page overrides any of it without `!important`. Layers a page
157
+ declared before the first Vela stylesheet rank below Vela's. Write CSS that restyles
158
+ components into `vela.custom` to sit above the kit and below your page's other CSS.
159
+
160
+ A component of your own (built with the kit's helpers, or copied with `vela-ui add --source`)
161
+ puts its base styles in `vela.ui`, like the kit's, so a theme's part CSS and your restyles
162
+ reach it. In `vela.custom` its rules would tie with the theme's, and whichever stylesheet
163
+ loaded last would win, usually the component's own.
164
+
165
+ Unlayered CSS also reaches the kit when you did not mean it to: a global reset such as
166
+ `button { background: none; }` or `input { border: 0; }` now restyles the kit's buttons and
167
+ fields. Scope such rules away from Vela (`button:where(:not(.vela-ui *)) { … }`), or move them
168
+ into a layer declared before Vela's (`@layer reset;` first in your stylesheet).
169
+
170
+ The kit's CSS does not reach the other way: a component's styles apply inside kit hosts and
171
+ the floating layers they open only, so a page's own components keep their look, even those
172
+ that use the same part names (`data-slot="select-trigger"`).
173
+
174
+ ## Overriding from a page's CSS
175
+
176
+ The theme layer sits below every other style, so a page's own CSS overrides any token without
177
+ `!important`. `[data-vela-theme]` reaches every themed host, chrome inside a chart included:
178
+
179
+ ```css
180
+ [data-vela-theme] { --vela-accent: #7c3aed; }
181
+ ```
182
+
183
+ ## Scrollbars
184
+
185
+ Every scroller inside a kit host (`.vela-ui`) and its floating layers shows the same
186
+ scrollbar: thin, a rounded thumb, no track and no arrows. `scroll` colors the thumb and
187
+ `scroll-size` sets the bar's width; set them like any token:
188
+
189
+ ```ts
190
+ createTheme({ tokens: { scroll: '#3b3f4a', 'scroll-size': '8px' } });
191
+ ```
192
+
193
+ Chromium and Safari draw it from the `::-webkit-scrollbar` parts, Firefox from
194
+ `scrollbar-width` and `scrollbar-color`. Setting `scrollbar-width` or `scrollbar-color` on an
195
+ element switches Chromium back to its native bar, so a page that sets them on every element
196
+ (`* { scrollbar-width: thin; }`) brings the native bar back inside the chart too. Leave the
197
+ kit out of that rule, or reset it:
198
+
199
+ ```css
200
+ .vela-ui, .vela-ui * { scrollbar-width: auto; scrollbar-color: auto; }
201
+ ```
202
+
203
+ A scroller outside any kit host takes the same scrollbar with `overlayScrollbarCss(selector)`
204
+ (`@luxalgo/vela-ui/styles`).
205
+
206
+ ## Without JavaScript
207
+
208
+ A page that uses the kit without building a theme can link a built-in theme as plain CSS; it
209
+ sets every token on the page root:
210
+
211
+ ```html
212
+ <link rel="stylesheet" href="node_modules/@luxalgo/vela-ui/dist/themes/dark.css" />
213
+ ```
214
+
215
+ Bundlers resolve `@luxalgo/vela-ui/themes/dark.css` and `@luxalgo/vela-ui/themes/light.css`.
216
+ The components still go in a kit host, which gives them their base styles: call
217
+ `ensureUIHost(el)` without a theme on the element that holds them.
@@ -1,20 +1,20 @@
1
- # What to change, and where
2
-
3
- | To change | Where | It reaches |
4
- | --- | --- | --- |
5
- | Chart colors: background, candles, grid, axis text | the theme's seven chart fields, or `colors` in `createTheme` | the chart's canvas, and the tokens derived from them |
6
- | Brand color, radius scale, font | `accent`, `radius`, `font` in `createTheme` | every component |
7
- | One token | `tokens` in `createTheme`, or CSS on `[data-vela-theme]` | every component that uses it |
8
- | Scrollbars | the `scroll` (thumb color) and `scroll-size` (width) tokens | every scroller inside a kit host |
9
- | Vela's own chrome: toolbars, sidebar, legends, status line | the same tokens; for more, CSS on its `.vela-*` classes in your page (the chrome sits in `@layer vela.chrome`, below it) | the chart's chrome |
10
- | A theme made of colors only | `createTheme({ colors })`; in Vela, `registerTheme` offers it in the chart settings | the chart and every component |
11
- | One component's sizes, radius, weight or variant colors | its settings in `components`, or CSS on its `--vela-<component>-*` variables | that component everywhere |
12
- | One component's whole look: shape, typography, states, decorations | its `css` in `components`, by part | that component wherever the theme applies |
13
- | Anything else about one component's look | CSS on its `data-slot`, `data-variant`, `data-size` | that component everywhere |
14
- | A component's behavior or markup | a component of your own, built from the kit's helpers ([Writing a component](writing-a-component.md)) | your screens |
15
-
16
- `dist/manifest.json` lists each component's parts and their slots, its settings, its
17
- variants and the attributes its CSS styles by. [Theming](theming.md) lists the tokens and the
18
- cascade layers each kind of change lands in. The chart's own canvas (candles, grid, axis
19
- text) is drawn from the theme object, not from CSS, so those colors change through the theme
20
- only.
1
+ # What to change, and where
2
+
3
+ | To change | Where | It reaches |
4
+ | --- | --- | --- |
5
+ | Chart colors: background, candles, grid, axis text | the theme's seven chart fields, or `colors` in `createTheme` | the chart's canvas, and the tokens derived from them |
6
+ | Brand color, radius scale, font | `accent`, `radius`, `font` in `createTheme` | every component |
7
+ | One token | `tokens` in `createTheme`, or CSS on `[data-vela-theme]` | every component that uses it |
8
+ | Scrollbars | the `scroll` (thumb color) and `scroll-size` (width) tokens | every scroller inside a kit host |
9
+ | Vela's own chrome: toolbars, sidebar, legends, status line | the same tokens; for more, CSS on its `.vela-*` classes in your page (the chrome sits in `@layer vela.chrome`, below it) | the chart's chrome |
10
+ | A theme made of colors only | `createTheme({ colors })`; in Vela, `registerTheme` offers it in the chart settings | the chart and every component |
11
+ | One component's sizes, radius, weight or variant colors | its settings in `components`, or CSS on its `--vela-<component>-*` variables | that component everywhere |
12
+ | One component's whole look: shape, typography, states, decorations | its `css` in `components`, by part | that component wherever the theme applies |
13
+ | Anything else about one component's look | CSS on its `data-slot`, `data-variant`, `data-size` | that component everywhere |
14
+ | A component's behavior or markup | a component of your own, built from the kit's helpers ([Writing a component](writing-a-component.md)) | your screens |
15
+
16
+ `dist/manifest.json` lists each component's parts and their slots, its settings, its
17
+ variants and the attributes its CSS styles by. [Theming](theming.md) lists the tokens and the
18
+ cascade layers each kind of change lands in. The chart's own canvas (candles, grid, axis
19
+ text) is drawn from the theme object, not from CSS, so those colors change through the theme
20
+ only.