@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,620 @@
1
+ // Select: a trigger button and a themed option list on a popover, with an overlay scrollbar
2
+ // for long lists. `md` is the shared 100px kit column and ellipsizes the trigger; `sm` is a
3
+ // compact toolbar select that hugs its widest option. The open list shows full labels.
4
+ import type { ChartTheme } from '@luxalgo/vela-ui/tokens';
5
+ import { iconEl } from '@luxalgo/vela-ui/icons';
6
+ import { css, defineStyles } from '@luxalgo/vela-ui';
7
+ import { defineComponent } from '@luxalgo/vela-ui';
8
+ import { ownTeardown } from '@luxalgo/vela-ui/dispose';
9
+ import { addSlot, h } from '@luxalgo/vela-ui';
10
+ import { t } from '@luxalgo/vela-ui';
11
+ import { variants } from '@luxalgo/vela-ui';
12
+ import { nextUid, normalizeProps, runMachine, spreadProps } from '@luxalgo/vela-ui/zag';
13
+ import * as zagListbox from '@zag-js/listbox';
14
+ import { Popover, closeOpenPopovers, openPopoverTrigger, type PlacementProps, type PopoverBoundary, type PopoverOptions } from '@luxalgo/vela-ui/popover';
15
+
16
+ export type SelectSize = 'sm' | 'md';
17
+
18
+ export interface SelectOption {
19
+ value: string;
20
+ label: string;
21
+ }
22
+
23
+ export interface SelectControllerOptions {
24
+ options: readonly SelectOption[];
25
+ value?: string;
26
+ /** The value it starts with when `value` is not given. */
27
+ defaultValue?: string;
28
+ /** Shown while no option is picked: the value stays `''` until the user picks one. Without
29
+ * it, the first option is picked to start with. */
30
+ placeholder?: string;
31
+ size?: SelectSize;
32
+ /** Stretch the trigger to its parent. Off: the shared 100px kit column (ellipsis). */
33
+ fill?: boolean;
34
+ disabled?: boolean;
35
+ /** Called when the user picks an option. */
36
+ onValueChange?: (value: string, label: string) => void;
37
+ /** @deprecated Use `onValueChange`. */
38
+ onChange?: (value: string, label: string) => void;
39
+ }
40
+
41
+ export interface SelectController {
42
+ options: readonly SelectOption[];
43
+ value: string;
44
+ size: SelectSize;
45
+ fill: boolean;
46
+ disabled: boolean;
47
+ setValue(v: string): void;
48
+ labelOf(value: string): string;
49
+ pick(value: string): { value: string; label: string };
50
+ }
51
+
52
+ /** The select's options and current value, without DOM. */
53
+ export function selectController(opts: SelectControllerOptions): SelectController {
54
+ const options = opts.options;
55
+ let value = opts.value ?? opts.defaultValue ?? (opts.placeholder !== undefined ? '' : (options[0]?.value ?? ''));
56
+ const size = opts.size ?? 'md';
57
+ return {
58
+ options,
59
+ get value() {
60
+ return value;
61
+ },
62
+ size,
63
+ fill: opts.fill ?? size !== 'sm',
64
+ disabled: opts.disabled ?? false,
65
+ setValue(v: string) {
66
+ value = v;
67
+ },
68
+ labelOf(v: string) {
69
+ return options.find((o) => o.value === v)?.label ?? v;
70
+ },
71
+ pick(v: string) {
72
+ value = v;
73
+ const label = options.find((o) => o.value === v)?.label ?? v;
74
+ opts.onValueChange?.(v, label);
75
+ opts.onChange?.(v, label);
76
+ return { value: v, label };
77
+ },
78
+ };
79
+ }
80
+
81
+ export const selectDef = defineComponent({
82
+ name: 'select',
83
+ parts: ['root', 'trigger', 'value', 'icon', 'sizer', 'native', 'content', 'viewport', 'item', 'rail', 'thumb'],
84
+ settings: { radius: t.radius.md, 'content-radius': t.radius.md, 'thumb-radius': '2px', 'focus-ring': `0 0 0 3px ${t.focus.soft}` },
85
+ });
86
+
87
+ export const selectVariants = variants({ size: ['md', 'sm'] });
88
+
89
+ /** Where the list opens and how (shadcn's placement props, defaults below and start-aligned,
90
+ * 4px away, as wide as the trigger at least). */
91
+ export interface SelectListPopoverOpts extends PlacementProps {
92
+ theme?: ChartTheme;
93
+ matchWidth?: boolean;
94
+ /** @deprecated Use `collisionBoundary`. */
95
+ boundary?: PopoverBoundary;
96
+ boundaryInset?: number;
97
+ /** @deprecated Use `sideOffset`. */
98
+ gap?: number;
99
+ host?: HTMLElement;
100
+ position?: PopoverOptions['position'];
101
+ zIndex?: string | number;
102
+ size?: SelectSize;
103
+ /** Move the focus into the open list, for the arrow keys and typeahead (and back to the
104
+ * trigger when it closes). Off by default: a trigger the user types in keeps the focus. */
105
+ focusList?: boolean;
106
+ onClose?: () => void;
107
+ }
108
+
109
+ export interface SelectOptions extends SelectControllerOptions, PlacementProps {
110
+ id?: string;
111
+ /** Submitted with its form under this name: a hidden native select carries the value. */
112
+ name?: string;
113
+ /** A form does not submit while no option is picked (with `placeholder`). */
114
+ required?: boolean;
115
+ theme?: ChartTheme;
116
+ /** The open list's other options (its host, layer, width). Its placement props are the
117
+ * select's own; set here, they give way to those. */
118
+ list?: SelectListPopoverOpts;
119
+ }
120
+
121
+ export type SelectProps = SelectOptions;
122
+
123
+ export const SELECT_STYLE_ID = 'vela-ui-select-3';
124
+
125
+ export const SELECT_CSS = css`
126
+ @layer vela.ui {
127
+ [data-slot='select-trigger'] {
128
+ display: flex;
129
+ align-items: center;
130
+ width: 100%;
131
+ min-width: 0;
132
+ box-sizing: border-box;
133
+ height: 34px;
134
+ padding-block: 0;
135
+ padding-inline: 8px 26px;
136
+ background: transparent;
137
+ border: 1px solid ${t.border.strong};
138
+ border-radius: ${selectDef.vars.radius};
139
+ color: ${t.fg.bright};
140
+ font-size: 14px;
141
+ font-family: inherit;
142
+ cursor: pointer;
143
+ text-align: start;
144
+ outline: 2px solid transparent;
145
+ transition:
146
+ border-color ${t.dur.fast} ease,
147
+ box-shadow ${t.dur.fast} ease;
148
+
149
+ &:hover {
150
+ border-color: ${t.fg.muted};
151
+ }
152
+ &:focus {
153
+ border-color: ${t.focus};
154
+ box-shadow: ${selectDef.vars['focus-ring']};
155
+ }
156
+ }
157
+ [data-slot='select-value'] {
158
+ flex: 1;
159
+ min-width: 0;
160
+ overflow: hidden;
161
+ text-overflow: ellipsis;
162
+ white-space: nowrap;
163
+ }
164
+ [data-slot='select-icon'] {
165
+ position: absolute;
166
+ inset-inline-end: 8px;
167
+ top: 50%;
168
+ transform: translateY(-50%);
169
+ pointer-events: none;
170
+ display: flex;
171
+ opacity: 0.55;
172
+ line-height: 0;
173
+ color: inherit;
174
+
175
+ & > span,
176
+ & svg {
177
+ width: 12px;
178
+ height: 12px;
179
+ display: block;
180
+ }
181
+ }
182
+ [data-slot='select-sizer'] {
183
+ visibility: hidden;
184
+ height: 0;
185
+ overflow: hidden;
186
+ font-size: 13px;
187
+
188
+ & span {
189
+ display: block;
190
+ height: 0;
191
+ white-space: nowrap;
192
+ padding-block: 0;
193
+ padding-inline: 8px 26px;
194
+ border-inline: 1px solid transparent;
195
+ }
196
+ }
197
+ [data-slot='select-viewport'] {
198
+ width: max-content;
199
+ min-width: 100%;
200
+ max-height: none;
201
+ overflow: hidden;
202
+ }
203
+ [data-slot='select-rail'] {
204
+ position: relative;
205
+ flex: none;
206
+ width: 3px;
207
+ margin-block: 2px;
208
+ margin-inline: 0 1px;
209
+ pointer-events: none;
210
+ }
211
+ [data-slot='select-thumb'] {
212
+ width: 3px;
213
+ border-radius: ${selectDef.vars['thumb-radius']};
214
+ background: ${t.scroll};
215
+ }
216
+ [data-slot='select-item'] {
217
+ display: block;
218
+ width: auto;
219
+ min-width: 100%;
220
+ white-space: nowrap;
221
+ text-align: start;
222
+ padding: 7px 10px;
223
+ border: none;
224
+ border-radius: ${t.radius.sm};
225
+ background: transparent;
226
+ color: inherit;
227
+ cursor: pointer;
228
+ font: inherit;
229
+ font-weight: 400;
230
+
231
+ &:hover,
232
+ &[data-highlighted] {
233
+ background: ${t.hover};
234
+ }
235
+ &[data-checked] {
236
+ background: ${t.hover.strong};
237
+ color: ${t.fg.bright};
238
+ }
239
+ &[data-checked]:hover,
240
+ &[data-checked][data-highlighted] {
241
+ background: ${t.hover.strong};
242
+ }
243
+ }
244
+ /* The highlighted option shows where the keyboard is; the list itself draws no ring. */
245
+ [data-slot='select-viewport']:focus {
246
+ outline: 2px solid transparent;
247
+ }
248
+ [data-slot='select-value'][data-placeholder] {
249
+ color: ${t.fg.muted};
250
+ }
251
+ /* Seen by forms and their validation, never by the user. */
252
+ [data-slot='select-native'] {
253
+ position: absolute;
254
+ width: 1px;
255
+ height: 1px;
256
+ margin: -1px;
257
+ padding: 0;
258
+ border: 0;
259
+ overflow: hidden;
260
+ clip-path: inset(50%);
261
+ white-space: nowrap;
262
+ pointer-events: none;
263
+ }
264
+ [data-slot='select'] {
265
+ position: relative;
266
+ min-width: 0;
267
+
268
+ &:where(:not([hidden])) {
269
+ display: inline-block;
270
+ }
271
+ &[data-fill] {
272
+ width: 100%;
273
+ }
274
+ /* The closed trigger matches NumberInput and TextField (100px); long labels
275
+ ellipsize, and the open list still sizes to the longest item. */
276
+ &:not([data-fill]) {
277
+ width: 100px;
278
+ flex: none;
279
+ justify-self: start;
280
+ }
281
+ &[data-size='sm'] [data-slot='select-trigger'] {
282
+ height: 28px;
283
+ background: ${t.surface.elev};
284
+ border-radius: ${t.radius.sm};
285
+ color: ${t.fg};
286
+ font-size: 13px;
287
+ box-shadow: none;
288
+ }
289
+ &[data-size='sm'] [data-slot='select-trigger']:focus {
290
+ box-shadow: none;
291
+ border-color: ${t.fg.muted};
292
+ }
293
+ /* Compact toolbar selects still hug the widest option (no 100px kit column). */
294
+ &[data-size='sm']:not([data-fill]) {
295
+ width: auto;
296
+ max-width: 200px;
297
+ }
298
+ }
299
+ [data-slot~='select-content'] {
300
+ width: max-content;
301
+ background: ${t.bg};
302
+ color: ${t.fg};
303
+ border: none;
304
+ border-radius: ${selectDef.vars['content-radius']};
305
+ box-shadow: ${t.shadow};
306
+ font: 14px ${t.font};
307
+ padding: 4px;
308
+ overflow: hidden;
309
+
310
+ &[data-size='sm'] {
311
+ font-size: 13px;
312
+ background: ${t.surface.overlay};
313
+ }
314
+ &[data-scroll] {
315
+ display: flex;
316
+ align-items: stretch;
317
+ gap: 2px;
318
+ }
319
+ &[data-scroll] [data-slot='select-viewport'] {
320
+ flex: 1 1 auto;
321
+ min-width: min-content;
322
+ max-height: 240px;
323
+ overflow-y: auto;
324
+ scrollbar-width: none;
325
+ }
326
+ &[data-scroll] [data-slot='select-viewport']::-webkit-scrollbar {
327
+ display: none;
328
+ width: 0;
329
+ height: 0;
330
+ }
331
+ }
332
+ }
333
+ `;
334
+
335
+ const injectStyles = defineStyles(SELECT_STYLE_ID, SELECT_CSS);
336
+
337
+ function syncThumb(list: HTMLElement, thumb: HTMLElement): void {
338
+ const view = list.clientHeight;
339
+ const total = list.scrollHeight;
340
+ if (total <= view) {
341
+ thumb.style.height = '0';
342
+ return;
343
+ }
344
+ const thumbH = Math.max(20, (view / total) * view);
345
+ const top = (list.scrollTop / (total - view)) * (view - thumbH);
346
+ thumb.style.height = `${Math.round(thumbH)}px`;
347
+ thumb.style.transform = `translateY(${Math.round(top)}px`;
348
+ }
349
+
350
+ /** Fill `menu` with the options, a listbox (Zag's listbox machine: the arrow keys, Home/End,
351
+ * Enter and typeahead while it has the focus). A click picks at once; one pick per fill.
352
+ * Call {@link decorateSelectScroll} after the menu is on screen; call the returned function
353
+ * when the menu goes away. */
354
+ export function fillSelectList(menu: HTMLElement, options: readonly SelectOption[], current: string, onPick: (value: string, label: string) => void): () => void {
355
+ injectStyles(menu.ownerDocument);
356
+ addSlot(menu, selectDef.slot('content'));
357
+ let picked = false;
358
+ const choose = (value: string): void => {
359
+ const option = options.find((o) => o.value === value);
360
+ if (picked || !option) return;
361
+ picked = true;
362
+ onPick(option.value, option.label);
363
+ };
364
+ const items = options.map((p) =>
365
+ h('button', {
366
+ className: 'vela-select-item',
367
+ slot: selectDef.slot('item'),
368
+ attrs: { type: 'button', tabindex: -1 },
369
+ data: { checked: p.value === current ? '1' : null },
370
+ text: p.label,
371
+ on: {
372
+ click: (e) => {
373
+ e.stopPropagation();
374
+ choose(p.value);
375
+ },
376
+ },
377
+ }),
378
+ );
379
+ const viewport = h('div', { className: 'vela-select-items', slot: selectDef.slot('viewport') }, items);
380
+ menu.replaceChildren(viewport);
381
+ const mid = nextUid('vela-select-list');
382
+ const known = options.some((o) => o.value === current);
383
+ const machine = runMachine(
384
+ zagListbox.machine,
385
+ {
386
+ id: mid,
387
+ collection: zagListbox.collection({ items: options, itemToValue: (o) => o.value, itemToString: (o) => o.label }),
388
+ selectionMode: 'single',
389
+ defaultValue: known ? [current] : [],
390
+ defaultHighlightedValue: known ? current : null,
391
+ // The keyboard's pick (Enter) arrives here, a beat after the key.
392
+ onSelect: ({ value }) => choose(value),
393
+ },
394
+ (service) => {
395
+ const api = zagListbox.connect(service, normalizeProps);
396
+ spreadProps(viewport, api.getContentProps(), mid);
397
+ options.forEach((item, i) => spreadProps(items[i]!, api.getItemProps({ item, highlightOnHover: true }), mid));
398
+ },
399
+ );
400
+ // After the machine's own handler: the picking key ends here, so it can't also press the
401
+ // trigger the focus returns to.
402
+ viewport.addEventListener('keydown', (e) => {
403
+ if (e.key === 'Enter' || e.key === ' ') e.preventDefault();
404
+ });
405
+ return () => machine.stop();
406
+ }
407
+
408
+ /** Overlay scrollbar + scroll-into-view — needs a laid-out list (after the popover is shown). */
409
+ export function decorateSelectScroll(menu: HTMLElement): void {
410
+ const list = menu.querySelector<HTMLElement>(`[data-slot='${selectDef.slot('viewport')}']`);
411
+ if (!list) return;
412
+ if (list.scrollHeight > 240) {
413
+ menu.classList.add('is-scroll');
414
+ menu.dataset.scroll = '';
415
+ const thumb = h('div', { className: 'vela-select-thumb', slot: selectDef.slot('thumb') });
416
+ menu.appendChild(h('div', { className: 'vela-select-rail', slot: selectDef.slot('rail') }, thumb));
417
+ list.addEventListener('scroll', () => syncThumb(list, thumb));
418
+ syncThumb(list, thumb);
419
+ }
420
+ menu.querySelector<HTMLElement>(`[data-slot='${selectDef.slot('item')}'][data-checked]`)?.scrollIntoView({ block: 'nearest' });
421
+ list.dispatchEvent(new Event('scroll'));
422
+ }
423
+
424
+ /** Open (or re-click close) a themed option list under `trigger`. */
425
+ export function toggleSelectList(
426
+ trigger: HTMLElement,
427
+ options: readonly SelectOption[],
428
+ current: string,
429
+ onPick: (value: string, label: string) => void,
430
+ opts: SelectListPopoverOpts = {},
431
+ ): Popover | null {
432
+ if (openPopoverTrigger() === trigger) {
433
+ closeOpenPopovers();
434
+ return null;
435
+ }
436
+ return openSelectList(trigger, options, current, onPick, opts);
437
+ }
438
+
439
+ export function openSelectList(
440
+ trigger: HTMLElement,
441
+ options: readonly SelectOption[],
442
+ current: string,
443
+ onPick: (value: string, label: string) => void,
444
+ opts: SelectListPopoverOpts = {},
445
+ ): Popover {
446
+ injectStyles(trigger.ownerDocument);
447
+ closeOpenPopovers();
448
+ let dispose: (() => void) | null = null;
449
+ const pop = new Popover({
450
+ trigger,
451
+ theme: opts.theme,
452
+ matchWidth: opts.matchWidth ?? true,
453
+ collisionBoundary: opts.collisionBoundary ?? opts.boundary,
454
+ boundaryInset: opts.boundaryInset,
455
+ side: opts.side,
456
+ sideOffset: opts.sideOffset ?? opts.gap ?? 4,
457
+ align: opts.align ?? 'start',
458
+ alignOffset: opts.alignOffset,
459
+ avoidCollisions: opts.avoidCollisions,
460
+ collisionPadding: opts.collisionPadding,
461
+ host: opts.host,
462
+ position: opts.position,
463
+ zIndex: opts.zIndex,
464
+ className: 'vela-select-list',
465
+ slot: selectDef.slot('content'),
466
+ onClose: () => {
467
+ dispose?.();
468
+ dispose = null;
469
+ const active = trigger.ownerDocument.activeElement;
470
+ if (opts.focusList && (!active || active === trigger.ownerDocument.body || pop.el.contains(active))) trigger.focus({ preventScroll: true });
471
+ opts.onClose?.();
472
+ },
473
+ content: (el) => {
474
+ if (opts.size) el.dataset.size = opts.size;
475
+ dispose = fillSelectList(el, options, current, (value, label) => {
476
+ pop.hide();
477
+ onPick(value, label);
478
+ });
479
+ },
480
+ });
481
+ pop.show();
482
+ decorateSelectScroll(pop.el);
483
+ pop.reposition();
484
+ if (opts.focusList) pop.el.querySelector<HTMLElement>(`[data-slot='${selectDef.slot('viewport')}']`)?.focus({ preventScroll: true });
485
+ return pop;
486
+ }
487
+
488
+ export class Select {
489
+ readonly el: HTMLElement;
490
+ private readonly trigger: HTMLButtonElement;
491
+ private readonly labelEl: HTMLElement;
492
+ private readonly ctrl: SelectController;
493
+ private readonly listOpts: SelectListPopoverOpts;
494
+ private readonly placeholder: string | undefined;
495
+ private readonly native: HTMLSelectElement | null;
496
+ private readonly release: () => void;
497
+ private list: Popover | null = null;
498
+
499
+ constructor(opts: SelectOptions) {
500
+ const doc = opts.list?.host?.ownerDocument ?? document;
501
+ injectStyles(doc);
502
+ this.ctrl = selectController(opts);
503
+ const placed = Object.fromEntries(
504
+ (['side', 'align', 'sideOffset', 'alignOffset', 'avoidCollisions', 'collisionPadding', 'collisionBoundary'] as const).filter((k) => opts[k] !== undefined).map((k) => [k, opts[k]]),
505
+ ) as PlacementProps;
506
+ this.listOpts = { ...opts.list, ...placed, theme: opts.theme ?? opts.list?.theme, size: this.ctrl.size };
507
+
508
+ this.placeholder = opts.placeholder;
509
+ const label = h('span', { className: 'vela-select-label', slot: selectDef.slot('value') });
510
+ const btn = h(
511
+ 'button',
512
+ {
513
+ className: 'vela-select-trigger',
514
+ slot: selectDef.slot('trigger'),
515
+ attrs: { type: 'button', id: opts.id, 'aria-haspopup': 'listbox', 'aria-expanded': 'false', 'aria-required': opts.required ? 'true' : undefined },
516
+ },
517
+ label,
518
+ h('span', { className: 'vela-select-chevron', slot: selectDef.slot('icon') }, iconEl('chevron-down', doc)),
519
+ );
520
+ btn.disabled = this.ctrl.disabled;
521
+ // Compact toolbar selects hug the widest option. md uses a fixed 100px
522
+ // column and ellipsizes the trigger; the open list still shows full labels.
523
+ const sizer =
524
+ this.ctrl.size === 'sm'
525
+ ? h(
526
+ 'div',
527
+ { className: 'vela-select-sizer', slot: selectDef.slot('sizer'), attrs: { 'aria-hidden': 'true' } },
528
+ this.ctrl.options.map((o) => h('span', { text: o.label })),
529
+ )
530
+ : null;
531
+ this.native =
532
+ opts.name !== undefined
533
+ ? h(
534
+ 'select',
535
+ { slot: selectDef.slot('native'), attrs: { name: opts.name, 'aria-hidden': 'true', tabindex: -1 } },
536
+ opts.placeholder !== undefined ? h('option', { attrs: { value: '' } }) : null,
537
+ this.ctrl.options.map((o) => h('option', { attrs: { value: o.value }, text: o.label })),
538
+ )
539
+ : null;
540
+ if (this.native) {
541
+ this.native.required = opts.required === true;
542
+ this.native.disabled = this.ctrl.disabled;
543
+ }
544
+ this.el = h('div', { className: 'vela-select', slot: selectDef.slot('root'), attrs: selectVariants({ size: this.ctrl.size }), data: { fill: this.ctrl.fill } }, btn, sizer, this.native);
545
+
546
+ // Suppress the default mousedown focus: when this press outside-dismisses an open
547
+ // popover, Chrome's focus action can scroll the dialog body under the pointer.
548
+ btn.addEventListener('pointerdown', (e) => {
549
+ e.preventDefault();
550
+ btn.focus({ preventScroll: true });
551
+ });
552
+ btn.addEventListener('click', (e) => {
553
+ e.stopPropagation();
554
+ this.toggle();
555
+ });
556
+ btn.addEventListener('keydown', (e) => {
557
+ if ((e.key === 'ArrowDown' || e.key === 'ArrowUp') && !this.list) {
558
+ e.preventDefault();
559
+ this.toggle();
560
+ }
561
+ });
562
+
563
+ this.trigger = btn;
564
+ this.labelEl = label;
565
+ this.paint();
566
+ this.release = ownTeardown(this.el, () => {
567
+ this.list?.hide();
568
+ this.list = null;
569
+ });
570
+ }
571
+
572
+ get value(): string {
573
+ return this.ctrl.value;
574
+ }
575
+
576
+ setValue(v: string): void {
577
+ this.ctrl.setValue(v);
578
+ this.paint();
579
+ }
580
+
581
+ /** The trigger shows the picked option's label, or the placeholder while none is picked. */
582
+ private paint(): void {
583
+ const v = this.ctrl.value;
584
+ const empty = this.placeholder !== undefined && !this.ctrl.options.some((o) => o.value === v);
585
+ this.labelEl.textContent = empty ? (this.placeholder ?? '') : this.ctrl.labelOf(v);
586
+ this.labelEl.toggleAttribute('data-placeholder', empty);
587
+ if (this.native) this.native.value = empty ? '' : v;
588
+ }
589
+
590
+ toggle(): void {
591
+ this.list = toggleSelectList(
592
+ this.trigger,
593
+ this.ctrl.options,
594
+ this.ctrl.value,
595
+ (value) => {
596
+ this.ctrl.pick(value);
597
+ this.paint();
598
+ this.list = null;
599
+ },
600
+ {
601
+ ...this.listOpts,
602
+ focusList: true,
603
+ onClose: () => {
604
+ this.list = null;
605
+ this.trigger.setAttribute('aria-expanded', 'false');
606
+ this.listOpts.onClose?.();
607
+ },
608
+ },
609
+ );
610
+ this.trigger.setAttribute('aria-expanded', String(this.list !== null));
611
+ }
612
+
613
+ destroy(): void {
614
+ this.release();
615
+ }
616
+ }
617
+
618
+ export function createSelect(props: SelectProps): Select {
619
+ return new Select(props);
620
+ }