@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.
- package/CHANGELOG.md +91 -0
- package/LICENSE +201 -0
- package/NOTICE +28 -0
- package/README.md +86 -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 +55 -0
- package/dist/button.js +11 -0
- package/dist/calendar.d.ts +24 -0
- package/dist/calendar.js +1 -0
- package/dist/callout-bubble.d.ts +103 -0
- package/dist/callout-bubble.js +177 -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-3Q32K4PE.js +85 -0
- package/dist/chunk-6QCILIT2.js +52 -0
- package/dist/chunk-7VMN7NKJ.js +133 -0
- package/dist/chunk-A2FJ7Y7D.js +55 -0
- package/dist/chunk-A72NWYNP.js +26 -0
- package/dist/chunk-B5ZSRUDQ.js +227 -0
- package/dist/chunk-BXMWQIBO.js +66 -0
- package/dist/chunk-C3ICYMI3.js +25 -0
- package/dist/chunk-CC3DDNFC.js +117 -0
- package/dist/chunk-E2FE6V2N.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-GVRX3UAV.js +82 -0
- package/dist/chunk-J2QJATCD.js +12 -0
- package/dist/chunk-LZWZV2ZS.js +18 -0
- package/dist/chunk-MJ4RUGX7.js +403 -0
- package/dist/chunk-MMTMOV6R.js +31 -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-TAKSIV57.js +90 -0
- package/dist/chunk-U3EH42YY.js +72 -0
- package/dist/chunk-V2Q4MRMS.js +573 -0
- package/dist/chunk-VMCR3S2A.js +22 -0
- package/dist/chunk-WBGSYCV2.js +101 -0
- package/dist/chunk-WGULXRWD.js +351 -0
- package/dist/chunk-WXH3EFV5.js +219 -0
- package/dist/chunk-X66RJAIS.js +14 -0
- package/dist/chunk-XBEL4K33.js +142 -0
- package/dist/chunk-Z5PINFQO.js +280 -0
- package/dist/collapsible.d.ts +49 -0
- package/dist/collapsible.js +106 -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 +17 -0
- package/dist/css.js +4 -0
- package/dist/data-table.d.ts +40 -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/h-Bl37qUis.d.ts +24 -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 +51 -0
- package/dist/index.js +13 -0
- package/dist/input-group.d.ts +57 -0
- package/dist/input-group.js +87 -0
- package/dist/input.d.ts +54 -0
- package/dist/input.js +9 -0
- package/dist/item.d.ts +72 -0
- package/dist/item.js +131 -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 +4508 -0
- package/dist/month-grid.d.ts +45 -0
- package/dist/month-grid.js +157 -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/slider.d.ts +46 -0
- package/dist/slider.js +111 -0
- package/dist/sort-button.d.ts +41 -0
- package/dist/sort-button.js +88 -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 +65 -0
- package/dist/tabs.js +155 -0
- package/dist/text-area.d.ts +54 -0
- package/dist/text-area.js +9 -0
- package/dist/theme.d.ts +199 -0
- package/dist/theme.js +8 -0
- package/dist/theme.schema.json +1994 -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 +217 -0
- package/docs/what-to-change.md +20 -0
- package/docs/writing-a-component.md +250 -0
- package/llms.txt +71 -0
- package/package.json +90 -6
- package/registry/badge.ts +119 -0
- package/registry/bar-chart.ts +215 -0
- package/registry/button.ts +379 -0
- package/registry/callout-bubble.ts +347 -0
- package/registry/checkbox.ts +234 -0
- package/registry/collapsible.ts +271 -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/item.ts +376 -0
- package/registry/kbd.ts +64 -0
- package/registry/line-chart.ts +218 -0
- package/registry/month-grid.ts +328 -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/slider.ts +259 -0
- package/registry/sort-button.ts +189 -0
- package/registry/sparkline.ts +114 -0
- package/registry/stat.ts +96 -0
- package/registry/switch.ts +205 -0
- package/registry/tabs.ts +426 -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 +137 -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 +379 -0
- package/src/components/callout-bubble.ts +347 -0
- package/src/components/checkbox.ts +234 -0
- package/src/components/collapsible.ts +271 -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/item.ts +376 -0
- package/src/components/kbd.ts +64 -0
- package/src/components/line-chart.ts +218 -0
- package/src/components/month-grid.ts +328 -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/slider.ts +259 -0
- package/src/components/sort-button.ts +189 -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 +426 -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 +117 -0
- package/src/lib/chart.ts +72 -0
- package/src/lib/color.ts +89 -0
- package/src/lib/component-index.ts +151 -0
- package/src/lib/css.ts +48 -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/scope.ts +135 -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 +664 -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
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/lib/page.ts
|
|
2
|
+
var ROOT = /* @__PURE__ */ Symbol.for("@luxalgo/vela-ui");
|
|
3
|
+
function pageState(name, init) {
|
|
4
|
+
const holder = globalThis;
|
|
5
|
+
const bag = holder[ROOT] ?? (holder[ROOT] = /* @__PURE__ */ Object.create(null));
|
|
6
|
+
if (!(name in bag)) bag[name] = init();
|
|
7
|
+
return bag[name];
|
|
8
|
+
}
|
|
9
|
+
function pageUid(prefix) {
|
|
10
|
+
const counter = pageState("uid@1", () => ({ n: 0 }));
|
|
11
|
+
return `${prefix}-${++counter.n}`;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { pageState, pageUid };
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { injectLayerOrder, injectStyles } from './chunk-2GQIZM5Z.js';
|
|
2
|
+
import { pageState } from './chunk-X66RJAIS.js';
|
|
3
|
+
|
|
4
|
+
// src/lib/scope.ts
|
|
5
|
+
var KIT_SCOPE = ":where(.vela-ui, .vela-ui *, .vela-ui-layer, .vela-ui-layer *, [data-vela-theme], [data-vela-theme] *)";
|
|
6
|
+
var GROUPING = /^@(?:layer|media|supports|container|scope|starting-style)\b/i;
|
|
7
|
+
var LEGACY_PSEUDO_ELEMENT = /^:(?:before|after|first-line|first-letter)(?![\w-])/i;
|
|
8
|
+
var SPACE = /\s/;
|
|
9
|
+
function skipOpaque(text, i) {
|
|
10
|
+
const c = text[i];
|
|
11
|
+
if (c === "\\") return i + 2;
|
|
12
|
+
if (c === '"' || c === "'") {
|
|
13
|
+
let j = i + 1;
|
|
14
|
+
while (j < text.length && text[j] !== c) j += text[j] === "\\" ? 2 : 1;
|
|
15
|
+
return j + 1;
|
|
16
|
+
}
|
|
17
|
+
if (c === "/" && text[i + 1] === "*") {
|
|
18
|
+
const end = text.indexOf("*/", i + 2);
|
|
19
|
+
return end < 0 ? text.length : end + 2;
|
|
20
|
+
}
|
|
21
|
+
return i;
|
|
22
|
+
}
|
|
23
|
+
function withoutComments(text) {
|
|
24
|
+
let out = "";
|
|
25
|
+
for (let i = 0; i < text.length; ) {
|
|
26
|
+
const next = skipOpaque(text, i);
|
|
27
|
+
if (next === i) out += text[i++];
|
|
28
|
+
else {
|
|
29
|
+
if (text[i] !== "/") out += text.slice(i, next);
|
|
30
|
+
i = next;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
function selectorsOf(list) {
|
|
36
|
+
const out = [];
|
|
37
|
+
let depth = 0;
|
|
38
|
+
let start = 0;
|
|
39
|
+
for (let i = 0; i < list.length; ) {
|
|
40
|
+
const next = skipOpaque(list, i);
|
|
41
|
+
if (next !== i) {
|
|
42
|
+
i = next;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
const c = list[i];
|
|
46
|
+
if (c === "(" || c === "[") depth += 1;
|
|
47
|
+
else if (c === ")" || c === "]") depth -= 1;
|
|
48
|
+
else if (c === "," && depth === 0) {
|
|
49
|
+
out.push(list.slice(start, i).trim());
|
|
50
|
+
start = i + 1;
|
|
51
|
+
}
|
|
52
|
+
i += 1;
|
|
53
|
+
}
|
|
54
|
+
out.push(list.slice(start).trim());
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
function scopeSelector(selector) {
|
|
58
|
+
if (!selector || /^[>+~]/.test(selector)) return selector;
|
|
59
|
+
let depth = 0;
|
|
60
|
+
let i = 0;
|
|
61
|
+
while (i < selector.length) {
|
|
62
|
+
const next = skipOpaque(selector, i);
|
|
63
|
+
if (next !== i) {
|
|
64
|
+
i = next;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const c = selector[i];
|
|
68
|
+
if (c === "(" || c === "[") depth += 1;
|
|
69
|
+
else if (c === ")" || c === "]") depth -= 1;
|
|
70
|
+
else if (depth === 0 && (SPACE.test(c) || c === ">" || c === "+" || c === "~")) break;
|
|
71
|
+
else if (depth === 0 && c === ":" && (selector[i + 1] === ":" || LEGACY_PSEUDO_ELEMENT.test(selector.slice(i)))) break;
|
|
72
|
+
i += 1;
|
|
73
|
+
}
|
|
74
|
+
return selector.slice(0, i) + KIT_SCOPE + selector.slice(i);
|
|
75
|
+
}
|
|
76
|
+
function scopeToKit(text) {
|
|
77
|
+
let out = "";
|
|
78
|
+
let copied = 0;
|
|
79
|
+
let start = 0;
|
|
80
|
+
let scoping = true;
|
|
81
|
+
const outer = [];
|
|
82
|
+
for (let i = 0; i < text.length; ) {
|
|
83
|
+
const next = skipOpaque(text, i);
|
|
84
|
+
if (next !== i) {
|
|
85
|
+
i = next;
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
const c = text[i];
|
|
89
|
+
if (c === ";") {
|
|
90
|
+
start = i + 1;
|
|
91
|
+
} else if (c === "{") {
|
|
92
|
+
const prelude = text.slice(start, i);
|
|
93
|
+
const head = withoutComments(prelude).trim();
|
|
94
|
+
outer.push(scoping);
|
|
95
|
+
if (head.startsWith("@")) {
|
|
96
|
+
scoping && (scoping = GROUPING.test(head));
|
|
97
|
+
} else {
|
|
98
|
+
if (scoping && head) {
|
|
99
|
+
const lead = /^\s*/.exec(prelude)[0];
|
|
100
|
+
const trail = /\s*$/.exec(prelude)[0];
|
|
101
|
+
out += text.slice(copied, start) + lead + selectorsOf(head).map(scopeSelector).join(", ") + trail;
|
|
102
|
+
copied = i;
|
|
103
|
+
}
|
|
104
|
+
scoping = false;
|
|
105
|
+
}
|
|
106
|
+
start = i + 1;
|
|
107
|
+
} else if (c === "}") {
|
|
108
|
+
scoping = outer.pop() ?? true;
|
|
109
|
+
start = i + 1;
|
|
110
|
+
}
|
|
111
|
+
i += 1;
|
|
112
|
+
}
|
|
113
|
+
return out + text.slice(copied);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// src/lib/css.ts
|
|
117
|
+
var written = pageState("written-css@1", () => /* @__PURE__ */ new Set());
|
|
118
|
+
function css(strings, ...values) {
|
|
119
|
+
let out = strings[0] ?? "";
|
|
120
|
+
for (let i = 0; i < values.length; i += 1) out += String(values[i]) + (strings[i + 1] ?? "");
|
|
121
|
+
written.add(out);
|
|
122
|
+
return out;
|
|
123
|
+
}
|
|
124
|
+
function isWrittenCss(text) {
|
|
125
|
+
return written.has(text);
|
|
126
|
+
}
|
|
127
|
+
function acceptCss(text) {
|
|
128
|
+
written.add(text);
|
|
129
|
+
}
|
|
130
|
+
function defineStyles(id, text) {
|
|
131
|
+
const injected = /* @__PURE__ */ new WeakMap();
|
|
132
|
+
let scoped;
|
|
133
|
+
return (root = document) => {
|
|
134
|
+
if (injected.get(root)?.isConnected) return;
|
|
135
|
+
injectLayerOrder(root);
|
|
136
|
+
injectStyles(id, scoped ?? (scoped = scopeToKit(text)), root);
|
|
137
|
+
const sheet = root.getElementById?.(id) ?? (root instanceof Document ? null : root.querySelector(`#${CSS.escape(id)}`));
|
|
138
|
+
if (sheet) injected.set(root, sheet);
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export { acceptCss, css, defineStyles, isWrittenCss };
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { variants } from './chunk-LZWZV2ZS.js';
|
|
2
|
+
import { iconEl } from './chunk-G7IQLY3A.js';
|
|
3
|
+
import { openPopoverTrigger, closeOpenPopovers, Popover } from './chunk-B5ZSRUDQ.js';
|
|
4
|
+
import { ownTeardown } from './chunk-A72NWYNP.js';
|
|
5
|
+
import { nextUid, runMachine, normalizeProps, spreadProps } from './chunk-P4MTEMT7.js';
|
|
6
|
+
import { addSlot, h } from './chunk-Q6WTDVH6.js';
|
|
7
|
+
import { defineComponent } from './chunk-VMCR3S2A.js';
|
|
8
|
+
import { css, defineStyles } from './chunk-XBEL4K33.js';
|
|
9
|
+
import { t } from './chunk-6QCILIT2.js';
|
|
10
|
+
import * as zagListbox from '@zag-js/listbox';
|
|
11
|
+
|
|
12
|
+
function selectController(opts) {
|
|
13
|
+
const options = opts.options;
|
|
14
|
+
let value = opts.value ?? opts.defaultValue ?? (opts.placeholder !== void 0 ? "" : options[0]?.value ?? "");
|
|
15
|
+
const size = opts.size ?? "md";
|
|
16
|
+
return {
|
|
17
|
+
options,
|
|
18
|
+
get value() {
|
|
19
|
+
return value;
|
|
20
|
+
},
|
|
21
|
+
size,
|
|
22
|
+
fill: opts.fill ?? size !== "sm",
|
|
23
|
+
disabled: opts.disabled ?? false,
|
|
24
|
+
setValue(v) {
|
|
25
|
+
value = v;
|
|
26
|
+
},
|
|
27
|
+
labelOf(v) {
|
|
28
|
+
return options.find((o) => o.value === v)?.label ?? v;
|
|
29
|
+
},
|
|
30
|
+
pick(v) {
|
|
31
|
+
value = v;
|
|
32
|
+
const label = options.find((o) => o.value === v)?.label ?? v;
|
|
33
|
+
opts.onValueChange?.(v, label);
|
|
34
|
+
opts.onChange?.(v, label);
|
|
35
|
+
return { value: v, label };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
var selectDef = defineComponent({
|
|
40
|
+
name: "select",
|
|
41
|
+
parts: ["root", "trigger", "value", "icon", "sizer", "native", "content", "viewport", "item", "rail", "thumb"],
|
|
42
|
+
settings: { radius: t.radius.md, "content-radius": t.radius.md, "thumb-radius": "2px", "focus-ring": `0 0 0 3px ${t.focus.soft}` }
|
|
43
|
+
});
|
|
44
|
+
var selectVariants = variants({ size: ["md", "sm"] });
|
|
45
|
+
var SELECT_STYLE_ID = "vela-ui-select-3";
|
|
46
|
+
var SELECT_CSS = css`@layer vela.ui{[data-slot=select-trigger]{box-sizing:border-box;border:1px solid ${t.border.strong};border-radius:${selectDef.vars.radius};width:100%;min-width:0;height:34px;color:${t.fg.bright};cursor:pointer;text-align:start;transition:border-color ${t.dur.fast} ease, box-shadow ${t.dur.fast} ease;background:0 0;outline:2px solid #0000;align-items:center;padding-block:0;padding-inline:8px 26px;font-family:inherit;font-size:14px;display:flex}[data-slot=select-trigger]:hover{border-color:${t.fg.muted}}[data-slot=select-trigger]:focus{border-color:${t.focus};box-shadow:${selectDef.vars["focus-ring"]}}[data-slot=select-value]{text-overflow:ellipsis;white-space:nowrap;flex:1;min-width:0;overflow:hidden}[data-slot=select-icon]{inset-inline-end:8px;pointer-events:none;opacity:.55;color:inherit;line-height:0;display:flex;position:absolute;top:50%;transform:translateY(-50%)}[data-slot=select-icon]>span,[data-slot=select-icon] svg{width:12px;height:12px;display:block}[data-slot=select-sizer]{visibility:hidden;height:0;font-size:13px;overflow:hidden}[data-slot=select-sizer] span{white-space:nowrap;border-inline:1px solid #0000;height:0;padding-block:0;padding-inline:8px 26px;display:block}[data-slot=select-viewport]{width:max-content;min-width:100%;max-height:none;overflow:hidden}[data-slot=select-rail]{pointer-events:none;flex:none;width:3px;margin-block:2px;margin-inline:0 1px;position:relative}[data-slot=select-thumb]{border-radius:${selectDef.vars["thumb-radius"]};background:${t.scroll};width:3px}[data-slot=select-item]{white-space:nowrap;text-align:start;border-radius:${t.radius.sm};width:auto;min-width:100%;color:inherit;cursor:pointer;font:inherit;background:0 0;border:none;padding:7px 10px;font-weight:400;display:block}[data-slot=select-item]:hover,[data-slot=select-item][data-highlighted]{background:${t.hover}}[data-slot=select-item][data-checked]{background:${t.hover.strong};color:${t.fg.bright}}[data-slot=select-item][data-checked]:hover,[data-slot=select-item][data-checked][data-highlighted]{background:${t.hover.strong}}[data-slot=select-viewport]:focus{outline:2px solid #0000}[data-slot=select-value][data-placeholder]{color:${t.fg.muted}}[data-slot=select-native]{clip-path:inset(50%);white-space:nowrap;pointer-events:none;border:0;width:1px;height:1px;margin:-1px;padding:0;position:absolute;overflow:hidden}[data-slot=select]{min-width:0;position:relative}[data-slot=select]:where(:not([hidden])){display:inline-block}[data-slot=select][data-fill]{width:100%}[data-slot=select]:not([data-fill]){flex:none;justify-self:start;width:100px}[data-slot=select][data-size=sm] [data-slot=select-trigger]{background:${t.surface.elev};border-radius:${t.radius.sm};height:28px;color:${t.fg};box-shadow:none;font-size:13px}[data-slot=select][data-size=sm] [data-slot=select-trigger]:focus{box-shadow:none;border-color:${t.fg.muted}}[data-slot=select][data-size=sm]:not([data-fill]){width:auto;max-width:200px}[data-slot~=select-content]{background:${t.bg};width:max-content;color:${t.fg};border-radius:${selectDef.vars["content-radius"]};box-shadow:${t.shadow};font:14px ${t.font};border:none;padding:4px;overflow:hidden}[data-slot~=select-content][data-size=sm]{background:${t.surface.overlay};font-size:13px}[data-slot~=select-content][data-scroll]{align-items:stretch;gap:2px;display:flex}[data-slot~=select-content][data-scroll] [data-slot=select-viewport]{scrollbar-width:none;flex:auto;min-width:min-content;max-height:240px;overflow-y:auto}[data-slot~=select-content][data-scroll] [data-slot=select-viewport]::-webkit-scrollbar{width:0;height:0;display:none}}`;
|
|
47
|
+
var injectStyles = defineStyles(SELECT_STYLE_ID, SELECT_CSS);
|
|
48
|
+
function syncThumb(list, thumb) {
|
|
49
|
+
const view = list.clientHeight;
|
|
50
|
+
const total = list.scrollHeight;
|
|
51
|
+
if (total <= view) {
|
|
52
|
+
thumb.style.height = "0";
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const thumbH = Math.max(20, view / total * view);
|
|
56
|
+
const top = list.scrollTop / (total - view) * (view - thumbH);
|
|
57
|
+
thumb.style.height = `${Math.round(thumbH)}px`;
|
|
58
|
+
thumb.style.transform = `translateY(${Math.round(top)}px`;
|
|
59
|
+
}
|
|
60
|
+
function fillSelectList(menu, options, current, onPick) {
|
|
61
|
+
injectStyles(menu.ownerDocument);
|
|
62
|
+
addSlot(menu, selectDef.slot("content"));
|
|
63
|
+
let picked = false;
|
|
64
|
+
const choose = (value) => {
|
|
65
|
+
const option = options.find((o) => o.value === value);
|
|
66
|
+
if (picked || !option) return;
|
|
67
|
+
picked = true;
|
|
68
|
+
onPick(option.value, option.label);
|
|
69
|
+
};
|
|
70
|
+
const items = options.map(
|
|
71
|
+
(p) => h("button", {
|
|
72
|
+
className: "vela-select-item",
|
|
73
|
+
slot: selectDef.slot("item"),
|
|
74
|
+
attrs: { type: "button", tabindex: -1 },
|
|
75
|
+
data: { checked: p.value === current ? "1" : null },
|
|
76
|
+
text: p.label,
|
|
77
|
+
on: {
|
|
78
|
+
click: (e) => {
|
|
79
|
+
e.stopPropagation();
|
|
80
|
+
choose(p.value);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
})
|
|
84
|
+
);
|
|
85
|
+
const viewport = h("div", { className: "vela-select-items", slot: selectDef.slot("viewport") }, items);
|
|
86
|
+
menu.replaceChildren(viewport);
|
|
87
|
+
const mid = nextUid("vela-select-list");
|
|
88
|
+
const known = options.some((o) => o.value === current);
|
|
89
|
+
const machine2 = runMachine(
|
|
90
|
+
zagListbox.machine,
|
|
91
|
+
{
|
|
92
|
+
id: mid,
|
|
93
|
+
collection: zagListbox.collection({ items: options, itemToValue: (o) => o.value, itemToString: (o) => o.label }),
|
|
94
|
+
selectionMode: "single",
|
|
95
|
+
defaultValue: known ? [current] : [],
|
|
96
|
+
defaultHighlightedValue: known ? current : null,
|
|
97
|
+
// The keyboard's pick (Enter) arrives here, a beat after the key.
|
|
98
|
+
onSelect: ({ value }) => choose(value)
|
|
99
|
+
},
|
|
100
|
+
(service) => {
|
|
101
|
+
const api = zagListbox.connect(service, normalizeProps);
|
|
102
|
+
spreadProps(viewport, api.getContentProps(), mid);
|
|
103
|
+
options.forEach((item, i) => spreadProps(items[i], api.getItemProps({ item, highlightOnHover: true }), mid));
|
|
104
|
+
}
|
|
105
|
+
);
|
|
106
|
+
viewport.addEventListener("keydown", (e) => {
|
|
107
|
+
if (e.key === "Enter" || e.key === " ") e.preventDefault();
|
|
108
|
+
});
|
|
109
|
+
return () => machine2.stop();
|
|
110
|
+
}
|
|
111
|
+
function decorateSelectScroll(menu) {
|
|
112
|
+
const list = menu.querySelector(`[data-slot='${selectDef.slot("viewport")}']`);
|
|
113
|
+
if (!list) return;
|
|
114
|
+
if (list.scrollHeight > 240) {
|
|
115
|
+
menu.classList.add("is-scroll");
|
|
116
|
+
menu.dataset.scroll = "";
|
|
117
|
+
const thumb = h("div", { className: "vela-select-thumb", slot: selectDef.slot("thumb") });
|
|
118
|
+
menu.appendChild(h("div", { className: "vela-select-rail", slot: selectDef.slot("rail") }, thumb));
|
|
119
|
+
list.addEventListener("scroll", () => syncThumb(list, thumb));
|
|
120
|
+
syncThumb(list, thumb);
|
|
121
|
+
}
|
|
122
|
+
menu.querySelector(`[data-slot='${selectDef.slot("item")}'][data-checked]`)?.scrollIntoView({ block: "nearest" });
|
|
123
|
+
list.dispatchEvent(new Event("scroll"));
|
|
124
|
+
}
|
|
125
|
+
function toggleSelectList(trigger, options, current, onPick, opts = {}) {
|
|
126
|
+
if (openPopoverTrigger() === trigger) {
|
|
127
|
+
closeOpenPopovers();
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
return openSelectList(trigger, options, current, onPick, opts);
|
|
131
|
+
}
|
|
132
|
+
function openSelectList(trigger, options, current, onPick, opts = {}) {
|
|
133
|
+
injectStyles(trigger.ownerDocument);
|
|
134
|
+
closeOpenPopovers();
|
|
135
|
+
let dispose = null;
|
|
136
|
+
const pop = new Popover({
|
|
137
|
+
trigger,
|
|
138
|
+
theme: opts.theme,
|
|
139
|
+
matchWidth: opts.matchWidth ?? true,
|
|
140
|
+
collisionBoundary: opts.collisionBoundary ?? opts.boundary,
|
|
141
|
+
boundaryInset: opts.boundaryInset,
|
|
142
|
+
side: opts.side,
|
|
143
|
+
sideOffset: opts.sideOffset ?? opts.gap ?? 4,
|
|
144
|
+
align: opts.align ?? "start",
|
|
145
|
+
alignOffset: opts.alignOffset,
|
|
146
|
+
avoidCollisions: opts.avoidCollisions,
|
|
147
|
+
collisionPadding: opts.collisionPadding,
|
|
148
|
+
host: opts.host,
|
|
149
|
+
position: opts.position,
|
|
150
|
+
zIndex: opts.zIndex,
|
|
151
|
+
className: "vela-select-list",
|
|
152
|
+
slot: selectDef.slot("content"),
|
|
153
|
+
onClose: () => {
|
|
154
|
+
dispose?.();
|
|
155
|
+
dispose = null;
|
|
156
|
+
const active = trigger.ownerDocument.activeElement;
|
|
157
|
+
if (opts.focusList && (!active || active === trigger.ownerDocument.body || pop.el.contains(active))) trigger.focus({ preventScroll: true });
|
|
158
|
+
opts.onClose?.();
|
|
159
|
+
},
|
|
160
|
+
content: (el) => {
|
|
161
|
+
if (opts.size) el.dataset.size = opts.size;
|
|
162
|
+
dispose = fillSelectList(el, options, current, (value, label) => {
|
|
163
|
+
pop.hide();
|
|
164
|
+
onPick(value, label);
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
pop.show();
|
|
169
|
+
decorateSelectScroll(pop.el);
|
|
170
|
+
pop.reposition();
|
|
171
|
+
if (opts.focusList) pop.el.querySelector(`[data-slot='${selectDef.slot("viewport")}']`)?.focus({ preventScroll: true });
|
|
172
|
+
return pop;
|
|
173
|
+
}
|
|
174
|
+
var Select = class {
|
|
175
|
+
constructor(opts) {
|
|
176
|
+
this.list = null;
|
|
177
|
+
const doc = opts.list?.host?.ownerDocument ?? document;
|
|
178
|
+
injectStyles(doc);
|
|
179
|
+
this.ctrl = selectController(opts);
|
|
180
|
+
const placed = Object.fromEntries(
|
|
181
|
+
["side", "align", "sideOffset", "alignOffset", "avoidCollisions", "collisionPadding", "collisionBoundary"].filter((k) => opts[k] !== void 0).map((k) => [k, opts[k]])
|
|
182
|
+
);
|
|
183
|
+
this.listOpts = { ...opts.list, ...placed, theme: opts.theme ?? opts.list?.theme, size: this.ctrl.size };
|
|
184
|
+
this.placeholder = opts.placeholder;
|
|
185
|
+
const label = h("span", { className: "vela-select-label", slot: selectDef.slot("value") });
|
|
186
|
+
const btn = h(
|
|
187
|
+
"button",
|
|
188
|
+
{
|
|
189
|
+
className: "vela-select-trigger",
|
|
190
|
+
slot: selectDef.slot("trigger"),
|
|
191
|
+
attrs: { type: "button", id: opts.id, "aria-haspopup": "listbox", "aria-expanded": "false", "aria-required": opts.required ? "true" : void 0 }
|
|
192
|
+
},
|
|
193
|
+
label,
|
|
194
|
+
h("span", { className: "vela-select-chevron", slot: selectDef.slot("icon") }, iconEl("chevron-down", doc))
|
|
195
|
+
);
|
|
196
|
+
btn.disabled = this.ctrl.disabled;
|
|
197
|
+
const sizer = this.ctrl.size === "sm" ? h(
|
|
198
|
+
"div",
|
|
199
|
+
{ className: "vela-select-sizer", slot: selectDef.slot("sizer"), attrs: { "aria-hidden": "true" } },
|
|
200
|
+
this.ctrl.options.map((o) => h("span", { text: o.label }))
|
|
201
|
+
) : null;
|
|
202
|
+
this.native = opts.name !== void 0 ? h(
|
|
203
|
+
"select",
|
|
204
|
+
{ slot: selectDef.slot("native"), attrs: { name: opts.name, "aria-hidden": "true", tabindex: -1 } },
|
|
205
|
+
opts.placeholder !== void 0 ? h("option", { attrs: { value: "" } }) : null,
|
|
206
|
+
this.ctrl.options.map((o) => h("option", { attrs: { value: o.value }, text: o.label }))
|
|
207
|
+
) : null;
|
|
208
|
+
if (this.native) {
|
|
209
|
+
this.native.required = opts.required === true;
|
|
210
|
+
this.native.disabled = this.ctrl.disabled;
|
|
211
|
+
}
|
|
212
|
+
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);
|
|
213
|
+
btn.addEventListener("pointerdown", (e) => {
|
|
214
|
+
e.preventDefault();
|
|
215
|
+
btn.focus({ preventScroll: true });
|
|
216
|
+
});
|
|
217
|
+
btn.addEventListener("click", (e) => {
|
|
218
|
+
e.stopPropagation();
|
|
219
|
+
this.toggle();
|
|
220
|
+
});
|
|
221
|
+
btn.addEventListener("keydown", (e) => {
|
|
222
|
+
if ((e.key === "ArrowDown" || e.key === "ArrowUp") && !this.list) {
|
|
223
|
+
e.preventDefault();
|
|
224
|
+
this.toggle();
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
this.trigger = btn;
|
|
228
|
+
this.labelEl = label;
|
|
229
|
+
this.paint();
|
|
230
|
+
this.release = ownTeardown(this.el, () => {
|
|
231
|
+
this.list?.hide();
|
|
232
|
+
this.list = null;
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
get value() {
|
|
236
|
+
return this.ctrl.value;
|
|
237
|
+
}
|
|
238
|
+
setValue(v) {
|
|
239
|
+
this.ctrl.setValue(v);
|
|
240
|
+
this.paint();
|
|
241
|
+
}
|
|
242
|
+
/** The trigger shows the picked option's label, or the placeholder while none is picked. */
|
|
243
|
+
paint() {
|
|
244
|
+
const v = this.ctrl.value;
|
|
245
|
+
const empty = this.placeholder !== void 0 && !this.ctrl.options.some((o) => o.value === v);
|
|
246
|
+
this.labelEl.textContent = empty ? this.placeholder ?? "" : this.ctrl.labelOf(v);
|
|
247
|
+
this.labelEl.toggleAttribute("data-placeholder", empty);
|
|
248
|
+
if (this.native) this.native.value = empty ? "" : v;
|
|
249
|
+
}
|
|
250
|
+
toggle() {
|
|
251
|
+
this.list = toggleSelectList(
|
|
252
|
+
this.trigger,
|
|
253
|
+
this.ctrl.options,
|
|
254
|
+
this.ctrl.value,
|
|
255
|
+
(value) => {
|
|
256
|
+
this.ctrl.pick(value);
|
|
257
|
+
this.paint();
|
|
258
|
+
this.list = null;
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
...this.listOpts,
|
|
262
|
+
focusList: true,
|
|
263
|
+
onClose: () => {
|
|
264
|
+
this.list = null;
|
|
265
|
+
this.trigger.setAttribute("aria-expanded", "false");
|
|
266
|
+
this.listOpts.onClose?.();
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
);
|
|
270
|
+
this.trigger.setAttribute("aria-expanded", String(this.list !== null));
|
|
271
|
+
}
|
|
272
|
+
destroy() {
|
|
273
|
+
this.release();
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
function createSelect(props) {
|
|
277
|
+
return new Select(props);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export { SELECT_CSS, SELECT_STYLE_ID, Select, createSelect, decorateSelectScroll, fillSelectList, openSelectList, selectController, selectDef, selectVariants, toggleSelectList };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { a as VariantProps, V as VariantFn } from './variants-B4stUBnY.js';
|
|
2
|
+
import { C as ComponentDef } from './define-D5u3F5Dj.js';
|
|
3
|
+
import './t.js';
|
|
4
|
+
|
|
5
|
+
declare const collapsibleDef: ComponentDef<"collapsible", "root" | "count" | "title" | "icon" | "trigger" | "content" | "chevron", "radius" | "trigger-height">;
|
|
6
|
+
declare const collapsibleVariants: VariantFn<{
|
|
7
|
+
readonly variant: readonly ["default", "label"];
|
|
8
|
+
}>;
|
|
9
|
+
type CollapsibleVariant = (typeof collapsibleVariants.spec.variant)[number];
|
|
10
|
+
interface CollapsibleProps extends VariantProps<typeof collapsibleVariants> {
|
|
11
|
+
/** The header's text. Without `trigger`, the collapsible draws its header with it. */
|
|
12
|
+
title?: string;
|
|
13
|
+
/** After the title, muted: a count, a total. Null shows none. */
|
|
14
|
+
count?: string | number | null;
|
|
15
|
+
/** Icon id from the kit's registry, before the title. */
|
|
16
|
+
icon?: string;
|
|
17
|
+
/** A host element that toggles the content instead of the header (a row's chevron
|
|
18
|
+
* button): it gets `aria-expanded`, `aria-controls` and `data-state`, and a click on it
|
|
19
|
+
* toggles. The root then holds only the content. */
|
|
20
|
+
trigger?: HTMLElement;
|
|
21
|
+
/** The content, or a function that fills the content element. */
|
|
22
|
+
content?: Node | ((content: HTMLElement) => void);
|
|
23
|
+
/** Open when created (default closed). */
|
|
24
|
+
defaultOpen?: boolean;
|
|
25
|
+
/** Opened or closed by the user. */
|
|
26
|
+
onOpenChange?: (open: boolean) => void;
|
|
27
|
+
disabled?: boolean;
|
|
28
|
+
/** Extra class names (layout hooks). */
|
|
29
|
+
className?: string;
|
|
30
|
+
}
|
|
31
|
+
interface CollapsibleHandle {
|
|
32
|
+
readonly el: HTMLElement;
|
|
33
|
+
/** What toggles it: its header, or the host's `trigger`. */
|
|
34
|
+
readonly trigger: HTMLElement;
|
|
35
|
+
/** The element that holds the content. */
|
|
36
|
+
readonly content: HTMLElement;
|
|
37
|
+
readonly open: boolean;
|
|
38
|
+
/** Open or close it without calling `onOpenChange`. */
|
|
39
|
+
setOpen(open: boolean): void;
|
|
40
|
+
/** A new header text (its own header only). */
|
|
41
|
+
setTitle(title: string): void;
|
|
42
|
+
/** A new count (its own header only); null hides it. */
|
|
43
|
+
setCount(count: string | number | null): void;
|
|
44
|
+
setDisabled(disabled: boolean): void;
|
|
45
|
+
destroy(): void;
|
|
46
|
+
}
|
|
47
|
+
declare function createCollapsible(props?: CollapsibleProps): CollapsibleHandle;
|
|
48
|
+
|
|
49
|
+
export { type CollapsibleHandle, type CollapsibleProps, type CollapsibleVariant, collapsibleDef, collapsibleVariants, createCollapsible };
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { variants } from './chunk-LZWZV2ZS.js';
|
|
2
|
+
import { iconEl } from './chunk-G7IQLY3A.js';
|
|
3
|
+
import { nextUid } from './chunk-P4MTEMT7.js';
|
|
4
|
+
import { h } from './chunk-Q6WTDVH6.js';
|
|
5
|
+
import { defineComponent } from './chunk-VMCR3S2A.js';
|
|
6
|
+
import { defineStyles, css } from './chunk-XBEL4K33.js';
|
|
7
|
+
import './chunk-2GQIZM5Z.js';
|
|
8
|
+
import './chunk-BXMWQIBO.js';
|
|
9
|
+
import './chunk-X66RJAIS.js';
|
|
10
|
+
import { t } from './chunk-6QCILIT2.js';
|
|
11
|
+
|
|
12
|
+
// src/components/collapsible.ts
|
|
13
|
+
var collapsibleDef = defineComponent({
|
|
14
|
+
name: "collapsible",
|
|
15
|
+
parts: ["root", "trigger", "icon", "title", "count", "chevron", "content"],
|
|
16
|
+
settings: { "trigger-height": "36px", radius: t.radius.md }
|
|
17
|
+
});
|
|
18
|
+
var collapsibleVariants = variants({ variant: ["default", "label"] });
|
|
19
|
+
var injectStyles = defineStyles(
|
|
20
|
+
"vela-ui-collapsible",
|
|
21
|
+
css`@layer vela.ui{[data-slot=collapsible]{min-width:0}[data-slot=collapsible-trigger]:where(:not([hidden])){all:unset;box-sizing:border-box;cursor:pointer;-webkit-user-select:none;user-select:none;-webkit-tap-highlight-color:transparent;align-items:center;gap:8px;width:100%;display:flex}[data-slot=collapsible-trigger]:where(:not([hidden])):focus-visible{outline:2px solid ${t.focus};outline-offset:-2px}[data-slot=collapsible-trigger]:where(:not([hidden]))[data-disabled]{cursor:default;opacity:.5}[data-slot=collapsible-trigger]:where(:not([hidden]))[data-variant=default]{min-height:${collapsibleDef.vars["trigger-height"]};border-radius:${collapsibleDef.vars.radius};color:${t.fg.bright};transition:background ${t.dur.fast} ease;padding:0 12px;font-size:13px;font-weight:600}[data-slot=collapsible-trigger]:where(:not([hidden]))[data-variant=default]:not([data-disabled]):hover{background:${t.hover}}[data-slot=collapsible-trigger]:where(:not([hidden]))[data-variant=label]{color:${t.fg.muted};letter-spacing:.08em;text-transform:uppercase;transition:color ${t.dur.fast} ease;gap:6px;padding:10px 4px 4px;font-size:10px;font-weight:700}[data-slot=collapsible-trigger]:where(:not([hidden]))[data-variant=label]:not([data-disabled]):hover{color:${t.fg}}[data-slot=collapsible-title]{text-overflow:ellipsis;white-space:nowrap;min-width:0;overflow:hidden}[data-slot=collapsible-count]{color:${t.fg.muted};font-variant-numeric:tabular-nums;flex:none;font-size:12px;font-weight:400}[data-slot=collapsible-count]:is([data-variant=label]>*){color:${t.fg.faint};font-size:inherit;letter-spacing:0;font-weight:600}[data-slot~=collapsible-icon],[data-slot~=collapsible-chevron]{flex:none;width:1em;height:1em;font-size:16px;line-height:0}:is([data-slot~=collapsible-icon],[data-slot~=collapsible-chevron])>svg{width:100%;height:100%}[data-slot=collapsible-chevron]{color:${t.fg.muted};transition:transform ${t.dur.med} ease;font-size:14px}[data-slot=collapsible-chevron]:is([data-variant=default]>*){margin-inline-start:auto}[data-slot=collapsible-chevron]:is([data-variant=label]>*){color:inherit;font-size:12px}[data-slot=collapsible-chevron]:is([data-variant=default][data-state=open]>*){transform:rotate(180deg)}[data-slot=collapsible-chevron]:is([data-variant=label][data-state=closed]>*){transform:rotate(-90deg)}[data-slot=collapsible-chevron]:is([data-variant=label][data-state=closed]>*):is(:lang(ae),:lang(ar),:lang(arc),:lang(bcc),:lang(bqi),:lang(ckb),:lang(dv),:lang(fa),:lang(glk),:lang(he),:lang(ku),:lang(mzn),:lang(nqo),:lang(pnb),:lang(ps),:lang(sd),:lang(ug),:lang(ur),:lang(yi)){transform:rotate(90deg)}}`
|
|
22
|
+
);
|
|
23
|
+
var CollapsibleImpl = class {
|
|
24
|
+
constructor(props) {
|
|
25
|
+
this.props = props;
|
|
26
|
+
this.countEl = null;
|
|
27
|
+
this.onClick = () => {
|
|
28
|
+
if (this.disabled) return;
|
|
29
|
+
this.paint(!this.isOpen);
|
|
30
|
+
this.props.onOpenChange?.(this.isOpen);
|
|
31
|
+
};
|
|
32
|
+
injectStyles(document);
|
|
33
|
+
const variant = collapsibleVariants.resolve(props).variant;
|
|
34
|
+
this.isOpen = props.defaultOpen ?? false;
|
|
35
|
+
this.disabled = props.disabled ?? false;
|
|
36
|
+
const id = nextUid("vela-collapsible");
|
|
37
|
+
this.content = h("div", { slot: collapsibleDef.slot("content"), attrs: { id } });
|
|
38
|
+
if (props.content instanceof Node) this.content.appendChild(props.content);
|
|
39
|
+
else props.content?.(this.content);
|
|
40
|
+
this.own = !props.trigger;
|
|
41
|
+
if (props.trigger) {
|
|
42
|
+
this.trigger = props.trigger;
|
|
43
|
+
this.titleEl = null;
|
|
44
|
+
} else {
|
|
45
|
+
let icon = null;
|
|
46
|
+
if (props.icon) {
|
|
47
|
+
icon = iconEl(props.icon, document);
|
|
48
|
+
icon.dataset.slot = collapsibleDef.slot("icon");
|
|
49
|
+
}
|
|
50
|
+
const chevron = iconEl("chevron-down", document);
|
|
51
|
+
chevron.dataset.slot = collapsibleDef.slot("chevron");
|
|
52
|
+
this.titleEl = h("span", { slot: collapsibleDef.slot("title"), text: props.title ?? "" });
|
|
53
|
+
this.trigger = h(
|
|
54
|
+
"button",
|
|
55
|
+
{ slot: collapsibleDef.slot("trigger"), data: { variant }, attrs: { type: "button" } },
|
|
56
|
+
variant === "label" ? chevron : null,
|
|
57
|
+
icon,
|
|
58
|
+
this.titleEl,
|
|
59
|
+
variant === "label" ? null : chevron
|
|
60
|
+
);
|
|
61
|
+
this.setCount(props.count ?? null);
|
|
62
|
+
}
|
|
63
|
+
this.trigger.setAttribute("aria-controls", id);
|
|
64
|
+
this.trigger.addEventListener("click", this.onClick);
|
|
65
|
+
this.el = h("div", { className: props.className, slot: collapsibleDef.slot("root"), data: { variant } }, this.own ? this.trigger : null, this.content);
|
|
66
|
+
this.paint(this.isOpen);
|
|
67
|
+
this.setDisabled(this.disabled);
|
|
68
|
+
}
|
|
69
|
+
get open() {
|
|
70
|
+
return this.isOpen;
|
|
71
|
+
}
|
|
72
|
+
setOpen(open) {
|
|
73
|
+
this.paint(open);
|
|
74
|
+
}
|
|
75
|
+
setTitle(title) {
|
|
76
|
+
if (this.titleEl) this.titleEl.textContent = title;
|
|
77
|
+
}
|
|
78
|
+
setCount(count) {
|
|
79
|
+
if (!this.own) return;
|
|
80
|
+
this.countEl?.remove();
|
|
81
|
+
this.countEl = count === null || count === "" ? null : h("span", { slot: collapsibleDef.slot("count"), text: String(count) });
|
|
82
|
+
if (this.countEl) this.titleEl.after(this.countEl);
|
|
83
|
+
}
|
|
84
|
+
setDisabled(disabled) {
|
|
85
|
+
this.disabled = disabled;
|
|
86
|
+
this.trigger.toggleAttribute("data-disabled", disabled);
|
|
87
|
+
if (this.trigger instanceof HTMLButtonElement) this.trigger.disabled = disabled;
|
|
88
|
+
else if (disabled) this.trigger.setAttribute("aria-disabled", "true");
|
|
89
|
+
else this.trigger.removeAttribute("aria-disabled");
|
|
90
|
+
}
|
|
91
|
+
destroy() {
|
|
92
|
+
this.trigger.removeEventListener("click", this.onClick);
|
|
93
|
+
}
|
|
94
|
+
paint(open) {
|
|
95
|
+
this.isOpen = open;
|
|
96
|
+
const state = open ? "open" : "closed";
|
|
97
|
+
this.trigger.setAttribute("aria-expanded", String(open));
|
|
98
|
+
for (const el of [this.trigger, this.content, this.el]) el?.setAttribute("data-state", state);
|
|
99
|
+
this.content.hidden = !open;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
function createCollapsible(props = {}) {
|
|
103
|
+
return new CollapsibleImpl(props);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export { collapsibleDef, collapsibleVariants, createCollapsible };
|