@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
package/dist/stat.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { V as VariantFn, a as VariantProps } from './variants-B4stUBnY.js';
|
|
2
|
+
import { C as ComponentDef } from './define-D5u3F5Dj.js';
|
|
3
|
+
import './t.js';
|
|
4
|
+
|
|
5
|
+
declare const statDef: ComponentDef<"stat", "root" | "label" | "sub" | "value", never>;
|
|
6
|
+
declare const statVariants: VariantFn<{
|
|
7
|
+
readonly tone: readonly ["neutral", "profit", "loss"];
|
|
8
|
+
}>;
|
|
9
|
+
type StatTone = (typeof statVariants.spec.tone)[number];
|
|
10
|
+
interface StatProps extends VariantProps<typeof statVariants> {
|
|
11
|
+
label: string;
|
|
12
|
+
/** The figure (default `—`). */
|
|
13
|
+
value?: string;
|
|
14
|
+
/** A line under the figure (a count, a percentage). */
|
|
15
|
+
sub?: string;
|
|
16
|
+
/** Extra class names (layout hooks). */
|
|
17
|
+
className?: string;
|
|
18
|
+
}
|
|
19
|
+
interface StatHandle {
|
|
20
|
+
readonly el: HTMLElement;
|
|
21
|
+
/** A new figure, its tone and its line (`null` hides the line). */
|
|
22
|
+
set(value: string, tone?: StatTone, sub?: string | null): void;
|
|
23
|
+
destroy(): void;
|
|
24
|
+
}
|
|
25
|
+
/** The tone of a signed figure: a gain, a loss, or neither. */
|
|
26
|
+
declare function toneOf(n: number): StatTone;
|
|
27
|
+
declare function createStat(props: StatProps): StatHandle;
|
|
28
|
+
|
|
29
|
+
export { type StatHandle, type StatProps, type StatTone, createStat, statDef, statVariants, toneOf };
|
package/dist/stat.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { variants } from './chunk-LZWZV2ZS.js';
|
|
2
|
+
import { h } from './chunk-Q6WTDVH6.js';
|
|
3
|
+
import { defineComponent } from './chunk-VMCR3S2A.js';
|
|
4
|
+
import { defineStyles, css } from './chunk-XBEL4K33.js';
|
|
5
|
+
import './chunk-2GQIZM5Z.js';
|
|
6
|
+
import './chunk-BXMWQIBO.js';
|
|
7
|
+
import './chunk-X66RJAIS.js';
|
|
8
|
+
import { t } from './chunk-6QCILIT2.js';
|
|
9
|
+
|
|
10
|
+
// src/components/stat.ts
|
|
11
|
+
var statDef = defineComponent({
|
|
12
|
+
name: "stat",
|
|
13
|
+
parts: ["root", "label", "value", "sub"]
|
|
14
|
+
});
|
|
15
|
+
var statVariants = variants({ tone: ["neutral", "profit", "loss"] });
|
|
16
|
+
function toneOf(n) {
|
|
17
|
+
return n > 0 ? "profit" : n < 0 ? "loss" : "neutral";
|
|
18
|
+
}
|
|
19
|
+
var injectStyles = defineStyles(
|
|
20
|
+
"vela-ui-stat",
|
|
21
|
+
css`@layer vela.ui{[data-slot=stat]:where(:not([hidden])){flex-direction:column;gap:3px;min-width:0;display:flex}[data-slot=stat-label]{color:${t.fg.muted};white-space:nowrap;text-overflow:ellipsis;font-size:11px;overflow:hidden}[data-slot=stat-value]{color:${t.fg.bright};font-variant-numeric:tabular-nums;white-space:nowrap;font-size:14px;font-weight:600}[data-slot=stat-value]:is([data-tone=profit]>*){color:${t.profit}}[data-slot=stat-value]:is([data-tone=loss]>*){color:${t.loss}}[data-slot=stat-sub]{color:${t.fg.muted};font-variant-numeric:tabular-nums;font-size:11px}}`
|
|
22
|
+
);
|
|
23
|
+
function createStat(props) {
|
|
24
|
+
injectStyles(document);
|
|
25
|
+
const value = h("span", { slot: statDef.slot("value"), text: props.value ?? "\u2014" });
|
|
26
|
+
const sub = h("span", { slot: statDef.slot("sub"), text: props.sub ?? "" });
|
|
27
|
+
sub.hidden = !props.sub;
|
|
28
|
+
const el = h("div", { className: props.className, slot: statDef.slot("root"), attrs: statVariants(props) }, h("span", { slot: statDef.slot("label"), text: props.label }), value, sub);
|
|
29
|
+
return {
|
|
30
|
+
el,
|
|
31
|
+
set(next, tone = "neutral", line = null) {
|
|
32
|
+
value.textContent = next;
|
|
33
|
+
el.setAttribute("data-tone", tone);
|
|
34
|
+
sub.textContent = line ?? "";
|
|
35
|
+
sub.hidden = !line;
|
|
36
|
+
},
|
|
37
|
+
destroy: () => el.remove()
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { createStat, statDef, statVariants, toneOf };
|
package/dist/styles.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export { withAlpha } from './color.js';
|
|
2
|
+
|
|
3
|
+
/** The kit's scrollbar on `selector`, for a scroller outside a kit host (inside one, every
|
|
4
|
+
* scroller already has it). `width` overrides the `--vela-scroll-size` token, in px. */
|
|
5
|
+
declare function overlayScrollbarCss(selector: string, width?: number): string;
|
|
6
|
+
/** Focus ring shared by typeable fields (combo inputs, textareas). */
|
|
7
|
+
declare const FIELD_FOCUS_CSS = "outline:none;transition:border-color .12s ease,box-shadow .12s ease;";
|
|
8
|
+
declare const FIELD_FOCUS_RING = "border-color:var(--vela-focus);box-shadow:0 0 0 3px var(--vela-focus-soft);";
|
|
9
|
+
/** The kit's cascade layers, lowest first. Declared before any layered sheet, so a host's
|
|
10
|
+
* own unlayered CSS beats every one of them without `!important`. */
|
|
11
|
+
declare const LAYER_ORDER = "@layer vela.theme, vela.ui, vela.chrome, vela.pro, vela.custom;";
|
|
12
|
+
/**
|
|
13
|
+
* Declare the layer order in a root, ahead of every Vela sheet already there: a layer's rank
|
|
14
|
+
* is its first appearance. It goes before the first `vela…` sheet rather than first in the
|
|
15
|
+
* head, so layers a host declared earlier (a framework's base styles) stay below Vela's.
|
|
16
|
+
*/
|
|
17
|
+
declare function injectLayerOrder(root?: Document | ShadowRoot): void;
|
|
18
|
+
/** Inject a stylesheet once per root (document or shadow root). Idempotent by id; returns
|
|
19
|
+
* the sheet's element. */
|
|
20
|
+
declare function injectStyles(id: string, css: string, root?: Document | ShadowRoot): HTMLStyleElement | null;
|
|
21
|
+
|
|
22
|
+
export { FIELD_FOCUS_CSS, FIELD_FOCUS_RING, LAYER_ORDER, injectLayerOrder, injectStyles, overlayScrollbarCss };
|
package/dist/styles.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Dispatched on a surface's element once it is shown. */
|
|
2
|
+
declare const SURFACE_OPEN_EVENT = "vela:surface-open";
|
|
3
|
+
/** Dispatched on a surface's element as it starts to close, before it hides or leaves the DOM. */
|
|
4
|
+
declare const SURFACE_CLOSE_EVENT = "vela:surface-close";
|
|
5
|
+
/** What opened or closed: a menu (submenus included), a popover (select lists, color
|
|
6
|
+
* pickers, mark cards, the layout picker), a dialog, a drawer, or a side panel. */
|
|
7
|
+
type SurfaceKind = 'menu' | 'popover' | 'dialog' | 'drawer' | 'panel';
|
|
8
|
+
/** The `detail` of a {@link SURFACE_OPEN_EVENT} / {@link SURFACE_CLOSE_EVENT} event. */
|
|
9
|
+
interface SurfaceEventDetail {
|
|
10
|
+
kind: SurfaceKind;
|
|
11
|
+
/** The element that opened it, when there is one (a menu's button, a popover's trigger). */
|
|
12
|
+
trigger: HTMLElement | null;
|
|
13
|
+
}
|
|
14
|
+
/** Announce that `el` opened or is closing. Bubbles and crosses shadow roots. */
|
|
15
|
+
declare function announceSurface(el: HTMLElement, open: boolean, kind: SurfaceKind, trigger?: HTMLElement | null): void;
|
|
16
|
+
|
|
17
|
+
export { SURFACE_CLOSE_EVENT, SURFACE_OPEN_EVENT, type SurfaceEventDetail, type SurfaceKind, announceSurface };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SURFACE_CLOSE_EVENT, SURFACE_OPEN_EVENT, announceSurface } from './chunk-J2QJATCD.js';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** The longest a close waits for its exit animation before it completes anyway. */
|
|
2
|
+
declare const SURFACE_EXIT_CAP_MS = 1000;
|
|
3
|
+
/** A close held for its exit animation. */
|
|
4
|
+
interface SurfaceExit {
|
|
5
|
+
/** The surface reopened: unmark it and make it interactive again, without completing the close. */
|
|
6
|
+
cancel(): void;
|
|
7
|
+
/** Complete the close now (a teardown cannot wait for the animation). */
|
|
8
|
+
finish(): void;
|
|
9
|
+
}
|
|
10
|
+
interface SurfaceExitOptions {
|
|
11
|
+
/** Elements to keep inert during the exit without marking them — a full-viewport
|
|
12
|
+
* positioner around the surface must not swallow clicks meant for the page. */
|
|
13
|
+
inert?: readonly HTMLElement[];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Close `els` (one surface, or a surface and its scrim) through their exit animation, then
|
|
17
|
+
* run `done` — the caller's hide or removal. The elements get `data-closing` and turn inert;
|
|
18
|
+
* `done` runs once every finite CSS animation or transition that attribute started on them
|
|
19
|
+
* or their descendants has finished, or after {@link SURFACE_EXIT_CAP_MS}, whichever comes
|
|
20
|
+
* first. Returns null when the close completed synchronously (no exit animation started, or
|
|
21
|
+
* the DOM cannot report animations); otherwise the handle to cancel or finish the exit.
|
|
22
|
+
*/
|
|
23
|
+
declare function holdForExit(els: HTMLElement | readonly HTMLElement[], done: () => void, opts?: SurfaceExitOptions): SurfaceExit | null;
|
|
24
|
+
|
|
25
|
+
export { SURFACE_EXIT_CAP_MS, type SurfaceExit, type SurfaceExitOptions, holdForExit };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SURFACE_EXIT_CAP_MS, holdForExit } from './chunk-S7USVSYP.js';
|
package/dist/switch.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { V as VariantFn } from './variants-B4stUBnY.js';
|
|
2
|
+
import { C as ComponentDef } from './define-D5u3F5Dj.js';
|
|
3
|
+
import './t.js';
|
|
4
|
+
|
|
5
|
+
type SwitchSize = 'default' | 'sm';
|
|
6
|
+
type SwitchVariant = 'default' | 'destructive';
|
|
7
|
+
declare const switchDef: ComponentDef<"switch", "root" | "thumb" | "control", "height" | "height-sm" | "width" | "thumb-size" | "width-sm" | "thumb-size-sm">;
|
|
8
|
+
declare const switchVariants: VariantFn<{
|
|
9
|
+
readonly size: readonly ["default", "sm"];
|
|
10
|
+
readonly variant: readonly ["default", "destructive"];
|
|
11
|
+
}>;
|
|
12
|
+
interface SwitchProps {
|
|
13
|
+
/** On or off. Given, the switch is controlled: it moves only through `setChecked`. */
|
|
14
|
+
checked?: boolean;
|
|
15
|
+
/** The state it starts in when `checked` is not given. */
|
|
16
|
+
defaultChecked?: boolean;
|
|
17
|
+
/** Called when the user toggles it, with the state asked for. */
|
|
18
|
+
onCheckedChange?: (checked: boolean) => void;
|
|
19
|
+
disabled?: boolean;
|
|
20
|
+
/** Submitted with its form under this name while on. */
|
|
21
|
+
name?: string;
|
|
22
|
+
/** What it submits while on (default `on`). */
|
|
23
|
+
value?: string;
|
|
24
|
+
/** A form does not submit while it is off. */
|
|
25
|
+
required?: boolean;
|
|
26
|
+
/** The id of its focusable control, so a `<label for>` reaches it. */
|
|
27
|
+
id?: string;
|
|
28
|
+
/** Its accessible name, when no `<label>` names it. */
|
|
29
|
+
label?: string;
|
|
30
|
+
size?: SwitchSize;
|
|
31
|
+
variant?: SwitchVariant;
|
|
32
|
+
}
|
|
33
|
+
declare class Switch {
|
|
34
|
+
readonly el: HTMLLabelElement;
|
|
35
|
+
private readonly input;
|
|
36
|
+
private readonly machine;
|
|
37
|
+
private readonly mid;
|
|
38
|
+
private readonly release;
|
|
39
|
+
private readonly control;
|
|
40
|
+
private readonly thumb;
|
|
41
|
+
/** The state as the switch's users see it, at once: the machine settles a beat later. */
|
|
42
|
+
private current;
|
|
43
|
+
private disabled;
|
|
44
|
+
constructor(opts?: SwitchProps);
|
|
45
|
+
get checked(): boolean;
|
|
46
|
+
setChecked(v: boolean): void;
|
|
47
|
+
setDisabled(disabled: boolean): void;
|
|
48
|
+
destroy(): void;
|
|
49
|
+
private api;
|
|
50
|
+
private render;
|
|
51
|
+
}
|
|
52
|
+
declare function createSwitch(props?: SwitchProps): Switch;
|
|
53
|
+
|
|
54
|
+
export { Switch, type SwitchProps, type SwitchSize, type SwitchVariant, createSwitch, switchDef, switchVariants };
|
package/dist/switch.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { variants } from './chunk-LZWZV2ZS.js';
|
|
2
|
+
import { ownTeardown } from './chunk-A72NWYNP.js';
|
|
3
|
+
import { nextUid, runMachine, normalizeProps, spreadProps } 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
|
+
import * as zagSwitch from '@zag-js/switch';
|
|
12
|
+
|
|
13
|
+
var switchDef = defineComponent({
|
|
14
|
+
name: "switch",
|
|
15
|
+
parts: ["root", "control", "thumb"],
|
|
16
|
+
settings: { width: "32px", height: "18px", "thumb-size": "14px", "width-sm": "24px", "height-sm": "14px", "thumb-size-sm": "10px" }
|
|
17
|
+
});
|
|
18
|
+
var switchVariants = variants({ size: ["default", "sm"], variant: ["default", "destructive"] });
|
|
19
|
+
var injectStyles = defineStyles(
|
|
20
|
+
"vela-ui-switch",
|
|
21
|
+
css`@layer vela.ui{[data-slot=switch]{--_w:${switchDef.vars.width};--_h:${switchDef.vars.height};--_thumb:${switchDef.vars["thumb-size"]};cursor:pointer;flex:none;align-items:center;line-height:0;position:relative}[data-slot=switch]:where(:not([hidden])){display:inline-flex}[data-slot=switch][data-size=sm]{--_w:${switchDef.vars["width-sm"]};--_h:${switchDef.vars["height-sm"]};--_thumb:${switchDef.vars["thumb-size-sm"]}}[data-slot=switch][data-disabled]{opacity:.5;cursor:default}[data-slot=switch-control]{width:var(--_w);height:var(--_h);background:color-mix(in srgb, ${t.fg.bright} 15%, transparent);transition:background ${t.dur.med} ease;border-radius:999px;flex:none;position:relative}[data-slot=switch-thumb]{top:calc((var(--_h) - var(--_thumb)) / 2);width:var(--_thumb);height:var(--_thumb);background:${t.fg.onFill};transition:inset-inline-start ${t.dur.med} ease, background ${t.dur.med} ease;border-radius:50%;position:absolute;inset-inline-start:calc((var(--_h) - var(--_thumb)) / 2)}[data-slot=switch][data-focus-visible] [data-slot=switch-control]{outline:2px solid ${t.focus};outline-offset:2px}[data-slot=switch][data-state=checked] [data-slot=switch-control]{background:${t.selected.bg}}[data-slot=switch][data-state=checked] [data-slot=switch-thumb]{background:${t.selected.fg};inset-inline-start:calc(var(--_w) - var(--_thumb) - (var(--_h) - var(--_thumb)) / 2)}[data-slot=switch][data-variant=destructive][data-state=checked] [data-slot=switch-control]{background:${t.danger}}[data-slot=switch][data-variant=destructive][data-state=checked] [data-slot=switch-thumb]{background:${t.fg.onFill}}}`
|
|
22
|
+
);
|
|
23
|
+
var Switch = class {
|
|
24
|
+
constructor(opts = {}) {
|
|
25
|
+
injectStyles(document);
|
|
26
|
+
this.mid = nextUid("vela-switch");
|
|
27
|
+
this.current = opts.checked ?? opts.defaultChecked ?? false;
|
|
28
|
+
this.disabled = opts.disabled ?? false;
|
|
29
|
+
const controlled = opts.checked !== void 0;
|
|
30
|
+
this.input = h("input", {});
|
|
31
|
+
this.thumb = h("span", { slot: switchDef.slot("thumb") });
|
|
32
|
+
this.control = h("span", { slot: switchDef.slot("control") }, this.thumb);
|
|
33
|
+
this.el = h("label", { className: "vela-toggle-switch", slot: switchDef.slot("root"), attrs: switchVariants({ size: opts.size ?? "default", variant: opts.variant ?? "default" }) }, this.input, this.control);
|
|
34
|
+
this.machine = runMachine(
|
|
35
|
+
zagSwitch.machine,
|
|
36
|
+
() => ({
|
|
37
|
+
id: this.mid,
|
|
38
|
+
...opts.id ? { ids: { hiddenInput: opts.id } } : {},
|
|
39
|
+
defaultChecked: this.current,
|
|
40
|
+
disabled: this.disabled,
|
|
41
|
+
...opts.name !== void 0 ? { name: opts.name } : {},
|
|
42
|
+
...opts.value !== void 0 ? { value: opts.value } : {},
|
|
43
|
+
...opts.required !== void 0 ? { required: opts.required } : {}
|
|
44
|
+
}),
|
|
45
|
+
(service) => this.render(service, opts.label)
|
|
46
|
+
);
|
|
47
|
+
this.release = ownTeardown(this.el, () => this.machine.stop());
|
|
48
|
+
this.input.addEventListener("change", () => {
|
|
49
|
+
const asked = this.input.checked;
|
|
50
|
+
if (controlled) this.api().setChecked(this.current);
|
|
51
|
+
else this.current = asked;
|
|
52
|
+
opts.onCheckedChange?.(asked);
|
|
53
|
+
});
|
|
54
|
+
this.el.addEventListener("pointerdown", (e) => {
|
|
55
|
+
if (this.disabled) return;
|
|
56
|
+
e.preventDefault();
|
|
57
|
+
this.input.focus({ preventScroll: true });
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
get checked() {
|
|
61
|
+
return this.current;
|
|
62
|
+
}
|
|
63
|
+
setChecked(v) {
|
|
64
|
+
if (v === this.current) return;
|
|
65
|
+
this.current = v;
|
|
66
|
+
this.api().setChecked(v);
|
|
67
|
+
}
|
|
68
|
+
setDisabled(disabled) {
|
|
69
|
+
if (disabled === this.disabled) return;
|
|
70
|
+
this.disabled = disabled;
|
|
71
|
+
this.machine.flush();
|
|
72
|
+
}
|
|
73
|
+
destroy() {
|
|
74
|
+
this.release();
|
|
75
|
+
}
|
|
76
|
+
api() {
|
|
77
|
+
return zagSwitch.connect(this.machine.service, normalizeProps);
|
|
78
|
+
}
|
|
79
|
+
render(service, label) {
|
|
80
|
+
const api = zagSwitch.connect(service, normalizeProps);
|
|
81
|
+
spreadProps(this.el, api.getRootProps(), this.mid);
|
|
82
|
+
spreadProps(this.control, api.getControlProps(), this.mid);
|
|
83
|
+
spreadProps(this.thumb, api.getThumbProps(), this.mid);
|
|
84
|
+
spreadProps(this.input, api.getHiddenInputProps(), this.mid);
|
|
85
|
+
if (label) this.input.setAttribute("aria-label", label);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
function createSwitch(props = {}) {
|
|
89
|
+
return new Switch(props);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export { Switch, createSwitch, switchDef, switchVariants };
|
package/dist/t.d.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
interface Token {
|
|
2
|
+
/** The custom property, `--vela-…`. */
|
|
3
|
+
readonly name: string;
|
|
4
|
+
/** `var(--vela-…)`, also what the token prints as in a template. */
|
|
5
|
+
readonly var: string;
|
|
6
|
+
toString(): string;
|
|
7
|
+
}
|
|
8
|
+
declare const t: {
|
|
9
|
+
space: {
|
|
10
|
+
readonly 1: Token;
|
|
11
|
+
readonly 2: Token;
|
|
12
|
+
readonly 3: Token;
|
|
13
|
+
readonly 4: Token;
|
|
14
|
+
};
|
|
15
|
+
radius: {
|
|
16
|
+
readonly sm: Token;
|
|
17
|
+
readonly md: Token;
|
|
18
|
+
readonly lg: Token;
|
|
19
|
+
};
|
|
20
|
+
z: {
|
|
21
|
+
readonly tooltip: Token;
|
|
22
|
+
readonly menu: Token;
|
|
23
|
+
readonly dialog: Token;
|
|
24
|
+
readonly popover: Token;
|
|
25
|
+
};
|
|
26
|
+
ease: Token;
|
|
27
|
+
dur: {
|
|
28
|
+
readonly fast: Token;
|
|
29
|
+
readonly med: Token;
|
|
30
|
+
};
|
|
31
|
+
fontSize: {
|
|
32
|
+
readonly sm: Token;
|
|
33
|
+
readonly md: Token;
|
|
34
|
+
readonly lg: Token;
|
|
35
|
+
};
|
|
36
|
+
font: Token;
|
|
37
|
+
bg: Token;
|
|
38
|
+
fg: Token & {
|
|
39
|
+
readonly muted: Token;
|
|
40
|
+
readonly faint: Token;
|
|
41
|
+
readonly bright: Token;
|
|
42
|
+
readonly onFill: Token;
|
|
43
|
+
};
|
|
44
|
+
surface: Token & {
|
|
45
|
+
readonly elev: Token;
|
|
46
|
+
readonly overlay: Token;
|
|
47
|
+
readonly sunken: Token;
|
|
48
|
+
};
|
|
49
|
+
border: Token & {
|
|
50
|
+
readonly strong: Token;
|
|
51
|
+
readonly soft: Token;
|
|
52
|
+
readonly faint: Token;
|
|
53
|
+
};
|
|
54
|
+
hover: Token & {
|
|
55
|
+
readonly strong: Token;
|
|
56
|
+
};
|
|
57
|
+
active: Token;
|
|
58
|
+
focus: Token & {
|
|
59
|
+
readonly soft: Token;
|
|
60
|
+
};
|
|
61
|
+
separatorHover: {
|
|
62
|
+
readonly band: Token;
|
|
63
|
+
readonly line: Token;
|
|
64
|
+
};
|
|
65
|
+
scroll: Token & {
|
|
66
|
+
readonly size: Token;
|
|
67
|
+
};
|
|
68
|
+
accent: Token & {
|
|
69
|
+
readonly bright: Token;
|
|
70
|
+
};
|
|
71
|
+
highlight: Token;
|
|
72
|
+
selected: {
|
|
73
|
+
readonly bg: Token;
|
|
74
|
+
readonly fg: Token;
|
|
75
|
+
};
|
|
76
|
+
up: Token;
|
|
77
|
+
down: Token;
|
|
78
|
+
profit: Token;
|
|
79
|
+
loss: Token;
|
|
80
|
+
danger: Token;
|
|
81
|
+
shadow: Token & {
|
|
82
|
+
readonly dialog: Token;
|
|
83
|
+
};
|
|
84
|
+
backdrop: Token;
|
|
85
|
+
};
|
|
86
|
+
/** Every token reachable from `t`, by custom property name. */
|
|
87
|
+
declare function tokenNames(): string[];
|
|
88
|
+
|
|
89
|
+
export { type Token, t, tokenNames };
|
package/dist/t.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t, tokenNames } from './chunk-6QCILIT2.js';
|
package/dist/tabs.d.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
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 tabsDef: ComponentDef<"tabs", "count" | "label" | "icon" | "trigger" | "content" | "description" | "list", "track-radius" | "trigger-radius" | "filled-radius" | "soft-radius" | "count-radius">;
|
|
6
|
+
declare const tabsVariants: VariantFn<{
|
|
7
|
+
readonly variant: readonly ["default", "line", "filled", "soft", "nav"];
|
|
8
|
+
}>;
|
|
9
|
+
type TabsVariant = (typeof tabsVariants.spec.variant)[number];
|
|
10
|
+
interface TabItem {
|
|
11
|
+
value: string;
|
|
12
|
+
label: string;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
/** Out of the strip for now (its content does not apply); the arrow keys skip it. */
|
|
15
|
+
hidden?: boolean;
|
|
16
|
+
/** Icon id from the kit's registry, before the label. */
|
|
17
|
+
icon?: string;
|
|
18
|
+
/** A count after the label (open orders, trades); null shows none. */
|
|
19
|
+
count?: number | null;
|
|
20
|
+
/** A second line under the label (a day strip's date under its weekday). */
|
|
21
|
+
description?: string;
|
|
22
|
+
}
|
|
23
|
+
interface TabsProps extends VariantProps<typeof tabsVariants> {
|
|
24
|
+
items: readonly TabItem[];
|
|
25
|
+
/** The selected tab (default: the first available one). */
|
|
26
|
+
defaultValue?: string;
|
|
27
|
+
onValueChange?: (value: string) => void;
|
|
28
|
+
/** Default `horizontal` (`nav` reads best vertical). */
|
|
29
|
+
orientation?: 'horizontal' | 'vertical';
|
|
30
|
+
/** `automatic` (default): moving focus with the arrow keys selects. `manual`: Enter or
|
|
31
|
+
* Space selects the focused tab. */
|
|
32
|
+
activationMode?: 'automatic' | 'manual';
|
|
33
|
+
/** The text direction the arrow keys follow (default `ltr`). */
|
|
34
|
+
dir?: 'ltr' | 'rtl';
|
|
35
|
+
/** Extra class names on the list (the host's layout of the strip). */
|
|
36
|
+
className?: string;
|
|
37
|
+
/** Extra class names on every trigger. */
|
|
38
|
+
triggerClassName?: string;
|
|
39
|
+
}
|
|
40
|
+
interface TabsHandle {
|
|
41
|
+
readonly el: HTMLElement;
|
|
42
|
+
/** The selected tab. */
|
|
43
|
+
readonly value: string | null;
|
|
44
|
+
/** Show a tab as selected without calling `onValueChange`. */
|
|
45
|
+
setValue(value: string | null): void;
|
|
46
|
+
setItems(items: readonly TabItem[]): void;
|
|
47
|
+
/** Hide or show a tab. Hiding the selected tab selects the first available one (and
|
|
48
|
+
* calls `onValueChange`). */
|
|
49
|
+
setHidden(value: string, hidden: boolean): void;
|
|
50
|
+
/** A tab's count (null: none). */
|
|
51
|
+
setCount(value: string, count: number | null): void;
|
|
52
|
+
/** The trigger of a tab (null: unknown value). */
|
|
53
|
+
trigger(value: string): HTMLButtonElement | null;
|
|
54
|
+
/** Make `el` the panel of tab `value`: it gets the tabpanel role, its link to the trigger,
|
|
55
|
+
* and `hidden` while another tab is selected. */
|
|
56
|
+
panel(value: string, el: HTMLElement): void;
|
|
57
|
+
destroy(): void;
|
|
58
|
+
}
|
|
59
|
+
/** A tab a user can reach: neither disabled nor hidden. */
|
|
60
|
+
declare const tabAvailable: (item: TabItem) => boolean;
|
|
61
|
+
declare const TABS_STYLE_ID = "vela-ui-tabs";
|
|
62
|
+
declare const TABS_CSS: string;
|
|
63
|
+
declare function createTabs(props: TabsProps): TabsHandle;
|
|
64
|
+
|
|
65
|
+
export { TABS_CSS, TABS_STYLE_ID, type TabItem, type TabsHandle, type TabsProps, type TabsVariant, createTabs, tabAvailable, tabsDef, tabsVariants };
|
package/dist/tabs.js
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { variants } from './chunk-LZWZV2ZS.js';
|
|
2
|
+
import { iconEl } from './chunk-G7IQLY3A.js';
|
|
3
|
+
import { ownTeardown } from './chunk-A72NWYNP.js';
|
|
4
|
+
import { nextUid, runMachine, normalizeProps, spreadProps } from './chunk-P4MTEMT7.js';
|
|
5
|
+
import { h } from './chunk-Q6WTDVH6.js';
|
|
6
|
+
import { defineComponent } from './chunk-VMCR3S2A.js';
|
|
7
|
+
import { css, defineStyles } from './chunk-XBEL4K33.js';
|
|
8
|
+
import './chunk-2GQIZM5Z.js';
|
|
9
|
+
import './chunk-BXMWQIBO.js';
|
|
10
|
+
import './chunk-X66RJAIS.js';
|
|
11
|
+
import { t } from './chunk-6QCILIT2.js';
|
|
12
|
+
import * as tabs from '@zag-js/tabs';
|
|
13
|
+
|
|
14
|
+
var tabsDef = defineComponent({
|
|
15
|
+
name: "tabs",
|
|
16
|
+
parts: ["list", "trigger", "icon", "count", "label", "description", "content"],
|
|
17
|
+
settings: { "track-radius": "8px", "trigger-radius": t.radius.md, "filled-radius": "5px", "soft-radius": "8px", "count-radius": "8px" }
|
|
18
|
+
});
|
|
19
|
+
var tabsVariants = variants({ variant: ["default", "line", "filled", "soft", "nav"] });
|
|
20
|
+
var tabAvailable = (item) => !item.disabled && !item.hidden;
|
|
21
|
+
var countEl = (count) => count == null ? null : h("span", { slot: tabsDef.slot("count"), text: String(count) });
|
|
22
|
+
var TABS_STYLE_ID = "vela-ui-tabs";
|
|
23
|
+
var TABS_CSS = css`@layer vela.ui{[data-slot=tabs-icon]{margin-inline-end:6px}[data-slot=tabs-count]{border-radius:${tabsDef.vars["count-radius"]};background:${t.hover};min-width:16px;height:16px;color:${t.fg.muted};font-variant-numeric:tabular-nums;margin-inline-start:6px;padding:0 5px;font-size:10px;font-weight:600}[data-slot=tabs-count]:where(:not([hidden])){justify-content:center;align-items:center;display:inline-flex}[data-slot=tabs-list]{display:flex}[data-slot=tabs-list][data-orientation=vertical]{flex-direction:column}[data-slot=tabs-list][data-variant=default]{box-sizing:border-box;border-radius:${tabsDef.vars["track-radius"]};background:color-mix(in srgb, ${t.fg.bright} 6%, transparent);gap:2px;padding:3px;display:inline-flex}[data-slot=tabs-list][data-variant=default][data-orientation=horizontal]{align-items:stretch;height:32px}[data-slot=tabs-list][data-variant=line]{border-bottom:1px solid ${t.border};gap:12px}[data-slot=tabs-list][data-variant=nav]{gap:2px}[data-slot=tabs-trigger]:where(:not([hidden])){all:unset;cursor:pointer;white-space:nowrap;-webkit-tap-highlight-color:transparent}[data-slot=tabs-trigger]:where(:not([hidden]))[data-disabled]{cursor:default;opacity:.45}[data-slot=tabs-trigger]:where(:not([hidden])):focus-visible{outline:2px solid ${t.focus};outline-offset:-2px}[data-slot=tabs-trigger]:where(:not([hidden]))[data-variant=default]{border-radius:${tabsDef.vars["trigger-radius"]};color:${t.fg.muted};transition:background ${t.dur.fast} ease, color ${t.dur.fast} ease;justify-content:center;align-items:center;padding:0 10px;font-size:13px;font-weight:500;display:inline-flex}[data-slot=tabs-trigger]:where(:not([hidden]))[data-variant=default][data-orientation=vertical]{justify-content:flex-start;padding:6px 10px}[data-slot=tabs-trigger]:where(:not([hidden]))[data-variant=default]:not([data-selected],[data-disabled]):hover{color:${t.fg.bright}}[data-slot=tabs-trigger]:where(:not([hidden]))[data-variant=default][data-selected]{background:color-mix(in srgb, ${t.fg.bright} 12%, transparent);color:${t.fg.bright}}[data-slot=tabs-trigger]:where(:not([hidden]))[data-variant=line]{color:${t.fg.muted};transition:color ${t.dur.fast} ease, border-color ${t.dur.fast} ease;border-bottom:2px solid #0000;margin-bottom:-1px;padding-bottom:8px;font-size:13px;font-weight:600;line-height:20px}[data-slot=tabs-trigger]:where(:not([hidden]))[data-variant=line]:not([data-selected],[data-disabled]):hover{color:${t.fg}}[data-slot=tabs-trigger]:where(:not([hidden]))[data-variant=line][data-selected]{color:${t.fg};border-bottom-color:${t.fg.bright}}[data-slot=tabs-trigger]:where(:not([hidden]))[data-variant=filled]{border-radius:${tabsDef.vars["filled-radius"]};color:${t.fg.muted};padding:3px 10px;font-size:13px;font-weight:600}[data-slot=tabs-trigger]:where(:not([hidden]))[data-variant=filled]:not([data-selected],[data-disabled]):hover{color:${t.fg}}[data-slot=tabs-trigger]:where(:not([hidden]))[data-variant=filled][data-selected]{background:${t.selected.bg};color:${t.selected.fg}}[data-slot=tabs-trigger]:where(:not([hidden]))[data-variant=soft]{border-radius:${tabsDef.vars["soft-radius"]};min-height:36px;color:${t.fg.muted};flex:none;align-items:center;padding:0 12px;font-size:13px;font-weight:600;display:inline-flex}[data-slot=tabs-trigger]:where(:not([hidden]))[data-variant=soft][data-selected]{color:${t.fg.bright};background:${t.hover}}[data-slot=tabs-trigger]:where(:not([hidden]))[data-variant=nav]{border-radius:${t.radius.md};color:${t.fg.muted};transition:background ${t.dur.fast} ease, color ${t.dur.fast} ease;padding:9px 12px;font-size:13px;font-weight:600}[data-slot=tabs-trigger]:where(:not([hidden]))[data-variant=nav]:not([data-selected],[data-disabled]):hover{background:${t.hover};color:${t.fg.bright}}[data-slot=tabs-trigger]:where(:not([hidden]))[data-variant=nav][data-selected]{background:${t.active};color:${t.fg.bright}}[data-slot=tabs-trigger]:where(:not([hidden]))[data-description]{flex-direction:column;justify-content:center;align-items:center;gap:2px;display:inline-flex}[data-slot=tabs-trigger]:where(:not([hidden]))[data-description]:not([data-variant=line]){padding-block:6px}[data-slot=tabs-list][data-variant=default]:has(>[data-description]){height:auto}[data-slot=tabs-label]{align-items:center;line-height:16px;display:inline-flex}[data-slot=tabs-description]{opacity:.85;font-size:11px;font-weight:400;line-height:14px}}`;
|
|
24
|
+
var injectStyles = defineStyles(TABS_STYLE_ID, TABS_CSS);
|
|
25
|
+
var TabsImpl = class {
|
|
26
|
+
constructor(props) {
|
|
27
|
+
this.triggers = /* @__PURE__ */ new Map();
|
|
28
|
+
this.panels = /* @__PURE__ */ new Map();
|
|
29
|
+
injectStyles(document);
|
|
30
|
+
this.variant = tabsVariants.resolve(props).variant;
|
|
31
|
+
this.triggerClassName = props.triggerClassName;
|
|
32
|
+
this.items = [...props.items];
|
|
33
|
+
this.current = props.defaultValue ?? this.items.find(tabAvailable)?.value ?? null;
|
|
34
|
+
this.mid = nextUid("vela-tabs");
|
|
35
|
+
this.el = h("div", {
|
|
36
|
+
className: props.className ? `vela-tabs ${props.className}` : "vela-tabs",
|
|
37
|
+
slot: tabsDef.slot("list"),
|
|
38
|
+
data: { variant: this.variant }
|
|
39
|
+
});
|
|
40
|
+
this.build();
|
|
41
|
+
this.machine = runMachine(
|
|
42
|
+
tabs.machine,
|
|
43
|
+
{
|
|
44
|
+
id: this.mid,
|
|
45
|
+
defaultValue: this.current,
|
|
46
|
+
orientation: props.orientation ?? "horizontal",
|
|
47
|
+
activationMode: props.activationMode ?? "automatic",
|
|
48
|
+
dir: props.dir ?? "ltr",
|
|
49
|
+
loopFocus: true,
|
|
50
|
+
onValueChange: ({ value }) => {
|
|
51
|
+
if (value == null) return;
|
|
52
|
+
this.current = value;
|
|
53
|
+
if (this.silentNext === value) {
|
|
54
|
+
this.silentNext = void 0;
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
props.onValueChange?.(value);
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
(service) => this.render(service)
|
|
61
|
+
);
|
|
62
|
+
this.release = ownTeardown(this.el, () => this.machine.stop());
|
|
63
|
+
}
|
|
64
|
+
get value() {
|
|
65
|
+
return this.current;
|
|
66
|
+
}
|
|
67
|
+
setValue(value) {
|
|
68
|
+
if (value === this.current) return;
|
|
69
|
+
this.current = value;
|
|
70
|
+
if (value === null) {
|
|
71
|
+
this.api().clearValue();
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
this.silentNext = value;
|
|
75
|
+
this.api().setValue(value);
|
|
76
|
+
}
|
|
77
|
+
setItems(items) {
|
|
78
|
+
this.items = [...items];
|
|
79
|
+
this.build();
|
|
80
|
+
if (this.current === null || !this.items.some((i) => i.value === this.current)) this.setValue(this.items.find(tabAvailable)?.value ?? null);
|
|
81
|
+
this.machine.flush();
|
|
82
|
+
}
|
|
83
|
+
setHidden(value, hidden) {
|
|
84
|
+
this.items = this.items.map((i) => i.value === value ? { ...i, hidden } : i);
|
|
85
|
+
if (hidden && this.current === value) {
|
|
86
|
+
const next = this.items.find(tabAvailable)?.value;
|
|
87
|
+
if (next !== void 0) {
|
|
88
|
+
this.current = next;
|
|
89
|
+
this.api().setValue(next);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
this.machine.flush();
|
|
93
|
+
}
|
|
94
|
+
setCount(value, count) {
|
|
95
|
+
const b = this.triggers.get(value);
|
|
96
|
+
if (!b) return;
|
|
97
|
+
this.items = this.items.map((i) => i.value === value ? { ...i, count } : i);
|
|
98
|
+
b.querySelector(`[data-slot="${tabsDef.slot("count")}"]`)?.remove();
|
|
99
|
+
const el = countEl(count);
|
|
100
|
+
if (el) (b.querySelector(`[data-slot="${tabsDef.slot("label")}"]`) ?? b).appendChild(el);
|
|
101
|
+
}
|
|
102
|
+
trigger(value) {
|
|
103
|
+
return this.triggers.get(value) ?? null;
|
|
104
|
+
}
|
|
105
|
+
panel(value, el) {
|
|
106
|
+
el.dataset.slot = tabsDef.slot("content");
|
|
107
|
+
this.panels.set(value, el);
|
|
108
|
+
this.machine.flush();
|
|
109
|
+
}
|
|
110
|
+
destroy() {
|
|
111
|
+
this.release();
|
|
112
|
+
}
|
|
113
|
+
api() {
|
|
114
|
+
return tabs.connect(this.machine.service, normalizeProps);
|
|
115
|
+
}
|
|
116
|
+
build() {
|
|
117
|
+
this.triggers.clear();
|
|
118
|
+
const className = this.triggerClassName ? `vela-tab ${this.triggerClassName}` : "vela-tab";
|
|
119
|
+
this.el.replaceChildren(
|
|
120
|
+
...this.items.map((item) => {
|
|
121
|
+
let icon = null;
|
|
122
|
+
if (item.icon) {
|
|
123
|
+
icon = iconEl(item.icon, document);
|
|
124
|
+
icon.dataset.slot = tabsDef.slot("icon");
|
|
125
|
+
}
|
|
126
|
+
const b = item.description ? h(
|
|
127
|
+
"button",
|
|
128
|
+
{ className, slot: tabsDef.slot("trigger"), data: { variant: this.variant, description: true } },
|
|
129
|
+
h("span", { slot: tabsDef.slot("label") }, icon, item.label, countEl(item.count)),
|
|
130
|
+
h("span", { slot: tabsDef.slot("description"), text: item.description })
|
|
131
|
+
) : h("button", { className, slot: tabsDef.slot("trigger"), data: { variant: this.variant } }, icon, item.label, countEl(item.count));
|
|
132
|
+
this.triggers.set(item.value, b);
|
|
133
|
+
return b;
|
|
134
|
+
})
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
render(service) {
|
|
138
|
+
const api = tabs.connect(service, normalizeProps);
|
|
139
|
+
spreadProps(this.el, api.getListProps(), this.mid);
|
|
140
|
+
for (const item of this.items) {
|
|
141
|
+
const b = this.triggers.get(item.value);
|
|
142
|
+
if (!b) continue;
|
|
143
|
+
const props = api.getTriggerProps({ value: item.value, disabled: !tabAvailable(item) });
|
|
144
|
+
if (!this.panels.has(item.value)) delete props["aria-controls"];
|
|
145
|
+
spreadProps(b, props, this.mid);
|
|
146
|
+
b.hidden = item.hidden === true;
|
|
147
|
+
}
|
|
148
|
+
for (const [value, el] of this.panels) spreadProps(el, api.getContentProps({ value }), this.mid);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
function createTabs(props) {
|
|
152
|
+
return new TabsImpl(props);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export { TABS_CSS, TABS_STYLE_ID, createTabs, tabAvailable, tabsDef, tabsVariants };
|