@luxalgo/vela-ui 0.1.0 → 0.3.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 (124) hide show
  1. package/CHANGELOG.md +89 -0
  2. package/README.md +5 -2
  3. package/dist/badge.js +1 -1
  4. package/dist/bar-chart.js +1 -1
  5. package/dist/button.d.ts +18 -4
  6. package/dist/button.js +4 -3
  7. package/dist/calendar.d.ts +3 -1
  8. package/dist/calendar.js +1 -1
  9. package/dist/callout-bubble.d.ts +6 -1
  10. package/dist/callout-bubble.js +12 -8
  11. package/dist/card.d.ts +52 -0
  12. package/dist/card.js +179 -0
  13. package/dist/checkbox.js +5 -5
  14. package/dist/{chunk-X4YPSIW6.js → chunk-5BJV5FY5.js} +1 -1
  15. package/dist/{chunk-FCO3YZLT.js → chunk-ALAHGSLC.js} +1 -1
  16. package/dist/{chunk-5QHXOAZA.js → chunk-B2EZB5ZG.js} +4 -4
  17. package/dist/{chunk-G7IQLY3A.js → chunk-C3PXY2SW.js} +5 -0
  18. package/dist/chunk-DXDCKZ2M.js +117 -0
  19. package/dist/{chunk-6NXY62JS.js → chunk-FYVQO5TN.js} +1 -1
  20. package/dist/{chunk-V6TTTMTE.js → chunk-GVRX3UAV.js} +4 -1
  21. package/dist/{chunk-XJAPCCOJ.js → chunk-IOOYDSSK.js} +4 -4
  22. package/dist/{chunk-OBLIX3VN.js → chunk-KKS6NEGI.js} +2 -2
  23. package/dist/{chunk-SAPURP46.js → chunk-OJ2SEMN6.js} +3 -3
  24. package/dist/{chunk-2Q4JRINP.js → chunk-OQXFQMZM.js} +3 -3
  25. package/dist/{chunk-AJ2IYSOI.js → chunk-TBXUF5YX.js} +35 -3
  26. package/dist/{chunk-ZB3BZHSN.js → chunk-UEO6W37Z.js} +4 -4
  27. package/dist/{chunk-CH3DV6FD.js → chunk-WWHNUKSZ.js} +5 -5
  28. package/dist/chunk-XBEL4K33.js +142 -0
  29. package/dist/collapsible.d.ts +49 -0
  30. package/dist/collapsible.js +106 -0
  31. package/dist/color-picker.js +5 -5
  32. package/dist/context-menu.js +5 -5
  33. package/dist/css.d.ts +3 -1
  34. package/dist/css.js +1 -1
  35. package/dist/data-table.d.ts +39 -2
  36. package/dist/data-table.js +1 -1
  37. package/dist/date-picker.js +3 -3
  38. package/dist/dialog.d.ts +8 -0
  39. package/dist/dialog.js +15 -5
  40. package/dist/donut.js +1 -1
  41. package/dist/drawer.js +2 -2
  42. package/dist/dropdown-menu.js +4 -4
  43. package/dist/empty.js +2 -2
  44. package/dist/field.js +13 -13
  45. package/dist/glyph-select.js +5 -5
  46. package/dist/h-Bl37qUis.d.ts +24 -0
  47. package/dist/hover-card.d.ts +1 -1
  48. package/dist/hover-card.js +3 -3
  49. package/dist/icons.js +1 -1
  50. package/dist/index.d.ts +10 -2
  51. package/dist/index.js +3 -3
  52. package/dist/input-group.js +4 -3
  53. package/dist/input.js +2 -2
  54. package/dist/item.d.ts +72 -0
  55. package/dist/item.js +131 -0
  56. package/dist/kbd.js +2 -2
  57. package/dist/line-chart.js +1 -1
  58. package/dist/manifest.json +1336 -65
  59. package/dist/month-grid.d.ts +45 -0
  60. package/dist/month-grid.js +157 -0
  61. package/dist/number-input.js +5 -5
  62. package/dist/popover.js +3 -3
  63. package/dist/scatter-chart.js +1 -1
  64. package/dist/select.js +7 -7
  65. package/dist/slider.d.ts +46 -0
  66. package/dist/slider.js +111 -0
  67. package/dist/sort-button.d.ts +41 -0
  68. package/dist/sort-button.js +88 -0
  69. package/dist/sparkline.js +1 -1
  70. package/dist/stat.js +1 -1
  71. package/dist/switch.js +3 -3
  72. package/dist/tabs.d.ts +3 -1
  73. package/dist/tabs.js +13 -8
  74. package/dist/text-area.js +2 -2
  75. package/dist/theme-Ct-q58xz.d.ts +341 -0
  76. package/dist/theme.d.ts +42 -181
  77. package/dist/theme.js +2 -2
  78. package/dist/theme.schema.json +541 -1
  79. package/dist/toast.d.ts +49 -0
  80. package/dist/toast.js +463 -0
  81. package/dist/toggle-group.js +4 -4
  82. package/dist/tooltip.js +2 -2
  83. package/dist/treemap.d.ts +80 -0
  84. package/dist/treemap.js +470 -0
  85. package/docs/theming.md +6 -0
  86. package/docs/writing-a-component.md +4 -1
  87. package/llms.txt +11 -3
  88. package/package.json +1 -1
  89. package/registry/button.ts +105 -21
  90. package/registry/callout-bubble.ts +14 -3
  91. package/registry/card.ts +379 -0
  92. package/registry/collapsible.ts +271 -0
  93. package/registry/dialog.ts +16 -0
  94. package/registry/dropdown-menu.ts +3 -3
  95. package/registry/item.ts +376 -0
  96. package/registry/month-grid.ts +328 -0
  97. package/registry/slider.ts +259 -0
  98. package/registry/sort-button.ts +189 -0
  99. package/registry/tabs.ts +38 -4
  100. package/registry/toast.ts +965 -0
  101. package/registry/treemap.ts +847 -0
  102. package/skills/using-vela-ui-components/SKILL.md +14 -9
  103. package/src/components/button.ts +105 -21
  104. package/src/components/callout-bubble.ts +14 -3
  105. package/src/components/card.ts +379 -0
  106. package/src/components/collapsible.ts +271 -0
  107. package/src/components/dialog.ts +16 -0
  108. package/src/components/dropdown-menu.ts +3 -3
  109. package/src/components/item.ts +376 -0
  110. package/src/components/month-grid.ts +328 -0
  111. package/src/components/slider.ts +259 -0
  112. package/src/components/sort-button.ts +189 -0
  113. package/src/components/tabs.ts +38 -4
  114. package/src/components/toast.ts +965 -0
  115. package/src/components/treemap.ts +847 -0
  116. package/src/lib/calendar.ts +5 -0
  117. package/src/lib/component-index.ts +34 -2
  118. package/src/lib/css.ts +6 -2
  119. package/src/lib/icons.ts +7 -0
  120. package/src/lib/scope.ts +135 -0
  121. package/src/lib/theme.ts +21 -5
  122. package/dist/chunk-EZQXTO6K.js +0 -89
  123. package/dist/chunk-IDA2BT7D.js +0 -29
  124. package/dist/data-table-DtU3FX9j.d.ts +0 -61
