@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,3 @@
|
|
|
1
|
+
/* @luxalgo/vela-ui: the built-in dark theme, every token on the page root. */
|
|
2
|
+
@layer vela.theme, vela.ui, vela.chrome, vela.pro, vela.custom;
|
|
3
|
+
@layer vela.theme { :root { --vela-space-1: 4px; --vela-space-2: 8px; --vela-space-3: 12px; --vela-space-4: 16px; --vela-radius-sm: 4px; --vela-radius-md: 6px; --vela-radius-lg: 10px; --vela-z-tooltip: 60; --vela-z-menu: 50; --vela-z-dialog: 40; --vela-z-popover: 6000; --vela-ease: cubic-bezier(0.22, 1, 0.36, 1); --vela-dur-fast: 90ms; --vela-dur-med: 160ms; --vela-font-size-sm: 11px; --vela-font-size-md: 12px; --vela-font-size-lg: 14px; --vela-scroll-size: 5px; --vela-font: sans-serif; --vela-bg: #151619; --vela-fg: #d1d4dc; --vela-fg-muted: #868a96; --vela-fg-faint: rgba(178,181,190,0.35); --vela-fg-bright: #f0f3fa; --vela-surface: #151619; --vela-surface-elev: rgb(28,29,32); --vela-surface-overlay: rgb(28,29,32); --vela-surface-sunken: #151619; --vela-border: #2a2b30; --vela-border-strong: #34353b; --vela-border-soft: #2a2b30; --vela-border-faint: rgba(178,181,190,0.08); --vela-hover: rgba(255,255,255,0.06); --vela-active: rgba(255,255,255,0.1); --vela-hover-strong: rgba(255,255,255,0.16); --vela-focus: rgba(178,181,190,0.5); --vela-focus-soft: rgba(178,181,190,0.12); --vela-separator-hover-band: rgba(178,181,190,0.1); --vela-separator-hover-line: rgba(178,181,190,0.55); --vela-scroll: #2a2b30; --vela-accent: #2962ff; --vela-accent-bright: #38c0fd; --vela-highlight: #e0b400; --vela-selected-bg: #f0f3fa; --vela-selected-fg: #151619; --vela-fg-on-fill: #ffffff; --vela-up: #089981; --vela-down: #f23645; --vela-profit: #089981; --vela-loss: #f23645; --vela-danger: #f23645; --vela-shadow: 0 8px 30px rgba(0,0,0,0.5); --vela-shadow-dialog: 0 20px 60px rgba(0,0,0,0.5); --vela-backdrop: rgba(0,0,0,0.45); } }
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/* @luxalgo/vela-ui: the built-in light theme, every token on the page root. */
|
|
2
|
+
@layer vela.theme, vela.ui, vela.chrome, vela.pro, vela.custom;
|
|
3
|
+
@layer vela.theme { :root { --vela-space-1: 4px; --vela-space-2: 8px; --vela-space-3: 12px; --vela-space-4: 16px; --vela-radius-sm: 4px; --vela-radius-md: 6px; --vela-radius-lg: 10px; --vela-z-tooltip: 60; --vela-z-menu: 50; --vela-z-dialog: 40; --vela-z-popover: 6000; --vela-ease: cubic-bezier(0.22, 1, 0.36, 1); --vela-dur-fast: 90ms; --vela-dur-med: 160ms; --vela-font-size-sm: 11px; --vela-font-size-md: 12px; --vela-font-size-lg: 14px; --vela-scroll-size: 5px; --vela-font: sans-serif; --vela-bg: #ffffff; --vela-fg: #1e293b; --vela-fg-muted: rgba(30,41,59,0.62); --vela-fg-faint: rgba(30,41,59,0.35); --vela-fg-bright: #000000; --vela-surface: #ffffff; --vela-surface-elev: rgb(244,244,245); --vela-surface-overlay: rgb(244,244,245); --vela-surface-sunken: #ffffff; --vela-border: #d4dae3; --vela-border-strong: rgba(30,41,59,0.28); --vela-border-soft: #d4dae3; --vela-border-faint: rgba(30,41,59,0.08); --vela-hover: rgba(30,41,59,0.08); --vela-active: rgba(30,41,59,0.12000000000000001); --vela-hover-strong: rgba(30,41,59,0.18); --vela-focus: rgba(30,41,59,0.5); --vela-focus-soft: rgba(30,41,59,0.12); --vela-separator-hover-band: rgba(30,41,59,0.1); --vela-separator-hover-line: rgba(30,41,59,0.55); --vela-scroll: #d4dae3; --vela-accent: #2962ff; --vela-accent-bright: #38c0fd; --vela-highlight: #e0b400; --vela-selected-bg: #1e293b; --vela-selected-fg: #ffffff; --vela-fg-on-fill: #ffffff; --vela-up: #089981; --vela-down: #f23645; --vela-profit: #089981; --vela-loss: #f23645; --vela-danger: #f23645; --vela-shadow: 0 8px 30px rgba(0,0,0,0.5); --vela-shadow-dialog: 0 20px 60px rgba(0,0,0,0.5); --vela-backdrop: rgba(0,0,0,0.45); } }
|
|
@@ -0,0 +1,56 @@
|
|
|
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 toggleGroupDef: ComponentDef<"toggle-group", "root" | "icon" | "item", "radius" | "radius-sm" | "item-radius" | "item-radius-sm">;
|
|
6
|
+
/** `default` = 32px; `sm` = 28px. */
|
|
7
|
+
declare const toggleGroupVariants: VariantFn<{
|
|
8
|
+
readonly size: readonly ["default", "sm"];
|
|
9
|
+
}>;
|
|
10
|
+
interface ToggleGroupItem {
|
|
11
|
+
value: string;
|
|
12
|
+
/** Visible text, or the accessible name of an icon-only option. */
|
|
13
|
+
label: string;
|
|
14
|
+
icon?: string;
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
/** Fill the option with a market color while it is on (buy and sell). */
|
|
17
|
+
tone?: 'up' | 'down';
|
|
18
|
+
}
|
|
19
|
+
interface ToggleGroupCommonProps extends VariantProps<typeof toggleGroupVariants> {
|
|
20
|
+
items: readonly ToggleGroupItem[];
|
|
21
|
+
/** Accessible name of the group. */
|
|
22
|
+
label?: string;
|
|
23
|
+
/** Options show their icon only; each label becomes its option's accessible name. */
|
|
24
|
+
iconOnly?: boolean;
|
|
25
|
+
dir?: 'ltr' | 'rtl';
|
|
26
|
+
/** Stretch across the parent, options sharing the width. */
|
|
27
|
+
fill?: boolean;
|
|
28
|
+
className?: string;
|
|
29
|
+
}
|
|
30
|
+
interface ToggleGroupSingleProps extends ToggleGroupCommonProps {
|
|
31
|
+
type?: 'single';
|
|
32
|
+
/** The chosen option (default: the first enabled one). */
|
|
33
|
+
defaultValue?: string;
|
|
34
|
+
onValueChange?: (value: string) => void;
|
|
35
|
+
}
|
|
36
|
+
interface ToggleGroupMultipleProps extends ToggleGroupCommonProps {
|
|
37
|
+
type: 'multiple';
|
|
38
|
+
/** The options turned on (default: none). */
|
|
39
|
+
defaultValue?: readonly string[];
|
|
40
|
+
onValueChange?: (value: string[]) => void;
|
|
41
|
+
}
|
|
42
|
+
type ToggleGroupProps = ToggleGroupSingleProps | ToggleGroupMultipleProps;
|
|
43
|
+
interface ToggleGroupHandle {
|
|
44
|
+
readonly el: HTMLElement;
|
|
45
|
+
/** The options turned on. */
|
|
46
|
+
readonly values: readonly string[];
|
|
47
|
+
/** Show options as on without calling `onValueChange`. */
|
|
48
|
+
setValue(value: string | readonly string[] | null): void;
|
|
49
|
+
setItems(items: readonly ToggleGroupItem[]): void;
|
|
50
|
+
destroy(): void;
|
|
51
|
+
}
|
|
52
|
+
declare const TOGGLE_GROUP_STYLE_ID = "vela-ui-toggle-group";
|
|
53
|
+
declare const TOGGLE_GROUP_CSS: string;
|
|
54
|
+
declare function createToggleGroup(props: ToggleGroupProps): ToggleGroupHandle;
|
|
55
|
+
|
|
56
|
+
export { TOGGLE_GROUP_CSS, TOGGLE_GROUP_STYLE_ID, type ToggleGroupHandle, type ToggleGroupItem, type ToggleGroupMultipleProps, type ToggleGroupProps, type ToggleGroupSingleProps, createToggleGroup, toggleGroupDef, toggleGroupVariants };
|
|
@@ -0,0 +1,130 @@
|
|
|
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 toggleGroup from '@zag-js/toggle-group';
|
|
13
|
+
|
|
14
|
+
var toggleGroupDef = defineComponent({
|
|
15
|
+
name: "toggle-group",
|
|
16
|
+
parts: ["root", "item", "icon"],
|
|
17
|
+
settings: { radius: "8px", "radius-sm": "7px", "item-radius": t.radius.md, "item-radius-sm": "5px" }
|
|
18
|
+
});
|
|
19
|
+
var toggleGroupVariants = variants({ size: ["default", "sm"] });
|
|
20
|
+
var TOGGLE_GROUP_STYLE_ID = "vela-ui-toggle-group";
|
|
21
|
+
var TOGGLE_GROUP_CSS = css`@layer vela.ui{[data-slot=toggle-group-item]{all:unset;box-sizing:border-box;border-radius:${toggleGroupDef.vars["item-radius"]};min-width:0;color:${t.fg.muted};white-space:nowrap;cursor:pointer;-webkit-tap-highlight-color:transparent;transition:background ${t.dur.fast} ease, color ${t.dur.fast} ease;justify-content:center;align-items:center;gap:6px;padding:0 10px;font-size:13px;font-weight:500;display:inline-flex}[data-slot=toggle-group-item]>[data-slot=toggle-group-icon]{flex:none;width:16px;height:16px}[data-slot=toggle-group-item][data-icon-only]{padding:0 8px}[data-slot=toggle-group-item][data-state=off]:not([data-disabled]):hover{color:${t.fg.bright}}[data-slot=toggle-group-item][data-state=on]{background:color-mix(in srgb, ${t.fg.bright} 12%, transparent);color:${t.fg.bright}}[data-slot=toggle-group-item][data-state=on][data-tone=up]{background:${t.up};color:${t.fg.onFill}}[data-slot=toggle-group-item][data-state=on][data-tone=down]{background:${t.down};color:${t.fg.onFill}}[data-slot=toggle-group-item][data-disabled]{cursor:default;opacity:.45}[data-slot=toggle-group-item]:focus-visible{outline:2px solid ${t.focus};outline-offset:-2px}[data-slot=toggle-group]{box-sizing:border-box;border-radius:${toggleGroupDef.vars.radius};background:color-mix(in srgb, ${t.fg.bright} 6%, transparent);align-items:stretch;gap:2px;height:32px;padding:3px}[data-slot=toggle-group]:where(:not([hidden])){display:inline-flex}[data-slot=toggle-group][data-size=sm]{border-radius:${toggleGroupDef.vars["radius-sm"]};height:28px;padding:2px}[data-slot=toggle-group][data-fill]{width:100%}[data-slot=toggle-group][data-fill]:where(:not([hidden])){display:flex}[data-slot=toggle-group][data-fill]>[data-slot=toggle-group-item]{flex:1 1 0}[data-slot=toggle-group][data-size=sm]>[data-slot=toggle-group-item]{border-radius:${toggleGroupDef.vars["item-radius-sm"]};padding:0 8px;font-size:12px}}`;
|
|
22
|
+
var injectStyles = defineStyles(TOGGLE_GROUP_STYLE_ID, TOGGLE_GROUP_CSS);
|
|
23
|
+
var keyOf = (values) => values.join("\0");
|
|
24
|
+
var ToggleGroupImpl = class {
|
|
25
|
+
constructor(props) {
|
|
26
|
+
this.buttons = /* @__PURE__ */ new Map();
|
|
27
|
+
injectStyles(document);
|
|
28
|
+
this.iconOnly = props.iconOnly ?? false;
|
|
29
|
+
this.label = props.label;
|
|
30
|
+
this.items = [...props.items];
|
|
31
|
+
const multiple = props.type === "multiple";
|
|
32
|
+
this.current = props.type === "multiple" ? [...props.defaultValue ?? []] : [props.defaultValue ?? props.items.find((i) => !i.disabled)?.value].filter((v) => v !== void 0);
|
|
33
|
+
this.mid = nextUid("vela-toggle-group");
|
|
34
|
+
this.el = h("div", {
|
|
35
|
+
className: props.className ? `vela-toggle-group ${props.className}` : "vela-toggle-group",
|
|
36
|
+
slot: toggleGroupDef.slot("root"),
|
|
37
|
+
attrs: toggleGroupVariants(props),
|
|
38
|
+
data: { fill: props.fill === true }
|
|
39
|
+
});
|
|
40
|
+
this.build();
|
|
41
|
+
const onValueChange = props.onValueChange;
|
|
42
|
+
this.machine = runMachine(
|
|
43
|
+
toggleGroup.machine,
|
|
44
|
+
{
|
|
45
|
+
id: this.mid,
|
|
46
|
+
multiple,
|
|
47
|
+
// A single group never empties: pressing the chosen option keeps it chosen.
|
|
48
|
+
deselectable: false,
|
|
49
|
+
defaultValue: [...this.current],
|
|
50
|
+
dir: props.dir ?? "ltr",
|
|
51
|
+
loopFocus: true,
|
|
52
|
+
rovingFocus: true,
|
|
53
|
+
onValueChange: ({ value }) => {
|
|
54
|
+
if (!multiple && value[0] === void 0) return;
|
|
55
|
+
const next = multiple ? [...value] : [value[0]];
|
|
56
|
+
const key = keyOf(next);
|
|
57
|
+
if (key === keyOf(this.current)) {
|
|
58
|
+
if (this.silentNext === key) this.silentNext = void 0;
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
this.current = next;
|
|
62
|
+
if (this.silentNext === key) {
|
|
63
|
+
this.silentNext = void 0;
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
onValueChange?.(multiple ? [...next] : next[0]);
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
(service) => this.render(service)
|
|
70
|
+
);
|
|
71
|
+
this.release = ownTeardown(this.el, () => this.machine.stop());
|
|
72
|
+
}
|
|
73
|
+
get values() {
|
|
74
|
+
return this.current;
|
|
75
|
+
}
|
|
76
|
+
setValue(value) {
|
|
77
|
+
const next = value === null ? [] : typeof value === "string" ? [value] : [...value];
|
|
78
|
+
const key = keyOf(next);
|
|
79
|
+
if (key === keyOf(this.current)) return;
|
|
80
|
+
this.current = next;
|
|
81
|
+
this.silentNext = key;
|
|
82
|
+
this.api().setValue(next);
|
|
83
|
+
}
|
|
84
|
+
setItems(items) {
|
|
85
|
+
this.items = [...items];
|
|
86
|
+
this.build();
|
|
87
|
+
const kept = this.current.filter((v) => this.items.some((i) => i.value === v));
|
|
88
|
+
if (kept.length !== this.current.length) this.setValue(kept);
|
|
89
|
+
this.machine.flush();
|
|
90
|
+
}
|
|
91
|
+
destroy() {
|
|
92
|
+
this.release();
|
|
93
|
+
}
|
|
94
|
+
api() {
|
|
95
|
+
return toggleGroup.connect(this.machine.service, normalizeProps);
|
|
96
|
+
}
|
|
97
|
+
build() {
|
|
98
|
+
this.buttons.clear();
|
|
99
|
+
const doc = this.el.ownerDocument;
|
|
100
|
+
this.el.replaceChildren(
|
|
101
|
+
...this.items.map((item) => {
|
|
102
|
+
const icon = item.icon ? iconEl(item.icon, doc) : null;
|
|
103
|
+
if (icon) icon.dataset.slot = toggleGroupDef.slot("icon");
|
|
104
|
+
const iconOnly = this.iconOnly && icon !== null;
|
|
105
|
+
const b = h(
|
|
106
|
+
"button",
|
|
107
|
+
{ className: "vela-toggle-group-item", slot: toggleGroupDef.slot("item"), data: { "icon-only": iconOnly, tone: item.tone ?? null }, attrs: { "aria-label": iconOnly ? item.label : null } },
|
|
108
|
+
icon,
|
|
109
|
+
iconOnly ? null : item.label
|
|
110
|
+
);
|
|
111
|
+
this.buttons.set(item.value, b);
|
|
112
|
+
return b;
|
|
113
|
+
})
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
render(service) {
|
|
117
|
+
const api = toggleGroup.connect(service, normalizeProps);
|
|
118
|
+
spreadProps(this.el, api.getRootProps(), this.mid);
|
|
119
|
+
if (this.label) this.el.setAttribute("aria-label", this.label);
|
|
120
|
+
for (const item of this.items) {
|
|
121
|
+
const b = this.buttons.get(item.value);
|
|
122
|
+
if (b) spreadProps(b, api.getItemProps({ value: item.value, disabled: item.disabled }), this.mid);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
function createToggleGroup(props) {
|
|
127
|
+
return new ToggleGroupImpl(props);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export { TOGGLE_GROUP_CSS, TOGGLE_GROUP_STYLE_ID, createToggleGroup, toggleGroupDef, toggleGroupVariants };
|
package/dist/tokens.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** A chart's colors and font, from which the theme tokens derive (Vela's `VelaTheme`). */
|
|
2
|
+
interface ChartTheme {
|
|
3
|
+
background: string;
|
|
4
|
+
textColor: string;
|
|
5
|
+
gridColor: string;
|
|
6
|
+
borderColor: string;
|
|
7
|
+
upColor: string;
|
|
8
|
+
downColor: string;
|
|
9
|
+
fontFamily: string;
|
|
10
|
+
}
|
|
11
|
+
/** Theme-independent tokens — the shared spacing/shape/motion/type scale. */
|
|
12
|
+
declare const STATIC_TOKENS: Record<string, string>;
|
|
13
|
+
/** Compute every theme token as a `--vela-*` → value map for one theme. */
|
|
14
|
+
declare function themeTokens(t: ChartTheme): Record<string, string>;
|
|
15
|
+
|
|
16
|
+
export { type ChartTheme, STATIC_TOKENS, themeTokens };
|
package/dist/tokens.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { C as ComponentDef } from './define-D5u3F5Dj.js';
|
|
2
|
+
import { PlacementProps } from './placement.js';
|
|
3
|
+
import * as tooltip from '@zag-js/tooltip';
|
|
4
|
+
import './t.js';
|
|
5
|
+
|
|
6
|
+
interface TooltipControllerOptions extends PlacementProps {
|
|
7
|
+
/** @deprecated Use `side` and `align`. */
|
|
8
|
+
placement?: tooltip.Placement;
|
|
9
|
+
/** ms before opening on hover (default 0 — the reference tooltips are instant). */
|
|
10
|
+
openDelay?: number;
|
|
11
|
+
closeDelay?: number;
|
|
12
|
+
/** Keep open while the pointer is over the content (rich tooltips). */
|
|
13
|
+
interactive?: boolean;
|
|
14
|
+
/** Share the trigger's DOM id with other machines composed on the SAME element
|
|
15
|
+
* (each Zag machine otherwise stamps its own id — last one wins and breaks the rest). */
|
|
16
|
+
triggerId?: string;
|
|
17
|
+
}
|
|
18
|
+
type TooltipService = tooltip.Service;
|
|
19
|
+
type TooltipApi = tooltip.Api;
|
|
20
|
+
interface TooltipController {
|
|
21
|
+
machine: typeof tooltip.machine;
|
|
22
|
+
props: Partial<tooltip.Props>;
|
|
23
|
+
connect(service: TooltipService): TooltipApi;
|
|
24
|
+
}
|
|
25
|
+
/** Zag's tooltip machine with the options mapped onto it, for any view layer. */
|
|
26
|
+
declare function tooltipController(opts?: TooltipControllerOptions): TooltipController;
|
|
27
|
+
declare const tooltipDef: ComponentDef<"tooltip", "content" | "positioner", "radius">;
|
|
28
|
+
interface TooltipOptions extends TooltipControllerOptions {
|
|
29
|
+
content: string | Node | (() => Node);
|
|
30
|
+
host?: HTMLElement;
|
|
31
|
+
}
|
|
32
|
+
interface TooltipProps extends TooltipOptions {
|
|
33
|
+
trigger: HTMLElement;
|
|
34
|
+
}
|
|
35
|
+
declare class Tooltip {
|
|
36
|
+
private readonly positioner;
|
|
37
|
+
private readonly content;
|
|
38
|
+
private readonly handle;
|
|
39
|
+
private readonly trigger;
|
|
40
|
+
private readonly release;
|
|
41
|
+
constructor(trigger: HTMLElement, opts: TooltipOptions);
|
|
42
|
+
setContent(content: string | Node | (() => Node)): void;
|
|
43
|
+
destroy(): void;
|
|
44
|
+
}
|
|
45
|
+
declare function createTooltip(props: TooltipProps): Tooltip;
|
|
46
|
+
|
|
47
|
+
export { Tooltip, type TooltipApi, type TooltipController, type TooltipControllerOptions, type TooltipOptions, type TooltipProps, type TooltipService, createTooltip, tooltipController, tooltipDef };
|
package/dist/tooltip.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { zagPositioning, splitPlacement } from './chunk-3Q32K4PE.js';
|
|
2
|
+
import { ownTeardown } from './chunk-A72NWYNP.js';
|
|
3
|
+
import { normalizeProps, nextUid, runMachine, 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 tooltip from '@zag-js/tooltip';
|
|
12
|
+
|
|
13
|
+
function tooltipController(opts = {}) {
|
|
14
|
+
return {
|
|
15
|
+
machine: tooltip.machine,
|
|
16
|
+
props: {
|
|
17
|
+
id: nextUid("vela-tooltip"),
|
|
18
|
+
openDelay: opts.openDelay ?? 0,
|
|
19
|
+
closeDelay: opts.closeDelay ?? 0,
|
|
20
|
+
interactive: opts.interactive ?? false,
|
|
21
|
+
ids: opts.triggerId ? { trigger: opts.triggerId } : void 0,
|
|
22
|
+
positioning: zagPositioning(opts, opts.placement ? splitPlacement(opts.placement) : { side: "top", align: "center" })
|
|
23
|
+
},
|
|
24
|
+
connect: (service) => tooltip.connect(service, normalizeProps)
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
var tooltipDef = defineComponent({
|
|
28
|
+
name: "tooltip",
|
|
29
|
+
parts: ["positioner", "content"],
|
|
30
|
+
settings: { radius: t.radius.md }
|
|
31
|
+
});
|
|
32
|
+
var injectStyles = defineStyles(
|
|
33
|
+
"vela-ui-tooltip",
|
|
34
|
+
css`@layer vela.ui{[data-slot=tooltip-content]{background:${t.bg};color:${t.fg};border:1px solid ${t.border.soft};border-radius:${tooltipDef.vars.radius};box-shadow:${t.shadow};font-size:${t.fontSize.md};padding:${t.space[1]} ${t.space[2]};pointer-events:none;max-width:280px;z-index:${t.z.tooltip};line-height:1.4}[data-slot=tooltip-content][data-interactive]{pointer-events:auto}[data-slot=tooltip-content][data-state=open]{animation:vela-tooltip-in ${t.dur.fast} ease}@keyframes vela-tooltip-in{0%{opacity:0;transform:scale(.97)}to{opacity:1;transform:scale(1)}}}`
|
|
35
|
+
);
|
|
36
|
+
function resolveHost(trigger, host) {
|
|
37
|
+
return host ?? trigger.closest(".vela-ui") ?? trigger.ownerDocument.body;
|
|
38
|
+
}
|
|
39
|
+
var Tooltip = class {
|
|
40
|
+
constructor(trigger, opts) {
|
|
41
|
+
this.trigger = trigger;
|
|
42
|
+
const doc = trigger.ownerDocument;
|
|
43
|
+
injectStyles(doc);
|
|
44
|
+
this.content = h("div", { className: "vela-tooltip", slot: tooltipDef.slot("content") });
|
|
45
|
+
this.positioner = h("div", { className: "vela-ui-layer", slot: tooltipDef.slot("positioner") }, this.content);
|
|
46
|
+
resolveHost(trigger, opts.host).appendChild(this.positioner);
|
|
47
|
+
this.setContent(opts.content);
|
|
48
|
+
const ctrl = tooltipController(opts);
|
|
49
|
+
const mid = String(ctrl.props.id);
|
|
50
|
+
if (opts.triggerId) trigger.id = opts.triggerId;
|
|
51
|
+
this.handle = runMachine(ctrl.machine, ctrl.props, (service) => {
|
|
52
|
+
const api = ctrl.connect(service);
|
|
53
|
+
spreadProps(trigger, api.getTriggerProps(), mid);
|
|
54
|
+
spreadProps(this.positioner, api.getPositionerProps(), mid);
|
|
55
|
+
spreadProps(this.content, api.getContentProps(), mid);
|
|
56
|
+
});
|
|
57
|
+
this.release = ownTeardown(trigger, () => {
|
|
58
|
+
this.handle.stop();
|
|
59
|
+
this.positioner.remove();
|
|
60
|
+
this.trigger.removeAttribute("data-scope");
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
setContent(content) {
|
|
64
|
+
this.content.replaceChildren(typeof content === "function" ? content() : content);
|
|
65
|
+
}
|
|
66
|
+
destroy() {
|
|
67
|
+
this.release();
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
function createTooltip(props) {
|
|
71
|
+
return new Tooltip(props.trigger, props);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export { Tooltip, createTooltip, tooltipController, tooltipDef };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
type VariantSpec = Readonly<Record<string, readonly string[]>>;
|
|
2
|
+
type VariantValues<S extends VariantSpec> = {
|
|
3
|
+
[K in keyof S]?: S[K][number];
|
|
4
|
+
};
|
|
5
|
+
interface VariantFn<S extends VariantSpec> {
|
|
6
|
+
(values?: VariantValues<S>): Record<string, string>;
|
|
7
|
+
readonly spec: S;
|
|
8
|
+
/** The value each key resolves to. */
|
|
9
|
+
resolve(values?: VariantValues<S>): {
|
|
10
|
+
[K in keyof S]: S[K][number];
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
type VariantProps<F> = F extends VariantFn<infer S> ? VariantValues<S> : never;
|
|
14
|
+
declare function variants<const S extends VariantSpec>(spec: S): VariantFn<S>;
|
|
15
|
+
|
|
16
|
+
export { type VariantFn as V, type VariantProps as a, type VariantSpec as b, type VariantValues as c, variants as v };
|
package/dist/zag.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export { normalizeProps, spreadProps } from '@zag-js/vanilla';
|
|
2
|
+
import { Machine, MachineSchema, Service } from '@zag-js/core';
|
|
3
|
+
|
|
4
|
+
/** The MachineHandle for a given machine definition (package schemas aren't exported —
|
|
5
|
+
* infer them from the machine value: `HandleOf<typeof tooltip.machine>`). */
|
|
6
|
+
type HandleOf<M> = M extends Machine<infer T extends MachineSchema> ? MachineHandle<T> : never;
|
|
7
|
+
interface MachineHandle<T extends MachineSchema> {
|
|
8
|
+
service: Service<T>;
|
|
9
|
+
/** Re-run the view projection now (e.g. after external DOM swaps). */
|
|
10
|
+
flush(): void;
|
|
11
|
+
stop(): void;
|
|
12
|
+
}
|
|
13
|
+
/** Start a machine and keep `render(service)` in sync with every transition.
|
|
14
|
+
* `render` runs once immediately (initial projection) and on each machine notification. */
|
|
15
|
+
declare function runMachine<T extends MachineSchema>(machine: Machine<T>, props: Partial<T['props']> | (() => Partial<T['props']>), render: (service: Service<T>) => void): MachineHandle<T>;
|
|
16
|
+
/** Unique ids for machine instances (Zag keys its DOM lookups on them). */
|
|
17
|
+
declare function nextUid(prefix: string): string;
|
|
18
|
+
|
|
19
|
+
export { type HandleOf, type MachineHandle, nextUid, runMachine };
|
package/dist/zag.js
ADDED
package/docs/theming.md
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
# Theming
|
|
2
|
+
|
|
3
|
+
A theme is data: the chart's colors and font, every design token, and the settings of each
|
|
4
|
+
component. `createTheme` builds one from a few choices; applied to a host, it is written once
|
|
5
|
+
per document (or shadow root) as a rule in the `vela.theme` cascade layer, keyed by the host's
|
|
6
|
+
`data-vela-theme` attribute.
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
import { createTheme, ensureUIHost } from '@luxalgo/vela-ui/theme';
|
|
10
|
+
|
|
11
|
+
const theme = createTheme({
|
|
12
|
+
base: 'dark', // 'dark' (default), 'light', or a chart theme's seven fields
|
|
13
|
+
accent: '#7c3aed', // brand color; the ink on it is derived
|
|
14
|
+
radius: 'sm', // none | sm | md | lg: scales every radius token
|
|
15
|
+
font: 'Inter, sans-serif',
|
|
16
|
+
tokens: { 'surface-elev': '#1b1c22' }, // any token, by name
|
|
17
|
+
components: { button: { radius: '2px' } }, // a component's own settings
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
ensureUIHost(document.getElementById('app')!, theme);
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
On a page of your own, `ensureUIHost(el, theme)` makes the element a kit host and themes it:
|
|
24
|
+
the kit's base styles apply inside it, and menus, dialogs and tooltips opened from it mount
|
|
25
|
+
there. `applyTheme(el, theme)` alone only themes an element, so a menu opened from it would
|
|
26
|
+
mount outside, unthemed; use it to switch a host that is already one to another theme.
|
|
27
|
+
|
|
28
|
+
In Vela, pass the theme as the chart's `theme` option or to `setTheme`, and offer it in the
|
|
29
|
+
chart settings with `registerTheme({ id, label, theme })`.
|
|
30
|
+
|
|
31
|
+
## Themes from colors alone
|
|
32
|
+
|
|
33
|
+
`colors` builds a whole theme from a few colors: grid and border derive from the background
|
|
34
|
+
and the text, and light or dark is read from the background.
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
const paper = createTheme({ colors: { background: '#fdf6e3', accent: '#268bd2' } });
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`up` and `down` are the candles' colors, and the `up`, `down`, `profit` and `loss` tokens
|
|
41
|
+
follow them. In Vela they are the candles' defaults: a chart's own `upColor` and
|
|
42
|
+
`downColor` options, and colors a user picks in its settings, win over them.
|
|
43
|
+
|
|
44
|
+
A theme of colors only is plain JSON that cannot break the UI: users can save their own, an
|
|
45
|
+
app can offer a picker, and an agent can write one. A theme file names the schema shipped in
|
|
46
|
+
the package, so editors and CI check it:
|
|
47
|
+
|
|
48
|
+
```json
|
|
49
|
+
{
|
|
50
|
+
"$schema": "./node_modules/@luxalgo/vela-ui/dist/theme.schema.json",
|
|
51
|
+
"colors": { "background": "#0f1117", "text": "#c9d1d9", "accent": "#7c3aed" }
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## The tokens
|
|
56
|
+
|
|
57
|
+
Every token is a custom property, `--vela-<name>`; in a theme, `tokens` takes the name
|
|
58
|
+
without the prefix, and in a component's CSS `t` reads it (`${t.fg.muted}`).
|
|
59
|
+
|
|
60
|
+
| Group | Tokens | What they set |
|
|
61
|
+
| --- | --- | --- |
|
|
62
|
+
| Text | `fg`, `fg-muted`, `fg-faint`, `fg-bright`, `fg-on-fill` | body text, secondary text, placeholders and disabled text, emphasized text, ink on a saturated fill |
|
|
63
|
+
| Surfaces | `bg`, `surface`, `surface-elev`, `surface-overlay`, `surface-sunken` | the chart's background, panels, menus and popovers (opaque, above the chart), recessed fields |
|
|
64
|
+
| Lines | `border`, `border-strong`, `border-soft`, `border-faint`, `separator-hover-band`, `separator-hover-line` | borders, field borders, rules inside a panel, a divider under the pointer |
|
|
65
|
+
| States | `hover`, `hover-strong`, `active`, `focus`, `focus-soft`, `selected-bg`, `selected-fg`, `highlight` | hover and pressed washes, the focus ring, the selected chip and its ink, favorites |
|
|
66
|
+
| Brand and meaning | `accent`, `accent-bright`, `up`, `down`, `profit`, `loss`, `danger` | the brand color, the candles' colors, gains and losses, destructive actions |
|
|
67
|
+
| Depth | `shadow`, `shadow-dialog`, `backdrop` | floating surfaces, dialogs, the dim behind a dialog |
|
|
68
|
+
| Scrollbars | `scroll`, `scroll-size` | the thumb's color (the chart's border color by default) and the bar's width (5px) |
|
|
69
|
+
| Scale | `space-1`…`space-4`, `radius-sm`, `radius-md`, `radius-lg`, `font`, `font-size-sm`, `font-size-md`, `font-size-lg`, `dur-fast`, `dur-med`, `ease`, `z-tooltip`, `z-menu`, `z-dialog`, `z-popover` | spacing, corners, type, motion and stacking, the same in every theme |
|
|
70
|
+
|
|
71
|
+
The colors derive from the chart theme's seven fields, so a theme that sets only those
|
|
72
|
+
(or only `colors`) still sets every token.
|
|
73
|
+
|
|
74
|
+
## Component settings
|
|
75
|
+
|
|
76
|
+
Each component declares a few settings with defaults that point at shared tokens (the
|
|
77
|
+
button's `radius` defaults to `radius-md`), so a theme that sets nothing looks exactly as
|
|
78
|
+
before. Each is written as `--vela-<component>-<setting>`, so a host can also set one in
|
|
79
|
+
its own CSS. The `components` field is typed from the declarations: a component or a setting
|
|
80
|
+
that does not exist fails the typecheck. `dist/manifest.json` lists every component's
|
|
81
|
+
settings.
|
|
82
|
+
|
|
83
|
+
## Restyling a component completely
|
|
84
|
+
|
|
85
|
+
When settings are not enough, a component's `css` restyles its parts: shape, typography,
|
|
86
|
+
borders, shadows, every variant and state. It is keyed by the parts the component declares:
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
import { createTheme, css, t } from '@luxalgo/vela-ui';
|
|
90
|
+
|
|
91
|
+
const theme = createTheme({
|
|
92
|
+
components: {
|
|
93
|
+
button: {
|
|
94
|
+
radius: '999px',
|
|
95
|
+
css: {
|
|
96
|
+
root: css`
|
|
97
|
+
text-transform: uppercase;
|
|
98
|
+
box-shadow: ${t.shadow};
|
|
99
|
+
&[data-variant='outline'] { border-width: 2px; }
|
|
100
|
+
&:hover:not(:disabled) { transform: translateY(-1px); }
|
|
101
|
+
`,
|
|
102
|
+
icon: css`order: 1;`,
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
- **The name and the part pick the element.** `components.button.css.icon` becomes a rule on
|
|
110
|
+
`[data-slot~='button-icon']`; `&` is that part, so its variants and states follow it.
|
|
111
|
+
- **Scoped to the theme.** Each part's rule sits under the theme's `data-vela-theme`, so two
|
|
112
|
+
charts with two themes on one page each keep their own. Floating layers mount inside their
|
|
113
|
+
themed host, so a select's list or a dialog's content is reached the same way.
|
|
114
|
+
- **In the last layer.** It goes into `@layer vela.custom`, after every layer of the kit, so
|
|
115
|
+
it wins without `!important`; a page's unlayered CSS still beats it.
|
|
116
|
+
- **Flattened at run time**, one level: `&` rules, rules without `&` (descendants), and
|
|
117
|
+
`@media`, `@supports` or `@container` around either. `@keyframes` and `@font-face` belong
|
|
118
|
+
in the page's stylesheet; the part uses them by name.
|
|
119
|
+
- **Written against the public contract**: the parts, `data-variant`, `data-size`, and the
|
|
120
|
+
state attributes (`data-state`, `data-selected`, `data-disabled`). Class names are not part
|
|
121
|
+
of it; `checkTheme` flags them, and `!important`. The shared stylelint config
|
|
122
|
+
(`@luxalgo/vela-ui/stylelint`) checks CSS written with the `css` tag in a project too.
|
|
123
|
+
- **Off for themes loaded from data.** CSS that was not written with the `css` tag (a saved
|
|
124
|
+
JSON, a shared file, a generated theme) is left out unless the host passes
|
|
125
|
+
`createTheme(input, { allowCss: true })`. CSS from someone else can restyle the page to
|
|
126
|
+
mislead and can load remote images that leak what the page shows. Colors and settings carry
|
|
127
|
+
no such risk.
|
|
128
|
+
|
|
129
|
+
CSS changes how a component looks, not its markup or behavior.
|
|
130
|
+
|
|
131
|
+
## Checking a theme
|
|
132
|
+
|
|
133
|
+
`checkTheme(input)` lists what a theme gets wrong: unknown tokens, a component, setting or
|
|
134
|
+
part that does not exist (the kit's components, and those the page declared with
|
|
135
|
+
`defineComponent`), colors the theme cannot derive from (it reads `#rrggbb` and `rgb()`),
|
|
136
|
+
text with too little contrast on its background, ink with too little contrast on the accent,
|
|
137
|
+
and part CSS that is left out or reaches past the component's contract. `createTheme` warns
|
|
138
|
+
about each problem once. The typecheck catches the same names in TypeScript; this catches
|
|
139
|
+
them in a theme loaded from JSON or written in plain JavaScript, where nothing else would.
|
|
140
|
+
|
|
141
|
+
## Cascade layers
|
|
142
|
+
|
|
143
|
+
Every style the kit and Vela write sits in a cascade layer, declared once per document (or
|
|
144
|
+
shadow root) in this order, lowest first:
|
|
145
|
+
|
|
146
|
+
| Layer | Holds | Written by |
|
|
147
|
+
| --- | --- | --- |
|
|
148
|
+
| `vela.theme` | the tokens and the scale | `applyTheme`, or a built-in theme's CSS file |
|
|
149
|
+
| `vela.ui` | the kit's components | each component, when it is first created |
|
|
150
|
+
| `vela.chrome` | Vela's own chrome: toolbars, legends, the status line, dialog layouts | Vela |
|
|
151
|
+
| `vela.pro` | Vela Pro's features | Vela Pro |
|
|
152
|
+
| `vela.custom` | a theme's component `css` | `applyTheme` |
|
|
153
|
+
| no layer | your page's CSS | you |
|
|
154
|
+
|
|
155
|
+
A later layer wins over an earlier one whatever the selectors' weight, and CSS in no layer
|
|
156
|
+
wins over all of them, so a page overrides any of it without `!important`. Layers a page
|
|
157
|
+
declared before the first Vela stylesheet rank below Vela's. Write CSS that restyles
|
|
158
|
+
components into `vela.custom` to sit above the kit and below your page's other CSS.
|
|
159
|
+
|
|
160
|
+
A component of your own (built with the kit's helpers, or copied with `vela-ui add --source`)
|
|
161
|
+
puts its base styles in `vela.ui`, like the kit's, so a theme's part CSS and your restyles
|
|
162
|
+
reach it. In `vela.custom` its rules would tie with the theme's, and whichever stylesheet
|
|
163
|
+
loaded last would win, usually the component's own.
|
|
164
|
+
|
|
165
|
+
Unlayered CSS also reaches the kit when you did not mean it to: a global reset such as
|
|
166
|
+
`button { background: none; }` or `input { border: 0; }` now restyles the kit's buttons and
|
|
167
|
+
fields. Scope such rules away from Vela (`button:where(:not(.vela-ui *)) { … }`), or move them
|
|
168
|
+
into a layer declared before Vela's (`@layer reset;` first in your stylesheet).
|
|
169
|
+
|
|
170
|
+
The kit's CSS does not reach the other way: a component's styles apply inside kit hosts and
|
|
171
|
+
the floating layers they open only, so a page's own components keep their look, even those
|
|
172
|
+
that use the same part names (`data-slot="select-trigger"`).
|
|
173
|
+
|
|
174
|
+
## Overriding from a page's CSS
|
|
175
|
+
|
|
176
|
+
The theme layer sits below every other style, so a page's own CSS overrides any token without
|
|
177
|
+
`!important`. `[data-vela-theme]` reaches every themed host, chrome inside a chart included:
|
|
178
|
+
|
|
179
|
+
```css
|
|
180
|
+
[data-vela-theme] { --vela-accent: #7c3aed; }
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## Scrollbars
|
|
184
|
+
|
|
185
|
+
Every scroller inside a kit host (`.vela-ui`) and its floating layers shows the same
|
|
186
|
+
scrollbar: thin, a rounded thumb, no track and no arrows. `scroll` colors the thumb and
|
|
187
|
+
`scroll-size` sets the bar's width; set them like any token:
|
|
188
|
+
|
|
189
|
+
```ts
|
|
190
|
+
createTheme({ tokens: { scroll: '#3b3f4a', 'scroll-size': '8px' } });
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
Chromium and Safari draw it from the `::-webkit-scrollbar` parts, Firefox from
|
|
194
|
+
`scrollbar-width` and `scrollbar-color`. Setting `scrollbar-width` or `scrollbar-color` on an
|
|
195
|
+
element switches Chromium back to its native bar, so a page that sets them on every element
|
|
196
|
+
(`* { scrollbar-width: thin; }`) brings the native bar back inside the chart too. Leave the
|
|
197
|
+
kit out of that rule, or reset it:
|
|
198
|
+
|
|
199
|
+
```css
|
|
200
|
+
.vela-ui, .vela-ui * { scrollbar-width: auto; scrollbar-color: auto; }
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
A scroller outside any kit host takes the same scrollbar with `overlayScrollbarCss(selector)`
|
|
204
|
+
(`@luxalgo/vela-ui/styles`).
|
|
205
|
+
|
|
206
|
+
## Without JavaScript
|
|
207
|
+
|
|
208
|
+
A page that uses the kit without building a theme can link a built-in theme as plain CSS; it
|
|
209
|
+
sets every token on the page root:
|
|
210
|
+
|
|
211
|
+
```html
|
|
212
|
+
<link rel="stylesheet" href="node_modules/@luxalgo/vela-ui/dist/themes/dark.css" />
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
Bundlers resolve `@luxalgo/vela-ui/themes/dark.css` and `@luxalgo/vela-ui/themes/light.css`.
|
|
216
|
+
The components still go in a kit host, which gives them their base styles: call
|
|
217
|
+
`ensureUIHost(el)` without a theme on the element that holds them.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# What to change, and where
|
|
2
|
+
|
|
3
|
+
| To change | Where | It reaches |
|
|
4
|
+
| --- | --- | --- |
|
|
5
|
+
| Chart colors: background, candles, grid, axis text | the theme's seven chart fields, or `colors` in `createTheme` | the chart's canvas, and the tokens derived from them |
|
|
6
|
+
| Brand color, radius scale, font | `accent`, `radius`, `font` in `createTheme` | every component |
|
|
7
|
+
| One token | `tokens` in `createTheme`, or CSS on `[data-vela-theme]` | every component that uses it |
|
|
8
|
+
| Scrollbars | the `scroll` (thumb color) and `scroll-size` (width) tokens | every scroller inside a kit host |
|
|
9
|
+
| Vela's own chrome: toolbars, sidebar, legends, status line | the same tokens; for more, CSS on its `.vela-*` classes in your page (the chrome sits in `@layer vela.chrome`, below it) | the chart's chrome |
|
|
10
|
+
| A theme made of colors only | `createTheme({ colors })`; in Vela, `registerTheme` offers it in the chart settings | the chart and every component |
|
|
11
|
+
| One component's sizes, radius, weight or variant colors | its settings in `components`, or CSS on its `--vela-<component>-*` variables | that component everywhere |
|
|
12
|
+
| One component's whole look: shape, typography, states, decorations | its `css` in `components`, by part | that component wherever the theme applies |
|
|
13
|
+
| Anything else about one component's look | CSS on its `data-slot`, `data-variant`, `data-size` | that component everywhere |
|
|
14
|
+
| A component's behavior or markup | a component of your own, built from the kit's helpers ([Writing a component](writing-a-component.md)) | your screens |
|
|
15
|
+
|
|
16
|
+
`dist/manifest.json` lists each component's parts and their slots, its settings, its
|
|
17
|
+
variants and the attributes its CSS styles by. [Theming](theming.md) lists the tokens and the
|
|
18
|
+
cascade layers each kind of change lands in. The chart's own canvas (candles, grid, axis
|
|
19
|
+
text) is drawn from the theme object, not from CSS, so those colors change through the theme
|
|
20
|
+
only.
|