@vokality/design-system 1.3.0 → 3.0.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 +54 -0
- package/README.md +51 -5
- package/dist/browser.d.ts +13 -0
- package/dist/browser.js +7 -0
- package/dist/charts/chart.d.ts +6 -5
- package/dist/charts/chart.js +44 -25
- package/dist/chat.d.ts +54 -0
- package/dist/chat.js +1 -0
- package/dist/components/Accordion/Accordion.js +1 -1
- package/dist/components/Alert/Alert.js +5 -2
- package/dist/components/AppShell/AppShell.js +10 -14
- package/dist/components/Avatar/Avatar.js +2 -2
- package/dist/components/AvatarGroup/AvatarGroup.js +2 -2
- package/dist/components/BarChart/BarChart.js +17 -15
- package/dist/components/Breadcrumbs/Breadcrumbs.js +6 -3
- package/dist/components/Calendar/Calendar.js +6 -5
- package/dist/components/Card/Card.js +2 -3
- package/dist/components/ChatInbox/ChatInbox.d.ts +11 -0
- package/dist/components/ChatInbox/ChatInbox.js +49 -0
- package/dist/components/ChatPanel/ChatPanel.d.ts +3 -0
- package/dist/components/ChatPanel/ChatPanel.js +13 -0
- package/dist/components/ChatPanel/composer.d.ts +5 -0
- package/dist/components/ChatPanel/composer.js +32 -0
- package/dist/components/ChatPanel/transcript.d.ts +13 -0
- package/dist/components/ChatPanel/transcript.js +39 -0
- package/dist/components/ChatWidget/ChatWidget.d.ts +12 -0
- package/dist/components/ChatWidget/ChatWidget.js +42 -0
- package/dist/components/Checkbox/Checkbox.d.ts +5 -10
- package/dist/components/Checkbox/Checkbox.js +5 -19
- package/dist/components/CodeBlock/CodeBlock.js +19 -5
- package/dist/components/Combobox/Combobox.js +22 -15
- package/dist/components/Combobox/ListPanel.js +20 -9
- package/dist/components/CommandPalette/CommandPalette.js +33 -14
- package/dist/components/ContextMenu/ContextMenu.d.ts +2 -2
- package/dist/components/ContextMenu/ContextMenu.js +5 -50
- package/dist/components/DatePicker/DatePicker.js +35 -29
- package/dist/components/DescriptionList/DescriptionList.js +1 -1
- package/dist/components/Dialog/Dialog.d.ts +24 -7
- package/dist/components/Dialog/Dialog.js +30 -41
- package/dist/components/Drawer/Drawer.d.ts +4 -2
- package/dist/components/EmptyState/EmptyState.js +2 -2
- package/dist/components/ErrorSummary/ErrorSummary.js +5 -3
- package/dist/components/FaqList/FaqList.js +1 -1
- package/dist/components/Field/Field.js +4 -4
- package/dist/components/Fieldset/Fieldset.js +3 -3
- package/dist/components/FileUpload/FileUpload.js +17 -9
- package/dist/components/Grid/Grid.d.ts +867 -5
- package/dist/components/Grid/Grid.js +3 -4
- package/dist/components/Heading/Heading.js +2 -1
- package/dist/components/Icon/Icon.js +4 -2
- package/dist/components/Inline/Inline.d.ts +867 -5
- package/dist/components/Inline/Inline.js +2 -3
- package/dist/components/LineChart/LineChart.js +17 -15
- package/dist/components/LinkProvider/LinkProvider.d.ts +1 -1
- package/dist/components/LinkProvider/LinkProvider.js +6 -2
- package/dist/components/List/List.js +1 -1
- package/dist/components/MediaCard/MediaCard.js +2 -2
- package/dist/components/Menu/Menu.js +6 -43
- package/dist/components/Menu/entries.d.ts +1 -30
- package/dist/components/Menu/entries.js +16 -100
- package/dist/components/MultiSelect/MultiSelect.js +43 -34
- package/dist/components/NumberInput/NumberInput.js +17 -18
- package/dist/components/OtpInput/OtpInput.d.ts +1 -1
- package/dist/components/OtpInput/OtpInput.js +10 -67
- package/dist/components/PageHeader/PageHeader.js +2 -2
- package/dist/components/Pagination/Pagination.js +3 -1
- package/dist/components/PasswordInput/PasswordInput.d.ts +1 -1
- package/dist/components/PasswordInput/PasswordInput.js +9 -4
- package/dist/components/Popover/Popover.d.ts +6 -7
- package/dist/components/Popover/Popover.js +2 -19
- package/dist/components/Progress/Progress.d.ts +1 -1
- package/dist/components/Progress/Progress.js +7 -11
- package/dist/components/Radio/Radio.d.ts +4 -2
- package/dist/components/RadioGroup/RadioGroup.d.ts +5 -12
- package/dist/components/RadioGroup/RadioGroup.js +6 -33
- package/dist/components/RichTextEditor/RichTextEditor.d.ts +63 -0
- package/dist/components/RichTextEditor/RichTextEditor.js +175 -0
- package/dist/components/RichTextEditor/toolbar.d.ts +15 -0
- package/dist/components/RichTextEditor/toolbar.js +142 -0
- package/dist/components/RichTextEditor/uploads.d.ts +41 -0
- package/dist/components/RichTextEditor/uploads.js +124 -0
- package/dist/components/SearchInput/SearchInput.js +4 -2
- package/dist/components/SectionHeader/SectionHeader.js +1 -3
- package/dist/components/SegmentedControl/SegmentedControl.js +2 -12
- package/dist/components/Select/Select.d.ts +15 -16
- package/dist/components/Select/Select.js +11 -252
- package/dist/components/Slider/Slider.js +11 -21
- package/dist/components/Sparkline/Sparkline.js +8 -3
- package/dist/components/Spinner/Spinner.js +5 -2
- package/dist/components/Stack/Stack.d.ts +867 -5
- package/dist/components/Stack/Stack.js +2 -3
- package/dist/components/Stat/Stat.js +6 -3
- package/dist/components/Steps/Steps.js +6 -3
- package/dist/components/Switch/Switch.d.ts +7 -7
- package/dist/components/Switch/Switch.js +4 -10
- package/dist/components/Table/Table.js +38 -19
- package/dist/components/Tabs/Tabs.js +2 -22
- package/dist/components/Tag/Tag.js +3 -1
- package/dist/components/Text/Text.d.ts +9 -5
- package/dist/components/Text/Text.js +3 -4
- package/dist/components/TileGrid/TileGrid.js +1 -1
- package/dist/components/TimePicker/TimePicker.js +35 -33
- package/dist/components/Timeline/Timeline.js +5 -4
- package/dist/components/Toaster/Toaster.js +21 -17
- package/dist/components/Tooltip/Tooltip.d.ts +6 -6
- package/dist/components/Tooltip/Tooltip.js +3 -17
- package/dist/components/TreeView/TreeView.js +15 -12
- package/dist/components.css +281 -60
- package/dist/hooks/useTheme.js +6 -6
- package/dist/icons/message-circle.svg +1 -0
- package/dist/internal/CharCount.js +3 -1
- package/dist/internal/choice.d.ts +10 -48
- package/dist/internal/choice.js +8 -96
- package/dist/internal/describedBy.d.ts +3 -0
- package/dist/internal/describedBy.js +4 -0
- package/dist/internal/options.d.ts +10 -5
- package/dist/internal/options.js +25 -11
- package/dist/internal/status.d.ts +3 -2
- package/dist/internal/status.js +10 -2
- package/dist/internal/useScrollActive.js +2 -2
- package/dist/internal/useToday.d.ts +3 -0
- package/dist/internal/useToday.js +42 -0
- package/dist/lib/dates.js +25 -15
- package/dist/lib/format.js +11 -8
- package/dist/lib/icons.d.ts +5 -0
- package/dist/lib/icons.js +2 -0
- package/dist/lib/math.js +17 -5
- package/dist/lib/rich-text.d.ts +13 -0
- package/dist/lib/rich-text.js +62 -0
- package/dist/lib/space.d.ts +1 -2
- package/dist/lib/space.js +4 -1
- package/dist/lib/text.js +1 -1
- package/dist/lib/theme.js +1 -1
- package/dist/localization.d.ts +166 -0
- package/dist/localization.js +142 -0
- package/dist/tokens.css +2 -0
- package/dist/tokens.dtcg.json +10 -0
- package/dist/tokens.json +10 -0
- package/dist/types.d.ts +6 -1
- package/dist/vokality.css +283 -60
- package/dist/vokality.iife.js +35981 -9698
- package/docs/brand.md +8 -5
- package/docs/components/AppShell/README.md +1 -1
- package/docs/components/Badge/README.md +1 -1
- package/docs/components/BarChart/README.md +1 -0
- package/docs/components/Button/README.md +4 -2
- package/docs/components/ChatInbox/README.md +41 -0
- package/docs/components/ChatWidget/README.md +47 -0
- package/docs/components/Checkbox/README.md +7 -3
- package/docs/components/ContextMenu/README.md +7 -3
- package/docs/components/Dialog/README.md +9 -4
- package/docs/components/Drawer/README.md +1 -1
- package/docs/components/Field/README.md +1 -1
- package/docs/components/Fieldset/README.md +2 -2
- package/docs/components/Inline/README.md +1 -1
- package/docs/components/LineChart/README.md +1 -0
- package/docs/components/LocaleProvider/README.md +48 -0
- package/docs/components/Menu/README.md +13 -8
- package/docs/components/OtpInput/README.md +9 -5
- package/docs/components/PasswordInput/README.md +11 -2
- package/docs/components/Popover/README.md +6 -3
- package/docs/components/Progress/README.md +3 -1
- package/docs/components/RadioGroup/README.md +5 -2
- package/docs/components/RichTextEditor/README.md +84 -0
- package/docs/components/SegmentedControl/README.md +2 -0
- package/docs/components/Select/README.md +13 -17
- package/docs/components/Skeleton/README.md +1 -1
- package/docs/components/Slider/README.md +4 -2
- package/docs/components/Steps/README.md +1 -1
- package/docs/components/Switch/README.md +5 -2
- package/docs/components/Tabs/README.md +4 -2
- package/docs/components/Text/README.md +1 -1
- package/docs/components/Toaster/README.md +3 -1
- package/docs/components/Tooltip/README.md +5 -3
- package/package.json +49 -5
|
@@ -1,262 +1,21 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { forwardRef
|
|
4
|
-
import { flushSync } from "react-dom";
|
|
3
|
+
import { forwardRef } from "react";
|
|
5
4
|
import { Select as Primitive } from "radix-ui";
|
|
5
|
+
import { useLocale } from "../../localization.js";
|
|
6
6
|
import { Icon } from "../Icon/Icon.js";
|
|
7
|
-
import { focusables } from "../../internal/focusables.js";
|
|
8
7
|
import { normalizeOptions } from "../../internal/options.js";
|
|
9
|
-
import { useIsoLayoutEffect } from "../../internal/useIsoLayoutEffect.js";
|
|
10
8
|
import { useUid } from "../../internal/useUid.js";
|
|
11
|
-
import { omit } from "../../lib/omit.js";
|
|
12
9
|
import { cx } from "../../lib/cx.js";
|
|
13
|
-
/**
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
function focusNext(from, dir) {
|
|
18
|
-
const body = from.ownerDocument.body;
|
|
19
|
-
const scope = from.closest('[aria-modal="true"]') || body;
|
|
20
|
-
const list = focusables(scope).filter((n) => n.tabIndex >= 0);
|
|
21
|
-
const at = list.indexOf(from);
|
|
22
|
-
let next = at >= 0 ? list[at + dir] : undefined;
|
|
23
|
-
if (!next && at >= 0 && scope !== body)
|
|
24
|
-
next = list[dir > 0 ? 0 : list.length - 1];
|
|
25
|
-
(next || from).focus();
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Custom select (Radix Select, popper position; WAI-ARIA select-only combobox); no native <select>.
|
|
29
|
-
* The ref is the trigger button. Radix forbids "" as an item value, so items carry their index
|
|
30
|
-
* and "" means nothing is chosen: any option value, "" included, works.
|
|
31
|
-
*/
|
|
32
|
-
export const Select = forwardRef(function Select(props, ref) {
|
|
33
|
-
const options = normalizeOptions(props.options);
|
|
10
|
+
/** Styled Radix Select. Radix owns state, form participation, focus, keys and dismissal. */
|
|
11
|
+
export const Select = forwardRef(function Select({ options: optionValues, placeholder, value, defaultValue, onChange, id, className, "aria-label": ariaLabel, "aria-labelledby": labelledBy, "aria-describedby": describedBy, "aria-invalid": invalid, ...rootProps }, ref) {
|
|
12
|
+
const { messages } = useLocale();
|
|
13
|
+
const options = normalizeOptions(optionValues);
|
|
34
14
|
const baseId = useUid("vk-select");
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const triggerRef = useRef(null);
|
|
40
|
-
const contentRef = useRef(null);
|
|
41
|
-
const held = useRef([]);
|
|
42
|
-
const tabbing = useRef(0);
|
|
43
|
-
const search = useRef({ text: "", timer: 0 });
|
|
44
|
-
let selectedIndex = -1;
|
|
45
|
-
for (let k = 0; k < options.length; k++)
|
|
46
|
-
if (options[k].value === value)
|
|
47
|
-
selectedIndex = k;
|
|
48
|
-
const selected = selectedIndex >= 0 ? options[selectedIndex] : null;
|
|
49
|
-
const choose = (i) => {
|
|
50
|
-
const o = options[i];
|
|
51
|
-
if (!o || o.disabled || i === selectedIndex)
|
|
52
|
-
return;
|
|
53
|
-
if (!controlled)
|
|
54
|
-
setValue(o.value);
|
|
55
|
-
props.onChange?.(o.value, o);
|
|
15
|
+
const onValueChange = (nextValue) => {
|
|
16
|
+
const option = options.find((candidate) => candidate.value === nextValue);
|
|
17
|
+
if (option)
|
|
18
|
+
onChange?.(option.value, option);
|
|
56
19
|
};
|
|
57
|
-
|
|
58
|
-
// "" only comes from a form reset back to "nothing chosen".
|
|
59
|
-
if (v === "") {
|
|
60
|
-
if (!controlled)
|
|
61
|
-
setValue(null);
|
|
62
|
-
}
|
|
63
|
-
else
|
|
64
|
-
choose(Number(v));
|
|
65
|
-
};
|
|
66
|
-
// Radix hands focus back to the trigger only after the list has unmounted (a frame or two
|
|
67
|
-
// later), so keys typed right after choosing or Escape would land on <body>. Close
|
|
68
|
-
// synchronously and move focus at once: to the trigger, or on from it after Tab.
|
|
69
|
-
const onOpenChange = (next) => {
|
|
70
|
-
if (next) {
|
|
71
|
-
setOpen(true);
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
held.current = [];
|
|
75
|
-
search.current.text = "";
|
|
76
|
-
const hadFocus = Boolean(contentRef.current?.contains(document.activeElement));
|
|
77
|
-
const dir = tabbing.current;
|
|
78
|
-
tabbing.current = 0;
|
|
79
|
-
flushSync(() => setOpen(false));
|
|
80
|
-
const trigger = triggerRef.current;
|
|
81
|
-
if (!trigger || (!hadFocus && !dir))
|
|
82
|
-
return;
|
|
83
|
-
if (dir)
|
|
84
|
-
focusNext(trigger, dir);
|
|
85
|
-
else
|
|
86
|
-
trigger.focus({ preventScroll: true });
|
|
87
|
-
};
|
|
88
|
-
const items = () => Array.from(contentRef.current?.querySelectorAll("[role=option]:not([data-disabled])") || []);
|
|
89
|
-
const highlighted = () => {
|
|
90
|
-
const el = document.activeElement;
|
|
91
|
-
return el && el.getAttribute("role") === "option" && contentRef.current?.contains(el) ? Number(el.dataset.index) : -1;
|
|
92
|
-
};
|
|
93
|
-
const focusItem = (el) => {
|
|
94
|
-
if (!el)
|
|
95
|
-
return;
|
|
96
|
-
el.focus({ preventScroll: true });
|
|
97
|
-
el.scrollIntoView({ block: "nearest" });
|
|
98
|
-
};
|
|
99
|
-
const setTriggerRef = useCallback((el) => {
|
|
100
|
-
triggerRef.current = el;
|
|
101
|
-
if (typeof ref === "function")
|
|
102
|
-
ref(el);
|
|
103
|
-
else if (ref)
|
|
104
|
-
ref.current = el;
|
|
105
|
-
}, [ref]);
|
|
106
|
-
// Radix opens on Enter, Space, ↓ and ↑. Home/End (PageUp/PageDown), ↑ with nothing chosen, and
|
|
107
|
-
// typing a letter that matches open the list too, at that spot; keys pressed while the list is
|
|
108
|
-
// still opening are handed to it once it has focus.
|
|
109
|
-
const onTriggerKeyDown = (e) => {
|
|
110
|
-
const key = e.key;
|
|
111
|
-
if (open) {
|
|
112
|
-
if (typed(e) || HELD.includes(key)) {
|
|
113
|
-
e.preventDefault();
|
|
114
|
-
held.current.push(key);
|
|
115
|
-
}
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
if (props.disabled)
|
|
119
|
-
return;
|
|
120
|
-
let start = null;
|
|
121
|
-
if (key === "Home" || key === "PageUp")
|
|
122
|
-
start = "Home";
|
|
123
|
-
else if (key === "End" || key === "PageDown")
|
|
124
|
-
start = "End";
|
|
125
|
-
else if (key === "ArrowUp" && selectedIndex < 0)
|
|
126
|
-
start = "End";
|
|
127
|
-
else if (typed(e) && key !== " ") {
|
|
128
|
-
// Radix would change the value without opening; open at the match instead.
|
|
129
|
-
e.preventDefault();
|
|
130
|
-
const ch = key.toLowerCase();
|
|
131
|
-
if (options.some((o) => !o.disabled && String(o.label).toLowerCase().indexOf(ch) === 0))
|
|
132
|
-
start = key;
|
|
133
|
-
}
|
|
134
|
-
if (start) {
|
|
135
|
-
e.preventDefault();
|
|
136
|
-
held.current = [start];
|
|
137
|
-
setOpen(true);
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
// Radix focuses the chosen (or first) option once the list is placed: replay the held keys there.
|
|
141
|
-
const onContentFocus = () => {
|
|
142
|
-
if (!held.current.length)
|
|
143
|
-
return;
|
|
144
|
-
const keys = held.current;
|
|
145
|
-
held.current = [];
|
|
146
|
-
const press = (list) => {
|
|
147
|
-
for (const key of list) {
|
|
148
|
-
const content = contentRef.current;
|
|
149
|
-
if (!content)
|
|
150
|
-
return;
|
|
151
|
-
const at = content.contains(document.activeElement) ? document.activeElement : content;
|
|
152
|
-
at.dispatchEvent(new window.KeyboardEvent("keydown", { key, bubbles: true, cancelable: true }));
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
// Moves happen at once, so the list never shows the interim option. A choosing key closes
|
|
156
|
-
// the list, which can't happen inside Radix's focus effect: it waits for the next task.
|
|
157
|
-
let cut = keys.findIndex((k) => k === "Enter" || k === " ");
|
|
158
|
-
if (cut < 0)
|
|
159
|
-
cut = keys.length;
|
|
160
|
-
press(keys.slice(0, cut));
|
|
161
|
-
if (cut < keys.length)
|
|
162
|
-
setTimeout(() => press(keys.slice(cut)));
|
|
163
|
-
};
|
|
164
|
-
// Type-to-jump, as Radix does it (1s buffer, a repeated letter cycles), but moving focus at once:
|
|
165
|
-
// Radix moves it in a timeout, so a quick Enter after a key would choose the old option.
|
|
166
|
-
const typeahead = (ch) => {
|
|
167
|
-
const s = search.current;
|
|
168
|
-
window.clearTimeout(s.timer);
|
|
169
|
-
s.text += ch.toLowerCase();
|
|
170
|
-
s.timer = window.setTimeout(() => (s.text = ""), 1000);
|
|
171
|
-
const repeated = s.text.length > 1 && Array.from(s.text).every((c) => c === s.text[0]);
|
|
172
|
-
const q = repeated ? s.text[0] : s.text;
|
|
173
|
-
const list = items();
|
|
174
|
-
const cur = list.indexOf(document.activeElement);
|
|
175
|
-
for (let n = 0; n < list.length; n++) {
|
|
176
|
-
const el = list[(Math.max(cur, 0) + n) % list.length];
|
|
177
|
-
if (q.length === 1 && el === list[cur])
|
|
178
|
-
continue;
|
|
179
|
-
if (String(options[Number(el.dataset.index)].label).toLowerCase().indexOf(q) === 0)
|
|
180
|
-
return focusItem(el);
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
const onContentKeyDown = (e) => {
|
|
184
|
-
const key = e.key;
|
|
185
|
-
const list = items();
|
|
186
|
-
const cur = list.indexOf(document.activeElement);
|
|
187
|
-
if (key === "Escape") {
|
|
188
|
-
// Radix closes the list; don't let a surrounding dialog close too.
|
|
189
|
-
e.stopPropagation();
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
if (key === "Enter") {
|
|
193
|
-
// The option has been chosen and focus is back on the trigger button: stop Enter from also clicking it open.
|
|
194
|
-
e.preventDefault();
|
|
195
|
-
}
|
|
196
|
-
else if (key === "Tab") {
|
|
197
|
-
// Choose the active option, close, and move focus on from the trigger.
|
|
198
|
-
e.preventDefault();
|
|
199
|
-
e.stopPropagation();
|
|
200
|
-
choose(highlighted());
|
|
201
|
-
tabbing.current = e.shiftKey ? -1 : 1;
|
|
202
|
-
onOpenChange(false);
|
|
203
|
-
}
|
|
204
|
-
else if (key === "ArrowUp" && e.altKey) {
|
|
205
|
-
e.preventDefault();
|
|
206
|
-
choose(highlighted());
|
|
207
|
-
onOpenChange(false);
|
|
208
|
-
}
|
|
209
|
-
else if (key === "ArrowDown" && e.altKey) {
|
|
210
|
-
e.preventDefault();
|
|
211
|
-
}
|
|
212
|
-
else if (key === "ArrowDown" || key === "ArrowUp" || key === "Home" || key === "End" || key === "PageUp" || key === "PageDown") {
|
|
213
|
-
// Moved here (not left to Radix's timeout) so the next key acts on the new option.
|
|
214
|
-
e.preventDefault();
|
|
215
|
-
const last = list.length - 1;
|
|
216
|
-
if (key === "ArrowDown")
|
|
217
|
-
focusItem(list[cur < 0 ? 0 : cur + 1]);
|
|
218
|
-
else if (key === "ArrowUp")
|
|
219
|
-
focusItem(list[cur < 0 ? last : cur - 1]);
|
|
220
|
-
else
|
|
221
|
-
focusItem(list[key === "Home" || key === "PageUp" ? 0 : last]);
|
|
222
|
-
}
|
|
223
|
-
else if (typed(e)) {
|
|
224
|
-
// Space while typing ahead is part of the search (see the option's onKeyDown).
|
|
225
|
-
if (key === " " && !search.current.text)
|
|
226
|
-
return;
|
|
227
|
-
e.preventDefault();
|
|
228
|
-
typeahead(key);
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
// A press outside the list and its trigger closes it. Radix does this too, but on slow machines
|
|
232
|
-
// (seen on CI) its dismiss can miss the press, leaving the list open over a page that ignores
|
|
233
|
-
// the pointer. Close on our own as well; a second close is a no-op.
|
|
234
|
-
const closeRef = useRef(onOpenChange);
|
|
235
|
-
useIsoLayoutEffect(() => {
|
|
236
|
-
closeRef.current = onOpenChange;
|
|
237
|
-
});
|
|
238
|
-
useEffect(() => {
|
|
239
|
-
if (!open)
|
|
240
|
-
return undefined;
|
|
241
|
-
const onDown = (e) => {
|
|
242
|
-
const target = e.target instanceof Node ? e.target : null;
|
|
243
|
-
if (!target || contentRef.current?.contains(target) || triggerRef.current?.contains(target))
|
|
244
|
-
return;
|
|
245
|
-
closeRef.current(false);
|
|
246
|
-
};
|
|
247
|
-
document.addEventListener("pointerdown", onDown, true);
|
|
248
|
-
return () => document.removeEventListener("pointerdown", onDown, true);
|
|
249
|
-
}, [open]);
|
|
250
|
-
// Radix chooses on Space; while a search is being typed, Space belongs to it instead.
|
|
251
|
-
const onOptionKeyDown = (e) => {
|
|
252
|
-
if (e.key === " " && search.current.text)
|
|
253
|
-
e.preventDefault();
|
|
254
|
-
};
|
|
255
|
-
// Focus has already been placed (see onOpenChange); don't let Radix pull it back to the trigger.
|
|
256
|
-
const onCloseAutoFocus = (e) => {
|
|
257
|
-
if (document.activeElement && document.activeElement !== document.body)
|
|
258
|
-
e.preventDefault();
|
|
259
|
-
};
|
|
260
|
-
const a11y = omit(props, ["options", "placeholder", "className", "value", "defaultValue", "onChange", "disabled", "name", "id", "defaultOpen", "required"]);
|
|
261
|
-
return (_jsxs("div", { className: cx("vk-select", props.className), children: [_jsxs(Primitive.Root, { value: selectedIndex >= 0 ? String(selectedIndex) : "", onValueChange: onValueChange, open: open, onOpenChange: onOpenChange, disabled: props.disabled, children: [_jsxs(Primitive.Trigger, { ref: setTriggerRef, id: props.id, className: "vk-input vk-select-trigger", "aria-haspopup": "listbox", "aria-required": props.required ? true : undefined, onKeyDown: onTriggerKeyDown, ...a11y, children: [_jsx("span", { className: selected ? "vk-select-value" : "vk-select-value vk-select-placeholder", children: selected ? selected.label : props.placeholder || "Select one" }), _jsx(Icon, { name: "chevron-down", className: "vk-select-icon" })] }), _jsx(Primitive.Portal, { children: _jsx(Primitive.Content, { ref: contentRef, position: "popper", side: "bottom", align: "start", sideOffset: 4, collisionPadding: 8, className: "vk-select-menu vk-select-content", "aria-label": props["aria-label"], "aria-labelledby": props["aria-labelledby"], onKeyDown: onContentKeyDown, onFocus: onContentFocus, onCloseAutoFocus: onCloseAutoFocus, children: _jsx(Primitive.Viewport, { className: "vk-select-viewport", children: options.map((o, i) => (_jsxs(Primitive.Item, { value: String(i), textValue: String(o.label), disabled: o.disabled, "data-index": i, "aria-describedby": o.description ? baseId + "-" + i + "-desc" : undefined, onKeyDown: onOptionKeyDown, className: "vk-select-option", children: [_jsxs("span", { className: "vk-select-option-text", children: [_jsx(Primitive.ItemText, { children: o.label }), o.description ? _jsx("span", { id: baseId + "-" + i + "-desc", className: "vk-select-option-description", children: o.description }) : null] }), i === selectedIndex ? _jsx(Icon, { name: "check", size: 16, className: "vk-select-check" }) : null] }, i + ":" + o.value))) }) }) })] }), props.name ? _jsx("input", { type: "hidden", name: props.name, value: value ?? "" }) : null] }));
|
|
20
|
+
return (_jsx("div", { className: cx("vk-select", className), children: _jsxs(Primitive.Root, { ...rootProps, value: value === null ? "" : value, defaultValue: defaultValue, onValueChange: onValueChange, children: [_jsxs(Primitive.Trigger, { ref: ref, id: id, className: "vk-input vk-select-trigger", "aria-label": ariaLabel, "aria-labelledby": labelledBy, "aria-describedby": describedBy, "aria-invalid": invalid, children: [_jsx("span", { className: "vk-select-value", children: _jsx(Primitive.Value, { placeholder: placeholder ?? messages.selectOne }) }), _jsx(Primitive.Icon, { asChild: true, children: _jsx(Icon, { name: "chevron-down", className: "vk-select-icon" }) })] }), _jsx(Primitive.Portal, { children: _jsx(Primitive.Content, { position: "popper", side: "bottom", align: "start", sideOffset: 4, collisionPadding: 8, className: "vk-select-menu vk-select-content", "aria-label": ariaLabel, "aria-labelledby": labelledBy, children: _jsx(Primitive.Viewport, { className: "vk-select-viewport", children: options.map((option, index) => (_jsxs(Primitive.Item, { value: option.value, textValue: option.label, disabled: option.disabled, "data-index": index, "aria-describedby": option.description ? baseId + "-" + String(index) + "-desc" : undefined, className: "vk-select-option", children: [_jsxs("span", { className: "vk-select-option-text", children: [_jsx(Primitive.ItemText, { children: option.label }), option.description ? _jsx("span", { id: baseId + "-" + String(index) + "-desc", className: "vk-select-option-description", children: option.description }) : null] }), _jsx(Primitive.ItemIndicator, { asChild: true, children: _jsx(Icon, { name: "check", size: 16, className: "vk-select-check" }) })] }, option.value))) }) }) })] }) }));
|
|
262
21
|
});
|
|
@@ -6,30 +6,20 @@ import { useUid } from "../../internal/useUid.js";
|
|
|
6
6
|
import { cx } from "../../lib/cx.js";
|
|
7
7
|
/** Picks a number from a range by dragging or with the keyboard (Radix Slider; WAI-ARIA slider). */
|
|
8
8
|
export function Slider(props) {
|
|
9
|
-
const min = props.min
|
|
10
|
-
|
|
11
|
-
const [
|
|
12
|
-
const value =
|
|
9
|
+
const min = props.min ?? 0, max = props.max ?? 100, step = props.step ?? 1;
|
|
10
|
+
// Radix owns the value; this mirror supplies only the optional output and formatted value text.
|
|
11
|
+
const [displayValue, setDisplayValue] = useState(props.defaultValue ?? min);
|
|
12
|
+
const value = props.value ?? displayValue;
|
|
13
13
|
const uid = useUid("vk-slider");
|
|
14
14
|
const id = props.id || uid;
|
|
15
|
-
const set = (n) => {
|
|
16
|
-
if (!controlled)
|
|
17
|
-
setUncontrolled(n);
|
|
18
|
-
props.onChange?.(n);
|
|
19
|
-
};
|
|
20
|
-
// PageUp / PageDown move a tenth of the range (Radix moves ten steps); the rest of the keys are Radix's.
|
|
21
|
-
const onKeyDown = (e) => {
|
|
22
|
-
if (props.disabled || (e.key !== "PageUp" && e.key !== "PageDown"))
|
|
23
|
-
return;
|
|
24
|
-
e.preventDefault();
|
|
25
|
-
const big = Math.max(step, (max - min) / 10);
|
|
26
|
-
const snapped = Math.round((value + (e.key === "PageUp" ? big : -big) - min) / step) * step + min;
|
|
27
|
-
const next = Math.max(min, Math.min(max, +snapped.toFixed(6)));
|
|
28
|
-
if (next !== value)
|
|
29
|
-
set(next);
|
|
30
|
-
};
|
|
31
15
|
const text = announce(props, value);
|
|
32
|
-
return (_jsxs("div", { className: cx("vk-slider", props.className), children: [props.showValue ? _jsx("output", { className: "vk-slider-value", htmlFor: id, children: text }) : null, _jsxs(Primitive.Root, { className: "vk-slider-track", min: min, max: max, step: step, name: props.name, disabled: props.disabled, value:
|
|
16
|
+
return (_jsxs("div", { className: cx("vk-slider", props.className), children: [props.showValue ? _jsx("output", { className: "vk-slider-value", htmlFor: id, children: text }) : null, _jsxs(Primitive.Root, { className: "vk-slider-track", min: min, max: max, step: step, name: props.name, disabled: props.disabled, value: props.value === undefined ? undefined : [props.value], defaultValue: [props.defaultValue ?? min], onValueChange: (values) => {
|
|
17
|
+
const next = values[0];
|
|
18
|
+
if (next === undefined)
|
|
19
|
+
return;
|
|
20
|
+
setDisplayValue(next);
|
|
21
|
+
props.onChange?.(next);
|
|
22
|
+
}, children: [_jsx(Primitive.Range, { className: "vk-slider-fill" }), _jsx(Primitive.Thumb, { id: id, className: "vk-slider-thumb", "aria-valuetext": text, "aria-label": props["aria-label"], "aria-labelledby": props["aria-labelledby"], "aria-describedby": props["aria-describedby"] })] }), props.showLimits ? _jsx(SliderLimits, { min: min, max: max, format: props.format }) : null] }));
|
|
33
23
|
}
|
|
34
24
|
// The value as shown and announced: valueText, else format, else the number.
|
|
35
25
|
function announce({ valueText, format }, value) {
|
|
@@ -1,15 +1,20 @@
|
|
|
1
|
+
"use client";
|
|
1
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useLocale } from "../../localization.js";
|
|
4
|
+
import { formatNumber } from "../../lib/format.js";
|
|
2
5
|
import { cx } from "../../lib/cx.js";
|
|
3
6
|
/** A word-sized trend line beside a number, in a table cell or a Stat. */
|
|
4
7
|
export function Sparkline(props) {
|
|
8
|
+
const { locale, messages } = useLocale();
|
|
5
9
|
const { width, height, tone, label, className } = props;
|
|
6
|
-
const values = props.values
|
|
10
|
+
const values = props.values;
|
|
7
11
|
const w = width || 96, hgt = height || 28, p = 3;
|
|
8
12
|
const min = Math.min(...values), max = Math.max(...values);
|
|
9
13
|
const span = max - min || 1;
|
|
10
14
|
const pt = (v, i) => [p + ((w - 2 * p) * i) / Math.max(1, values.length - 1), hgt - p - ((v - min) / span) * (hgt - 2 * p)];
|
|
11
15
|
const pts = values.map((v, i) => pt(v, i).join(",")).join(" ");
|
|
12
|
-
const
|
|
16
|
+
const last = values.at(-1);
|
|
17
|
+
const end = last === undefined ? null : pt(last, values.length - 1);
|
|
13
18
|
const color = tone ? "var(--" + tone + ")" : "var(--chart-1)";
|
|
14
|
-
return (_jsxs("svg", { className: cx("vk-sparkline", className), width: w, height: hgt, viewBox:
|
|
19
|
+
return (_jsxs("svg", { className: cx("vk-sparkline", className), width: w, height: hgt, viewBox: `0 0 ${String(w)} ${String(hgt)}`, role: "img", "aria-label": label || messages.trend(values.map((value) => formatNumber(value, { locale })).join(", ")), children: [_jsx("polyline", { points: pts, fill: "none", stroke: color, strokeWidth: 1.5, strokeLinejoin: "round", strokeLinecap: "round" }), end ? _jsx("circle", { cx: end[0], cy: end[1], r: 2.5, fill: color }) : null] }));
|
|
15
20
|
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
"use client";
|
|
1
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useLocale } from "../../localization.js";
|
|
2
4
|
import { cx } from "../../lib/cx.js";
|
|
3
5
|
/** A small loading indicator for waits under a few seconds. */
|
|
4
6
|
export function Spinner({ size: sizeProp, label, showLabel, className }) {
|
|
7
|
+
const { messages } = useLocale();
|
|
5
8
|
const size = sizeProp || 16;
|
|
6
|
-
const text = label ||
|
|
7
|
-
return (_jsxs("span", { role: "status", className: cx("vk-spinner-wrap", className), children: [_jsx("span", { className: "vk-spinner", style: { width: size + "px", height: size + "px" }, "aria-hidden": "true" }), showLabel ? _jsx("span", { className: "vk-spinner-label", children: text }) : _jsx("span", { className: "vk-sr-only", children: text })] }));
|
|
9
|
+
const text = label || messages.loading;
|
|
10
|
+
return (_jsxs("span", { role: "status", className: cx("vk-spinner-wrap", className), children: [_jsx("span", { className: "vk-spinner", style: { width: String(size) + "px", height: String(size) + "px" }, "aria-hidden": "true" }), showLabel ? _jsx("span", { className: "vk-spinner-label", children: text }) : _jsx("span", { className: "vk-sr-only", children: text })] }));
|
|
8
11
|
}
|