@@ -0,0 +1,189 @@
1
+ // SortButton: the header of a column that sorts a list which is not a table (a watchlist's
2
+ // Last and Day %). A press steps the sort: `firstDirection`, the other direction, then none
3
+ // when `clearable`. An arrow shows the direction, and a screen reader hears it after the
4
+ // label. Several of them sort one list: the host keeps one sorted and clears the others with
5
+ // `setDirection(null)`.
6
+ import { css, defineStyles } from '../lib/css';
7
+ import { defineComponent } from '../lib/define';
8
+ import { msg, textOf, type Translator } from '../lib/i18n';
9
+ import { h } from '../lib/h';
10
+ import { iconEl } from '../lib/icons';
11
+ import { kitTranslator } from '../lib/kit-text';
12
+ import { t } from '../lib/t';
13
+ import { variants, type VariantProps } from '../lib/variants';
14
+ import { nextUid } from '../lib/zag';
15
+
16
+ export const sortButtonDef = defineComponent({
17
+ name: 'sort-button',
18
+ parts: ['root', 'icon', 'state'],
19
+ settings: { radius: t.radius.sm },
20
+ });
21
+
22
+ export const sortButtonVariants = variants({ align: ['start', 'end'] });
23
+
24
+ export type SortDirection = 'asc' | 'desc';
25
+
26
+ export interface SortButtonProps extends VariantProps<typeof sortButtonVariants> {
27
+ /** The column's name. */
28
+ label: string;
29
+ /** The sort it starts with (default none). */
30
+ direction?: SortDirection | null;
31
+ /** What the first press sorts by (default `desc`: the largest first). */
32
+ firstDirection?: SortDirection;
33
+ /** A press after both directions clears the sort (default true). */
34
+ clearable?: boolean;
35
+ /** A press changed the sort; null: unsorted. */
36
+ onSortChange?: (direction: SortDirection | null) => void;
37
+ /** A tooltip (`Sort by Last`). */
38
+ title?: string;
39
+ disabled?: boolean;
40
+ /** The translator of the words a screen reader hears ("sorted ascending"). Default: the
41
+ * kit build's, else English. */
42
+ i18n?: Translator;
43
+ /** Extra class names (layout hooks). */
44
+ className?: string;
45
+ }
46
+
47
+ export interface SortButtonHandle {
48
+ readonly el: HTMLButtonElement;
49
+ readonly direction: SortDirection | null;
50
+ /** Show a sort without calling `onSortChange`. */
51
+ setDirection(direction: SortDirection | null): void;
52
+ setDisabled(disabled: boolean): void;
53
+ destroy(): void;
54
+ }
55
+
56
+ const TEXT = {
57
+ asc: msg('ui.sortButton.ascending', 'sorted ascending'),
58
+ desc: msg('ui.sortButton.descending', 'sorted descending'),
59
+ };
60
+
61
+ const injectStyles = defineStyles(
62
+ 'vela-ui-sort-button',
63
+ css`
64
+ @layer vela.ui {
65
+ [data-slot='sort-button']:where(:not([hidden])) {
66
+ all: unset;
67
+ box-sizing: border-box;
68
+ display: inline-flex;
69
+ align-items: center;
70
+ gap: 3px;
71
+ max-width: 100%;
72
+ border-radius: ${sortButtonDef.vars.radius};
73
+ color: ${t.fg.muted};
74
+ font-size: 11px;
75
+ font-weight: 500;
76
+ white-space: nowrap;
77
+ cursor: pointer;
78
+ user-select: none;
79
+ transition: color ${t.dur.fast} ease;
80
+
81
+ &[data-align='end'] {
82
+ justify-content: flex-end;
83
+ text-align: end;
84
+ }
85
+ &:disabled {
86
+ cursor: default;
87
+ opacity: 0.5;
88
+ }
89
+ &:focus-visible {
90
+ outline: 2px solid ${t.focus};
91
+ outline-offset: 1px;
92
+ }
93
+ &:not(:disabled):hover,
94
+ &[data-direction] {
95
+ color: ${t.fg.bright};
96
+ }
97
+ }
98
+ [data-slot='sort-button-icon'] {
99
+ flex: none;
100
+ width: 1em;
101
+ height: 1em;
102
+ font-size: 11px;
103
+ line-height: 0;
104
+
105
+ & > svg {
106
+ width: 100%;
107
+ height: 100%;
108
+ }
109
+ }
110
+ [data-slot='sort-button-state'] {
111
+ position: absolute;
112
+ width: 1px;
113
+ height: 1px;
114
+ overflow: hidden;
115
+ clip-path: inset(50%);
116
+ white-space: nowrap;
117
+ }
118
+ }
119
+ `,
120
+ );
121
+
122
+ class SortButtonImpl implements SortButtonHandle {
123
+ readonly el: HTMLButtonElement;
124
+ private readonly state: HTMLElement;
125
+ private readonly i18n: Translator | null;
126
+ private current: SortDirection | null;
127
+
128
+ constructor(private readonly props: SortButtonProps) {
129
+ injectStyles(document);
130
+ this.i18n = props.i18n ?? kitTranslator();
131
+ this.current = props.direction ?? null;
132
+ const stateId = nextUid('vela-sort');
133
+ this.state = h('span', { slot: sortButtonDef.slot('state'), attrs: { id: stateId } });
134
+ this.el = h(
135
+ 'button',
136
+ {
137
+ className: props.className,
138
+ slot: sortButtonDef.slot('root'),
139
+ attrs: { type: 'button', title: props.title ?? null, 'aria-label': props.label, 'aria-describedby': stateId, ...sortButtonVariants(props) },
140
+ on: { click: () => this.step() },
141
+ },
142
+ props.label,
143
+ this.state,
144
+ );
145
+ this.el.disabled = props.disabled ?? false;
146
+ this.paint();
147
+ }
148
+
149
+ get direction(): SortDirection | null {
150
+ return this.current;
151
+ }
152
+
153
+ setDirection(direction: SortDirection | null): void {
154
+ this.current = direction;
155
+ this.paint();
156
+ }
157
+
158
+ setDisabled(disabled: boolean): void {
159
+ this.el.disabled = disabled;
160
+ }
161
+
162
+ destroy(): void {}
163
+
164
+ private step(): void {
165
+ const first = this.props.firstDirection ?? 'desc';
166
+ const second: SortDirection = first === 'desc' ? 'asc' : 'desc';
167
+ const clearable = this.props.clearable ?? true;
168
+ this.current = this.current === null ? first : this.current === first ? second : clearable ? null : first;
169
+ this.paint();
170
+ this.props.onSortChange?.(this.current);
171
+ }
172
+
173
+ private paint(): void {
174
+ const dir = this.current;
175
+ this.el.querySelector(`[data-slot="${sortButtonDef.slot('icon')}"]`)?.remove();
176
+ if (dir) {
177
+ const icon = iconEl(dir === 'asc' ? 'arrow-up' : 'arrow-down', document);
178
+ icon.dataset.slot = sortButtonDef.slot('icon');
179
+ this.state.before(icon);
180
+ }
181
+ this.el.toggleAttribute('data-direction', dir !== null);
182
+ if (dir) this.el.dataset.direction = dir;
183
+ this.state.textContent = dir ? textOf(this.i18n, TEXT[dir]) : '';
184
+ }
185
+ }
186
+
187
+ export function createSortButton(props: SortButtonProps): SortButtonHandle {
188
+ return new SortButtonImpl(props);
189
+ }
@@ -3,7 +3,8 @@
3
3
  // select; the caller shows what the selected tab stands for, through panels it attaches or as
