@vokality/design-system 2.0.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 +28 -0
- package/README.md +49 -3
- 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 +2 -2
- package/dist/components/FileUpload/FileUpload.js +17 -9
- package/dist/components/Grid/Grid.d.ts +5 -5
- package/dist/components/Grid/Grid.js +1 -1
- package/dist/components/Heading/Heading.js +2 -1
- package/dist/components/Icon/Icon.js +4 -2
- package/dist/components/Inline/Inline.d.ts +7 -7
- 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 +5 -5
- 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 +1 -1
- 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 +179 -8
- 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/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/vokality.css +179 -8
- package/dist/vokality.iife.js +35986 -9685
- package/docs/brand.md +6 -3
- package/docs/components/AppShell/README.md +1 -1
- package/docs/components/BarChart/README.md +1 -0
- 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/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/Toaster/README.md +3 -1
- package/docs/components/Tooltip/README.md +5 -3
- package/package.json +49 -5
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { useLocale } from "../../localization.js";
|
|
3
4
|
import { useEffect, useRef, useState } from "react";
|
|
4
5
|
import { Dialog } from "../Dialog/Dialog.js";
|
|
5
6
|
import { Icon } from "../Icon/Icon.js";
|
|
@@ -11,6 +12,7 @@ import { useUid } from "../../internal/useUid.js";
|
|
|
11
12
|
import { cx } from "../../lib/cx.js";
|
|
12
13
|
/** A searchable list of every action and destination in an app, opened with ⌘K (Ctrl+K). Its shell is the Radix-based Dialog. */
|
|
13
14
|
export function CommandPalette({ commands, open: openProp, onOpenChange, hotkey, placeholder, emptyText, title }) {
|
|
15
|
+
const { messages } = useLocale();
|
|
14
16
|
const controlled = openProp !== undefined;
|
|
15
17
|
const [openState, setOpenState] = useState(false);
|
|
16
18
|
const open = openProp ?? openState;
|
|
@@ -20,33 +22,49 @@ export function CommandPalette({ commands, open: openProp, onOpenChange, hotkey,
|
|
|
20
22
|
onOpenChange?.(v);
|
|
21
23
|
};
|
|
22
24
|
const uid = useUid("vk-cmd");
|
|
25
|
+
// A keyboard command has no Dialog.Trigger: its invoker is application context.
|
|
26
|
+
const invokerRef = useRef(null);
|
|
23
27
|
// The hotkey listener toggles from the latest state without re-subscribing on every change.
|
|
24
|
-
const toggleRef = useRef(() => setOpen(!open));
|
|
25
|
-
useIsoLayoutEffect(() => { toggleRef.current = () => setOpen(!open); });
|
|
28
|
+
const toggleRef = useRef(() => { setOpen(!open); });
|
|
29
|
+
useIsoLayoutEffect(() => { toggleRef.current = () => { setOpen(!open); }; });
|
|
26
30
|
useEffect(() => {
|
|
27
31
|
if (hotkey === false)
|
|
28
32
|
return undefined;
|
|
29
33
|
const onKey = (e) => {
|
|
30
34
|
if ((e.metaKey || e.ctrlKey) && (e.key === "k" || e.key === "K")) {
|
|
31
35
|
e.preventDefault();
|
|
36
|
+
if (e.target instanceof HTMLElement && !e.target.closest(".vk-cmd"))
|
|
37
|
+
invokerRef.current = e.target;
|
|
32
38
|
toggleRef.current();
|
|
33
39
|
}
|
|
34
40
|
};
|
|
35
41
|
document.addEventListener("keydown", onKey);
|
|
36
|
-
return () => document.removeEventListener("keydown", onKey);
|
|
42
|
+
return () => { document.removeEventListener("keydown", onKey); };
|
|
37
43
|
}, [hotkey]);
|
|
38
|
-
return (_jsxs(Dialog, { open: open,
|
|
44
|
+
return (_jsxs(Dialog, { open: open, onOpenChange: setOpen, title: title || messages.commandPalette, className: "vk-cmd", size: "md", contentProps: {
|
|
45
|
+
onOpenAutoFocus(event) {
|
|
46
|
+
event.preventDefault();
|
|
47
|
+
document.getElementById(uid + "-search")?.focus();
|
|
48
|
+
},
|
|
49
|
+
onCloseAutoFocus(event) {
|
|
50
|
+
if (invokerRef.current?.isConnected) {
|
|
51
|
+
event.preventDefault();
|
|
52
|
+
invokerRef.current.focus();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}, children: [_jsx(PaletteSearch, { uid: uid, commands: commands, placeholder: placeholder, emptyText: emptyText, close: () => { setOpen(false); } }), _jsxs("div", { className: "vk-cmd-footer", "aria-hidden": "true", children: [_jsx(Kbd, { children: "↑" }), _jsx(Kbd, { children: "↓" }), messages.commandMove, _jsx(Kbd, { children: "Enter" }), messages.commandRun, _jsx(Kbd, { children: "Esc" }), messages.commandClose] })] }));
|
|
39
56
|
}
|
|
40
57
|
/** The search box and the matching commands. */
|
|
41
58
|
function PaletteSearch({ uid, commands, placeholder, emptyText, close }) {
|
|
59
|
+
const { messages } = useLocale();
|
|
42
60
|
const [query, setQuery] = useState("");
|
|
43
61
|
const [active, setActive] = useState(0);
|
|
44
62
|
const listRef = useRef(null);
|
|
45
|
-
const cmds =
|
|
63
|
+
const cmds = commands.filter((c) => {
|
|
46
64
|
if (!query)
|
|
47
65
|
return true;
|
|
48
66
|
const q = query.toLowerCase();
|
|
49
|
-
return
|
|
67
|
+
return c.label.toLowerCase().includes(q) || (c.keywords || []).some((k) => k.toLowerCase().includes(q)) || (c.group && c.group.toLowerCase().includes(q));
|
|
50
68
|
});
|
|
51
69
|
useScrollActive(true, listRef, active);
|
|
52
70
|
const run = (c) => {
|
|
@@ -60,11 +78,12 @@ function PaletteSearch({ uid, commands, placeholder, emptyText, close }) {
|
|
|
60
78
|
cmds.forEach((c, i) => {
|
|
61
79
|
const g = c.group || "";
|
|
62
80
|
const last = groups[groups.length - 1];
|
|
63
|
-
if (
|
|
64
|
-
|
|
65
|
-
|
|
81
|
+
if (last && last.name === g)
|
|
82
|
+
last.items.push({ c, i });
|
|
83
|
+
else
|
|
84
|
+
groups.push({ name: g, items: [{ c, i }] });
|
|
66
85
|
});
|
|
67
|
-
return (_jsxs(_Fragment, { children: [_jsxs("div", { className: "vk-cmd-search", children: [_jsx(Icon, { name: "search", size: 16, className: "vk-search-icon" }), _jsx("input", {
|
|
86
|
+
return (_jsxs(_Fragment, { children: [_jsxs("div", { className: "vk-cmd-search", children: [_jsx(Icon, { name: "search", size: 16, className: "vk-search-icon" }), _jsx("input", { id: uid + "-search", type: "text", role: "combobox", className: "vk-input vk-search-input", placeholder: placeholder || messages.commandSearch, autoComplete: "off", value: query, "aria-expanded": "true", "aria-controls": uid + "-list", "aria-activedescendant": cmds.length ? uid + "-" + String(active) : undefined, "aria-autocomplete": "list", onChange: (e) => { setQuery(e.target.value); setActive(0); }, onKeyDown: (e) => {
|
|
68
87
|
if (e.key === "ArrowDown") {
|
|
69
88
|
e.preventDefault();
|
|
70
89
|
setActive(Math.min(cmds.length - 1, active + 1));
|
|
@@ -78,9 +97,9 @@ function PaletteSearch({ uid, commands, placeholder, emptyText, close }) {
|
|
|
78
97
|
run(cmds[active]);
|
|
79
98
|
}
|
|
80
99
|
} })] }), cmds.length
|
|
81
|
-
? (_jsx("div", { ref: listRef, id: uid + "-list", role: "listbox", "aria-label":
|
|
100
|
+
? (_jsx("div", { ref: listRef, id: uid + "-list", role: "listbox", "aria-label": messages.commands, className: "vk-cmd-list", children: groups.map((g) => (_jsxs("div", { role: "group", "aria-label": g.name || undefined, children: [g.name ? _jsx("div", { className: "vk-menu-label", "aria-hidden": "true", children: g.name }) : null, g.items.map(({ c, i }) => (_jsxs("div", { id: uid + "-" + String(i), "data-index": i, role: "option", "aria-selected": i === active ? "true" : "false", "aria-disabled": c.disabled ? "true" : undefined, className: cx("vk-menu-item", "vk-cmd-item", i === active ? "vk-cmd-item-active" : null), onMouseMove: () => { if (active !== i)
|
|
82
101
|
setActive(i); },
|
|
83
102
|
// Keep focus in the search box while clicking a command.
|
|
84
|
-
onMouseDown: (e) => e.preventDefault(), onClick: () => run(c), children: [c.icon ? _jsx(Icon, { name: c.icon, size: 16, className: "vk-menu-item-icon" }) : _jsx("span", { className: "vk-menu-item-icon" }), _jsx("span", { className: "vk-menu-item-label", children: highlight(c.label, query) }), c.shortcut ? _jsx("kbd", { className: "vk-menu-shortcut", children: c.shortcut }) : null] }, c.id || c.label)))] }, g.name || "_"))) }))
|
|
85
|
-
: _jsx("p", { className: "vk-select-empty", role: "status", children: emptyText ||
|
|
103
|
+
onMouseDown: (e) => { e.preventDefault(); }, onClick: () => { run(c); }, children: [c.icon ? _jsx(Icon, { name: c.icon, size: 16, className: "vk-menu-item-icon" }) : _jsx("span", { className: "vk-menu-item-icon" }), _jsx("span", { className: "vk-menu-item-label", children: highlight(c.label, query) }), c.shortcut ? _jsx("kbd", { className: "vk-menu-shortcut", children: c.shortcut }) : null] }, c.id || c.label)))] }, g.name || "_"))) }))
|
|
104
|
+
: _jsx("p", { className: "vk-select-empty", role: "status", children: emptyText || messages.noCommands(query) })] }));
|
|
86
105
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
2
|
import type { MenuEntry } from "../../types.js";
|
|
3
3
|
export interface ContextMenuProps {
|
|
4
4
|
items: MenuEntry[];
|
|
@@ -7,5 +7,5 @@ export interface ContextMenuProps {
|
|
|
7
7
|
disabled?: boolean;
|
|
8
8
|
className?: string;
|
|
9
9
|
}
|
|
10
|
-
/**
|
|
10
|
+
/** Actions for a region, with trigger gestures and focus supplied by Radix ContextMenu. */
|
|
11
11
|
export declare function ContextMenu({ items, children, label, disabled, className }: ContextMenuProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,56 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import {
|
|
3
|
+
import { useLocale } from "../../localization.js";
|
|
4
4
|
import { ContextMenu as Primitive } from "radix-ui";
|
|
5
5
|
import { cx } from "../../lib/cx.js";
|
|
6
|
-
import { MenuEntries
|
|
7
|
-
/**
|
|
6
|
+
import { MenuEntries } from "../Menu/entries.js";
|
|
7
|
+
/** Actions for a region, with trigger gestures and focus supplied by Radix ContextMenu. */
|
|
8
8
|
export function ContextMenu({ items, children, label, disabled, className }) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const [state, setState] = useState("closed");
|
|
12
|
-
const open = state === "open";
|
|
13
|
-
const { defer, flush } = useDeferredSelect();
|
|
14
|
-
const { arm, onFocus } = useFocusOnOpen();
|
|
15
|
-
const onOpenChange = (next) => {
|
|
16
|
-
arm(next ? "first" : null);
|
|
17
|
-
// An open menu stays open while Radix moves it to a new point.
|
|
18
|
-
setState((s) => (!next ? "closed" : s === "open" ? "open" : "opening"));
|
|
19
|
-
};
|
|
20
|
-
useEffect(() => {
|
|
21
|
-
if (state === "opening")
|
|
22
|
-
setState("open");
|
|
23
|
-
}, [state]);
|
|
24
|
-
// Scrolling the page (not the menu itself) closes it: the menu is anchored to a point, not an element.
|
|
25
|
-
useEffect(() => {
|
|
26
|
-
if (!open)
|
|
27
|
-
return undefined;
|
|
28
|
-
const onScroll = (e) => {
|
|
29
|
-
if (e.target instanceof Element && e.target.closest(".vk-menu"))
|
|
30
|
-
return;
|
|
31
|
-
arm(null);
|
|
32
|
-
setState("closed");
|
|
33
|
-
};
|
|
34
|
-
window.addEventListener("scroll", onScroll, true);
|
|
35
|
-
return () => window.removeEventListener("scroll", onScroll, true);
|
|
36
|
-
}, [open, arm]);
|
|
37
|
-
return (_jsxs(Primitive.Root, { open: open, onOpenChange: onOpenChange, modal: false, children: [_jsx(Primitive.Trigger, { asChild: true, disabled: disabled, children: _jsx("div", { className: cx("vk-context-target", className), onContextMenu: (e) => {
|
|
38
|
-
// React bubbles events through portals: ignore right-clicks inside the open menu.
|
|
39
|
-
if (!e.currentTarget.contains(e.target))
|
|
40
|
-
e.preventDefault();
|
|
41
|
-
}, onKeyDown: (e) => {
|
|
42
|
-
if (disabled || !e.currentTarget.contains(e.target))
|
|
43
|
-
return;
|
|
44
|
-
if ((e.key === "F10" && e.shiftKey) || e.key === "ContextMenu") {
|
|
45
|
-
// Radix opens on the contextmenu event only, which not every browser sends for these keys:
|
|
46
|
-
// open it at the focused element instead, as a right-click there would.
|
|
47
|
-
e.preventDefault();
|
|
48
|
-
const target = e.target;
|
|
49
|
-
const r = target.getBoundingClientRect();
|
|
50
|
-
target.dispatchEvent(new MouseEvent("contextmenu", { bubbles: true, cancelable: true, clientX: r.left + 8, clientY: r.bottom }));
|
|
51
|
-
}
|
|
52
|
-
}, children: children }) }), _jsx(Primitive.Portal, { children: _jsx(Primitive.Content, { className: "vk-menu vk-context-menu", "aria-label": label || "Actions", collisionPadding: 8, loop: true, onFocus: onFocus, onKeyDownCapture: moveFocusNow, onCloseAutoFocus: () => flush(), onKeyDown: (e) => { if (e.key === "Tab") {
|
|
53
|
-
e.preventDefault();
|
|
54
|
-
onOpenChange(false);
|
|
55
|
-
} }, children: _jsx(MenuEntries, { parts: Primitive, items: items || [], defer: defer }) }) })] }));
|
|
9
|
+
const { messages } = useLocale();
|
|
10
|
+
return (_jsxs(Primitive.Root, { children: [_jsx(Primitive.Trigger, { asChild: true, disabled: disabled, children: _jsx("div", { className: cx("vk-context-target", className), children: children }) }), _jsx(Primitive.Portal, { children: _jsx(Primitive.Content, { className: "vk-menu vk-context-menu", "aria-label": label || messages.actions, collisionPadding: 8, children: _jsx(MenuEntries, { parts: Primitive, items: items }) }) })] }));
|
|
56
11
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { LocaleProvider, useLocale } from "../../localization.js";
|
|
3
4
|
import { forwardRef, useCallback, useRef, useState } from "react";
|
|
4
5
|
import { Popover as Primitive } from "radix-ui";
|
|
5
6
|
import { Button } from "../Button/Button.js";
|
|
@@ -7,9 +8,9 @@ import { Calendar } from "../Calendar/Calendar.js";
|
|
|
7
8
|
import { Icon } from "../Icon/Icon.js";
|
|
8
9
|
import { focusables } from "../../internal/focusables.js";
|
|
9
10
|
import { useUid } from "../../internal/useUid.js";
|
|
11
|
+
import { useToday } from "../../internal/useToday.js";
|
|
10
12
|
import { cx } from "../../lib/cx.js";
|
|
11
13
|
import { parseDateInput, parseISO, toISO } from "../../lib/dates.js";
|
|
12
|
-
import { resolveLocale } from "../../lib/format.js";
|
|
13
14
|
import { dateFormat } from "../../lib/intl.js";
|
|
14
15
|
import { omit } from "../../lib/omit.js";
|
|
15
16
|
const tabbable = (el) => focusables(el).filter((n) => n.tabIndex >= 0);
|
|
@@ -31,7 +32,7 @@ function dateLabel(fmt, range, value) {
|
|
|
31
32
|
const start = range ? parseISO(rangeValue?.start) : parseISO(typeof value === "string" ? value : null);
|
|
32
33
|
const end = range ? parseISO(rangeValue?.end) : null;
|
|
33
34
|
if (start && range && end)
|
|
34
|
-
return fmt
|
|
35
|
+
return typeof Reflect.get(fmt, "formatRange") === "function" ? fmt.formatRange(start, end) : fmt.format(start) + " – " + fmt.format(end);
|
|
35
36
|
if (start && range)
|
|
36
37
|
return fmt.format(start) + " – …";
|
|
37
38
|
if (start)
|
|
@@ -62,8 +63,9 @@ function allowedDate(iso, props) {
|
|
|
62
63
|
return iso !== null && d !== null && !(minD && d < minD) && !(maxD && d > maxD) && !props.isDateDisabled?.(iso);
|
|
63
64
|
}
|
|
64
65
|
/** Typing mode: a text input, with a button that opens the calendar. */
|
|
65
|
-
function TypedField(p) {
|
|
66
|
-
|
|
66
|
+
function TypedField({ fieldRef, popRef, ...p }) {
|
|
67
|
+
const { messages } = useLocale();
|
|
68
|
+
return (_jsx(Primitive.Anchor, { asChild: true, children: _jsxs("div", { className: "vk-combobox-field vk-date-field", children: [_jsx("input", { ref: fieldRef, id: p.id, type: "text", autoComplete: "off", className: "vk-input vk-date-input", placeholder: p.placeholder, disabled: p.disabled, value: p.text, onChange: (e) => { p.onType(e.target.value); }, onKeyDown: (e) => {
|
|
67
69
|
if (e.key === "Enter") {
|
|
68
70
|
e.preventDefault();
|
|
69
71
|
p.onCommit();
|
|
@@ -73,29 +75,31 @@ function TypedField(p) {
|
|
|
73
75
|
p.onOpen();
|
|
74
76
|
}
|
|
75
77
|
}, onBlur: (e) => {
|
|
76
|
-
if (!(
|
|
78
|
+
if (!(popRef.current && popRef.current.contains(e.relatedTarget)))
|
|
77
79
|
p.onCommit();
|
|
78
|
-
}, ...p.a11y, "aria-invalid": p.invalid || p.a11y["aria-invalid"] ? true : undefined, ...(p.invalid ? { "aria-describedby": cx(p.a11y["aria-describedby"], p.errId) } : null) }), _jsx(Primitive.Trigger, { asChild: true, children: _jsx("button", { type: "button", className: "vk-field-clear vk-date-button", disabled: p.disabled, "aria-label": (p.dialogLabel ||
|
|
80
|
+
}, ...p.a11y, "aria-invalid": p.invalid || p.a11y["aria-invalid"] ? true : undefined, ...(p.invalid ? { "aria-describedby": cx(p.a11y["aria-describedby"], p.errId) } : null) }), _jsx(Primitive.Trigger, { asChild: true, children: _jsx("button", { type: "button", className: "vk-field-clear vk-date-button", disabled: p.disabled, "aria-label": (p.dialogLabel || messages.chooseDate) + (p.label ? ", " + p.label : ""), onClick: p.onButtonClick, children: _jsx(Icon, { name: "calendar", size: 16 }) }) })] }) }));
|
|
79
81
|
}
|
|
80
82
|
/** Without typing: a button that shows the chosen date(s) and opens the calendar. */
|
|
81
83
|
function ButtonField({ fieldRef, id, disabled, open, label, placeholder, range, a11y, onOpen }) {
|
|
84
|
+
const { messages } = useLocale();
|
|
82
85
|
return (_jsx(Primitive.Trigger, { asChild: true, children: _jsxs("button", { ref: fieldRef, id: id, type: "button", className: "vk-input vk-select-trigger vk-date-trigger", disabled: disabled, onKeyDown: (e) => {
|
|
83
86
|
if (e.key === "ArrowDown" && !open) {
|
|
84
87
|
e.preventDefault();
|
|
85
88
|
onOpen();
|
|
86
89
|
}
|
|
87
|
-
}, ...a11y, children: [_jsx(Icon, { name: "calendar", size: 16, className: "vk-date-icon" }), _jsx("span", { className: label ? "vk-select-value" : "vk-select-value vk-select-placeholder", children: label || placeholder || (range ?
|
|
90
|
+
}, ...a11y, children: [_jsx(Icon, { name: "calendar", size: 16, className: "vk-date-icon" }), _jsx("span", { className: label ? "vk-select-value" : "vk-select-value vk-select-placeholder", children: label || placeholder || (range ? messages.selectDates : messages.selectDate) })] }) }));
|
|
88
91
|
}
|
|
89
92
|
/** The portalled popover dialog: the Calendar, with Clear and (single mode) Today. */
|
|
90
|
-
function DatePanel({ props, range, locale, value, todayISO, rootRef, popRef,
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
+
function DatePanel({ props, range, locale, value, todayISO, rootRef, popRef, refocusRef, changeOpen, set }) {
|
|
94
|
+
const { messages } = useLocale();
|
|
95
|
+
const close = () => { changeOpen(false); };
|
|
96
|
+
return (_jsx(Primitive.Portal, { children: _jsxs(Primitive.Content, { ref: popRef, "aria-label": props.dialogLabel || (range ? messages.chooseDates : messages.chooseDate), className: "vk-popover vk-date-popover", side: "bottom", align: "start", sideOffset: 4, collisionPadding: 8, onInteractOutside: (e) => {
|
|
93
97
|
// The field and its button belong to the picker: pressing them keeps it open (the button toggles it).
|
|
94
|
-
if (rootRef.current && rootRef.current.contains(e.target))
|
|
98
|
+
if (e.target instanceof Node && rootRef.current && rootRef.current.contains(e.target))
|
|
95
99
|
e.preventDefault();
|
|
96
100
|
else
|
|
97
|
-
|
|
98
|
-
}, onCloseAutoFocus: (e) => e.preventDefault(), onKeyDown: (e) => {
|
|
101
|
+
refocusRef.current = false;
|
|
102
|
+
}, onCloseAutoFocus: (e) => { e.preventDefault(); }, onKeyDown: (e) => {
|
|
99
103
|
// Radix closes the panel on Escape; an enclosing dialog stays open.
|
|
100
104
|
if (e.key === "Escape")
|
|
101
105
|
e.stopPropagation();
|
|
@@ -108,23 +112,24 @@ function DatePanel({ props, range, locale, value, todayISO, rootRef, popRef, ref
|
|
|
108
112
|
e.preventDefault();
|
|
109
113
|
e.stopPropagation();
|
|
110
114
|
const next = tabTarget(rootRef.current, content, e.shiftKey);
|
|
111
|
-
|
|
115
|
+
refocusRef.current = !next;
|
|
112
116
|
changeOpen(false);
|
|
113
117
|
next?.focus();
|
|
114
|
-
}, children: [_jsx(Calendar, { mode: props.mode, locale: locale, value: value, min: props.min, max: props.max, isDateDisabled: props.isDateDisabled, weekStartsOn: props.weekStartsOn, today:
|
|
118
|
+
}, children: [_jsx(Calendar, { mode: props.mode, locale: locale, value: value, min: props.min, max: props.max, isDateDisabled: props.isDateDisabled, weekStartsOn: props.weekStartsOn, today: todayISO, autoFocus: true, onChange: (next) => {
|
|
115
119
|
set(next);
|
|
116
120
|
if (!range || (typeof next === "object" && next.start && next.end))
|
|
117
121
|
close();
|
|
118
122
|
} }), _jsxs("div", { className: "vk-popover-footer", children: [_jsx(Button, { variant: "ghost", size: "sm", onClick: () => {
|
|
119
123
|
set(range ? { start: null, end: null } : null);
|
|
120
124
|
close();
|
|
121
|
-
}, children:
|
|
125
|
+
}, children: messages.clear }), range ? null : (_jsx(Button, { variant: "outline", size: "sm", onClick: () => {
|
|
122
126
|
set(todayISO);
|
|
123
127
|
close();
|
|
124
|
-
}, children:
|
|
128
|
+
}, children: messages.today }))] })] }) }));
|
|
125
129
|
}
|
|
126
130
|
function InvalidDate({ id, message, example }) {
|
|
127
|
-
|
|
131
|
+
const { messages } = useLocale();
|
|
132
|
+
return _jsx("span", { id: id, className: "vk-field-error vk-inline-error", children: message || messages.invalidDate(example) });
|
|
128
133
|
}
|
|
129
134
|
/** The value for forms: name=YYYY-MM-DD, or name_start and name_end in range mode. */
|
|
130
135
|
function HiddenDate({ name, range, value }) {
|
|
@@ -138,8 +143,8 @@ function HiddenDate({ name, range, value }) {
|
|
|
138
143
|
* to the text input, or to the trigger button when typing is off.
|
|
139
144
|
*/
|
|
140
145
|
export const DatePicker = forwardRef(function DatePicker(props, ref) {
|
|
146
|
+
const { locale } = useLocale(props.locale);
|
|
141
147
|
const range = props.mode === "range";
|
|
142
|
-
const locale = resolveLocale(props.locale);
|
|
143
148
|
const base = useUid("vk-date");
|
|
144
149
|
const triggerId = props.id || base + "-trigger";
|
|
145
150
|
const { value, set, draft, setDraft } = useDateValue(props, range);
|
|
@@ -155,18 +160,19 @@ export const DatePicker = forwardRef(function DatePicker(props, ref) {
|
|
|
155
160
|
ref.current = el;
|
|
156
161
|
}, [ref]);
|
|
157
162
|
// False when the panel closes because people clicked or tabbed elsewhere: focus stays there.
|
|
158
|
-
const
|
|
163
|
+
const refocusRef = useRef(true);
|
|
159
164
|
const changeOpen = (next) => {
|
|
160
165
|
if (next)
|
|
161
|
-
|
|
166
|
+
refocusRef.current = true;
|
|
162
167
|
setOpen(next);
|
|
163
168
|
// Focus returns right away rather than after the exit animation.
|
|
164
|
-
if (!next &&
|
|
169
|
+
if (!next && refocusRef.current)
|
|
165
170
|
fieldRef.current?.focus();
|
|
166
171
|
};
|
|
167
172
|
const fmt = dateFormat(locale, { month: "short", day: "numeric", year: "numeric" });
|
|
168
173
|
const label = dateLabel(fmt, range, value);
|
|
169
|
-
const
|
|
174
|
+
const todayDate = useToday(props.today);
|
|
175
|
+
const todayISO = toISO(todayDate);
|
|
170
176
|
const typing = !range && props.allowTyping !== false;
|
|
171
177
|
const text = draft ? draft.text : label || "";
|
|
172
178
|
const invalid = Boolean(draft?.invalid);
|
|
@@ -188,11 +194,11 @@ export const DatePicker = forwardRef(function DatePicker(props, ref) {
|
|
|
188
194
|
};
|
|
189
195
|
const a11y = omit(props, ["mode", "locale", "id", "value", "defaultValue", "onChange", "placeholder", "min", "max", "isDateDisabled", "weekStartsOn", "name", "disabled", "defaultOpen", "className", "today", "dialogLabel", "allowTyping", "invalidMessage"]);
|
|
190
196
|
const errId = base + "-err";
|
|
191
|
-
const example = fmt.format(
|
|
192
|
-
const trigger = typing ? (_jsx(TypedField, { fieldRef: setFieldRef, id: triggerId, placeholder: props.placeholder || example, disabled: props.disabled, text: text, invalid: invalid, errId: errId, a11y: a11y, dialogLabel: props.dialogLabel, label: label, onType: (t) => setDraft({ text: t, invalid: false, value }), onCommit: commitTyped, onOpen: () => changeOpen(true), onButtonClick: () => {
|
|
197
|
+
const example = fmt.format(todayDate);
|
|
198
|
+
const trigger = typing ? (_jsx(TypedField, { fieldRef: setFieldRef, id: triggerId, placeholder: props.placeholder || example, disabled: props.disabled, text: text, invalid: invalid, errId: errId, a11y: a11y, dialogLabel: props.dialogLabel, label: label, onType: (t) => { setDraft({ text: t, invalid: false, value }); }, onCommit: commitTyped, onOpen: () => { changeOpen(true); }, onButtonClick: () => {
|
|
193
199
|
// Closing with the button leaves focus on it.
|
|
194
200
|
if (open)
|
|
195
|
-
|
|
196
|
-
}, popRef: popRef })) : (_jsx(ButtonField, { fieldRef: setFieldRef, id: triggerId, disabled: props.disabled, open: open, label: label, placeholder: props.placeholder, range: range, a11y: a11y, onOpen: () => changeOpen(true) }));
|
|
197
|
-
return (_jsx(Primitive.Root, { open: open, onOpenChange: changeOpen, children: _jsxs("div", { ref: rootRef, className: cx("vk-select", "vk-datepicker", props.className), "data-state": open ? "open" : "closed", children: [trigger, _jsx(DatePanel, { props: props, range: range, locale: locale, value: value, todayISO: todayISO, rootRef: rootRef, popRef: popRef,
|
|
201
|
+
refocusRef.current = false;
|
|
202
|
+
}, popRef: popRef })) : (_jsx(ButtonField, { fieldRef: setFieldRef, id: triggerId, disabled: props.disabled, open: open, label: label, placeholder: props.placeholder, range: range, a11y: a11y, onOpen: () => { changeOpen(true); } }));
|
|
203
|
+
return (_jsx(LocaleProvider, { locale: locale, children: _jsx(Primitive.Root, { open: open, onOpenChange: changeOpen, children: _jsxs("div", { ref: rootRef, className: cx("vk-select", "vk-datepicker", props.className), "data-state": open ? "open" : "closed", children: [trigger, _jsx(DatePanel, { props: props, range: range, locale: locale, value: value, todayISO: todayISO, rootRef: rootRef, popRef: popRef, refocusRef: refocusRef, changeOpen: changeOpen, set: set }), invalid ? _jsx(InvalidDate, { id: errId, message: props.invalidMessage, example: example }) : null, props.name ? _jsx(HiddenDate, { name: props.name, range: range, value: value }) : null] }) }) }));
|
|
198
204
|
});
|
|
@@ -2,5 +2,5 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { cx } from "../../lib/cx.js";
|
|
3
3
|
/** Label and value pairs for a record's details. */
|
|
4
4
|
export function DescriptionList({ items, layout, columns, className }) {
|
|
5
|
-
return (_jsx("dl", { className: cx("vk-dl", layout === "stacked" && "vk-dl-stacked", columns === 2 && "vk-dl-2", className), children:
|
|
5
|
+
return (_jsx("dl", { className: cx("vk-dl", layout === "stacked" && "vk-dl-stacked", columns === 2 && "vk-dl-2", className), children: items.map((it, i) => (_jsxs("div", { className: "vk-dl-row", children: [_jsx("dt", { children: it.term }), _jsx("dd", { children: it.description })] }, (typeof it.term === "string" ? it.term : "") + "#" + String(i)))) }));
|
|
6
6
|
}
|
|
@@ -1,23 +1,40 @@
|
|
|
1
|
-
import { type ReactNode } from "react";
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { type ReactElement, type ReactNode } from "react";
|
|
2
|
+
import { AlertDialog, Dialog as Primitive } from "radix-ui";
|
|
3
|
+
interface DialogFrameProps extends Pick<Primitive.DialogProps, 'open' | 'defaultOpen' | 'onOpenChange'> {
|
|
4
|
+
/** Compatibility alias for onOpenChange(false). */
|
|
4
5
|
onClose?: () => void;
|
|
6
|
+
/** Radix Trigger asChild: supplies opening behavior and focus restoration. */
|
|
7
|
+
trigger?: ReactElement;
|
|
5
8
|
title: ReactNode;
|
|
6
9
|
description?: ReactNode;
|
|
7
10
|
children?: ReactNode;
|
|
8
11
|
footer?: ReactNode;
|
|
9
12
|
size?: 'sm' | 'md' | 'lg';
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
closeOnBackdrop?: boolean;
|
|
13
|
+
/** Presentation only; Escape and outside interaction remain Radix behavior. */
|
|
14
|
+
hideCloseButton?: boolean;
|
|
13
15
|
closeLabel?: string;
|
|
14
16
|
className?: string;
|
|
15
17
|
}
|
|
18
|
+
/** The content contract follows the selected Radix component without widening event props. */
|
|
19
|
+
export type DialogProps = DialogFrameProps & ({
|
|
20
|
+
role?: 'dialog';
|
|
21
|
+
contentProps?: Omit<Primitive.DialogContentProps, 'children' | 'className'>;
|
|
22
|
+
cancel?: never;
|
|
23
|
+
action?: never;
|
|
24
|
+
} | {
|
|
25
|
+
role: 'alertdialog';
|
|
26
|
+
contentProps?: Omit<AlertDialog.AlertDialogContentProps, 'children' | 'className'>;
|
|
27
|
+
/** Radix Cancel receives initial focus when supplied. */
|
|
28
|
+
cancel?: ReactElement;
|
|
29
|
+
/** Radix Action closes after the supplied action. */
|
|
30
|
+
action?: ReactElement;
|
|
31
|
+
});
|
|
16
32
|
/**
|
|
17
33
|
* Modal dialog (Radix Dialog; Radix AlertDialog for `role="alertdialog"`): focus moves in and is
|
|
18
|
-
* trapped, the page behind is inert and can't scroll, and closing returns focus to
|
|
34
|
+
* trapped, the page behind is inert and can't scroll, and closing returns focus to its Radix Trigger.
|
|
19
35
|
*/
|
|
20
36
|
export declare function Dialog(props: DialogProps & {
|
|
21
37
|
/** Set by Drawer: renders the panel as a sheet on this side. */
|
|
22
38
|
side?: 'right' | 'left';
|
|
23
39
|
}): import("react/jsx-runtime").JSX.Element;
|
|
40
|
+
export {};
|
|
@@ -1,53 +1,42 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import {
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useLocale } from "../../localization.js";
|
|
4
|
+
import { createElement } from "react";
|
|
4
5
|
import { AlertDialog, Dialog as Primitive } from "radix-ui";
|
|
5
6
|
import { IconButton } from "../IconButton/IconButton.js";
|
|
6
|
-
import { focusables } from "../../internal/focusables.js";
|
|
7
|
-
import { useIsoLayoutEffect } from "../../internal/useIsoLayoutEffect.js";
|
|
8
7
|
import { cx } from "../../lib/cx.js";
|
|
9
8
|
import { para } from "../../lib/text.js";
|
|
10
9
|
/**
|
|
11
10
|
* Modal dialog (Radix Dialog; Radix AlertDialog for `role="alertdialog"`): focus moves in and is
|
|
12
|
-
* trapped, the page behind is inert and can't scroll, and closing returns focus to
|
|
11
|
+
* trapped, the page behind is inert and can't scroll, and closing returns focus to its Radix Trigger.
|
|
13
12
|
*/
|
|
14
13
|
export function Dialog(props) {
|
|
15
|
-
const { open,
|
|
14
|
+
const { open, defaultOpen, onOpenChange, onClose, trigger, children, size, role, className, side } = props;
|
|
16
15
|
const alert = role === "alertdialog";
|
|
17
16
|
// The same Radix parts either way; AlertDialog also ignores outside presses.
|
|
18
|
-
const P =
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const r = restoreRef.current;
|
|
44
|
-
if (r && r.focus && document.contains(r))
|
|
45
|
-
r.focus();
|
|
46
|
-
}, onEscapeKeyDown: (e) => { if (!dismissible)
|
|
47
|
-
e.preventDefault(); }, onPointerDownOutside: (e) => { if (!closeOnBackdrop)
|
|
48
|
-
e.preventDefault(); }, children: [_jsxs("div", { className: "vk-dialog-header", children: [_jsxs("div", { className: "vk-dialog-heading", children: [_jsx(P.Title, { className: "vk-dialog-title", children: title }), description
|
|
49
|
-
? _jsx(P.Description, { asChild: true, children: _jsx(Description, { className: "vk-dialog-description", children: description }) })
|
|
50
|
-
: null] }), dismissible
|
|
51
|
-
? _jsx(P.Close, { asChild: true, children: _jsx(IconButton, { icon: "x", label: closeLabel || "Close", className: "vk-dialog-close" }) })
|
|
52
|
-
: null] }), children ? _jsx("div", { className: "vk-dialog-body", children: children }) : null, footer ? _jsx("div", { className: "vk-dialog-footer", children: footer }) : null] }) }) }) }));
|
|
17
|
+
const P = alert ? AlertDialog : Primitive;
|
|
18
|
+
const content = (_jsxs(_Fragment, { children: [_jsx(DialogHeader, { ...props }), children ? _jsx("div", { className: "vk-dialog-body", children: children }) : null, _jsx(DialogFooter, { ...props })] }));
|
|
19
|
+
const contentClass = cx("vk-dialog", side ? "vk-drawer vk-drawer-" + side : "vk-dialog-" + (size || "md"), className);
|
|
20
|
+
return (_jsxs(P.Root, { open: open, defaultOpen: defaultOpen, onOpenChange: (next) => { onOpenChange?.(next); if (!next)
|
|
21
|
+
onClose?.(); }, children: [trigger ? _jsx(P.Trigger, { asChild: true, children: trigger }) : null, _jsx(P.Portal, { children: _jsx(P.Overlay, { className: cx("vk-overlay", side ? "vk-overlay-drawer" : null), children: props.role === "alertdialog"
|
|
22
|
+
? _jsx(AlertDialog.Content, { ...props.contentProps, "aria-modal": "true", className: contentClass, children: content })
|
|
23
|
+
: _jsx(Primitive.Content, { ...props.contentProps, "aria-modal": "true", className: contentClass, children: content }) }) })] }));
|
|
24
|
+
}
|
|
25
|
+
/** Styled title, description and native close control; Radix owns all interaction. */
|
|
26
|
+
function DialogHeader({ title, description, role, hideCloseButton, closeLabel }) {
|
|
27
|
+
const { messages } = useLocale();
|
|
28
|
+
const alert = role === "alertdialog";
|
|
29
|
+
const P = alert ? AlertDialog : Primitive;
|
|
30
|
+
return (_jsxs("div", { className: "vk-dialog-header", children: [_jsxs("div", { className: "vk-dialog-heading", children: [_jsx(P.Title, { className: "vk-dialog-title", children: title }), description
|
|
31
|
+
? _jsx(P.Description, { asChild: true, children: createElement(para(description), { className: "vk-dialog-description" }, description) })
|
|
32
|
+
: null] }), !alert && !hideCloseButton
|
|
33
|
+
? _jsx(Primitive.Close, { asChild: true, children: _jsx(IconButton, { icon: "x", label: closeLabel || messages.close, className: "vk-dialog-close" }) })
|
|
34
|
+
: null] }));
|
|
35
|
+
}
|
|
36
|
+
/** The footer only composes content and native AlertDialog actions. */
|
|
37
|
+
function DialogFooter(props) {
|
|
38
|
+
const { footer } = props;
|
|
39
|
+
return (footer || (props.role === "alertdialog" && (props.cancel || props.action))
|
|
40
|
+
? _jsxs("div", { className: "vk-dialog-footer", children: [footer, props.role === "alertdialog" && props.cancel ? _jsx(AlertDialog.Cancel, { asChild: true, children: props.cancel }) : null, props.role === "alertdialog" && props.action ? _jsx(AlertDialog.Action, { asChild: true, children: props.action }) : null] })
|
|
41
|
+
: null);
|
|
53
42
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { type DialogProps } from "../Dialog/Dialog.js";
|
|
2
|
-
|
|
2
|
+
type AsDrawer<Props> = Props extends DialogProps ? Omit<Props, 'size'> & {
|
|
3
3
|
side?: 'right' | 'left';
|
|
4
|
-
}
|
|
4
|
+
} : never;
|
|
5
|
+
export type DrawerProps = AsDrawer<DialogProps>;
|
|
5
6
|
/** A modal panel that slides in from the side: a Dialog rendered as a sheet. */
|
|
6
7
|
export declare function Drawer(props: DrawerProps): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export {};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { createElement } from "react";
|
|
2
3
|
import { SquareGlyph } from "../SquareGlyph/SquareGlyph.js";
|
|
3
4
|
import { cx } from "../../lib/cx.js";
|
|
4
5
|
import { para } from "../../lib/text.js";
|
|
5
6
|
/** What a list, table or page shows when it has nothing in it yet. */
|
|
6
7
|
export function EmptyState({ title, children, actions, glyph, headingAs, className }) {
|
|
7
8
|
const HeadingTag = headingAs || "h3";
|
|
8
|
-
|
|
9
|
-
return (_jsxs("div", { className: cx("vk-empty", className), children: [_jsxs("div", { className: "vk-empty-glyphs", "aria-hidden": "true", children: [_jsx(SquareGlyph, { children: glyph || "+" }), _jsx("span", { className: "vk-empty-glyph-ghost" }), _jsx("span", { className: "vk-empty-glyph-ghost" })] }), _jsx(HeadingTag, { className: "vk-empty-title", children: title }), children ? _jsx(Body, { className: "vk-empty-text", children: children }) : null, actions ? _jsx("div", { className: "vk-row vk-empty-actions", children: actions }) : null] }));
|
|
9
|
+
return (_jsxs("div", { className: cx("vk-empty", className), children: [_jsxs("div", { className: "vk-empty-glyphs", "aria-hidden": "true", children: [_jsx(SquareGlyph, { children: glyph || "+" }), _jsx("span", { className: "vk-empty-glyph-ghost" }), _jsx("span", { className: "vk-empty-glyph-ghost" })] }), _jsx(HeadingTag, { className: "vk-empty-title", children: title }), children ? createElement(para(children), { className: "vk-empty-text" }, children) : null, actions ? _jsx("div", { className: "vk-row vk-empty-actions", children: actions }) : null] }));
|
|
10
10
|
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useLocale } from "../../localization.js";
|
|
3
4
|
import { useEffect, useRef } from "react";
|
|
4
5
|
import { Icon } from "../Icon/Icon.js";
|
|
5
6
|
/** A form's problems at the top of the form after a failed submit; each item links to its field. */
|
|
6
7
|
export function ErrorSummary(props) {
|
|
8
|
+
const { messages } = useLocale();
|
|
7
9
|
const ref = useRef(null);
|
|
8
|
-
const errors = props.errors
|
|
10
|
+
const errors = props.errors;
|
|
9
11
|
// Focus follows a change in the number of errors, not a change of autoFocus: the effect reads the latest value.
|
|
10
12
|
const autoFocusRef = useRef(props.autoFocus);
|
|
11
13
|
useEffect(() => { autoFocusRef.current = props.autoFocus; }, [props.autoFocus]);
|
|
@@ -15,13 +17,13 @@ export function ErrorSummary(props) {
|
|
|
15
17
|
}, [errors.length]);
|
|
16
18
|
if (!errors.length)
|
|
17
19
|
return null;
|
|
18
|
-
const title = props.title || (errors.length
|
|
20
|
+
const title = props.title || messages.fixProblems(errors.length);
|
|
19
21
|
return (_jsxs("div", { ref: ref, tabIndex: -1, role: "alert", className: "vk-alert vk-alert-danger vk-error-summary", "aria-labelledby": "vk-errsum-title", children: [_jsx(Icon, { name: "circle-alert", size: 18, className: "vk-alert-icon" }), _jsxs("div", { className: "vk-alert-body", children: [_jsx("p", { id: "vk-errsum-title", className: "vk-alert-title", children: title }), _jsx("ul", { className: "vk-error-summary-list", children: errors.map(({ field, message }) => (_jsx("li", { children: field ? (_jsx("a", { href: "#" + field, className: "vk-link", onClick: (ev) => {
|
|
20
22
|
const el = document.getElementById(field);
|
|
21
23
|
if (el) {
|
|
22
24
|
ev.preventDefault();
|
|
23
25
|
el.focus();
|
|
24
|
-
if (el
|
|
26
|
+
if (typeof Reflect.get(el, "scrollIntoView") === "function")
|
|
25
27
|
el.scrollIntoView({ block: "center" });
|
|
26
28
|
}
|
|
27
29
|
}, children: message })) : (message) }, field || message))) })] })] }));
|
|
@@ -2,5 +2,5 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { cx } from "../../lib/cx.js";
|
|
3
3
|
/** Question-and-answer panels as a description list. */
|
|
4
4
|
export function FaqList({ items, columns }) {
|
|
5
|
-
return (_jsx("dl", { className: cx("vk-faq-list", columns === 2 && "vk-faq-list-2"), children:
|
|
5
|
+
return (_jsx("dl", { className: cx("vk-faq-list", columns === 2 && "vk-faq-list-2"), children: items.map((item) => (_jsxs("div", { className: "vk-faq-item", children: [_jsx("dt", { className: "vk-faq-question", children: item.question }), _jsx("dd", { className: "vk-faq-answer", children: item.answer })] }, item.question))) }));
|
|
6
6
|
}
|
|
@@ -13,10 +13,10 @@ export function Field(props) {
|
|
|
13
13
|
const control = isValidElement(props.children)
|
|
14
14
|
? cloneElement(props.children, { id, "aria-labelledby": labelId, "aria-describedby": describedBy(id, props.hint, props.error), "aria-invalid": props.error ? true : undefined })
|
|
15
15
|
: props.children;
|
|
16
|
-
// A
|
|
16
|
+
// A contenteditable editor is not a labelable HTML element.
|
|
17
17
|
const focusControl = (e) => {
|
|
18
18
|
const el = document.getElementById(id);
|
|
19
|
-
if (el
|
|
19
|
+
if (el?.isContentEditable) {
|
|
20
20
|
e.preventDefault();
|
|
21
21
|
el.focus();
|
|
22
22
|
}
|