@luxalgo/vela-ui 0.0.0-stage → 0.1.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.
- package/CHANGELOG.md +43 -0
- package/LICENSE +201 -0
- package/NOTICE +28 -0
- package/README.md +83 -3
- package/cli/engine.mjs +282 -0
- package/cli/index.mjs +154 -0
- package/dist/badge.d.ts +26 -0
- package/dist/badge.js +44 -0
- package/dist/bar-chart.d.ts +40 -0
- package/dist/bar-chart.js +105 -0
- package/dist/button.d.ts +41 -0
- package/dist/button.js +10 -0
- package/dist/calendar.d.ts +22 -0
- package/dist/calendar.js +1 -0
- package/dist/callout-bubble.d.ts +98 -0
- package/dist/callout-bubble.js +173 -0
- package/dist/chart.d.ts +30 -0
- package/dist/chart.js +1 -0
- package/dist/checkbox.d.ts +60 -0
- package/dist/checkbox.js +12 -0
- package/dist/chunk-2GQIZM5Z.js +28 -0
- package/dist/chunk-2Q4JRINP.js +403 -0
- package/dist/chunk-3Q32K4PE.js +85 -0
- package/dist/chunk-5QHXOAZA.js +351 -0
- package/dist/chunk-6NXY62JS.js +25 -0
- package/dist/chunk-6QCILIT2.js +52 -0
- package/dist/chunk-A2FJ7Y7D.js +55 -0
- package/dist/chunk-A72NWYNP.js +26 -0
- package/dist/chunk-AJ2IYSOI.js +553 -0
- package/dist/chunk-BXMWQIBO.js +66 -0
- package/dist/chunk-CH3DV6FD.js +280 -0
- package/dist/chunk-EZQXTO6K.js +89 -0
- package/dist/chunk-FCO3YZLT.js +81 -0
- package/dist/chunk-FN2BUFNM.js +10 -0
- package/dist/chunk-FVH6L7FM.js +18 -0
- package/dist/chunk-G7IQLY3A.js +183 -0
- package/dist/chunk-IDA2BT7D.js +29 -0
- package/dist/chunk-J2QJATCD.js +12 -0
- package/dist/chunk-LZWZV2ZS.js +18 -0
- package/dist/chunk-MMTMOV6R.js +31 -0
- package/dist/chunk-OBLIX3VN.js +227 -0
- package/dist/chunk-P4MTEMT7.js +23 -0
- package/dist/chunk-Q6WTDVH6.js +31 -0
- package/dist/chunk-S7USVSYP.js +50 -0
- package/dist/chunk-SAPURP46.js +133 -0
- package/dist/chunk-TAKSIV57.js +90 -0
- package/dist/chunk-V6TTTMTE.js +79 -0
- package/dist/chunk-VMCR3S2A.js +22 -0
- package/dist/chunk-X4YPSIW6.js +72 -0
- package/dist/chunk-X66RJAIS.js +14 -0
- package/dist/chunk-XJAPCCOJ.js +101 -0
- package/dist/chunk-ZB3BZHSN.js +219 -0
- package/dist/color-picker.d.ts +103 -0
- package/dist/color-picker.js +19 -0
- package/dist/color.d.ts +24 -0
- package/dist/color.js +1 -0
- package/dist/context-menu.d.ts +72 -0
- package/dist/context-menu.js +161 -0
- package/dist/css.d.ts +15 -0
- package/dist/css.js +4 -0
- package/dist/data-table-DtU3FX9j.d.ts +61 -0
- package/dist/data-table.d.ts +3 -0
- package/dist/data-table.js +88 -0
- package/dist/date-picker.d.ts +90 -0
- package/dist/date-picker.js +257 -0
- package/dist/define-D5u3F5Dj.d.ts +21 -0
- package/dist/dialog.d.ts +89 -0
- package/dist/dialog.js +258 -0
- package/dist/dispose.d.ts +9 -0
- package/dist/dispose.js +2 -0
- package/dist/donut.d.ts +27 -0
- package/dist/donut.js +67 -0
- package/dist/drawer.d.ts +119 -0
- package/dist/drawer.js +326 -0
- package/dist/dropdown-menu.d.ts +114 -0
- package/dist/dropdown-menu.js +18 -0
- package/dist/empty.d.ts +21 -0
- package/dist/empty.js +38 -0
- package/dist/field.d.ts +147 -0
- package/dist/field.js +328 -0
- package/dist/glyph-select.d.ts +57 -0
- package/dist/glyph-select.js +17 -0
- package/dist/headless.d.ts +6 -0
- package/dist/headless.js +9 -0
- package/dist/hover-card.d.ts +43 -0
- package/dist/hover-card.js +97 -0
- package/dist/i18n.d.ts +20 -0
- package/dist/i18n.js +1 -0
- package/dist/icons.d.ts +20 -0
- package/dist/icons.js +2 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.js +13 -0
- package/dist/input-group.d.ts +57 -0
- package/dist/input-group.js +86 -0
- package/dist/input.d.ts +54 -0
- package/dist/input.js +9 -0
- package/dist/kbd.d.ts +19 -0
- package/dist/kbd.js +8 -0
- package/dist/kit-text.d.ts +8 -0
- package/dist/kit-text.js +2 -0
- package/dist/line-chart.d.ts +32 -0
- package/dist/line-chart.js +120 -0
- package/dist/manifest.json +3854 -0
- package/dist/number-input.d.ts +99 -0
- package/dist/number-input.js +14 -0
- package/dist/page.d.ts +7 -0
- package/dist/page.js +1 -0
- package/dist/palette.d.ts +55 -0
- package/dist/palette.js +1 -0
- package/dist/placement.d.ts +98 -0
- package/dist/placement.js +1 -0
- package/dist/popover.d.ts +107 -0
- package/dist/popover.js +15 -0
- package/dist/scatter-chart.d.ts +32 -0
- package/dist/scatter-chart.js +121 -0
- package/dist/select.d.ts +112 -0
- package/dist/select.js +19 -0
- package/dist/sparkline.d.ts +22 -0
- package/dist/sparkline.js +72 -0
- package/dist/stat.d.ts +29 -0
- package/dist/stat.js +41 -0
- package/dist/styles.d.ts +22 -0
- package/dist/styles.js +2 -0
- package/dist/surface-events.d.ts +17 -0
- package/dist/surface-events.js +1 -0
- package/dist/surface-exit.d.ts +25 -0
- package/dist/surface-exit.js +1 -0
- package/dist/switch.d.ts +54 -0
- package/dist/switch.js +92 -0
- package/dist/t.d.ts +89 -0
- package/dist/t.js +1 -0
- package/dist/tabs.d.ts +63 -0
- package/dist/tabs.js +150 -0
- package/dist/text-area.d.ts +54 -0
- package/dist/text-area.js +9 -0
- package/dist/theme.d.ts +188 -0
- package/dist/theme.js +8 -0
- package/dist/theme.schema.json +1745 -0
- package/dist/themes/dark.css +3 -0
- package/dist/themes/light.css +3 -0
- package/dist/toggle-group.d.ts +56 -0
- package/dist/toggle-group.js +130 -0
- package/dist/tokens.d.ts +16 -0
- package/dist/tokens.js +3 -0
- package/dist/tooltip.d.ts +47 -0
- package/dist/tooltip.js +74 -0
- package/dist/variants-B4stUBnY.d.ts +16 -0
- package/dist/zag.d.ts +19 -0
- package/dist/zag.js +2 -0
- package/docs/theming.md +211 -0
- package/docs/what-to-change.md +20 -0
- package/docs/writing-a-component.md +247 -0
- package/llms.txt +66 -0
- package/package.json +90 -6
- package/registry/badge.ts +119 -0
- package/registry/bar-chart.ts +215 -0
- package/registry/button.ts +303 -0
- package/registry/callout-bubble.ts +336 -0
- package/registry/checkbox.ts +234 -0
- package/registry/color-picker.ts +582 -0
- package/registry/context-menu.ts +208 -0
- package/registry/data-table.ts +215 -0
- package/registry/date-picker.ts +483 -0
- package/registry/dialog.ts +535 -0
- package/registry/donut.ts +145 -0
- package/registry/drawer.ts +636 -0
- package/registry/dropdown-menu.ts +762 -0
- package/registry/empty.ts +91 -0
- package/registry/field.ts +585 -0
- package/registry/glyph-select.ts +268 -0
- package/registry/hover-card.ts +222 -0
- package/registry/input-group.ts +229 -0
- package/registry/input.ts +181 -0
- package/registry/kbd.ts +64 -0
- package/registry/line-chart.ts +218 -0
- package/registry/number-input.ts +443 -0
- package/registry/popover.ts +368 -0
- package/registry/scatter-chart.ts +221 -0
- package/registry/select.ts +620 -0
- package/registry/sparkline.ts +114 -0
- package/registry/stat.ts +96 -0
- package/registry/switch.ts +205 -0
- package/registry/tabs.ts +392 -0
- package/registry/text-area.ts +186 -0
- package/registry/toggle-group.ts +295 -0
- package/registry/tooltip.ts +156 -0
- package/skills/theming-vela-ui/SKILL.md +137 -0
- package/skills/using-vela-ui-components/SKILL.md +134 -0
- package/skills/writing-vela-ui-components/SKILL.md +163 -0
- package/src/components/badge.ts +119 -0
- package/src/components/bar-chart.ts +215 -0
- package/src/components/button.ts +303 -0
- package/src/components/callout-bubble.ts +336 -0
- package/src/components/checkbox.ts +234 -0
- package/src/components/color-picker.ts +582 -0
- package/src/components/context-menu.ts +208 -0
- package/src/components/data-table.ts +215 -0
- package/src/components/date-picker.ts +483 -0
- package/src/components/dialog.ts +535 -0
- package/src/components/donut.ts +145 -0
- package/src/components/drawer.ts +636 -0
- package/src/components/dropdown-menu.ts +762 -0
- package/src/components/empty.ts +91 -0
- package/src/components/field.ts +585 -0
- package/src/components/glyph-select.ts +268 -0
- package/src/components/hover-card.ts +222 -0
- package/src/components/input-group.ts +229 -0
- package/src/components/input.ts +181 -0
- package/src/components/kbd.ts +64 -0
- package/src/components/line-chart.ts +218 -0
- package/src/components/number-input.ts +443 -0
- package/src/components/popover.ts +368 -0
- package/src/components/scatter-chart.ts +221 -0
- package/src/components/select.ts +620 -0
- package/src/components/sparkline.ts +114 -0
- package/src/components/stat.ts +96 -0
- package/src/components/switch.ts +205 -0
- package/src/components/tabs.ts +392 -0
- package/src/components/text-area.ts +186 -0
- package/src/components/toggle-group.ts +295 -0
- package/src/components/tooltip.ts +156 -0
- package/src/index.ts +24 -0
- package/src/lib/calendar.ts +112 -0
- package/src/lib/chart.ts +72 -0
- package/src/lib/color.ts +89 -0
- package/src/lib/component-index.ts +131 -0
- package/src/lib/css.ts +44 -0
- package/src/lib/define.ts +45 -0
- package/src/lib/dispose.ts +36 -0
- package/src/lib/h.ts +55 -0
- package/src/lib/headless.ts +16 -0
- package/src/lib/i18n.ts +30 -0
- package/src/lib/icons.ts +237 -0
- package/src/lib/kit-text.ts +26 -0
- package/src/lib/page.ts +24 -0
- package/src/lib/palette.ts +81 -0
- package/src/lib/placement.ts +188 -0
- package/src/lib/styles.ts +53 -0
- package/src/lib/surface-events.ts +31 -0
- package/src/lib/surface-exit.ts +87 -0
- package/src/lib/t.ts +68 -0
- package/src/lib/theme.ts +654 -0
- package/src/lib/tokens.ts +111 -0
- package/src/lib/variants.ts +32 -0
- package/src/lib/zag.ts +46 -0
- package/stylelint/index.mjs +60 -0
- package/stylelint/lint.mjs +81 -0
- package/stylelint/plugin.mjs +115 -0
package/registry/tabs.ts
ADDED
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
// Tabs: a tab list over Zag's tabs machine (WAI-ARIA tabs: roving focus, the arrow keys along
|
|
2
|
+
// the orientation, Home/End, automatic or manual activation). Clicks and the arrow keys
|
|
3
|
+
// select; the caller shows what the selected tab stands for, through panels it attaches or as
|
|
4
|
+
// a filter of one view. `default` puts the tabs on one tinted track, `line` underlines the
|
|
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.
|
|
7
|
+
import * as tabs from '@zag-js/tabs';
|
|
8
|
+
import { css, defineStyles } from '@luxalgo/vela-ui';
|
|
9
|
+
import { defineComponent } from '@luxalgo/vela-ui';
|
|
10
|
+
import { ownTeardown } from '@luxalgo/vela-ui/dispose';
|
|
11
|
+
import { h } from '@luxalgo/vela-ui';
|
|
12
|
+
import { iconEl } from '@luxalgo/vela-ui/icons';
|
|
13
|
+
import { t } from '@luxalgo/vela-ui';
|
|
14
|
+
import { variants, type VariantProps } from '@luxalgo/vela-ui';
|
|
15
|
+
import { nextUid, normalizeProps, runMachine, spreadProps, type HandleOf } from '@luxalgo/vela-ui/zag';
|
|
16
|
+
|
|
17
|
+
export const tabsDef = defineComponent({
|
|
18
|
+
name: 'tabs',
|
|
19
|
+
parts: ['list', 'trigger', 'icon', 'count', 'content'],
|
|
20
|
+
settings: { 'track-radius': '8px', 'trigger-radius': t.radius.md, 'filled-radius': '5px', 'soft-radius': '8px', 'count-radius': '8px' },
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
export const tabsVariants = variants({ variant: ['default', 'line', 'filled', 'soft', 'nav'] });
|
|
24
|
+
|
|
25
|
+
export type TabsVariant = (typeof tabsVariants.spec.variant)[number];
|
|
26
|
+
|
|
27
|
+
export interface TabItem {
|
|
28
|
+
value: string;
|
|
29
|
+
label: string;
|
|
30
|
+
disabled?: boolean;
|
|
31
|
+
/** Out of the strip for now (its content does not apply); the arrow keys skip it. */
|
|
32
|
+
hidden?: boolean;
|
|
33
|
+
/** Icon id from the kit's registry, before the label. */
|
|
34
|
+
icon?: string;
|
|
35
|
+
/** A count after the label (open orders, trades); null shows none. */
|
|
36
|
+
count?: number | null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface TabsProps extends VariantProps<typeof tabsVariants> {
|
|
40
|
+
items: readonly TabItem[];
|
|
41
|
+
/** The selected tab (default: the first available one). */
|
|
42
|
+
defaultValue?: string;
|
|
43
|
+
onValueChange?: (value: string) => void;
|
|
44
|
+
/** Default `horizontal` (`nav` reads best vertical). */
|
|
45
|
+
orientation?: 'horizontal' | 'vertical';
|
|
46
|
+
/** `automatic` (default): moving focus with the arrow keys selects. `manual`: Enter or
|
|
47
|
+
* Space selects the focused tab. */
|
|
48
|
+
activationMode?: 'automatic' | 'manual';
|
|
49
|
+
/** The text direction the arrow keys follow (default `ltr`). */
|
|
50
|
+
dir?: 'ltr' | 'rtl';
|
|
51
|
+
/** Extra class names on the list (the host's layout of the strip). */
|
|
52
|
+
className?: string;
|
|
53
|
+
/** Extra class names on every trigger. */
|
|
54
|
+
triggerClassName?: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface TabsHandle {
|
|
58
|
+
readonly el: HTMLElement;
|
|
59
|
+
/** The selected tab. */
|
|
60
|
+
readonly value: string | null;
|
|
61
|
+
/** Show a tab as selected without calling `onValueChange`. */
|
|
62
|
+
setValue(value: string | null): void;
|
|
63
|
+
setItems(items: readonly TabItem[]): void;
|
|
64
|
+
/** Hide or show a tab. Hiding the selected tab selects the first available one (and
|
|
65
|
+
* calls `onValueChange`). */
|
|
66
|
+
setHidden(value: string, hidden: boolean): void;
|
|
67
|
+
/** A tab's count (null: none). */
|
|
68
|
+
setCount(value: string, count: number | null): void;
|
|
69
|
+
/** The trigger of a tab (null: unknown value). */
|
|
70
|
+
trigger(value: string): HTMLButtonElement | null;
|
|
71
|
+
/** Make `el` the panel of tab `value`: it gets the tabpanel role, its link to the trigger,
|
|
72
|
+
* and `hidden` while another tab is selected. */
|
|
73
|
+
panel(value: string, el: HTMLElement): void;
|
|
74
|
+
destroy(): void;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** A tab a user can reach: neither disabled nor hidden. */
|
|
78
|
+
export const tabAvailable = (item: TabItem): boolean => !item.disabled && !item.hidden;
|
|
79
|
+
|
|
80
|
+
const countEl = (count: number | null | undefined): HTMLElement | null => (count == null ? null : h('span', { slot: tabsDef.slot('count'), text: String(count) }));
|
|
81
|
+
|
|
82
|
+
export const TABS_STYLE_ID = 'vela-ui-tabs';
|
|
83
|
+
|
|
84
|
+
export const TABS_CSS = css`
|
|
85
|
+
@layer vela.ui {
|
|
86
|
+
[data-slot='tabs-icon'] {
|
|
87
|
+
margin-inline-end: 6px;
|
|
88
|
+
}
|
|
89
|
+
[data-slot='tabs-count'] {
|
|
90
|
+
min-width: 16px;
|
|
91
|
+
height: 16px;
|
|
92
|
+
margin-inline-start: 6px;
|
|
93
|
+
padding: 0 5px;
|
|
94
|
+
border-radius: ${tabsDef.vars['count-radius']};
|
|
95
|
+
background: ${t.hover};
|
|
96
|
+
color: ${t.fg.muted};
|
|
97
|
+
font-size: 10px;
|
|
98
|
+
font-weight: 600;
|
|
99
|
+
font-variant-numeric: tabular-nums;
|
|
100
|
+
|
|
101
|
+
&:where(:not([hidden])) {
|
|
102
|
+
display: inline-flex;
|
|
103
|
+
align-items: center;
|
|
104
|
+
justify-content: center;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
[data-slot='tabs-list'] {
|
|
108
|
+
display: flex;
|
|
109
|
+
|
|
110
|
+
&[data-orientation='vertical'] {
|
|
111
|
+
flex-direction: column;
|
|
112
|
+
}
|
|
113
|
+
&[data-variant='default'] {
|
|
114
|
+
display: inline-flex;
|
|
115
|
+
gap: 2px;
|
|
116
|
+
padding: 3px;
|
|
117
|
+
box-sizing: border-box;
|
|
118
|
+
border-radius: ${tabsDef.vars['track-radius']};
|
|
119
|
+
background: color-mix(in srgb, ${t.fg.bright} 6%, transparent);
|
|
120
|
+
}
|
|
121
|
+
&[data-variant='default'][data-orientation='horizontal'] {
|
|
122
|
+
height: 32px;
|
|
123
|
+
align-items: stretch;
|
|
124
|
+
}
|
|
125
|
+
&[data-variant='line'] {
|
|
126
|
+
gap: 12px;
|
|
127
|
+
border-bottom: 1px solid ${t.border};
|
|
128
|
+
}
|
|
129
|
+
&[data-variant='nav'] {
|
|
130
|
+
gap: 2px;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
[data-slot='tabs-trigger']:where(:not([hidden])) {
|
|
134
|
+
all: unset;
|
|
135
|
+
cursor: pointer;
|
|
136
|
+
white-space: nowrap;
|
|
137
|
+
-webkit-tap-highlight-color: transparent;
|
|
138
|
+
|
|
139
|
+
&[data-disabled] {
|
|
140
|
+
cursor: default;
|
|
141
|
+
opacity: 0.45;
|
|
142
|
+
}
|
|
143
|
+
&:focus-visible {
|
|
144
|
+
outline: 2px solid ${t.focus};
|
|
145
|
+
outline-offset: -2px;
|
|
146
|
+
}
|
|
147
|
+
&[data-variant='default'] {
|
|
148
|
+
display: inline-flex;
|
|
149
|
+
align-items: center;
|
|
150
|
+
justify-content: center;
|
|
151
|
+
padding: 0 10px;
|
|
152
|
+
border-radius: ${tabsDef.vars['trigger-radius']};
|
|
153
|
+
color: ${t.fg.muted};
|
|
154
|
+
font-size: 13px;
|
|
155
|
+
font-weight: 500;
|
|
156
|
+
transition:
|
|
157
|
+
background ${t.dur.fast} ease,
|
|
158
|
+
color ${t.dur.fast} ease;
|
|
159
|
+
}
|
|
160
|
+
&[data-variant='default'][data-orientation='vertical'] {
|
|
161
|
+
justify-content: flex-start;
|
|
162
|
+
padding: 6px 10px;
|
|
163
|
+
}
|
|
164
|
+
&[data-variant='default']:not([data-selected], [data-disabled]):hover {
|
|
165
|
+
color: ${t.fg.bright};
|
|
166
|
+
}
|
|
167
|
+
&[data-variant='default'][data-selected] {
|
|
168
|
+
background: color-mix(in srgb, ${t.fg.bright} 12%, transparent);
|
|
169
|
+
color: ${t.fg.bright};
|
|
170
|
+
}
|
|
171
|
+
&[data-variant='line'] {
|
|
172
|
+
padding-bottom: 8px;
|
|
173
|
+
margin-bottom: -1px;
|
|
174
|
+
border-bottom: 2px solid transparent;
|
|
175
|
+
font-size: 13px;
|
|
176
|
+
font-weight: 600;
|
|
177
|
+
line-height: 20px;
|
|
178
|
+
color: ${t.fg.muted};
|
|
179
|
+
transition:
|
|
180
|
+
color ${t.dur.fast} ease,
|
|
181
|
+
border-color ${t.dur.fast} ease;
|
|
182
|
+
}
|
|
183
|
+
&[data-variant='line']:not([data-selected], [data-disabled]):hover {
|
|
184
|
+
color: ${t.fg};
|
|
185
|
+
}
|
|
186
|
+
&[data-variant='line'][data-selected] {
|
|
187
|
+
color: ${t.fg};
|
|
188
|
+
border-bottom-color: ${t.fg.bright};
|
|
189
|
+
}
|
|
190
|
+
&[data-variant='filled'] {
|
|
191
|
+
padding: 3px 10px;
|
|
192
|
+
border-radius: ${tabsDef.vars['filled-radius']};
|
|
193
|
+
color: ${t.fg.muted};
|
|
194
|
+
font-size: 13px;
|
|
195
|
+
font-weight: 600;
|
|
196
|
+
}
|
|
197
|
+
&[data-variant='filled']:not([data-selected], [data-disabled]):hover {
|
|
198
|
+
color: ${t.fg};
|
|
199
|
+
}
|
|
200
|
+
&[data-variant='filled'][data-selected] {
|
|
201
|
+
background: ${t.selected.bg};
|
|
202
|
+
color: ${t.selected.fg};
|
|
203
|
+
}
|
|
204
|
+
&[data-variant='soft'] {
|
|
205
|
+
flex: none;
|
|
206
|
+
min-height: 36px;
|
|
207
|
+
padding: 0 12px;
|
|
208
|
+
display: inline-flex;
|
|
209
|
+
align-items: center;
|
|
210
|
+
border-radius: ${tabsDef.vars['soft-radius']};
|
|
211
|
+
font-size: 13px;
|
|
212
|
+
font-weight: 600;
|
|
213
|
+
color: ${t.fg.muted};
|
|
214
|
+
}
|
|
215
|
+
&[data-variant='soft'][data-selected] {
|
|
216
|
+
color: ${t.fg.bright};
|
|
217
|
+
background: ${t.hover};
|
|
218
|
+
}
|
|
219
|
+
&[data-variant='nav'] {
|
|
220
|
+
padding: 9px 12px;
|
|
221
|
+
border-radius: ${t.radius.md};
|
|
222
|
+
color: ${t.fg.muted};
|
|
223
|
+
font-size: 13px;
|
|
224
|
+
font-weight: 600;
|
|
225
|
+
transition:
|
|
226
|
+
background ${t.dur.fast} ease,
|
|
227
|
+
color ${t.dur.fast} ease;
|
|
228
|
+
}
|
|
229
|
+
&[data-variant='nav']:not([data-selected], [data-disabled]):hover {
|
|
230
|
+
background: ${t.hover};
|
|
231
|
+
color: ${t.fg.bright};
|
|
232
|
+
}
|
|
233
|
+
&[data-variant='nav'][data-selected] {
|
|
234
|
+
background: ${t.active};
|
|
235
|
+
color: ${t.fg.bright};
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
`;
|
|
240
|
+
|
|
241
|
+
const injectStyles = defineStyles(TABS_STYLE_ID, TABS_CSS);
|
|
242
|
+
|
|
243
|
+
class TabsImpl implements TabsHandle {
|
|
244
|
+
readonly el: HTMLElement;
|
|
245
|
+
private readonly machine: HandleOf<typeof tabs.machine>;
|
|
246
|
+
private readonly mid: string;
|
|
247
|
+
private readonly release: () => void;
|
|
248
|
+
private readonly variant: TabsVariant;
|
|
249
|
+
private readonly triggerClassName: string | undefined;
|
|
250
|
+
private items: TabItem[];
|
|
251
|
+
private readonly triggers = new Map<string, HTMLButtonElement>();
|
|
252
|
+
private readonly panels = new Map<string, HTMLElement>();
|
|
253
|
+
/** The selection as of the last write or report: the machine applies events on a
|
|
254
|
+
* microtask, so its own value lags a write. */
|
|
255
|
+
private current: string | null;
|
|
256
|
+
/** A host write the machine has yet to report: that report is not the user's change. */
|
|
257
|
+
private silentNext: string | undefined;
|
|
258
|
+
|
|
259
|
+
constructor(props: TabsProps) {
|
|
260
|
+
injectStyles(document);
|
|
261
|
+
this.variant = tabsVariants.resolve(props).variant;
|
|
262
|
+
this.triggerClassName = props.triggerClassName;
|
|
263
|
+
this.items = [...props.items];
|
|
264
|
+
this.current = props.defaultValue ?? this.items.find(tabAvailable)?.value ?? null;
|
|
265
|
+
this.mid = nextUid('vela-tabs');
|
|
266
|
+
this.el = h('div', {
|
|
267
|
+
className: props.className ? `vela-tabs ${props.className}` : 'vela-tabs',
|
|
268
|
+
slot: tabsDef.slot('list'),
|
|
269
|
+
data: { variant: this.variant },
|
|
270
|
+
});
|
|
271
|
+
this.build();
|
|
272
|
+
this.machine = runMachine(
|
|
273
|
+
tabs.machine,
|
|
274
|
+
{
|
|
275
|
+
id: this.mid,
|
|
276
|
+
defaultValue: this.current,
|
|
277
|
+
orientation: props.orientation ?? 'horizontal',
|
|
278
|
+
activationMode: props.activationMode ?? 'automatic',
|
|
279
|
+
dir: props.dir ?? 'ltr',
|
|
280
|
+
loopFocus: true,
|
|
281
|
+
onValueChange: ({ value }) => {
|
|
282
|
+
if (value == null) return;
|
|
283
|
+
this.current = value;
|
|
284
|
+
if (this.silentNext === value) {
|
|
285
|
+
this.silentNext = undefined;
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
props.onValueChange?.(value);
|
|
289
|
+
},
|
|
290
|
+
},
|
|
291
|
+
(service) => this.render(service),
|
|
292
|
+
);
|
|
293
|
+
this.release = ownTeardown(this.el, () => this.machine.stop());
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
get value(): string | null {
|
|
297
|
+
return this.current;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
setValue(value: string | null): void {
|
|
301
|
+
if (value === this.current) return;
|
|
302
|
+
this.current = value;
|
|
303
|
+
if (value === null) {
|
|
304
|
+
this.api().clearValue();
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
this.silentNext = value;
|
|
308
|
+
this.api().setValue(value);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
setItems(items: readonly TabItem[]): void {
|
|
312
|
+
this.items = [...items];
|
|
313
|
+
this.build();
|
|
314
|
+
if (this.current === null || !this.items.some((i) => i.value === this.current)) this.setValue(this.items.find(tabAvailable)?.value ?? null);
|
|
315
|
+
this.machine.flush();
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
setHidden(value: string, hidden: boolean): void {
|
|
319
|
+
this.items = this.items.map((i) => (i.value === value ? { ...i, hidden } : i));
|
|
320
|
+
if (hidden && this.current === value) {
|
|
321
|
+
const next = this.items.find(tabAvailable)?.value;
|
|
322
|
+
if (next !== undefined) {
|
|
323
|
+
this.current = next;
|
|
324
|
+
this.api().setValue(next);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
this.machine.flush();
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
setCount(value: string, count: number | null): void {
|
|
331
|
+
const b = this.triggers.get(value);
|
|
332
|
+
if (!b) return;
|
|
333
|
+
this.items = this.items.map((i) => (i.value === value ? { ...i, count } : i));
|
|
334
|
+
b.querySelector(`[data-slot="${tabsDef.slot('count')}"]`)?.remove();
|
|
335
|
+
const el = countEl(count);
|
|
336
|
+
if (el) b.appendChild(el);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
trigger(value: string): HTMLButtonElement | null {
|
|
340
|
+
return this.triggers.get(value) ?? null;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
panel(value: string, el: HTMLElement): void {
|
|
344
|
+
el.dataset.slot = tabsDef.slot('content');
|
|
345
|
+
this.panels.set(value, el);
|
|
346
|
+
this.machine.flush();
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
destroy(): void {
|
|
350
|
+
this.release();
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
private api(): tabs.Api {
|
|
354
|
+
return tabs.connect(this.machine.service, normalizeProps);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
private build(): void {
|
|
358
|
+
this.triggers.clear();
|
|
359
|
+
const className = this.triggerClassName ? `vela-tab ${this.triggerClassName}` : 'vela-tab';
|
|
360
|
+
this.el.replaceChildren(
|
|
361
|
+
...this.items.map((item) => {
|
|
362
|
+
let icon: HTMLElement | null = null;
|
|
363
|
+
if (item.icon) {
|
|
364
|
+
icon = iconEl(item.icon, document);
|
|
365
|
+
icon.dataset.slot = tabsDef.slot('icon');
|
|
366
|
+
}
|
|
367
|
+
const b = h('button', { className, slot: tabsDef.slot('trigger'), data: { variant: this.variant } }, icon, item.label, countEl(item.count));
|
|
368
|
+
this.triggers.set(item.value, b);
|
|
369
|
+
return b;
|
|
370
|
+
}),
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
private render(service: tabs.Service): void {
|
|
375
|
+
const api = tabs.connect(service, normalizeProps);
|
|
376
|
+
spreadProps(this.el, api.getListProps(), this.mid);
|
|
377
|
+
for (const item of this.items) {
|
|
378
|
+
const b = this.triggers.get(item.value);
|
|
379
|
+
if (!b) continue;
|
|
380
|
+
// A hidden tab is a disabled trigger to the machine, so the arrow keys skip it.
|
|
381
|
+
const props = api.getTriggerProps({ value: item.value, disabled: !tabAvailable(item) }) as Record<string, unknown>;
|
|
382
|
+
if (!this.panels.has(item.value)) delete props['aria-controls'];
|
|
383
|
+
spreadProps(b, props, this.mid);
|
|
384
|
+
b.hidden = item.hidden === true;
|
|
385
|
+
}
|
|
386
|
+
for (const [value, el] of this.panels) spreadProps(el, api.getContentProps({ value }), this.mid);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
export function createTabs(props: TabsProps): TabsHandle {
|
|
391
|
+
return new TabsImpl(props);
|
|
392
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
// TextArea: a multi-line text input that commits on blur, and can grow with its content up to
|
|
2
|
+
// a number of lines before it scrolls.
|
|
3
|
+
import { css, defineStyles } from '@luxalgo/vela-ui';
|
|
4
|
+
import { defineComponent } from '@luxalgo/vela-ui';
|
|
5
|
+
import { h } from '@luxalgo/vela-ui';
|
|
6
|
+
import { t } from '@luxalgo/vela-ui';
|
|
7
|
+
import { variants } from '@luxalgo/vela-ui';
|
|
8
|
+
|
|
9
|
+
export type TextAreaSize = 'sm' | 'md';
|
|
10
|
+
|
|
11
|
+
export interface TextAreaControllerOptions {
|
|
12
|
+
value?: string;
|
|
13
|
+
/** The text it starts with when `value` is not given. */
|
|
14
|
+
defaultValue?: string;
|
|
15
|
+
size?: TextAreaSize;
|
|
16
|
+
rows?: number;
|
|
17
|
+
disabled?: boolean;
|
|
18
|
+
onChange?: (value: string) => void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface TextAreaController {
|
|
22
|
+
value: string;
|
|
23
|
+
size: TextAreaSize;
|
|
24
|
+
rows: number;
|
|
25
|
+
disabled: boolean;
|
|
26
|
+
commit(next: string): string | null;
|
|
27
|
+
sync(next: string): void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The text area's last committed string, without DOM. */
|
|
31
|
+
export function textAreaController(opts: TextAreaControllerOptions = {}): TextAreaController {
|
|
32
|
+
let value = opts.value ?? opts.defaultValue ?? '';
|
|
33
|
+
return {
|
|
34
|
+
get value() {
|
|
35
|
+
return value;
|
|
36
|
+
},
|
|
37
|
+
size: opts.size ?? 'md',
|
|
38
|
+
rows: opts.rows ?? 3,
|
|
39
|
+
disabled: opts.disabled ?? false,
|
|
40
|
+
commit(next: string) {
|
|
41
|
+
if (next === value) return null;
|
|
42
|
+
value = next;
|
|
43
|
+
opts.onChange?.(next);
|
|
44
|
+
return next;
|
|
45
|
+
},
|
|
46
|
+
sync(next: string) {
|
|
47
|
+
value = next;
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export const textAreaDef = defineComponent({
|
|
53
|
+
name: 'text-area',
|
|
54
|
+
parts: ['root', 'input'],
|
|
55
|
+
settings: { radius: t.radius.md, 'focus-ring': `0 0 0 3px ${t.focus.soft}` },
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
export const textAreaVariants = variants({ size: ['md', 'sm'] });
|
|
59
|
+
|
|
60
|
+
export interface TextAreaOptions extends TextAreaControllerOptions {
|
|
61
|
+
/** Submitted with its form under this name. */
|
|
62
|
+
name?: string;
|
|
63
|
+
required?: boolean;
|
|
64
|
+
id?: string;
|
|
65
|
+
placeholder?: string;
|
|
66
|
+
/** Grow with content up to `maxLines`, then scroll. */
|
|
67
|
+
autoGrow?: boolean;
|
|
68
|
+
maxLines?: number;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export type TextAreaProps = TextAreaOptions;
|
|
72
|
+
|
|
73
|
+
const injectStyles = defineStyles(
|
|
74
|
+
'vela-ui-textarea',
|
|
75
|
+
css`
|
|
76
|
+
@layer vela.ui {
|
|
77
|
+
[data-slot='text-area-input'] {
|
|
78
|
+
display: block;
|
|
79
|
+
width: 100%;
|
|
80
|
+
box-sizing: border-box;
|
|
81
|
+
min-height: 64px;
|
|
82
|
+
background: transparent;
|
|
83
|
+
border: 1px solid ${t.border.strong};
|
|
84
|
+
border-radius: ${textAreaDef.vars.radius};
|
|
85
|
+
color: ${t.fg.bright};
|
|
86
|
+
padding: 8px;
|
|
87
|
+
font-size: 14px;
|
|
88
|
+
font-family: inherit;
|
|
89
|
+
line-height: 1.4;
|
|
90
|
+
resize: vertical;
|
|
91
|
+
outline: 2px solid transparent;
|
|
92
|
+
transition:
|
|
93
|
+
border-color ${t.dur.fast} ease,
|
|
94
|
+
box-shadow ${t.dur.fast} ease;
|
|
95
|
+
/* Selectable even under a user-select:none host (chart wrapper, .vela-ui). */
|
|
96
|
+
user-select: text;
|
|
97
|
+
-webkit-user-select: text;
|
|
98
|
+
|
|
99
|
+
&:hover {
|
|
100
|
+
border-color: ${t.fg.muted};
|
|
101
|
+
}
|
|
102
|
+
&:focus {
|
|
103
|
+
border-color: ${t.focus};
|
|
104
|
+
box-shadow: ${textAreaDef.vars['focus-ring']};
|
|
105
|
+
}
|
|
106
|
+
&::placeholder {
|
|
107
|
+
color: currentColor;
|
|
108
|
+
opacity: 0.4;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
[data-slot='text-area'] {
|
|
112
|
+
width: 100%;
|
|
113
|
+
min-width: 0;
|
|
114
|
+
|
|
115
|
+
&:where(:not([hidden])) {
|
|
116
|
+
display: block;
|
|
117
|
+
}
|
|
118
|
+
&[data-autogrow] [data-slot='text-area-input'] {
|
|
119
|
+
resize: none;
|
|
120
|
+
overflow-y: hidden;
|
|
121
|
+
min-height: 46px;
|
|
122
|
+
}
|
|
123
|
+
&[data-size='sm'] [data-slot='text-area-input'] {
|
|
124
|
+
font-size: 13px;
|
|
125
|
+
min-height: 46px;
|
|
126
|
+
padding: 6px 9px;
|
|
127
|
+
line-height: 18px;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
`,
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
export class TextArea {
|
|
135
|
+
readonly el: HTMLElement;
|
|
136
|
+
readonly input: HTMLTextAreaElement;
|
|
137
|
+
private readonly ctrl: TextAreaController;
|
|
138
|
+
private readonly autoGrow: boolean;
|
|
139
|
+
private readonly maxLines: number;
|
|
140
|
+
|
|
141
|
+
constructor(opts: TextAreaOptions = {}) {
|
|
142
|
+
injectStyles(document);
|
|
143
|
+
this.ctrl = textAreaController(opts);
|
|
144
|
+
this.autoGrow = opts.autoGrow === true;
|
|
145
|
+
this.maxLines = opts.maxLines ?? 4;
|
|
146
|
+
|
|
147
|
+
const ta = h('textarea', { className: 'vela-textarea-field', slot: textAreaDef.slot('input'), attrs: { id: opts.id, placeholder: opts.placeholder, name: opts.name } });
|
|
148
|
+
ta.required = opts.required === true;
|
|
149
|
+
ta.rows = this.ctrl.rows;
|
|
150
|
+
ta.value = this.ctrl.value;
|
|
151
|
+
ta.disabled = this.ctrl.disabled;
|
|
152
|
+
ta.addEventListener('blur', () => {
|
|
153
|
+
this.ctrl.commit(ta.value);
|
|
154
|
+
});
|
|
155
|
+
if (this.autoGrow) ta.addEventListener('input', () => this.grow());
|
|
156
|
+
this.el = h('div', { className: 'vela-textarea', slot: textAreaDef.slot('root'), attrs: textAreaVariants({ size: this.ctrl.size }), data: { autogrow: this.autoGrow } }, ta);
|
|
157
|
+
this.input = ta;
|
|
158
|
+
if (this.autoGrow) this.grow();
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
get value(): string {
|
|
162
|
+
return this.ctrl.value;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
setValue(v: string): void {
|
|
166
|
+
this.ctrl.sync(v);
|
|
167
|
+
this.input.value = v;
|
|
168
|
+
if (this.autoGrow) this.grow();
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
destroy(): void {}
|
|
172
|
+
|
|
173
|
+
private grow(): void {
|
|
174
|
+
const ta = this.input;
|
|
175
|
+
const lh = parseFloat(getComputedStyle(ta).lineHeight) || 18;
|
|
176
|
+
const pad = ta.clientHeight - (ta.offsetHeight ? lh * (ta.rows || 1) : 0);
|
|
177
|
+
const max = lh * this.maxLines + (Number.isFinite(pad) && pad > 0 ? pad : 12);
|
|
178
|
+
ta.style.height = 'auto';
|
|
179
|
+
ta.style.height = `${Math.min(ta.scrollHeight, max)}px`;
|
|
180
|
+
ta.style.overflowY = ta.scrollHeight > max ? 'auto' : 'hidden';
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export function createTextArea(props: TextAreaProps = {}): TextArea {
|
|
185
|
+
return new TextArea(props);
|
|
186
|
+
}
|