4
4
  // a filter of one view. `default` puts the tabs on one tinted track, `line` underlines the
5
5
  // selected one (the indicator dialog), `filled` is the symbol picker's market strip, `soft`
6
- // the drawings drawer's category strip, `nav` a vertical settings rail.
6
+ // the drawings drawer's category strip, `nav` a vertical settings rail. A tab with a
7
+ // `description` reads on two lines, its label over it (a day strip: the weekday, then the date).
7
8
  import * as tabs from '@zag-js/tabs';
8
9
  import { css, defineStyles } from '../lib/css';
9
10
  import { defineComponent } from '../lib/define';
@@ -16,7 +17,7 @@ import { nextUid, normalizeProps, runMachine, spreadProps, type HandleOf } from
16
17
 
17
18
  export const tabsDef = defineComponent({
18
19
  name: 'tabs',
19
- parts: ['list', 'trigger', 'icon', 'count', 'content'],
20
+ parts: ['list', 'trigger', 'icon', 'count', 'label', 'description', 'content'],
20
21
  settings: { 'track-radius': '8px', 'trigger-radius': t.radius.md, 'filled-radius': '5px', 'soft-radius': '8px', 'count-radius': '8px' },
21
22
  });
22
23
 
@@ -34,6 +35,8 @@ export interface TabItem {
34
35
  icon?: string;
35
36
  /** A count after the label (open orders, trades); null shows none. */
36
37
  count?: number | null;
38
+ /** A second line under the label (a day strip's date under its weekday). */
39
+ description?: string;
37
40
  }
