@luxalgo/vela-ui 0.1.0 → 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 (122) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/README.md +5 -2
  3. package/dist/badge.js +2 -2
  4. package/dist/bar-chart.d.ts +1 -1
  5. package/dist/bar-chart.js +2 -2
  6. package/dist/button.d.ts +18 -4
  7. package/dist/button.js +4 -3
  8. package/dist/calendar.d.ts +3 -1
  9. package/dist/calendar.js +1 -1
  10. package/dist/callout-bubble.d.ts +7 -2
  11. package/dist/callout-bubble.js +12 -8
  12. package/dist/checkbox.js +4 -4
  13. package/dist/{chunk-SAPURP46.js → chunk-7VMN7NKJ.js} +3 -3
  14. package/dist/{chunk-OBLIX3VN.js → chunk-B5ZSRUDQ.js} +3 -3
  15. package/dist/{chunk-6NXY62JS.js → chunk-C3ICYMI3.js} +2 -2
  16. package/dist/chunk-CC3DDNFC.js +117 -0
  17. package/dist/{chunk-FCO3YZLT.js → chunk-E2FE6V2N.js} +2 -2
  18. package/dist/{chunk-V6TTTMTE.js → chunk-GVRX3UAV.js} +4 -1
  19. package/dist/{chunk-2Q4JRINP.js → chunk-MJ4RUGX7.js} +4 -4
  20. package/dist/{chunk-X4YPSIW6.js → chunk-U3EH42YY.js} +2 -2
  21. package/dist/{chunk-AJ2IYSOI.js → chunk-V2Q4MRMS.js} +23 -3
  22. package/dist/{chunk-XJAPCCOJ.js → chunk-WBGSYCV2.js} +3 -3
  23. package/dist/{chunk-5QHXOAZA.js → chunk-WGULXRWD.js} +4 -4
  24. package/dist/{chunk-ZB3BZHSN.js → chunk-WXH3EFV5.js} +3 -3
  25. package/dist/chunk-XBEL4K33.js +142 -0
  26. package/dist/{chunk-CH3DV6FD.js → chunk-Z5PINFQO.js} +4 -4
  27. package/dist/collapsible.d.ts +49 -0
  28. package/dist/collapsible.js +106 -0
  29. package/dist/color-picker.js +6 -6
  30. package/dist/context-menu.js +5 -5
  31. package/dist/css.d.ts +3 -1
  32. package/dist/css.js +1 -1
  33. package/dist/data-table.d.ts +39 -2
  34. package/dist/data-table.js +2 -2
  35. package/dist/date-picker.d.ts +1 -1
  36. package/dist/date-picker.js +3 -3
  37. package/dist/dialog.d.ts +1 -1
  38. package/dist/dialog.js +5 -5
  39. package/dist/donut.d.ts +1 -1
  40. package/dist/donut.js +2 -2
  41. package/dist/drawer.d.ts +1 -1
  42. package/dist/drawer.js +3 -3
  43. package/dist/dropdown-menu.d.ts +1 -1
  44. package/dist/dropdown-menu.js +4 -4
  45. package/dist/empty.d.ts +1 -1
  46. package/dist/empty.js +2 -2
  47. package/dist/field.js +12 -12
  48. package/dist/glyph-select.js +5 -5
  49. package/dist/h-Bl37qUis.d.ts +24 -0
  50. package/dist/hover-card.d.ts +1 -1
  51. package/dist/hover-card.js +3 -3
  52. package/dist/index.d.ts +7 -1
  53. package/dist/index.js +3 -3
  54. package/dist/input-group.d.ts +1 -1
  55. package/dist/input-group.js +4 -3
  56. package/dist/input.js +3 -3
  57. package/dist/item.d.ts +72 -0
  58. package/dist/item.js +131 -0
  59. package/dist/kbd.d.ts +1 -1
  60. package/dist/kbd.js +3 -3
  61. package/dist/line-chart.d.ts +1 -1
  62. package/dist/line-chart.js +2 -2
  63. package/dist/manifest.json +665 -11
  64. package/dist/month-grid.d.ts +45 -0
  65. package/dist/month-grid.js +157 -0
  66. package/dist/number-input.d.ts +1 -1
  67. package/dist/number-input.js +4 -4
  68. package/dist/popover.js +4 -4
  69. package/dist/scatter-chart.d.ts +1 -1
  70. package/dist/scatter-chart.js +2 -2
  71. package/dist/select.js +6 -6
  72. package/dist/slider.d.ts +46 -0
  73. package/dist/slider.js +111 -0
  74. package/dist/sort-button.d.ts +41 -0
  75. package/dist/sort-button.js +88 -0
  76. package/dist/sparkline.d.ts +1 -1
  77. package/dist/sparkline.js +2 -2
  78. package/dist/stat.d.ts +1 -1
  79. package/dist/stat.js +2 -2
  80. package/dist/switch.d.ts +1 -1
  81. package/dist/switch.js +3 -3
  82. package/dist/tabs.d.ts +3 -1
  83. package/dist/tabs.js +12 -7
  84. package/dist/text-area.d.ts +1 -1
  85. package/dist/text-area.js +3 -3
  86. package/dist/theme.d.ts +17 -6
  87. package/dist/theme.js +2 -2
  88. package/dist/theme.schema.json +250 -1
  89. package/dist/toggle-group.d.ts +1 -1
  90. package/dist/toggle-group.js +3 -3
  91. package/dist/tooltip.js +3 -3
  92. package/docs/theming.md +6 -0
  93. package/docs/writing-a-component.md +4 -1
  94. package/llms.txt +8 -3
  95. package/package.json +1 -1
  96. package/registry/button.ts +97 -21
  97. package/registry/callout-bubble.ts +14 -3
  98. package/registry/collapsible.ts +271 -0
  99. package/registry/dropdown-menu.ts +3 -3
  100. package/registry/item.ts +376 -0
  101. package/registry/month-grid.ts +328 -0
  102. package/registry/slider.ts +259 -0
  103. package/registry/sort-button.ts +189 -0
  104. package/registry/tabs.ts +38 -4
  105. package/skills/using-vela-ui-components/SKILL.md +12 -9
  106. package/src/components/button.ts +97 -21
  107. package/src/components/callout-bubble.ts +14 -3
  108. package/src/components/collapsible.ts +271 -0
  109. package/src/components/dropdown-menu.ts +3 -3
  110. package/src/components/item.ts +376 -0
  111. package/src/components/month-grid.ts +328 -0
  112. package/src/components/slider.ts +259 -0
  113. package/src/components/sort-button.ts +189 -0
  114. package/src/components/tabs.ts +38 -4
  115. package/src/lib/calendar.ts +5 -0
  116. package/src/lib/component-index.ts +22 -2
  117. package/src/lib/css.ts +6 -2
  118. package/src/lib/scope.ts +135 -0
  119. package/src/lib/theme.ts +15 -5
  120. package/dist/chunk-EZQXTO6K.js +0 -89
  121. package/dist/chunk-IDA2BT7D.js +0 -29
  122. package/dist/data-table-DtU3FX9j.d.ts +0 -61
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luxalgo/vela-ui",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "The component kit of Vela: one file per component, Zag state machines for behavior, CSS in cascade layers over design tokens.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "LuxAlgo",
@@ -1,20 +1,24 @@
1
- // Button: a <button> with optional icons before and after its text. `default` is filled with
2
- // the selection color (OK, Apply), `outline` bordered (the dialogs' Cancel), `secondary` a
3
- // sunken fill, `ghost` bare until hovered (toolbar and header icons), `destructive` tinted
4
- // with the danger color, `link` text that underlines on hover, `up` and `down` filled with the
5
- // market's colors (buy and sell). Heights: `xs` 26px, `sm` 30px
6
- // (panels), `default` 34px (dialog footers), `lg` 40px (touch); the `icon*` sizes are the
7
- // same heights, square, for an icon alone, which `label` names.
1
+ // Button: a <button> with optional icons and key caps before and after its text (`↵ Open`,
2
+ // `Esc Close` in a picker's footer). `default` is filled with the selection color (OK, Apply),
3
+ // `outline` bordered (the dialogs' Cancel), `secondary` a sunken fill, `ghost` bare until
4
+ // hovered (toolbar and header icons), `destructive` tinted with the danger color, `link` text
5
+ // that underlines on hover, `up` and `down` filled with the market's colors (buy and sell),
6
+ // `favorite` a bare star whose pressed state takes the favorites color. Heights: `xs` 26px,
7
+ // `sm` 30px (panels), `default` 34px (dialog footers), `lg` 40px (touch); the `icon*` sizes
8
+ // are the same heights, square, for an icon alone, which `label` names. A toggle button
9
+ // (`pressed`, `defaultPressed` or `onPressedChange`) says its state through `aria-pressed`;
10
+ // uncontrolled it flips on a press, given `pressed` it only asks, until `setPressed` moves it.
8
11
  import { iconEl } from '@luxalgo/vela-ui/icons';
