@luxalgo/vela-ui 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +43 -0
- package/LICENSE +201 -0
- package/NOTICE +28 -0
- package/README.md +83 -3
- package/cli/engine.mjs +282 -0
- package/cli/index.mjs +154 -0
- package/dist/badge.d.ts +26 -0
- package/dist/badge.js +44 -0
- package/dist/bar-chart.d.ts +40 -0
- package/dist/bar-chart.js +105 -0
- package/dist/button.d.ts +41 -0
- package/dist/button.js +10 -0
- package/dist/calendar.d.ts +22 -0
- package/dist/calendar.js +1 -0
- package/dist/callout-bubble.d.ts +98 -0
- package/dist/callout-bubble.js +173 -0
- package/dist/chart.d.ts +30 -0
- package/dist/chart.js +1 -0
- package/dist/checkbox.d.ts +60 -0
- package/dist/checkbox.js +12 -0
- package/dist/chunk-2GQIZM5Z.js +28 -0
- package/dist/chunk-2Q4JRINP.js +403 -0
- package/dist/chunk-3Q32K4PE.js +85 -0
- package/dist/chunk-5QHXOAZA.js +351 -0
- package/dist/chunk-6NXY62JS.js +25 -0
- package/dist/chunk-6QCILIT2.js +52 -0
- package/dist/chunk-A2FJ7Y7D.js +55 -0
- package/dist/chunk-A72NWYNP.js +26 -0
- package/dist/chunk-AJ2IYSOI.js +553 -0
- package/dist/chunk-BXMWQIBO.js +66 -0
- package/dist/chunk-CH3DV6FD.js +280 -0
- package/dist/chunk-EZQXTO6K.js +89 -0
- package/dist/chunk-FCO3YZLT.js +81 -0
- package/dist/chunk-FN2BUFNM.js +10 -0
- package/dist/chunk-FVH6L7FM.js +18 -0
- package/dist/chunk-G7IQLY3A.js +183 -0
- package/dist/chunk-IDA2BT7D.js +29 -0
- package/dist/chunk-J2QJATCD.js +12 -0
- package/dist/chunk-LZWZV2ZS.js +18 -0
- package/dist/chunk-MMTMOV6R.js +31 -0
- package/dist/chunk-OBLIX3VN.js +227 -0
- package/dist/chunk-P4MTEMT7.js +23 -0
- package/dist/chunk-Q6WTDVH6.js +31 -0
- package/dist/chunk-S7USVSYP.js +50 -0
- package/dist/chunk-SAPURP46.js +133 -0
- package/dist/chunk-TAKSIV57.js +90 -0
- package/dist/chunk-V6TTTMTE.js +79 -0
- package/dist/chunk-VMCR3S2A.js +22 -0
- package/dist/chunk-X4YPSIW6.js +72 -0
- package/dist/chunk-X66RJAIS.js +14 -0
- package/dist/chunk-XJAPCCOJ.js +101 -0
- package/dist/chunk-ZB3BZHSN.js +219 -0
- package/dist/color-picker.d.ts +103 -0
- package/dist/color-picker.js +19 -0
- package/dist/color.d.ts +24 -0
- package/dist/color.js +1 -0
- package/dist/context-menu.d.ts +72 -0
- package/dist/context-menu.js +161 -0
- package/dist/css.d.ts +15 -0
- package/dist/css.js +4 -0
- package/dist/data-table-DtU3FX9j.d.ts +61 -0
- package/dist/data-table.d.ts +3 -0
- package/dist/data-table.js +88 -0
- package/dist/date-picker.d.ts +90 -0
- package/dist/date-picker.js +257 -0
- package/dist/define-D5u3F5Dj.d.ts +21 -0
- package/dist/dialog.d.ts +89 -0
- package/dist/dialog.js +258 -0
- package/dist/dispose.d.ts +9 -0
- package/dist/dispose.js +2 -0
- package/dist/donut.d.ts +27 -0
- package/dist/donut.js +67 -0
- package/dist/drawer.d.ts +119 -0
- package/dist/drawer.js +326 -0
- package/dist/dropdown-menu.d.ts +114 -0
- package/dist/dropdown-menu.js +18 -0
- package/dist/empty.d.ts +21 -0
- package/dist/empty.js +38 -0
- package/dist/field.d.ts +147 -0
- package/dist/field.js +328 -0
- package/dist/glyph-select.d.ts +57 -0
- package/dist/glyph-select.js +17 -0
- package/dist/headless.d.ts +6 -0
- package/dist/headless.js +9 -0
- package/dist/hover-card.d.ts +43 -0
- package/dist/hover-card.js +97 -0
- package/dist/i18n.d.ts +20 -0
- package/dist/i18n.js +1 -0
- package/dist/icons.d.ts +20 -0
- package/dist/icons.js +2 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.js +13 -0
- package/dist/input-group.d.ts +57 -0
- package/dist/input-group.js +86 -0
- package/dist/input.d.ts +54 -0
- package/dist/input.js +9 -0
- package/dist/kbd.d.ts +19 -0
- package/dist/kbd.js +8 -0
- package/dist/kit-text.d.ts +8 -0
- package/dist/kit-text.js +2 -0
- package/dist/line-chart.d.ts +32 -0
- package/dist/line-chart.js +120 -0
- package/dist/manifest.json +3854 -0
- package/dist/number-input.d.ts +99 -0
- package/dist/number-input.js +14 -0
- package/dist/page.d.ts +7 -0
- package/dist/page.js +1 -0
- package/dist/palette.d.ts +55 -0
- package/dist/palette.js +1 -0
- package/dist/placement.d.ts +98 -0
- package/dist/placement.js +1 -0
- package/dist/popover.d.ts +107 -0
- package/dist/popover.js +15 -0
- package/dist/scatter-chart.d.ts +32 -0
- package/dist/scatter-chart.js +121 -0
- package/dist/select.d.ts +112 -0
- package/dist/select.js +19 -0
- package/dist/sparkline.d.ts +22 -0
- package/dist/sparkline.js +72 -0
- package/dist/stat.d.ts +29 -0
- package/dist/stat.js +41 -0
- package/dist/styles.d.ts +22 -0
- package/dist/styles.js +2 -0
- package/dist/surface-events.d.ts +17 -0
- package/dist/surface-events.js +1 -0
- package/dist/surface-exit.d.ts +25 -0
- package/dist/surface-exit.js +1 -0
- package/dist/switch.d.ts +54 -0
- package/dist/switch.js +92 -0
- package/dist/t.d.ts +89 -0
- package/dist/t.js +1 -0
- package/dist/tabs.d.ts +63 -0
- package/dist/tabs.js +150 -0
- package/dist/text-area.d.ts +54 -0
- package/dist/text-area.js +9 -0
- package/dist/theme.d.ts +188 -0
- package/dist/theme.js +8 -0
- package/dist/theme.schema.json +1745 -0
- package/dist/themes/dark.css +3 -0
- package/dist/themes/light.css +3 -0
- package/dist/toggle-group.d.ts +56 -0
- package/dist/toggle-group.js +130 -0
- package/dist/tokens.d.ts +16 -0
- package/dist/tokens.js +3 -0
- package/dist/tooltip.d.ts +47 -0
- package/dist/tooltip.js +74 -0
- package/dist/variants-B4stUBnY.d.ts +16 -0
- package/dist/zag.d.ts +19 -0
- package/dist/zag.js +2 -0
- package/docs/theming.md +211 -0
- package/docs/what-to-change.md +20 -0
- package/docs/writing-a-component.md +247 -0
- package/llms.txt +66 -0
- package/package.json +90 -6
- package/registry/badge.ts +119 -0
- package/registry/bar-chart.ts +215 -0
- package/registry/button.ts +303 -0
- package/registry/callout-bubble.ts +336 -0
- package/registry/checkbox.ts +234 -0
- package/registry/color-picker.ts +582 -0
- package/registry/context-menu.ts +208 -0
- package/registry/data-table.ts +215 -0
- package/registry/date-picker.ts +483 -0
- package/registry/dialog.ts +535 -0
- package/registry/donut.ts +145 -0
- package/registry/drawer.ts +636 -0
- package/registry/dropdown-menu.ts +762 -0
- package/registry/empty.ts +91 -0
- package/registry/field.ts +585 -0
- package/registry/glyph-select.ts +268 -0
- package/registry/hover-card.ts +222 -0
- package/registry/input-group.ts +229 -0
- package/registry/input.ts +181 -0
- package/registry/kbd.ts +64 -0
- package/registry/line-chart.ts +218 -0
- package/registry/number-input.ts +443 -0
- package/registry/popover.ts +368 -0
- package/registry/scatter-chart.ts +221 -0
- package/registry/select.ts +620 -0
- package/registry/sparkline.ts +114 -0
- package/registry/stat.ts +96 -0
- package/registry/switch.ts +205 -0
- package/registry/tabs.ts +392 -0
- package/registry/text-area.ts +186 -0
- package/registry/toggle-group.ts +295 -0
- package/registry/tooltip.ts +156 -0
- package/skills/theming-vela-ui/SKILL.md +137 -0
- package/skills/using-vela-ui-components/SKILL.md +134 -0
- package/skills/writing-vela-ui-components/SKILL.md +163 -0
- package/src/components/badge.ts +119 -0
- package/src/components/bar-chart.ts +215 -0
- package/src/components/button.ts +303 -0
- package/src/components/callout-bubble.ts +336 -0
- package/src/components/checkbox.ts +234 -0
- package/src/components/color-picker.ts +582 -0
- package/src/components/context-menu.ts +208 -0
- package/src/components/data-table.ts +215 -0
- package/src/components/date-picker.ts +483 -0
- package/src/components/dialog.ts +535 -0
- package/src/components/donut.ts +145 -0
- package/src/components/drawer.ts +636 -0
- package/src/components/dropdown-menu.ts +762 -0
- package/src/components/empty.ts +91 -0
- package/src/components/field.ts +585 -0
- package/src/components/glyph-select.ts +268 -0
- package/src/components/hover-card.ts +222 -0
- package/src/components/input-group.ts +229 -0
- package/src/components/input.ts +181 -0
- package/src/components/kbd.ts +64 -0
- package/src/components/line-chart.ts +218 -0
- package/src/components/number-input.ts +443 -0
- package/src/components/popover.ts +368 -0
- package/src/components/scatter-chart.ts +221 -0
- package/src/components/select.ts +620 -0
- package/src/components/sparkline.ts +114 -0
- package/src/components/stat.ts +96 -0
- package/src/components/switch.ts +205 -0
- package/src/components/tabs.ts +392 -0
- package/src/components/text-area.ts +186 -0
- package/src/components/toggle-group.ts +295 -0
- package/src/components/tooltip.ts +156 -0
- package/src/index.ts +24 -0
- package/src/lib/calendar.ts +112 -0
- package/src/lib/chart.ts +72 -0
- package/src/lib/color.ts +89 -0
- package/src/lib/component-index.ts +131 -0
- package/src/lib/css.ts +44 -0
- package/src/lib/define.ts +45 -0
- package/src/lib/dispose.ts +36 -0
- package/src/lib/h.ts +55 -0
- package/src/lib/headless.ts +16 -0
- package/src/lib/i18n.ts +30 -0
- package/src/lib/icons.ts +237 -0
- package/src/lib/kit-text.ts +26 -0
- package/src/lib/page.ts +24 -0
- package/src/lib/palette.ts +81 -0
- package/src/lib/placement.ts +188 -0
- package/src/lib/styles.ts +53 -0
- package/src/lib/surface-events.ts +31 -0
- package/src/lib/surface-exit.ts +87 -0
- package/src/lib/t.ts +68 -0
- package/src/lib/theme.ts +654 -0
- package/src/lib/tokens.ts +111 -0
- package/src/lib/variants.ts +32 -0
- package/src/lib/zag.ts +46 -0
- package/stylelint/index.mjs +60 -0
- package/stylelint/lint.mjs +81 -0
- package/stylelint/plugin.mjs +115 -0
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
// Button: a <button> with optional icons before and after its text. `default` is filled with
|
|
2
|
+
// the selection color (OK, Apply), `outline` bordered (the dialogs' Cancel), `secondary` a
|
|
3
|
+
// sunken fill, `ghost` bare until hovered (toolbar and header icons), `destructive` tinted
|
|
4
|
+
// with the danger color, `link` text that underlines on hover, `up` and `down` filled with the
|
|
5
|
+
// market's colors (buy and sell). Heights: `xs` 26px, `sm` 30px
|
|
6
|
+
// (panels), `default` 34px (dialog footers), `lg` 40px (touch); the `icon*` sizes are the
|
|
7
|
+
// same heights, square, for an icon alone, which `label` names.
|
|
8
|
+
import { iconEl } from '../lib/icons';
|
|
9
|
+
import { css, defineStyles } from '../lib/css';
|
|
10
|
+
import { defineComponent } from '../lib/define';
|
|
11
|
+
import { h } from '../lib/h';
|
|
12
|
+
import { t } from '../lib/t';
|
|
13
|
+
import { variants, type VariantProps } from '../lib/variants';
|
|
14
|
+
|
|
15
|
+
export const buttonDef = defineComponent({
|
|
16
|
+
name: 'button',
|
|
17
|
+
parts: ['root', 'icon'],
|
|
18
|
+
settings: {
|
|
19
|
+
radius: t.radius.md,
|
|
20
|
+
height: '34px',
|
|
21
|
+
'height-xs': '26px',
|
|
22
|
+
'height-sm': '30px',
|
|
23
|
+
'height-lg': '40px',
|
|
24
|
+
'font-size': '14px',
|
|
25
|
+
'font-size-xs': '12px',
|
|
26
|
+
'font-size-sm': '13px',
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export const buttonVariants = variants({
|
|
31
|
+
variant: ['default', 'outline', 'secondary', 'ghost', 'destructive', 'link', 'up', 'down'],
|
|
32
|
+
size: ['default', 'xs', 'sm', 'lg', 'icon', 'icon-xs', 'icon-sm', 'icon-lg'],
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
export type ButtonVariant = (typeof buttonVariants.spec.variant)[number];
|
|
36
|
+
export type ButtonSize = (typeof buttonVariants.spec.size)[number];
|
|
37
|
+
|
|
38
|
+
export interface ButtonProps extends VariantProps<typeof buttonVariants> {
|
|
39
|
+
/** The visible text (the `icon*` sizes show none; `label` names them). */
|
|
40
|
+
text?: string;
|
|
41
|
+
/** Icon id from the kit's registry, before the text (the icon of an `icon*` size). */
|
|
42
|
+
icon?: string;
|
|
43
|
+
/** Icon id after the text (a menu trigger's chevron). */
|
|
44
|
+
iconEnd?: string;
|
|
45
|
+
/** Accessible name; required for the `icon*` sizes, defaults to `text`. */
|
|
46
|
+
label?: string;
|
|
47
|
+
/** A toggle button's state (`aria-pressed`). Omitted: not a toggle. */
|
|
48
|
+
pressed?: boolean;
|
|
49
|
+
disabled?: boolean;
|
|
50
|
+
onClick?: (e: MouseEvent) => void;
|
|
51
|
+
/** Extra class names (layout hooks). */
|
|
52
|
+
className?: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface ButtonHandle {
|
|
56
|
+
readonly el: HTMLButtonElement;
|
|
57
|
+
readonly pressed: boolean | undefined;
|
|
58
|
+
setPressed(pressed: boolean): void;
|
|
59
|
+
setDisabled(disabled: boolean): void;
|
|
60
|
+
/** New text (or, for an `icon*` size, a new accessible name). */
|
|
61
|
+
setText(text: string): void;
|
|
62
|
+
destroy(): void;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export const BUTTON_STYLE_ID = 'vela-ui-button';
|
|
66
|
+
|
|
67
|
+
export const BUTTON_CSS = css`
|
|
68
|
+
@layer vela.ui {
|
|
69
|
+
[data-slot='button'] {
|
|
70
|
+
cursor: pointer;
|
|
71
|
+
height: ${buttonDef.vars.height};
|
|
72
|
+
padding: 0 11px;
|
|
73
|
+
border-radius: ${buttonDef.vars.radius};
|
|
74
|
+
border: 1px solid ${t.border.strong};
|
|
75
|
+
background: transparent;
|
|
76
|
+
color: ${t.fg};
|
|
77
|
+
font-weight: 400;
|
|
78
|
+
font-size: ${buttonDef.vars['font-size']};
|
|
79
|
+
font-family: inherit;
|
|
80
|
+
white-space: nowrap;
|
|
81
|
+
transition:
|
|
82
|
+
background ${t.dur.fast} ease,
|
|
83
|
+
color ${t.dur.fast} ease,
|
|
84
|
+
opacity ${t.dur.fast} ease,
|
|
85
|
+
border-color ${t.dur.fast} ease;
|
|
86
|
+
|
|
87
|
+
&:where(:not([hidden])) {
|
|
88
|
+
display: inline-flex;
|
|
89
|
+
align-items: center;
|
|
90
|
+
justify-content: center;
|
|
91
|
+
gap: 6px;
|
|
92
|
+
}
|
|
93
|
+
/* Icons draw at 1em: one size for every button size but the smallest. The slot
|
|
94
|
+
is sized too, so an icon registered without width and height fills it. */
|
|
95
|
+
& > [data-icon] {
|
|
96
|
+
font-size: 16px;
|
|
97
|
+
width: 1em;
|
|
98
|
+
height: 1em;
|
|
99
|
+
flex: none;
|
|
100
|
+
|
|
101
|
+
& > svg {
|
|
102
|
+
width: 100%;
|
|
103
|
+
height: 100%;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
&[data-size='xs'] > [data-icon],
|
|
107
|
+
&[data-size='icon-xs'] > [data-icon] {
|
|
108
|
+
font-size: 12px;
|
|
109
|
+
}
|
|
110
|
+
&[data-size='sm'],
|
|
111
|
+
&[data-size='icon-sm'] {
|
|
112
|
+
height: ${buttonDef.vars['height-sm']};
|
|
113
|
+
font-size: ${buttonDef.vars['font-size-sm']};
|
|
114
|
+
}
|
|
115
|
+
&[data-size='xs'],
|
|
116
|
+
&[data-size='icon-xs'] {
|
|
117
|
+
height: ${buttonDef.vars['height-xs']};
|
|
118
|
+
padding: 0 8px;
|
|
119
|
+
font-size: ${buttonDef.vars['font-size-xs']};
|
|
120
|
+
border-radius: ${t.radius.sm};
|
|
121
|
+
}
|
|
122
|
+
&[data-size='lg'],
|
|
123
|
+
&[data-size='icon-lg'] {
|
|
124
|
+
height: ${buttonDef.vars['height-lg']};
|
|
125
|
+
padding: 0 14px;
|
|
126
|
+
}
|
|
127
|
+
&[data-size='icon'] {
|
|
128
|
+
width: ${buttonDef.vars.height};
|
|
129
|
+
padding: 0;
|
|
130
|
+
}
|
|
131
|
+
&[data-size='icon-sm'] {
|
|
132
|
+
width: ${buttonDef.vars['height-sm']};
|
|
133
|
+
padding: 0;
|
|
134
|
+
}
|
|
135
|
+
&[data-size='icon-xs'] {
|
|
136
|
+
width: ${buttonDef.vars['height-xs']};
|
|
137
|
+
padding: 0;
|
|
138
|
+
}
|
|
139
|
+
&[data-size='icon-lg'] {
|
|
140
|
+
width: ${buttonDef.vars['height-lg']};
|
|
141
|
+
padding: 0;
|
|
142
|
+
}
|
|
143
|
+
&:disabled {
|
|
144
|
+
cursor: default;
|
|
145
|
+
opacity: 0.5;
|
|
146
|
+
}
|
|
147
|
+
&:focus-visible {
|
|
148
|
+
outline: 2px solid ${t.focus};
|
|
149
|
+
outline-offset: 1px;
|
|
150
|
+
}
|
|
151
|
+
&:not(:disabled):hover,
|
|
152
|
+
&[aria-expanded='true'] {
|
|
153
|
+
background: ${t.hover};
|
|
154
|
+
color: ${t.fg.bright};
|
|
155
|
+
border-color: ${t.fg.muted};
|
|
156
|
+
}
|
|
157
|
+
&[data-variant='default'] {
|
|
158
|
+
border-color: ${t.selected.bg};
|
|
159
|
+
background: ${t.selected.bg};
|
|
160
|
+
color: ${t.selected.fg};
|
|
161
|
+
}
|
|
162
|
+
&[data-variant='default']:not(:disabled):hover,
|
|
163
|
+
&[data-variant='default'][aria-expanded='true'] {
|
|
164
|
+
background: ${t.selected.bg};
|
|
165
|
+
color: ${t.selected.fg};
|
|
166
|
+
opacity: 0.85;
|
|
167
|
+
border-color: ${t.selected.bg};
|
|
168
|
+
}
|
|
169
|
+
&[data-variant='secondary'] {
|
|
170
|
+
background: ${t.surface.sunken};
|
|
171
|
+
border-color: ${t.border};
|
|
172
|
+
}
|
|
173
|
+
&[data-variant='secondary']:not(:disabled):hover,
|
|
174
|
+
&[data-variant='secondary'][aria-expanded='true'] {
|
|
175
|
+
border-color: ${t.border.strong};
|
|
176
|
+
}
|
|
177
|
+
&[data-variant='ghost'] {
|
|
178
|
+
border-color: transparent;
|
|
179
|
+
color: ${t.fg.muted};
|
|
180
|
+
}
|
|
181
|
+
&[data-variant='ghost']:not(:disabled):hover,
|
|
182
|
+
&[data-variant='ghost'][aria-expanded='true'] {
|
|
183
|
+
border-color: transparent;
|
|
184
|
+
}
|
|
185
|
+
&[data-variant='destructive'] {
|
|
186
|
+
border-color: transparent;
|
|
187
|
+
background: color-mix(in srgb, ${t.danger} 14%, transparent);
|
|
188
|
+
color: ${t.danger};
|
|
189
|
+
}
|
|
190
|
+
&[data-variant='destructive']:not(:disabled):hover {
|
|
191
|
+
border-color: transparent;
|
|
192
|
+
background: color-mix(in srgb, ${t.danger} 24%, transparent);
|
|
193
|
+
color: ${t.danger};
|
|
194
|
+
}
|
|
195
|
+
&[data-variant='link'] {
|
|
196
|
+
border-color: transparent;
|
|
197
|
+
background: transparent;
|
|
198
|
+
color: ${t.accent};
|
|
199
|
+
padding-inline: 0;
|
|
200
|
+
text-underline-offset: 4px;
|
|
201
|
+
}
|
|
202
|
+
&[data-variant='link']:not(:disabled):hover {
|
|
203
|
+
border-color: transparent;
|
|
204
|
+
background: transparent;
|
|
205
|
+
color: ${t.accent};
|
|
206
|
+
text-decoration: underline;
|
|
207
|
+
}
|
|
208
|
+
&[data-variant='up'],
|
|
209
|
+
&[data-variant='up']:not(:disabled):hover {
|
|
210
|
+
border-color: transparent;
|
|
211
|
+
background: ${t.up};
|
|
212
|
+
color: ${t.fg.onFill};
|
|
213
|
+
}
|
|
214
|
+
&[data-variant='down'],
|
|
215
|
+
&[data-variant='down']:not(:disabled):hover {
|
|
216
|
+
border-color: transparent;
|
|
217
|
+
background: ${t.down};
|
|
218
|
+
color: ${t.fg.onFill};
|
|
219
|
+
}
|
|
220
|
+
&[data-variant='up']:not(:disabled):hover,
|
|
221
|
+
&[data-variant='down']:not(:disabled):hover {
|
|
222
|
+
opacity: 0.88;
|
|
223
|
+
}
|
|
224
|
+
&[data-pressed] {
|
|
225
|
+
background: ${t.active};
|
|
226
|
+
color: ${t.fg.bright};
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
`;
|
|
231
|
+
|
|
232
|
+
const injectStyles = defineStyles(BUTTON_STYLE_ID, BUTTON_CSS);
|
|
233
|
+
|
|
234
|
+
class ButtonImpl implements ButtonHandle {
|
|
235
|
+
readonly el: HTMLButtonElement;
|
|
236
|
+
private readonly iconOnly: boolean;
|
|
237
|
+
private readonly textNode: Text | null;
|
|
238
|
+
private label: string | undefined;
|
|
239
|
+
private pressedState: boolean | undefined;
|
|
240
|
+
|
|
241
|
+
constructor(props: ButtonProps) {
|
|
242
|
+
injectStyles(document);
|
|
243
|
+
const { variant, size } = buttonVariants.resolve(props);
|
|
244
|
+
this.iconOnly = size.startsWith('icon');
|
|
245
|
+
this.label = props.label ?? props.text;
|
|
246
|
+
this.pressedState = props.pressed;
|
|
247
|
+
const icon = (id: string, side: 'inline-start' | 'inline-end'): HTMLElement => {
|
|
248
|
+
const el = iconEl(id, document);
|
|
249
|
+
el.dataset.slot = buttonDef.slot('icon');
|
|
250
|
+
el.dataset.icon = side;
|
|
251
|
+
return el;
|
|
252
|
+
};
|
|
253
|
+
this.textNode = !this.iconOnly && props.text !== undefined ? document.createTextNode(props.text) : null;
|
|
254
|
+
this.el = h(
|
|
255
|
+
'button',
|
|
256
|
+
{
|
|
257
|
+
className: props.className ? `vela-btn ${props.className}` : 'vela-btn',
|
|
258
|
+
slot: buttonDef.slot('root'),
|
|
259
|
+
attrs: { type: 'button', ...buttonVariants({ variant, size }) },
|
|
260
|
+
on: props.onClick ? { click: props.onClick } : undefined,
|
|
261
|
+
},
|
|
262
|
+
props.icon ? icon(props.icon, 'inline-start') : null,
|
|
263
|
+
this.textNode,
|
|
264
|
+
props.iconEnd && !this.iconOnly ? icon(props.iconEnd, 'inline-end') : null,
|
|
265
|
+
);
|
|
266
|
+
this.el.disabled = props.disabled ?? false;
|
|
267
|
+
this.paint();
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
get pressed(): boolean | undefined {
|
|
271
|
+
return this.pressedState;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
setPressed(pressed: boolean): void {
|
|
275
|
+
this.pressedState = pressed;
|
|
276
|
+
this.paint();
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
setDisabled(disabled: boolean): void {
|
|
280
|
+
this.el.disabled = disabled;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
setText(text: string): void {
|
|
284
|
+
this.label = text;
|
|
285
|
+
if (this.textNode) this.textNode.data = text;
|
|
286
|
+
this.paint();
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
destroy(): void {}
|
|
290
|
+
|
|
291
|
+
private paint(): void {
|
|
292
|
+
const el = this.el;
|
|
293
|
+
el.toggleAttribute('data-pressed', this.pressedState === true);
|
|
294
|
+
if (this.pressedState === undefined) el.removeAttribute('aria-pressed');
|
|
295
|
+
else el.setAttribute('aria-pressed', String(this.pressedState));
|
|
296
|
+
if (this.iconOnly && this.label !== undefined) el.setAttribute('aria-label', this.label);
|
|
297
|
+
else el.removeAttribute('aria-label');
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
export function createButton(props: ButtonProps = {}): ButtonHandle {
|
|
302
|
+
return new ButtonImpl(props);
|
|
303
|
+
}
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
// CalloutBubble: a small tinted circle with a centered icon. When a panel is declared,
|
|
2
|
+
// clicking it deploys a popover of text and action buttons (below the bubble, flipping above
|
|
3
|
+
// near the bottom edge). Content is data, so contribution seams route it without handing
|
|
4
|
+
// over DOM. The bubble is a single element the caller places and decorates (tooltips stay
|
|
5
|
+
// the caller's: renderer chrome attaches its bare-chart tips, widget chrome the kit's).
|
|
6
|
+
import { iconAt } from '../lib/icons';
|
|
7
|
+
import type { ChartTheme } from '../lib/tokens';
|
|
8
|
+
import { css, defineStyles } from '../lib/css';
|
|
9
|
+
import { defineComponent } from '../lib/define';
|
|
10
|
+
import { t } from '../lib/t';
|
|
11
|
+
import { Popover, type PlacementProps, type PopoverBoundary } from './popover';
|
|
12
|
+
|
|
13
|
+
/** One block of a deployed callout panel — plain text, or a button running a caller action. */
|
|
14
|
+
export type CalloutPanelItem =
|
|
15
|
+
| { type: 'text'; text: string }
|
|
16
|
+
| {
|
|
17
|
+
type: 'button';
|
|
18
|
+
label: string;
|
|
19
|
+
/** Emphasized (selection-colored) button — the panel's main action. */
|
|
20
|
+
primary?: boolean;
|
|
21
|
+
/** Close the panel after `run` (default true — an action answers the panel). */
|
|
22
|
+
close?: boolean;
|
|
23
|
+
run(): void;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/** The deployed panel: an optional heading over ordered text/button blocks. */
|
|
27
|
+
export interface CalloutPanel {
|
|
28
|
+
title?: string;
|
|
29
|
+
items: CalloutPanelItem[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** What dresses the bubble itself (the panel is what the click deploys). */
|
|
33
|
+
export interface CalloutBubbleSpec {
|
|
34
|
+
/** Icon id in the icon registry (`registerIcon`), centered in the bubble. */
|
|
35
|
+
icon: string;
|
|
36
|
+
/** Bubble fill — any CSS color, token expressions included. */
|
|
37
|
+
background: string;
|
|
38
|
+
/** Icon ink (default: `currentColor` inherited from the slot). */
|
|
39
|
+
color?: string;
|
|
40
|
+
/** Accessible name. Callers typically show the same text in their own tooltip. */
|
|
41
|
+
label: string;
|
|
42
|
+
/** Deployed panel — presence makes the bubble clickable. */
|
|
43
|
+
panel?: CalloutPanel;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Whether activating a panel button also closes the panel (defaults to yes). */
|
|
47
|
+
export function closesPanel(item: Extract<CalloutPanelItem, { type: 'button' }>): boolean {
|
|
48
|
+
return item.close !== false;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** A panel row as the view lays it out: one text block, or a run of adjacent buttons. */
|
|
52
|
+
export type CalloutPanelRow = { type: 'text'; text: string } | { type: 'buttons'; buttons: Array<Extract<CalloutPanelItem, { type: 'button' }>> };
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Group a panel's ordered items into layout rows: consecutive buttons share one row
|
|
56
|
+
* (the common "text above, actions below" shape falls out naturally), text blocks
|
|
57
|
+
* stand alone. Pure — unit-tested apart from the DOM.
|
|
58
|
+
*/
|
|
59
|
+
export function calloutPanelRows(items: CalloutPanelItem[]): CalloutPanelRow[] {
|
|
60
|
+
const rows: CalloutPanelRow[] = [];
|
|
61
|
+
for (const item of items) {
|
|
62
|
+
if (item.type === 'text') {
|
|
63
|
+
rows.push({ type: 'text', text: item.text });
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const last = rows[rows.length - 1];
|
|
67
|
+
if (last && last.type === 'buttons') last.buttons.push(item);
|
|
68
|
+
else rows.push({ type: 'buttons', buttons: [item] });
|
|
69
|
+
}
|
|
70
|
+
return rows;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export const calloutBubbleDef = defineComponent({
|
|
74
|
+
name: 'callout-bubble',
|
|
75
|
+
parts: ['root', 'panel', 'title', 'text', 'actions', 'button'],
|
|
76
|
+
settings: { 'panel-radius': t.radius.md, 'button-radius': '5px' },
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
/** The panel opens where the placement props say (default below and start-aligned, 6px away,
|
|
80
|
+
* flipping above near the bottom edge). */
|
|
81
|
+
export interface CalloutBubbleOptions extends CalloutBubbleSpec, PlacementProps {
|
|
82
|
+
/** Bubble diameter in px (default 16; the icon renders 4px smaller). */
|
|
83
|
+
size?: number;
|
|
84
|
+
/** Where the deployed panel portals (default: the document body). Pass the chart
|
|
85
|
+
* or widget root so the panel lives inside the host's DOM. */
|
|
86
|
+
host?: HTMLElement;
|
|
87
|
+
/** Live theme, for a panel deployed OUTSIDE a `.vela-ui` token host (renderer
|
|
88
|
+
* chrome on a bare chart passes its theme getter; widget chrome may omit it). */
|
|
89
|
+
theme?: () => ChartTheme;
|
|
90
|
+
/** @deprecated Use `collisionBoundary`. */
|
|
91
|
+
boundary?: PopoverBoundary;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export type CalloutBubbleProps = CalloutBubbleOptions;
|
|
95
|
+
|
|
96
|
+
export const CALLOUT_STYLE_ID = 'vela-ui-callout-bubble';
|
|
97
|
+
|
|
98
|
+
export const CALLOUT_CSS = css`
|
|
99
|
+
@layer vela.ui {
|
|
100
|
+
[data-slot='callout-bubble'] {
|
|
101
|
+
place-items: center;
|
|
102
|
+
border-radius: 50%;
|
|
103
|
+
flex: none;
|
|
104
|
+
line-height: 0;
|
|
105
|
+
box-sizing: border-box;
|
|
106
|
+
cursor: default;
|
|
107
|
+
user-select: none;
|
|
108
|
+
-webkit-user-select: none;
|
|
109
|
+
|
|
110
|
+
&:where(:not([hidden])) {
|
|
111
|
+
display: inline-grid;
|
|
112
|
+
}
|
|
113
|
+
&[role='button'] {
|
|
114
|
+
cursor: pointer;
|
|
115
|
+
}
|
|
116
|
+
& svg {
|
|
117
|
+
display: block;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/* The deployed panel carries the kit's elevated-card look itself (the popover shell
|
|
121
|
+
is bare positioning chrome). */
|
|
122
|
+
[data-slot='callout-bubble-panel'] {
|
|
123
|
+
display: flex;
|
|
124
|
+
flex-direction: column;
|
|
125
|
+
gap: 8px;
|
|
126
|
+
padding: 10px 12px;
|
|
127
|
+
max-width: 280px;
|
|
128
|
+
box-sizing: border-box;
|
|
129
|
+
background: ${t.surface.elev};
|
|
130
|
+
border: 1px solid ${t.border.strong};
|
|
131
|
+
border-radius: ${calloutBubbleDef.vars['panel-radius']};
|
|
132
|
+
box-shadow: ${t.shadow};
|
|
133
|
+
color: ${t.fg};
|
|
134
|
+
font: ${t.fontSize.md} ${t.font};
|
|
135
|
+
}
|
|
136
|
+
[data-slot='callout-bubble-title'] {
|
|
137
|
+
font-weight: 600;
|
|
138
|
+
color: ${t.fg.bright};
|
|
139
|
+
}
|
|
140
|
+
[data-slot='callout-bubble-text'] {
|
|
141
|
+
color: ${t.fg.muted};
|
|
142
|
+
line-height: 1.45;
|
|
143
|
+
white-space: pre-line;
|
|
144
|
+
}
|
|
145
|
+
[data-slot='callout-bubble-actions'] {
|
|
146
|
+
display: flex;
|
|
147
|
+
flex-wrap: wrap;
|
|
148
|
+
gap: 8px;
|
|
149
|
+
}
|
|
150
|
+
[data-slot='callout-bubble-button'] {
|
|
151
|
+
cursor: pointer;
|
|
152
|
+
height: 26px;
|
|
153
|
+
padding: 0 10px;
|
|
154
|
+
border-radius: ${calloutBubbleDef.vars['button-radius']};
|
|
155
|
+
border: 1px solid ${t.border};
|
|
156
|
+
background: transparent;
|
|
157
|
+
color: ${t.fg};
|
|
158
|
+
font-size: ${t.fontSize.md};
|
|
159
|
+
font-family: inherit;
|
|
160
|
+
transition:
|
|
161
|
+
background ${t.dur.fast} ease,
|
|
162
|
+
color ${t.dur.fast} ease,
|
|
163
|
+
opacity ${t.dur.fast} ease,
|
|
164
|
+
border-color ${t.dur.fast} ease;
|
|
165
|
+
|
|
166
|
+
&:where([data-primary]) {
|
|
167
|
+
border-color: ${t.selected.bg};
|
|
168
|
+
background: ${t.selected.bg};
|
|
169
|
+
color: ${t.selected.fg};
|
|
170
|
+
}
|
|
171
|
+
&:hover {
|
|
172
|
+
background: ${t.hover};
|
|
173
|
+
color: ${t.fg.bright};
|
|
174
|
+
border-color: ${t.fg.muted};
|
|
175
|
+
}
|
|
176
|
+
&:where([data-primary]):hover {
|
|
177
|
+
background: ${t.selected.bg};
|
|
178
|
+
color: ${t.selected.fg};
|
|
179
|
+
opacity: 0.85;
|
|
180
|
+
border-color: ${t.selected.bg};
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
`;
|
|
185
|
+
|
|
186
|
+
const injectStyles = defineStyles(CALLOUT_STYLE_ID, CALLOUT_CSS);
|
|
187
|
+
|
|
188
|
+
export class CalloutBubble {
|
|
189
|
+
readonly el: HTMLElement;
|
|
190
|
+
private spec: CalloutBubbleSpec;
|
|
191
|
+
private readonly size: number;
|
|
192
|
+
private readonly host: HTMLElement | undefined;
|
|
193
|
+
private readonly theme: (() => ChartTheme) | undefined;
|
|
194
|
+
private readonly placement: PlacementProps;
|
|
195
|
+
private pop: Popover | null = null;
|
|
196
|
+
|
|
197
|
+
constructor(opts: CalloutBubbleOptions) {
|
|
198
|
+
this.spec = { icon: opts.icon, background: opts.background, label: opts.label };
|
|
199
|
+
if (opts.color !== undefined) this.spec.color = opts.color;
|
|
200
|
+
if (opts.panel !== undefined) this.spec.panel = opts.panel;
|
|
201
|
+
this.size = opts.size ?? 16;
|
|
202
|
+
this.host = opts.host;
|
|
203
|
+
this.theme = opts.theme;
|
|
204
|
+
this.placement = { ...opts, collisionBoundary: opts.collisionBoundary ?? opts.boundary };
|
|
205
|
+
const doc = (opts.host ?? document.body).ownerDocument;
|
|
206
|
+
injectStyles(doc);
|
|
207
|
+
this.el = doc.createElement('span');
|
|
208
|
+
this.el.className = 'vela-callout';
|
|
209
|
+
this.el.dataset.slot = calloutBubbleDef.slot('root');
|
|
210
|
+
this.el.style.width = `${this.size}px`;
|
|
211
|
+
this.el.style.height = `${this.size}px`;
|
|
212
|
+
// A click's job is the panel — never the row/chip underneath (selection,
|
|
213
|
+
// settings dialogs); a dblclick on the bubble must stay the bubble's too.
|
|
214
|
+
this.el.addEventListener('click', (e) => {
|
|
215
|
+
if (!this.spec.panel) return;
|
|
216
|
+
e.stopPropagation();
|
|
217
|
+
this.toggle();
|
|
218
|
+
});
|
|
219
|
+
this.el.addEventListener('dblclick', (e) => {
|
|
220
|
+
if (this.spec.panel) e.stopPropagation();
|
|
221
|
+
});
|
|
222
|
+
this.el.addEventListener('keydown', (e) => {
|
|
223
|
+
if (!this.spec.panel || (e.key !== 'Enter' && e.key !== ' ')) return;
|
|
224
|
+
e.preventDefault();
|
|
225
|
+
this.toggle();
|
|
226
|
+
});
|
|
227
|
+
this.dress();
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** Re-dress the bubble (a status change: new icon, tint, label, panel). */
|
|
231
|
+
set(spec: Partial<CalloutBubbleSpec>): void {
|
|
232
|
+
this.spec = { ...this.spec, ...spec };
|
|
233
|
+
// The open panel (if any) belongs to the previous state — retire it.
|
|
234
|
+
if ('panel' in spec) this.pop?.hide();
|
|
235
|
+
this.dress();
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** Whether the deployed panel is currently open. */
|
|
239
|
+
get open(): boolean {
|
|
240
|
+
return this.pop?.open ?? false;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/** Close the deployed panel, if any. The bubble itself stays. */
|
|
244
|
+
hidePanel(): void {
|
|
245
|
+
this.pop?.hide();
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
destroy(): void {
|
|
249
|
+
this.pop?.destroy();
|
|
250
|
+
this.pop = null;
|
|
251
|
+
this.el.remove();
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
private dress(): void {
|
|
255
|
+
const clickable = this.spec.panel !== undefined;
|
|
256
|
+
this.el.style.background = this.spec.background;
|
|
257
|
+
this.el.style.color = this.spec.color ?? '';
|
|
258
|
+
this.el.innerHTML = iconAt(this.spec.icon, this.size - 4);
|
|
259
|
+
this.el.setAttribute('aria-label', this.spec.label);
|
|
260
|
+
if (clickable) {
|
|
261
|
+
this.el.setAttribute('role', 'button');
|
|
262
|
+
this.el.tabIndex = 0;
|
|
263
|
+
} else {
|
|
264
|
+
this.el.removeAttribute('role');
|
|
265
|
+
this.el.removeAttribute('tabindex');
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
private toggle(): void {
|
|
270
|
+
if (this.pop?.open) {
|
|
271
|
+
this.pop.hide();
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
const panel = this.spec.panel;
|
|
275
|
+
if (!panel) return;
|
|
276
|
+
// A fresh popover per deploy: the content projects the CURRENT panel data,
|
|
277
|
+
// and the theme is read at open time (never a stale capture).
|
|
278
|
+
this.pop?.destroy();
|
|
279
|
+
this.pop = new Popover({
|
|
280
|
+
trigger: this.el,
|
|
281
|
+
side: this.placement.side,
|
|
282
|
+
align: this.placement.align,
|
|
283
|
+
sideOffset: this.placement.sideOffset ?? 6,
|
|
284
|
+
alignOffset: this.placement.alignOffset,
|
|
285
|
+
avoidCollisions: this.placement.avoidCollisions,
|
|
286
|
+
collisionPadding: this.placement.collisionPadding,
|
|
287
|
+
content: (body) => this.buildPanel(body, panel),
|
|
288
|
+
...(this.host ? { host: this.host } : {}),
|
|
289
|
+
...(this.theme ? { theme: this.theme() } : {}),
|
|
290
|
+
...(this.placement.collisionBoundary ? { collisionBoundary: this.placement.collisionBoundary } : {}),
|
|
291
|
+
});
|
|
292
|
+
this.pop.show();
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
private buildPanel(body: HTMLElement, panel: CalloutPanel): void {
|
|
296
|
+
const doc = body.ownerDocument;
|
|
297
|
+
const part = <K extends keyof HTMLElementTagNameMap>(tag: K, className: string, name: (typeof calloutBubbleDef.parts)[number]): HTMLElementTagNameMap[K] => {
|
|
298
|
+
const el = doc.createElement(tag);
|
|
299
|
+
el.className = className;
|
|
300
|
+
el.dataset.slot = calloutBubbleDef.slot(name);
|
|
301
|
+
return el;
|
|
302
|
+
};
|
|
303
|
+
const root = part('div', 'vela-callout-panel', 'panel');
|
|
304
|
+
if (panel.title) {
|
|
305
|
+
const title = part('div', 'vela-callout-title', 'title');
|
|
306
|
+
title.textContent = panel.title;
|
|
307
|
+
root.appendChild(title);
|
|
308
|
+
}
|
|
309
|
+
for (const row of calloutPanelRows(panel.items)) {
|
|
310
|
+
if (row.type === 'text') {
|
|
311
|
+
const text = part('div', 'vela-callout-text', 'text');
|
|
312
|
+
text.textContent = row.text;
|
|
313
|
+
root.appendChild(text);
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
const actions = part('div', 'vela-callout-actions', 'actions');
|
|
317
|
+
for (const item of row.buttons) {
|
|
318
|
+
const btn = part('button', 'vela-callout-btn' + (item.primary ? ' vela-callout-btn-primary' : ''), 'button');
|
|
319
|
+
btn.type = 'button';
|
|
320
|
+
if (item.primary) btn.dataset.primary = '';
|
|
321
|
+
btn.textContent = item.label;
|
|
322
|
+
btn.addEventListener('click', () => {
|
|
323
|
+
item.run();
|
|
324
|
+
if (closesPanel(item)) this.pop?.hide();
|
|
325
|
+
});
|
|
326
|
+
actions.appendChild(btn);
|
|
327
|
+
}
|
|
328
|
+
root.appendChild(actions);
|
|
329
|
+
}
|
|
330
|
+
body.appendChild(root);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
export function createCalloutBubble(props: CalloutBubbleProps): CalloutBubble {
|
|
335
|
+
return new CalloutBubble(props);
|
|
336
|
+
}
|