38
41
 
39
42
  export interface TabsProps extends VariantProps<typeof tabsVariants> {
@@ -234,6 +237,30 @@ export const TABS_CSS = css`
234
237
  background: ${t.active};
235
238
  color: ${t.fg.bright};
236
239
  }
240
+ &[data-description] {
241
+ display: inline-flex;
242
+ flex-direction: column;
243
+ align-items: center;
244
+ justify-content: center;
245
+ gap: 2px;
246
+ }
247
+ &[data-description]:not([data-variant='line']) {
248
+ padding-block: 6px;
249
+ }
250
+ }
251
+ [data-slot='tabs-list'][data-variant='default']:has(> [data-description]) {
252
+ height: auto;
253
+ }
254
+ [data-slot='tabs-label'] {
255
+ display: inline-flex;
256
+ align-items: center;
257
+ line-height: 16px;
258
+ }
259
+ [data-slot='tabs-description'] {
260
+ font-size: 11px;
261
+ font-weight: 400;
262
+ line-height: 14px;
263
+ opacity: 0.85;
237
264
  }
238
265
  }
239
266
  `;
@@ -333,7 +360,7 @@ class TabsImpl implements TabsHandle {
333
360
  this.items = this.items.map((i) => (i.value === value ? { ...i, count } : i));
334
361
  b.querySelector(`[data-slot="${tabsDef.slot('count')}"]`)?.remove();
335
362
  const el = countEl(count);
336
- if (el) b.appendChild(el);
363
+ if (el) (b.querySelector(`[data-slot="${tabsDef.slot('label')}"]`) ?? b).appendChild(el);
337
364
  }
338
365
 
339
366
  trigger(value: string): HTMLButtonElement | null {
@@ -364,7 +391,14 @@ class TabsImpl implements TabsHandle {
364
391
  icon = iconEl(item.icon, document);
365
392
  icon.dataset.slot = tabsDef.slot('icon');
366
393
  }
367
- const b = h('button', { className, slot: tabsDef.slot('trigger'), data: { variant: this.variant } }, icon, item.label, countEl(item.count));
394
+ const b = item.description
395
+ ? h(
396
+ 'button',
397
+ { className, slot: tabsDef.slot('trigger'), data: { variant: this.variant, description: true } },
398
+ h('span', { slot: tabsDef.slot('label') }, icon, item.label, countEl(item.count)),
399
+ h('span', { slot: tabsDef.slot('description'), text: item.description }),
400
+ )
401
+ : h('button', { className, slot: tabsDef.slot('trigger'), data: { variant: this.variant } }, icon, item.label, countEl(item.count));
368
402
  this.triggers.set(item.value, b);
369
403
  return b;
370
404
  }),