9
12
  import { css, defineStyles } from '@luxalgo/vela-ui';
10
13
  import { defineComponent } from '@luxalgo/vela-ui';
11
14
  import { h } from '@luxalgo/vela-ui';
12
15
  import { t } from '@luxalgo/vela-ui';
13
16
  import { variants, type VariantProps } from '@luxalgo/vela-ui';
17
+ import { createKbd } from '@luxalgo/vela-ui/kbd';
14
18
 
15
19
  export const buttonDef = defineComponent({
16
20
  name: 'button',
17
- parts: ['root', 'icon'],
21
+ parts: ['root', 'icon', 'keys'],
18
22
  settings: {
19
23
  radius: t.radius.md,
20
24
  height: '34px',
@@ -28,7 +32,7 @@ export const buttonDef = defineComponent({
28
32
  });
29
33
 
30
34
  export const buttonVariants = variants({
31
- variant: ['default', 'outline', 'secondary', 'ghost', 'destructive', 'link', 'up', 'down'],
35
+ variant: ['default', 'outline', 'secondary', 'ghost', 'destructive', 'link', 'up', 'down', 'favorite'],
32
36
  size: ['default', 'xs', 'sm', 'lg', 'icon', 'icon-xs', 'icon-sm', 'icon-lg'],
33
37
  });
34
38
 
@@ -38,14 +42,27 @@ export type ButtonSize = (typeof buttonVariants.spec.size)[number];
38
42
  export interface ButtonProps extends VariantProps<typeof buttonVariants> {
39
43
  /** The visible text (the `icon*` sizes show none; `label` names them). */
40
44
  text?: string;
41
- /** Icon id from the kit's registry, before the text (the icon of an `icon*` size). */
45
+ /** Icon id from the kit's registry, before the text (the icon of an `icon*` size).
46
+ * `favorite` defaults to `star`. */
42
47
  icon?: string;
48
+ /** The icon while pressed (`star-filled` for `star`). `favorite` defaults to `star-filled`. */
49
+ iconPressed?: string;
43
50
  /** Icon id after the text (a menu trigger's chevron). */
44
51
  iconEnd?: string;
52
+ /** Key caps before the text, one per key (`['↑', '↓']`). */
53
+ keys?: readonly string[];
54
+ /** Key caps after the text. */
55
+ keysEnd?: readonly string[];
45
56
  /** Accessible name; required for the `icon*` sizes, defaults to `text`. */
46
57
  label?: string;
47
- /** A toggle button's state (`aria-pressed`). Omitted: not a toggle. */
58
+ /** A controlled toggle's state (`aria-pressed`): a press only calls `onPressedChange`, and
59
+ * `setPressed` moves it. Omitted with `defaultPressed` and `onPressedChange`: not a toggle. */
48
60
  pressed?: boolean;
61
+ /** An uncontrolled toggle's first state: a press flips it and calls `onPressedChange`. */
62
+ defaultPressed?: boolean;
63
+ /** A press asked for this state (a toggle without `pressed` or `defaultPressed` starts
64
+ * unpressed). */
65
+ onPressedChange?: (pressed: boolean) => void;
49
66
  disabled?: boolean;
50
67
  onClick?: (e: MouseEvent) => void;
51
68
  /** Extra class names (layout hooks). */
@@ -55,6 +72,7 @@ export interface ButtonProps extends VariantProps<typeof buttonVariants> {
55
72
  export interface ButtonHandle {
56
73
  readonly el: HTMLButtonElement;
57
74
  readonly pressed: boolean | undefined;
75
+ /** Show a toggle's state, without calling `onPressedChange`. */
58
76
  setPressed(pressed: boolean): void;
59
77
  setDisabled(disabled: boolean): void;
60
78
  /** New text (or, for an `icon*` size, a new accessible name). */
@@ -107,6 +125,13 @@ export const BUTTON_CSS = css`
107
125
  &[data-size='icon-xs'] > [data-icon] {
108
126
  font-size: 12px;
109
127
  }
128
+ & > [data-keys] {
129
+ flex: none;
130
+ gap: 2px;
131
+ }
132
+ & > [data-keys]:where(:not([hidden])) {
133
+ display: inline-flex;
134
+ }
110
135
  &[data-size='sm'],
111
136
  &[data-size='icon-sm'] {
112
137
  height: ${buttonDef.vars['height-sm']};
@@ -225,43 +250,85 @@ export const BUTTON_CSS = css`
225
250
  background: ${t.active};
226
251
  color: ${t.fg.bright};
227
252
  }
253
+ &[data-variant='favorite'] {
254
+ border-color: transparent;
255
+ color: ${t.fg.muted};
256
+ }
257
+ &[data-variant='favorite']:not(:disabled):hover {
258
+ border-color: transparent;
259
+ }
260
+ &[data-variant='favorite'][data-pressed] {
261
+ background: transparent;
262
+ color: ${t.highlight};
263
+ }
264
+ &[data-variant='favorite'][data-pressed]:where(:not(:disabled)):hover {
265
+ background: ${t.hover};
266
+ color: ${t.highlight};
267
+ }
228
268
  }
229
269
  }
230
270
  `;
231
271
 
232
272
  const injectStyles = defineStyles(BUTTON_STYLE_ID, BUTTON_CSS);
233
273
 
274
+ const iconPart = (id: string, side: 'inline-start' | 'inline-end'): HTMLElement => {
275
+ const el = iconEl(id, document);
276
+ el.dataset.slot = buttonDef.slot('icon');
277
+ el.dataset.icon = side;
278
+ return el;
279
+ };
280
+
281
+ const keysPart = (keys: readonly string[] | undefined, side: 'inline-start' | 'inline-end'): HTMLElement | null =>
282
+ keys?.length ? h('span', { slot: buttonDef.slot('keys'), data: { keys: side } }, ...keys.map((key) => createKbd({ text: key }).el)) : null;
283
+
234
284
  class ButtonImpl implements ButtonHandle {
235
285
  readonly el: HTMLButtonElement;
236
286
  private readonly iconOnly: boolean;
237
287
  private readonly textNode: Text | null;
288
+ private readonly toggle: boolean;
289
+ private readonly controlled: boolean;
290
+ private readonly icon: string | undefined;
291
+ private readonly iconPressed: string | undefined;
292
+ private iconStart: HTMLElement | null;
293
+ private shownIcon: string | undefined;
238
294
  private label: string | undefined;
239
295
  private pressedState: boolean | undefined;
240
296
 
241
297
  constructor(props: ButtonProps) {
242
298
  injectStyles(document);
243
299
  const { variant, size } = buttonVariants.resolve(props);
300
+ const favorite = variant === 'favorite';
244
301
  this.iconOnly = size.startsWith('icon');
245
302
  this.label = props.label ?? props.text;
246
- this.pressedState = props.pressed;
247
- const icon = (id: string, side: 'inline-start' | 'inline-end'): HTMLElement => {
248
- const el = iconEl(id, document);
249
- el.dataset.slot = buttonDef.slot('icon');
250
- el.dataset.icon = side;
251
- return el;
252
- };
303
+ this.controlled = props.pressed !== undefined;
304
+ this.toggle = this.controlled || props.defaultPressed !== undefined || props.onPressedChange !== undefined;
305
+ this.pressedState = props.pressed ?? props.defaultPressed ?? (this.toggle ? false : undefined);
306
+ this.icon = props.icon ?? (favorite ? 'star' : undefined);
307
+ this.iconPressed = props.iconPressed ?? (favorite ? 'star-filled' : undefined);
308
+ this.iconStart = this.icon ? iconPart(this.icon, 'inline-start') : null;
309
+ this.shownIcon = this.icon;
253
310
  this.textNode = !this.iconOnly && props.text !== undefined ? document.createTextNode(props.text) : null;
311
+ const onClick = (e: MouseEvent): void => {
312
+ if (this.toggle) {
313
+ const next = !this.pressedState;
314
+ if (!this.controlled) this.setPressed(next);
315
+ props.onPressedChange?.(next);
316
+ }
317
+ props.onClick?.(e);
318
+ };
254
319
  this.el = h(
255
320
  'button',
256
321
  {
257
322
  className: props.className ? `vela-btn ${props.className}` : 'vela-btn',
258
323
  slot: buttonDef.slot('root'),
259
324
  attrs: { type: 'button', ...buttonVariants({ variant, size }) },
260
- on: props.onClick ? { click: props.onClick } : undefined,
325
+ on: this.toggle || props.onClick ? { click: onClick } : undefined,
261
326
  },
262
- props.icon ? icon(props.icon, 'inline-start') : null,
327
+ this.iconStart,
328
+ this.iconOnly ? null : keysPart(props.keys, 'inline-start'),
263
329
  this.textNode,
264
- props.iconEnd && !this.iconOnly ? icon(props.iconEnd, 'inline-end') : null,
330
+ this.iconOnly ? null : keysPart(props.keysEnd, 'inline-end'),
331
+ props.iconEnd && !this.iconOnly ? iconPart(props.iconEnd, 'inline-end') : null,
265
332
  );
266
333
  this.el.disabled = props.disabled ?? false;
267
334
  this.paint();
@@ -290,6 +357,15 @@ class ButtonImpl implements ButtonHandle {
290
357
 
291
358
  private paint(): void {
292
359
  const el = this.el;
360
+ if (this.iconStart && this.iconPressed) {
361
+ const icon = this.pressedState ? this.iconPressed : this.icon!;
362
+ if (icon !== this.shownIcon) {
363
+ const next = iconPart(icon, 'inline-start');
364
+ this.iconStart.replaceWith(next);
365
+ this.iconStart = next;
366
+ this.shownIcon = icon;
367
+ }
368
+ }
293
369
  el.toggleAttribute('data-pressed', this.pressedState === true);
294
370
  if (this.pressedState === undefined) el.removeAttribute('aria-pressed');
295
371
  else el.setAttribute('aria-pressed', String(this.pressedState));
@@ -7,6 +7,7 @@ import { iconAt } from '@luxalgo/vela-ui/icons';
7
7
  import type { ChartTheme } from '@luxalgo/vela-ui/tokens';
8
8
  import { css, defineStyles } from '@luxalgo/vela-ui';
9
9
  import { defineComponent } from '@luxalgo/vela-ui';
10
+ import { addSlot } from '@luxalgo/vela-ui';
10
11
  import { t } from '@luxalgo/vela-ui';
11
12
  import { Popover, type PlacementProps, type PopoverBoundary } from '@luxalgo/vela-ui/popover';
12
13
 
@@ -185,6 +186,17 @@ export const CALLOUT_CSS = css`
185
186
 
186
187
  const injectStyles = defineStyles(CALLOUT_STYLE_ID, CALLOUT_CSS);
187
188
 
189
+ /** A part of the deployed panel, as {@link calloutPart} gives it. */
190
+ export type CalloutPanelPart = Exclude<(typeof calloutBubbleDef.parts)[number], 'root'>;
191
+
192
+ /** Make `el` a part of a deployed panel, with the panel's look: for a panel built without a
193
+ * bubble, such as a chart's timeline-mark popup. Returns `el`. */
194
+ export function calloutPart<E extends HTMLElement>(el: E, part: CalloutPanelPart): E {
195
+ injectStyles(el.ownerDocument);
196
+ addSlot(el, calloutBubbleDef.slot(part));
197
+ return el;
198
+ }
199
+
188
200
  export class CalloutBubble {
189
201
  readonly el: HTMLElement;
190
202
  private spec: CalloutBubbleSpec;
@@ -294,11 +306,10 @@ export class CalloutBubble {
294
306
 
295
307
  private buildPanel(body: HTMLElement, panel: CalloutPanel): void {
296
308
  const doc = body.ownerDocument;
297
- const part = <K extends keyof HTMLElementTagNameMap>(tag: K, className: string, name: (typeof calloutBubbleDef.parts)[number]): HTMLElementTagNameMap[K] => {
309
+ const part = <K extends keyof HTMLElementTagNameMap>(tag: K, className: string, name: CalloutPanelPart): HTMLElementTagNameMap[K] => {
298
310
  const el = doc.createElement(tag);
299
311
  el.className = className;
300
- el.dataset.slot = calloutBubbleDef.slot(name);
301
- return el;
312
+ return calloutPart(el, name);
302
313
  };
303
314
  const root = part('div', 'vela-callout-panel', 'panel');
304
315
  if (panel.title) {
@@ -0,0 +1,271 @@
1
+ // Collapsible: a section that shows or hides its content. Its own trigger is a header (a title,
2
+ // an optional count, a chevron) that toggles it on a click, Enter or Space; or the host hands
3
+ // it a trigger of its own, such as a row's chevron button, and places the content where it
4
+ // likes. `default` is a section header with the chevron at its end (a panel's drawers),
5
+ // `label` a small uppercase group label with the chevron before it (a list's groups). The
6
+ // content is `hidden` while closed.
7
+ import { css, defineStyles } from '@luxalgo/vela-ui';
8
+ import { defineComponent } from '@luxalgo/vela-ui';
9
+ import { h } from '@luxalgo/vela-ui';
10
+ import { iconEl } from '@luxalgo/vela-ui/icons';
11
+ import { t } from '@luxalgo/vela-ui';
12
+ import { variants, type VariantProps } from '@luxalgo/vela-ui';
13
+ import { nextUid } from '@luxalgo/vela-ui/zag';
14
+
15
+ export const collapsibleDef = defineComponent({
16
+ name: 'collapsible',
17
+ parts: ['root', 'trigger', 'icon', 'title', 'count', 'chevron', 'content'],
18
+ settings: { 'trigger-height': '36px', radius: t.radius.md },
19
+ });
20
+
21
+ export const collapsibleVariants = variants({ variant: ['default', 'label'] });
22
+
23
+ export type CollapsibleVariant = (typeof collapsibleVariants.spec.variant)[number];
24
+
25
+ export interface CollapsibleProps extends VariantProps<typeof collapsibleVariants> {
26
+ /** The header's text. Without `trigger`, the collapsible draws its header with it. */
27
+ title?: string;
28
+ /** After the title, muted: a count, a total. Null shows none. */
29
+ count?: string | number | null;
30
+ /** Icon id from the kit's registry, before the title. */
31
+ icon?: string;
32
+ /** A host element that toggles the content instead of the header (a row's chevron
33
+ * button): it gets `aria-expanded`, `aria-controls` and `data-state`, and a click on it
34
+ * toggles. The root then holds only the content. */
35
+ trigger?: HTMLElement;
36
+ /** The content, or a function that fills the content element. */
37
+ content?: Node | ((content: HTMLElement) => void);
38
+ /** Open when created (default closed). */
39
+ defaultOpen?: boolean;
40
+ /** Opened or closed by the user. */
41
+ onOpenChange?: (open: boolean) => void;
42
+ disabled?: boolean;
43
+ /** Extra class names (layout hooks). */
44
+ className?: string;
45
+ }
46
+
47
+ export interface CollapsibleHandle {
48
+ readonly el: HTMLElement;
49
+ /** What toggles it: its header, or the host's `trigger`. */
50
+ readonly trigger: HTMLElement;
51
+ /** The element that holds the content. */
52
+ readonly content: HTMLElement;
53
+ readonly open: boolean;
54
+ /** Open or close it without calling `onOpenChange`. */
55
+ setOpen(open: boolean): void;
56
+ /** A new header text (its own header only). */
57
+ setTitle(title: string): void;
58
+ /** A new count (its own header only); null hides it. */
59
+ setCount(count: string | number | null): void;
60
+ setDisabled(disabled: boolean): void;
61
+ destroy(): void;
62
+ }
63
+
64
+ const injectStyles = defineStyles(
65
+ 'vela-ui-collapsible',
66
+ css`
67
+ @layer vela.ui {
68
+ [data-slot='collapsible'] {
69
+ min-width: 0;
70
+ }
71
+ [data-slot='collapsible-trigger']:where(:not([hidden])) {
72
+ all: unset;
73
+ box-sizing: border-box;
74
+ display: flex;
75
+ align-items: center;
76
+ gap: 8px;
77
+ width: 100%;
78
+ cursor: pointer;
79
+ user-select: none;
80
+ -webkit-tap-highlight-color: transparent;
81
+
82
+ &:focus-visible {
83
+ outline: 2px solid ${t.focus};
84
+ outline-offset: -2px;
85
+ }
86
+ &[data-disabled] {
87
+ cursor: default;
88
+ opacity: 0.5;
89
+ }
90
+ &[data-variant='default'] {
91
+ min-height: ${collapsibleDef.vars['trigger-height']};
92
+ padding: 0 12px;
93
+ border-radius: ${collapsibleDef.vars.radius};
94
+ color: ${t.fg.bright};
95
+ font-size: 13px;
96
+ font-weight: 600;
97
+ transition: background ${t.dur.fast} ease;
98
+ }
99
+ &[data-variant='default']:not([data-disabled]):hover {
100
+ background: ${t.hover};
101
+ }
102
+ &[data-variant='label'] {
103
+ gap: 6px;
104
+ padding: 10px 4px 4px;
105
+ color: ${t.fg.muted};
106
+ font-size: 10px;
107
+ font-weight: 700;
108
+ letter-spacing: 0.08em;
109
+ text-transform: uppercase;
110
+ transition: color ${t.dur.fast} ease;
111
+ }
112
+ &[data-variant='label']:not([data-disabled]):hover {
113
+ color: ${t.fg};
114
+ }
115
+ }
116
+ [data-slot='collapsible-title'] {
117
+ min-width: 0;
118
+ overflow: hidden;
119
+ text-overflow: ellipsis;
120
+ white-space: nowrap;
121
+ }
122
+ [data-slot='collapsible-count'] {
123
+ flex: none;
124
+ color: ${t.fg.muted};
125
+ font-size: 12px;
126
+ font-weight: 400;
127
+ font-variant-numeric: tabular-nums;
128
+
129
+ &:is([data-variant='label'] > *) {
130
+ color: ${t.fg.faint};
131
+ font-size: inherit;
132
+ font-weight: 600;
133
+ letter-spacing: 0;
134
+ }
135
+ }
136
+ [data-slot~='collapsible-icon'],
137
+ [data-slot~='collapsible-chevron'] {
138
+ flex: none;
139
+ width: 1em;
140
+ height: 1em;
141
+ font-size: 16px;
142
+ line-height: 0;
143
+
144
+ & > svg {
145
+ width: 100%;
146
+ height: 100%;
147
+ }
148
+ }
149
+ [data-slot='collapsible-chevron'] {
150
+ font-size: 14px;
151
+ color: ${t.fg.muted};
152
+ transition: transform ${t.dur.med} ease;
153
+
154
+ &:is([data-variant='default'] > *) {
155
+ margin-inline-start: auto;
156
+ }
157
+ &:is([data-variant='label'] > *) {
158
+ font-size: 12px;
159
+ color: inherit;
160
+ }
161
+ &:is([data-variant='default'][data-state='open'] > *) {
162
+ transform: rotate(180deg);
163
+ }
164
+ &:is([data-variant='label'][data-state='closed'] > *) {
165
+ transform: rotate(-90deg);
166
+ }
167
+ &:is([data-variant='label'][data-state='closed'] > *):dir(rtl) {
168
+ transform: rotate(90deg);
169
+ }
170
+ }
171
+ }
172
+ `,
173
+ );
174
+
175
+ class CollapsibleImpl implements CollapsibleHandle {
176
+ readonly el: HTMLElement;
177
+ readonly trigger: HTMLElement;
178
+ readonly content: HTMLElement;
179
+ private readonly own: boolean;
180
+ private readonly titleEl: HTMLElement | null;
181
+ private countEl: HTMLElement | null = null;
182
+ private isOpen: boolean;
183
+ private disabled: boolean;
184
+ private readonly onClick = (): void => {
185
+ if (this.disabled) return;
186
+ this.paint(!this.isOpen);
187
+ this.props.onOpenChange?.(this.isOpen);
188
+ };
189
+
190
+ constructor(private readonly props: CollapsibleProps) {
191
+ injectStyles(document);
192
+ const variant = collapsibleVariants.resolve(props).variant;
193
+ this.isOpen = props.defaultOpen ?? false;
194
+ this.disabled = props.disabled ?? false;
195
+ const id = nextUid('vela-collapsible');
196
+ this.content = h('div', { slot: collapsibleDef.slot('content'), attrs: { id } });
197
+ if (props.content instanceof Node) this.content.appendChild(props.content);
198
+ else props.content?.(this.content);
199
+ this.own = !props.trigger;
200
+ if (props.trigger) {
201
+ this.trigger = props.trigger;
202
+ this.titleEl = null;
203
+ } else {
204
+ let icon: HTMLElement | null = null;
205
+ if (props.icon) {
206
+ icon = iconEl(props.icon, document);
207
+ icon.dataset.slot = collapsibleDef.slot('icon');
208
+ }
209
+ const chevron = iconEl('chevron-down', document);
210
+ chevron.dataset.slot = collapsibleDef.slot('chevron');
211
+ this.titleEl = h('span', { slot: collapsibleDef.slot('title'), text: props.title ?? '' });
212
+ this.trigger = h(
213
+ 'button',
214
+ { slot: collapsibleDef.slot('trigger'), data: { variant }, attrs: { type: 'button' } },
215
+ variant === 'label' ? chevron : null,
216
+ icon,
217
+ this.titleEl,
218
+ variant === 'label' ? null : chevron,
219
+ );
220
+ this.setCount(props.count ?? null);
221
+ }
222
+ this.trigger.setAttribute('aria-controls', id);
223
+ this.trigger.addEventListener('click', this.onClick);
224
+ this.el = h('div', { className: props.className, slot: collapsibleDef.slot('root'), data: { variant } }, this.own ? this.trigger : null, this.content);
225
+ this.paint(this.isOpen);
226
+ this.setDisabled(this.disabled);
227
+ }
228
+
229
+ get open(): boolean {
230
+ return this.isOpen;
231
+ }
232
+
233
+ setOpen(open: boolean): void {
234
+ this.paint(open);
235
+ }
236
+
237
+ setTitle(title: string): void {
238
+ if (this.titleEl) this.titleEl.textContent = title;
239
+ }
240
+
241
+ setCount(count: string | number | null): void {
242
+ if (!this.own) return;
243
+ this.countEl?.remove();
244
+ this.countEl = count === null || count === '' ? null : h('span', { slot: collapsibleDef.slot('count'), text: String(count) });
245
+ if (this.countEl) this.titleEl!.after(this.countEl);
246
+ }
247
+
248
+ setDisabled(disabled: boolean): void {
249
+ this.disabled = disabled;
250
+ this.trigger.toggleAttribute('data-disabled', disabled);
251
+ if (this.trigger instanceof HTMLButtonElement) this.trigger.disabled = disabled;
252
+ else if (disabled) this.trigger.setAttribute('aria-disabled', 'true');
253
+ else this.trigger.removeAttribute('aria-disabled');
254
+ }
255
+
256
+ destroy(): void {
257
+ this.trigger.removeEventListener('click', this.onClick);
258
+ }
259
+
260
+ private paint(open: boolean): void {
261
+ this.isOpen = open;
262
+ const state = open ? 'open' : 'closed';
263
+ this.trigger.setAttribute('aria-expanded', String(open));
264
+ for (const el of [this.trigger, this.content, this.el]) el?.setAttribute('data-state', state);
265
+ this.content.hidden = !open;
266
+ }
267
+ }
268
+
269
+ export function createCollapsible(props: CollapsibleProps = {}): CollapsibleHandle {
270
+ return new CollapsibleImpl(props);
271
+ }
@@ -310,12 +310,12 @@ const injectStyles = defineStyles(
310
310
  background ${t.dur.med} ease;
311
311
  }
312
312
  &[data-on] {
313
- background: var(${t.accent.bright.name}, ${t.accent});
314
- border-color: var(${t.accent.bright.name}, ${t.accent});
313
+ background: ${t.selected.bg};
314
+ border-color: ${t.selected.bg};
315
315
  }
316
316
  &[data-on]::after {
317
317
  transform: translateX(16px);
318
- background: ${t.bg};
318
+ background: ${t.selected.fg};
319
319
  }
320
320
  }
321
321
  [data-slot~='dropdown-menu-separator'] {