@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,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createElement } from "react";
|
|
2
2
|
import { cx } from "../../lib/cx.js";
|
|
3
3
|
import { space } from "../../lib/space.js";
|
|
4
4
|
/** Lays children out vertically with one gap from the spacing scale. */
|
|
5
5
|
export function Stack({ as, gap, align, children, className, style, ...rest }) {
|
|
6
|
-
|
|
7
|
-
return _jsx(Tag, { className: cx("vk-layout-stack", className), style: { gap: space(gap, "md"), alignItems: align, ...style }, ...rest, children: children });
|
|
6
|
+
return createElement(as || "div", { className: cx("vk-layout-stack", className), style: { gap: space(gap, "md"), alignItems: align, ...style }, ...rest }, children);
|
|
8
7
|
}
|
|
@@ -1,9 +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 { Icon } from "../Icon/Icon.js";
|
|
3
5
|
import { cx } from "../../lib/cx.js";
|
|
4
6
|
const DIRECTIONS = {
|
|
5
|
-
up: { icon: "arrow-up"
|
|
6
|
-
down: { icon: "arrow-down"
|
|
7
|
+
up: { icon: "arrow-up" },
|
|
8
|
+
down: { icon: "arrow-down" },
|
|
7
9
|
};
|
|
8
10
|
// Up is good unless upIsGood is false; without a trend the change is neutral.
|
|
9
11
|
function deltaTone(trend, upIsGood) {
|
|
@@ -13,8 +15,9 @@ function deltaTone(trend, upIsGood) {
|
|
|
13
15
|
return good ? "success" : "danger";
|
|
14
16
|
}
|
|
15
17
|
function StatDelta({ delta, deltaContext, trend, upIsGood }) {
|
|
18
|
+
const { messages } = useLocale();
|
|
16
19
|
const dir = trend === "up" || trend === "down" ? DIRECTIONS[trend] : null;
|
|
17
|
-
return (_jsxs("p", { className: "vk-stat-delta vk-stat-" + deltaTone(trend, upIsGood), children: [dir ? _jsx(Icon, { name: dir.icon, size: 14 }) : null, _jsx("span", { className: "vk-sr-only", children: dir ?
|
|
20
|
+
return (_jsxs("p", { className: "vk-stat-delta vk-stat-" + deltaTone(trend, upIsGood), children: [dir ? _jsx(Icon, { name: dir.icon, size: 14 }) : null, _jsx("span", { className: "vk-sr-only", children: dir ? (trend === "up" ? messages.up : messages.down) : "" }), _jsx("span", { children: delta }), deltaContext ? _jsx("span", { className: "vk-stat-context", children: " " + deltaContext }) : null] }));
|
|
18
21
|
}
|
|
19
22
|
/** One key number with its label and the change since the last period. */
|
|
20
23
|
export function Stat({ label, value, unit, delta, deltaContext, trend, upIsGood, className }) {
|
|
@@ -1,13 +1,16 @@
|
|
|
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 { Icon } from "../Icon/Icon.js";
|
|
3
5
|
import { cx } from "../../lib/cx.js";
|
|
4
6
|
import { pad } from "../../lib/text.js";
|
|
5
7
|
/** Shows where someone is in a fixed sequence: onboarding, a checkout, a multi-page form. */
|
|
6
8
|
export function Steps({ steps: stepsProp, current: currentProp, orientation, label, className }) {
|
|
7
|
-
const
|
|
9
|
+
const { messages } = useLocale();
|
|
10
|
+
const steps = stepsProp;
|
|
8
11
|
const current = currentProp || 0;
|
|
9
|
-
return (_jsx("ol", { className: cx("vk-steps", orientation === "vertical" && "vk-steps-vertical", className), "aria-label": label ||
|
|
12
|
+
return (_jsx("ol", { className: cx("vk-steps", orientation === "vertical" && "vk-steps-vertical", className), "aria-label": label || messages.progress, children: steps.map((s, i) => {
|
|
10
13
|
const state = i < current ? "complete" : i === current ? "current" : "upcoming";
|
|
11
|
-
return (_jsxs("li", { className: "vk-step vk-step-" + state, "aria-current": state === "current" ? "step" : undefined, children: [_jsx("span", { className: "vk-step-marker", "aria-hidden": "true", children: state === "complete" ? _jsx(Icon, { name: "check", size: 14 }) : pad(i + 1) }), _jsxs("span", { className: "vk-step-text", children: [_jsx("span", { className: "vk-step-label", children: s.label }), _jsx("span", { className: "vk-sr-only", children: state === "complete" ?
|
|
14
|
+
return (_jsxs("li", { className: "vk-step vk-step-" + state, "aria-current": state === "current" ? "step" : undefined, children: [_jsx("span", { className: "vk-step-marker", "aria-hidden": "true", children: state === "complete" ? _jsx(Icon, { name: "check", size: 14 }) : pad(i + 1) }), _jsxs("span", { className: "vk-step-text", children: [_jsx("span", { className: "vk-step-label", children: s.label }), _jsx("span", { className: "vk-sr-only", children: state === "complete" ? messages.completedStep : state === "current" ? messages.currentStep : "" }), s.description ? _jsx("span", { className: "vk-step-description", children: s.description }) : null] })] }, (typeof s.label === "string" ? s.label : "") + "#" + String(i)));
|
|
12
15
|
}) }));
|
|
13
16
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*/
|
|
7
|
-
export declare const Switch: import("react").ForwardRefExoticComponent<
|
|
1
|
+
import { type ComponentPropsWithoutRef } from "react";
|
|
2
|
+
import { Switch as Primitive } from "radix-ui";
|
|
3
|
+
import { type ChoiceTextProps } from "../../internal/choice.js";
|
|
4
|
+
export interface SwitchProps extends Omit<ComponentPropsWithoutRef<typeof Primitive.Root>, "asChild" | "children" | "onChange">, ChoiceTextProps {
|
|
5
|
+
}
|
|
6
|
+
/** Styled Radix Switch; onCheckedChange receives the boolean state and DOM events target its button. */
|
|
7
|
+
export declare const Switch: import("react").ForwardRefExoticComponent<SwitchProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
@@ -2,15 +2,9 @@
|
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { forwardRef } from "react";
|
|
4
4
|
import { Switch as Primitive } from "radix-ui";
|
|
5
|
-
import { ChoiceLabel, hiddenLabel
|
|
5
|
+
import { ChoiceLabel, hiddenLabel } from "../../internal/choice.js";
|
|
6
6
|
import { omit } from "../../lib/omit.js";
|
|
7
|
-
/**
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*/
|
|
11
|
-
export const Switch = forwardRef(function Switch(props, ref) {
|
|
12
|
-
const toggle = useChoiceToggle(props);
|
|
13
|
-
// Radix owns data-state on the control, so a trigger's data-state (Tooltip, Popover) is not passed on.
|
|
14
|
-
const rest = omit(props, ["label", "description", "className", "indeterminate", "hideLabel", "checked", "defaultChecked", "onChange", "onClick", "value", "data-state"]);
|
|
15
|
-
return (_jsx(ChoiceLabel, { kind: "vk-switch", label: props.label, description: props.description, hideLabel: props.hideLabel, disabled: props.disabled, className: props.className, children: _jsx(Primitive.Root, { "aria-label": hiddenLabel(props), ...rest, ref: ref, className: "vk-switch-track", value: props.value == null ? undefined : String(props.value), checked: toggle.checked, onClick: toggle.onClick, onCheckedChange: toggle.change, children: _jsx(Primitive.Thumb, { className: "vk-switch-thumb" }) }) }));
|
|
7
|
+
/** Styled Radix Switch; onCheckedChange receives the boolean state and DOM events target its button. */
|
|
8
|
+
export const Switch = forwardRef(function Switch({ label, description, hideLabel, className, ...props }, ref) {
|
|
9
|
+
return (_jsx(ChoiceLabel, { kind: "vk-switch", label: label, description: description, hideLabel: hideLabel, disabled: props.disabled, className: className, children: _jsx(Primitive.Root, { ...omit(props, ["data-state"]), ref: ref, "aria-label": props["aria-label"] || hiddenLabel({ label, hideLabel }), className: "vk-switch-track", children: _jsx(Primitive.Thumb, { className: "vk-switch-thumb" }) }) }));
|
|
16
10
|
});
|
|
@@ -1,27 +1,28 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { useLocale } from "../../localization.js";
|
|
4
|
+
import { isValidElement, useState } from "react";
|
|
4
5
|
import { Checkbox } from "../Checkbox/Checkbox.js";
|
|
5
6
|
import { Icon } from "../Icon/Icon.js";
|
|
6
7
|
import { Pagination } from "../Pagination/Pagination.js";
|
|
7
8
|
import { Skeleton } from "../Skeleton/Skeleton.js";
|
|
8
9
|
import { cx } from "../../lib/cx.js";
|
|
9
10
|
/** Reads a row's field by name: columns and `rowKey` address rows by string keys. */
|
|
10
|
-
const field = (row, key) => row
|
|
11
|
+
const field = (row, key) => typeof row === "object" && row !== null ? Reflect.get(row, key) : undefined;
|
|
11
12
|
/** A row's key: rowKey(row), else row[rowKey || "id"], else its index. Keys are strings or numbers by contract. */
|
|
12
13
|
function keyOfRow(rowKey, r, i) {
|
|
13
14
|
if (typeof rowKey === "function")
|
|
14
15
|
return rowKey(r);
|
|
15
16
|
const k = field(r, rowKey || "id");
|
|
16
|
-
return k
|
|
17
|
+
return typeof k === "string" || typeof k === "number" ? k : i;
|
|
17
18
|
}
|
|
18
19
|
/** `rows` in `sort` order, by the column's sortValue or else the field itself. */
|
|
19
|
-
function sortRows(rows, columns, sort) {
|
|
20
|
+
function sortRows(rows, columns, sort, locale) {
|
|
20
21
|
const col = columns.find((c) => c.key === sort.key);
|
|
21
22
|
const get = col?.sortValue || ((r) => field(r, sort.key));
|
|
22
23
|
return rows.slice().sort((a, b) => {
|
|
23
24
|
const x = get(a), y = get(b);
|
|
24
|
-
const cmp = typeof x === "number" && typeof y === "number" ? x - y : String(x).localeCompare(String(y),
|
|
25
|
+
const cmp = typeof x === "number" && typeof y === "number" ? x - y : String(x).localeCompare(String(y), locale, { numeric: true });
|
|
25
26
|
return sort.direction === "asc" ? cmp : -cmp;
|
|
26
27
|
});
|
|
27
28
|
}
|
|
@@ -58,32 +59,45 @@ const alignsEnd = (c) => c.numeric || c.align === "end";
|
|
|
58
59
|
function TableHeaderCell({ column: c, sort, onSort }) {
|
|
59
60
|
// The active sort direction for this column, if it is the sorted one.
|
|
60
61
|
const dir = sort && sort.key === c.key ? sort.direction : null;
|
|
61
|
-
return (_jsx("th", { scope: "col", style: c.width ? { width: c.width } : undefined, className: cx(alignsEnd(c) && "vk-td-end"), "aria-sort": c.sortable ? (dir ? ARIA_SORT[dir] : "none") : undefined, children: c.sortable ? (_jsxs("button", { type: "button", className: cx("vk-th-sort", dir && "vk-th-sort-active"), onClick: () => onSort(c.key), children: [c.header, _jsx(Icon, { name: dir ? SORT_ICON[dir] : "chevrons-up-down", size: 14, className: "vk-th-sort-icon" })] })) : (c.header) }));
|
|
62
|
+
return (_jsx("th", { scope: "col", style: c.width ? { width: c.width } : undefined, className: cx(alignsEnd(c) && "vk-td-end"), "aria-sort": c.sortable ? (dir ? ARIA_SORT[dir] : "none") : undefined, children: c.sortable ? (_jsxs("button", { type: "button", className: cx("vk-th-sort", dir && "vk-th-sort-active"), onClick: () => { onSort(c.key); }, children: [c.header, _jsx(Icon, { name: dir ? SORT_ICON[dir] : "chevrons-up-down", size: 14, className: "vk-th-sort-icon" })] })) : (c.header) }));
|
|
62
63
|
}
|
|
63
64
|
/** The header row: the details column, the select-all checkbox and the column headers. */
|
|
64
65
|
function TableHead({ columns, sort, onSort, expandable, expandColumnLabel, selectable, selectAllLabel, allKeys, selCount, onSelectAll }) {
|
|
65
|
-
|
|
66
|
+
const { messages } = useLocale();
|
|
67
|
+
return (_jsxs("tr", { children: [expandable ? (_jsx("th", { className: "vk-td-select", scope: "col", children: _jsx("span", { className: "vk-sr-only", children: expandColumnLabel || messages.details }) })) : null, selectable ? (_jsx("th", { className: "vk-td-select", scope: "col", children: _jsx(Checkbox, { label: selectAllLabel || messages.selectAllRows, hideLabel: true, checked: selCount > 0 && selCount < allKeys.length ? "indeterminate" : allKeys.length > 0 && selCount === allKeys.length, onCheckedChange: onSelectAll }) })) : null, columns.map((c) => _jsx(TableHeaderCell, { column: c, sort: sort, onSort: onSort }, c.key))] }));
|
|
68
|
+
}
|
|
69
|
+
/** Unknown row fields must be renderable; richer values need the column's typed render callback. */
|
|
70
|
+
function cellContent(value) {
|
|
71
|
+
if (value == null || typeof value === "string" || typeof value === "number" || typeof value === "boolean")
|
|
72
|
+
return value;
|
|
73
|
+
if (isValidElement(value))
|
|
74
|
+
return value;
|
|
75
|
+
if (Array.isArray(value))
|
|
76
|
+
return value.map(cellContent);
|
|
77
|
+
throw new TypeError("Table cells must contain renderable values; provide a column render callback for objects.");
|
|
66
78
|
}
|
|
67
79
|
/** A row's data cells: the first is the row header unless `rowHeader` is false. */
|
|
68
80
|
function TableCells({ row: r, columns, rowHeader }) {
|
|
69
81
|
return columns.map((c, ci) => {
|
|
70
|
-
const content = c.render ? c.render(r) : field(r, c.key);
|
|
82
|
+
const content = c.render ? c.render(r) : cellContent(field(r, c.key));
|
|
71
83
|
const cls = cx(c.numeric && "vk-td-num", alignsEnd(c) && "vk-td-end", (c.nowrap || c.numeric) && "vk-td-nowrap");
|
|
72
84
|
return ci === 0 && rowHeader !== false ? (_jsx("th", { scope: "row", className: cx("vk-td-rowheader", cls), children: content }, c.key)) : (_jsx("td", { className: cls, children: content }, c.key));
|
|
73
85
|
});
|
|
74
86
|
}
|
|
75
87
|
/** The cell with the button that shows or hides a row's details. */
|
|
76
88
|
function RowToggleCell({ rowKey: k, name, isOpen, onToggle }) {
|
|
77
|
-
|
|
89
|
+
const { messages } = useLocale();
|
|
90
|
+
return (_jsx("td", { className: "vk-td-select", children: _jsx("button", { type: "button", className: "vk-icon-btn vk-icon-btn-ghost vk-row-toggle", "aria-expanded": isOpen ? "true" : "false", "aria-controls": "vk-row-" + String(k), "aria-label": isOpen ? messages.hideDetails(name) : messages.showDetails(name), onClick: onToggle, children: _jsx(Icon, { name: "chevron-right", size: 14, className: cx("vk-tree-caret", isOpen && "vk-tree-caret-open") }) }) }));
|
|
78
91
|
}
|
|
79
92
|
/** One record: its details toggle and checkbox, its cells, and its details row when open. */
|
|
80
93
|
function TableRow({ row: r, index: i, rowKey: k, columns, colCount, selectable, isSel, isOpen, rowLabel, rowHeader, renderExpanded, onToggleSelect, onToggleOpen }) {
|
|
94
|
+
const { messages } = useLocale();
|
|
81
95
|
const label = rowLabel ? rowLabel(r) : null;
|
|
82
|
-
return (_jsxs(_Fragment, { children: [_jsxs("tr", { "aria-selected": selectable ?
|
|
96
|
+
return (_jsxs(_Fragment, { children: [_jsxs("tr", { "aria-selected": selectable ? isSel : undefined, className: cx(isSel && "vk-tr-selected", isOpen && "vk-tr-open"), children: [renderExpanded ? _jsx(RowToggleCell, { rowKey: k, name: label != null ? label.replace(/^Select /, "") : messages.row(i + 1), isOpen: isOpen, onToggle: onToggleOpen }) : null, selectable ? (_jsx("td", { className: "vk-td-select", children: _jsx(Checkbox, { label: label != null ? label : messages.selectRow(i + 1), hideLabel: true, checked: isSel, onCheckedChange: onToggleSelect }) })) : null, _jsx(TableCells, { row: r, columns: columns, rowHeader: rowHeader })] }), renderExpanded && isOpen ? (_jsx("tr", { id: "vk-row-" + String(k), className: "vk-tr-expanded", children: _jsx("td", { colSpan: colCount, children: renderExpanded(r) }) })) : null] }));
|
|
83
97
|
}
|
|
84
98
|
/** Placeholder rows while the data loads. */
|
|
85
99
|
function TableLoadingRows({ rows, colCount }) {
|
|
86
|
-
return Array.from({ length: rows }, (_, li) => (_jsx("tr", { className: "vk-tr-loading", children: Array.from({ length: colCount }, (_, ci) => (_jsx("td", { children: _jsx(Skeleton, { width: ci === 0 ? "70%" : "50%", height: "0.8rem" }) }, ci))) }, "_load" + li)));
|
|
100
|
+
return Array.from({ length: rows }, (_, li) => (_jsx("tr", { className: "vk-tr-loading", children: Array.from({ length: colCount }, (_, ci) => (_jsx("td", { children: _jsx(Skeleton, { width: ci === 0 ? "70%" : "50%", height: "0.8rem" }) }, ci))) }, "_load" + String(li))));
|
|
87
101
|
}
|
|
88
102
|
/** The scroll container around the table: a focusable, labelled region when it has a max height. */
|
|
89
103
|
function TableWrap({ maxHeight, caption, density, loading, className, children }) {
|
|
@@ -91,9 +105,10 @@ function TableWrap({ maxHeight, caption, density, loading, className, children }
|
|
|
91
105
|
}
|
|
92
106
|
/** The rows on view: sorted unless `manualSort`, then cut to the current page when `pageSize` is set. */
|
|
93
107
|
function useTableView(props, columns) {
|
|
108
|
+
const { locale } = useLocale();
|
|
94
109
|
const { sort, setSort } = useTableSort(props);
|
|
95
|
-
const rows = props.rows
|
|
96
|
-
const sorted = sort && !props.manualSort ? sortRows(rows, columns, sort) : rows;
|
|
110
|
+
const rows = props.rows;
|
|
111
|
+
const sorted = sort && !props.manualSort ? sortRows(rows, columns, sort, locale) : rows;
|
|
97
112
|
const pageSize = props.pageSize;
|
|
98
113
|
const [pageState, setPage] = useState(1);
|
|
99
114
|
const pageCount = pageSize ? Math.max(1, Math.ceil(sorted.length / pageSize)) : 1;
|
|
@@ -103,11 +118,12 @@ function useTableView(props, columns) {
|
|
|
103
118
|
}
|
|
104
119
|
/** The pager below a paginated table, with its "1–10 of 42" summary; nothing when everything fits on one page. */
|
|
105
120
|
function TablePager({ page, pageCount, onChange, pageSize, total, summaryFormat }) {
|
|
121
|
+
const { messages } = useLocale();
|
|
106
122
|
if (total <= pageSize)
|
|
107
123
|
return null;
|
|
108
124
|
const from = (page - 1) * pageSize + 1;
|
|
109
125
|
const to = Math.min(total, page * pageSize);
|
|
110
|
-
return _jsx(Pagination, { page: page, pageCount: pageCount, onChange: onChange, summary: summaryFormat ? summaryFormat(from, to, total) : from
|
|
126
|
+
return _jsx(Pagination, { page: page, pageCount: pageCount, onChange: onChange, summary: summaryFormat ? summaryFormat(from, to, total) : messages.pageSummary(from, to, total) });
|
|
111
127
|
}
|
|
112
128
|
/** The record rows, each with its selection and details state. */
|
|
113
129
|
function TableBodyRows({ view, allKeys, selected, setSelected, expanded, setExpanded, ...rowProps }) {
|
|
@@ -115,15 +131,18 @@ function TableBodyRows({ view, allKeys, selected, setSelected, expanded, setExpa
|
|
|
115
131
|
const expandedSet = new Set(expanded);
|
|
116
132
|
return view.map((r, i) => {
|
|
117
133
|
const k = allKeys[i];
|
|
134
|
+
if (k === undefined)
|
|
135
|
+
return null;
|
|
118
136
|
const isSel = selectedSet.has(k);
|
|
119
137
|
const isOpen = expandedSet.has(k);
|
|
120
|
-
return (_jsx(TableRow, { ...rowProps, row: r, index: i, rowKey: k, isSel: isSel, isOpen: isOpen, onToggleSelect: () => setSelected(isSel ? selected.filter((x) => x !== k) : selected.concat([k])), onToggleOpen: () => setExpanded(isOpen ? expanded.filter((x) => x !== k) : expanded.concat([k])) }, k));
|
|
138
|
+
return (_jsx(TableRow, { ...rowProps, row: r, index: i, rowKey: k, isSel: isSel, isOpen: isOpen, onToggleSelect: () => { setSelected(isSel ? selected.filter((x) => x !== k) : selected.concat([k])); }, onToggleOpen: () => { setExpanded(isOpen ? expanded.filter((x) => x !== k) : expanded.concat([k])); } }, k));
|
|
121
139
|
});
|
|
122
140
|
}
|
|
123
141
|
/** A data table for comparing records: sortable columns, row selection, numeric alignment and an empty state. */
|
|
124
142
|
export function Table(props) {
|
|
143
|
+
const { messages } = useLocale();
|
|
125
144
|
const { caption, selectable, loading, renderExpanded, pageSize, className } = props;
|
|
126
|
-
const columns = props.columns
|
|
145
|
+
const columns = props.columns;
|
|
127
146
|
const { sort, setSort, view, page, pageCount, setPage, total } = useTableView(props, columns);
|
|
128
147
|
const { selected, setSelected } = useTableSelection(props);
|
|
129
148
|
const [expanded, setExpanded] = useState(props.defaultExpanded || []);
|
|
@@ -131,13 +150,13 @@ export function Table(props) {
|
|
|
131
150
|
const allKeys = view.map((r, i) => keyOfRow(props.rowKey, r, i));
|
|
132
151
|
const selectedSet = new Set(selected);
|
|
133
152
|
const selCount = allKeys.filter((k) => selectedSet.has(k)).length;
|
|
134
|
-
let body = _jsx("tr", { children: _jsx("td", { className: "vk-td-empty", colSpan: colCount, children: props.emptyText ||
|
|
153
|
+
let body = _jsx("tr", { children: _jsx("td", { className: "vk-td-empty", colSpan: colCount, children: props.emptyText || messages.nothingToShow }) });
|
|
135
154
|
if (loading)
|
|
136
155
|
body = _jsx(TableLoadingRows, { rows: props.loadingRows || 5, colCount: colCount });
|
|
137
156
|
else if (view.length) {
|
|
138
157
|
body = (_jsx(TableBodyRows, { view: view, allKeys: allKeys, selected: selected, setSelected: setSelected, expanded: expanded, setExpanded: setExpanded, columns: columns, colCount: colCount, selectable: selectable, rowLabel: props.rowLabel, rowHeader: props.rowHeader, renderExpanded: renderExpanded }));
|
|
139
158
|
}
|
|
140
|
-
const table = (_jsx(TableWrap, { maxHeight: props.maxHeight, caption: caption, density: props.density, loading: loading, className: pageSize ? undefined : className, children: _jsxs("table", { className: "vk-table", children: [caption ? _jsx("caption", { className: props.captionHidden ? "vk-sr-only" : "vk-table-caption", children: caption }) : null, _jsx("thead", { children: _jsx(TableHead, { columns: columns, sort: sort, onSort: setSort, expandable: Boolean(renderExpanded), expandColumnLabel: props.expandColumnLabel, selectable: selectable, selectAllLabel: props.selectAllLabel, allKeys: allKeys, selCount: selCount, onSelectAll: () => setSelected(selCount === allKeys.length ? [] : allKeys) }) }), _jsx("tbody", { children: body })] }) }));
|
|
159
|
+
const table = (_jsx(TableWrap, { maxHeight: props.maxHeight, caption: caption, density: props.density, loading: loading, className: pageSize ? undefined : className, children: _jsxs("table", { className: "vk-table", children: [caption ? _jsx("caption", { className: props.captionHidden ? "vk-sr-only" : "vk-table-caption", children: caption }) : null, _jsx("thead", { children: _jsx(TableHead, { columns: columns, sort: sort, onSort: setSort, expandable: Boolean(renderExpanded), expandColumnLabel: props.expandColumnLabel, selectable: selectable, selectAllLabel: props.selectAllLabel, allKeys: allKeys, selCount: selCount, onSelectAll: () => { setSelected(selCount === allKeys.length ? [] : allKeys); } }) }), _jsx("tbody", { children: body })] }) }));
|
|
141
160
|
if (!pageSize)
|
|
142
161
|
return table;
|
|
143
162
|
return (_jsxs("div", { className: cx("vk-table-paged", className), children: [table, _jsx(TablePager, { page: page, pageCount: pageCount, onChange: setPage, pageSize: pageSize, total: total, summaryFormat: props.summaryFormat })] }));
|
|
@@ -1,29 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { useRef, useState } from "react";
|
|
4
3
|
import { Tabs as Primitive } from "radix-ui";
|
|
5
4
|
import { cx } from "../../lib/cx.js";
|
|
6
5
|
/** Tabs with automatic activation (Radix Tabs): arrow keys move focus and selection, wrapping; Home and End jump. */
|
|
7
6
|
export function Tabs({ tabs: tabsProp, value: valueProp, defaultValue, onChange, label, keepMounted, className }) {
|
|
8
|
-
const tabs = tabsProp
|
|
9
|
-
|
|
10
|
-
const [internal, setInternal] = useState(defaultValue !== undefined ? defaultValue : tabs.length ? tabs[0].id : undefined);
|
|
11
|
-
const value = controlled ? valueProp : internal;
|
|
12
|
-
// A mouse press reports the same tab twice in one event (focus, then press); pass it on once.
|
|
13
|
-
const reported = useRef(null);
|
|
14
|
-
const select = (id) => {
|
|
15
|
-
if (reported.current === id)
|
|
16
|
-
return;
|
|
17
|
-
reported.current = id;
|
|
18
|
-
queueMicrotask(() => { reported.current = null; });
|
|
19
|
-
if (!controlled)
|
|
20
|
-
setInternal(id);
|
|
21
|
-
onChange?.(id);
|
|
22
|
-
};
|
|
23
|
-
return (_jsxs(Primitive.Root, { className: cx("vk-tabs", className), value: value ?? "", onValueChange: select, activationMode: "automatic", children: [_jsx(Primitive.List, { "aria-label": label, className: "vk-tablist", loop: true, children: tabs.map((t) => (_jsxs(Primitive.Trigger, { value: t.id, disabled: t.disabled, className: "vk-tab", "data-tab": t.id, children: [t.label, t.count != null ? _jsx("span", { className: "vk-tab-count", children: t.count }) : null] }, t.id))) }), tabs.map((t) => {
|
|
24
|
-
const selected = t.id === value;
|
|
25
|
-
// Every panel stays in the DOM (hidden when not selected) so each tab's aria-controls resolves;
|
|
26
|
-
// only the selected panel renders its content unless keepMounted.
|
|
27
|
-
return (_jsx(Primitive.Content, { value: t.id, forceMount: true, hidden: !selected, className: "vk-tabpanel", children: selected || keepMounted ? t.content : null }, t.id));
|
|
28
|
-
})] }));
|
|
7
|
+
const tabs = tabsProp;
|
|
8
|
+
return (_jsxs(Primitive.Root, { className: cx("vk-tabs", className), value: valueProp, defaultValue: defaultValue, onValueChange: onChange, activationMode: "automatic", children: [_jsx(Primitive.List, { "aria-label": label, className: "vk-tablist", loop: true, children: tabs.map((t) => (_jsxs(Primitive.Trigger, { value: t.id, disabled: t.disabled, className: "vk-tab", "data-tab": t.id, children: [t.label, t.count != null ? _jsx("span", { className: "vk-tab-count", children: t.count }) : null] }, t.id))) }), tabs.map((t) => (_jsx(Primitive.Content, { value: t.id, forceMount: keepMounted ? true : undefined, className: "vk-tabpanel", children: t.content }, t.id)))] }));
|
|
29
9
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
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 { Icon } from "../Icon/Icon.js";
|
|
4
5
|
import { cx } from "../../lib/cx.js";
|
|
5
6
|
/** Chip for a chosen value or filter, optionally removable. */
|
|
6
7
|
export function Tag({ children, onRemove, removeLabel, className, removeTabIndex }) {
|
|
7
|
-
|
|
8
|
+
const { messages } = useLocale();
|
|
9
|
+
return (_jsxs("span", { className: cx("vk-tag", className), children: [_jsx("span", { className: "vk-tag-label", children: children }), onRemove ? (_jsx("button", { type: "button", className: "vk-tag-remove", tabIndex: removeTabIndex, "aria-label": removeLabel || messages.remove(typeof children === "string" ? children : ""), onMouseDown: (e) => { e.preventDefault(); }, onClick: onRemove, children: _jsx(Icon, { name: "x", size: 12 }) })) : null] }));
|
|
8
10
|
}
|
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type {
|
|
3
|
-
export interface
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { ElementTag, PolymorphicProps } from "../../types.js";
|
|
3
|
+
export interface TextOwnProps {
|
|
4
4
|
size?: string;
|
|
5
5
|
tone?: "muted" | "subtle" | "primary" | "danger" | "success";
|
|
6
6
|
children?: ReactNode;
|
|
7
|
+
className?: string;
|
|
7
8
|
/** Space Grotesk with tabular figures for numbers, codes and identifiers. */
|
|
8
9
|
numeric?: boolean;
|
|
9
10
|
/** Allow long identifiers to wrap without widening their container. */
|
|
10
|
-
|
|
11
|
+
overflowWrap?: "normal" | "anywhere";
|
|
11
12
|
/** Keep one line and show an ellipsis when the available width is exhausted. */
|
|
12
13
|
truncate?: boolean;
|
|
13
14
|
/** Emphasis independent of the selected type size. */
|
|
14
15
|
weight?: "regular" | "medium" | "semibold" | "bold";
|
|
15
16
|
}
|
|
17
|
+
export type TextProps<T extends ElementTag = "p"> = PolymorphicProps<T, TextOwnProps>;
|
|
16
18
|
/** Running text in one of the system's text styles and tones. */
|
|
17
|
-
export declare function Text({ as, size, tone, numeric,
|
|
19
|
+
export declare function Text<T extends ElementTag = "p">({ as, size, tone, numeric, overflowWrap, truncate, weight, children, className, ...rest }: TextProps<T>): import("react").ReactElement<{
|
|
20
|
+
className: string;
|
|
21
|
+
} & Omit<TextProps<T>, "numeric" | "size" | "tone" | "truncate" | "overflowWrap" | "className" | "children" | "weight" | "as">, string | import("react").JSXElementConstructor<any>>;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createElement } from "react";
|
|
2
2
|
import { cx } from "../../lib/cx.js";
|
|
3
3
|
/** Running text in one of the system's text styles and tones. */
|
|
4
|
-
export function Text({ as, size, tone, numeric,
|
|
5
|
-
|
|
6
|
-
return _jsx(Tag, { className: cx("vk-text", "vk-text-" + (size || "body"), tone && "vk-tone-" + tone, numeric && "vk-text-numeric", wrap === "anywhere" && "vk-text-wrap-anywhere", truncate && "vk-text-truncate", weight && "vk-weight-" + weight, className), ...rest, children: children });
|
|
4
|
+
export function Text({ as, size, tone, numeric, overflowWrap, truncate, weight, children, className, ...rest }) {
|
|
5
|
+
return createElement(as || "p", { className: cx("vk-text", "vk-text-" + (size || "body"), tone && "vk-tone-" + tone, numeric && "vk-text-numeric", overflowWrap === "anywhere" && "vk-text-wrap-anywhere", truncate && "vk-text-truncate", weight && "vk-weight-" + weight, className), ...rest }, children);
|
|
7
6
|
}
|
|
@@ -4,5 +4,5 @@ import { cx } from "../../lib/cx.js";
|
|
|
4
4
|
/** Grid of link tiles between sibling pages; the current one is marked active. */
|
|
5
5
|
export function TileGrid({ heading, headingId: id, label, items }) {
|
|
6
6
|
const headingId = id || "tiles-heading";
|
|
7
|
-
return (_jsxs("nav", { "aria-labelledby": heading ? headingId : undefined, "aria-label": heading ? undefined : label, children: [heading ? _jsx("h2", { id: headingId, className: "vk-tile-heading", children: heading }) : null, _jsx("ul", { className: "vk-tile-grid", children:
|
|
7
|
+
return (_jsxs("nav", { "aria-labelledby": heading ? headingId : undefined, "aria-label": heading ? undefined : label, children: [heading ? _jsx("h2", { id: headingId, className: "vk-tile-heading", children: heading }) : null, _jsx("ul", { className: "vk-tile-grid", children: items.map((item) => (_jsx("li", { children: _jsx(Anchor, { href: item.href, className: cx("vk-tile", item.active && "vk-tile-active"), "aria-current": item.active ? "page" : undefined, children: _jsx("span", { className: "vk-tile-label", children: item.label }) }) }, item.label))) })] }));
|
|
8
8
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
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 { forwardRef, useCallback, useEffect, useRef, useState } from "react";
|
|
4
5
|
import { Popover as Primitive } from "radix-ui";
|
|
5
6
|
import { Icon } from "../Icon/Icon.js";
|
|
6
7
|
import { useUid } from "../../internal/useUid.js";
|
|
7
8
|
import { cx } from "../../lib/cx.js";
|
|
8
9
|
import { formatTime, pad2, parseTime } from "../../lib/dates.js";
|
|
9
|
-
import { resolveLocale } from "../../lib/format.js";
|
|
10
10
|
import { omit } from "../../lib/omit.js";
|
|
11
11
|
/** Every step from `from` to `to`. An unparseable min or max (null) matches no time. */
|
|
12
12
|
function timeOptions(stepMin, from, to, locale) {
|
|
@@ -33,16 +33,14 @@ function useTimeValue(props, locale, from, to) {
|
|
|
33
33
|
const controlled = valueProp !== undefined;
|
|
34
34
|
const [uncontrolled, setUncontrolled] = useState(props.defaultValue || null);
|
|
35
35
|
const value = controlled ? valueProp : uncontrolled;
|
|
36
|
-
const [
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}, [value, locale]);
|
|
36
|
+
const [draft, setDraft] = useState(null);
|
|
37
|
+
const current = draft && draft.value === value && draft.locale === locale ? draft : null;
|
|
38
|
+
const text = current ? current.text : formatTime(value, locale);
|
|
39
|
+
const invalid = Boolean(current?.invalid);
|
|
41
40
|
const commit = (v) => {
|
|
42
41
|
if (!controlled)
|
|
43
42
|
setUncontrolled(v);
|
|
44
|
-
|
|
45
|
-
setInvalid(false);
|
|
43
|
+
setDraft(null);
|
|
46
44
|
props.onChange?.(v);
|
|
47
45
|
};
|
|
48
46
|
const commitText = () => {
|
|
@@ -54,12 +52,9 @@ function useTimeValue(props, locale, from, to) {
|
|
|
54
52
|
if (v && allowed(v, props, from, to))
|
|
55
53
|
commit(v);
|
|
56
54
|
else
|
|
57
|
-
|
|
58
|
-
};
|
|
59
|
-
const type = (next) => {
|
|
60
|
-
setText(next);
|
|
61
|
-
setInvalid(false);
|
|
55
|
+
setDraft({ text, invalid: true, value, locale });
|
|
62
56
|
};
|
|
57
|
+
const type = (next) => { setDraft({ text: next, invalid: false, value, locale }); };
|
|
63
58
|
return { value, text, invalid, type, commit, commitText };
|
|
64
59
|
}
|
|
65
60
|
/** The field's aria-invalid, and aria-describedby pointing at the error while the typed time is invalid. */
|
|
@@ -70,17 +65,21 @@ function invalidAria(invalid, props, errId) {
|
|
|
70
65
|
};
|
|
71
66
|
}
|
|
72
67
|
function InvalidTime({ id, message, locale }) {
|
|
73
|
-
|
|
68
|
+
const { messages } = useLocale(locale);
|
|
69
|
+
return _jsx("span", { id: id, className: "vk-field-error vk-inline-error", children: message || messages.invalidTime(formatTime("14:30", locale)) });
|
|
74
70
|
}
|
|
75
71
|
/** The portalled list of times. */
|
|
76
|
-
function TimeList({ listId, label, times, value, open, active, setActive, onPick, rootRef,
|
|
72
|
+
function TimeList({ listId, label, times, value, open, active, setActive, onPick, rootRef, escapedRef }) {
|
|
77
73
|
// The list mounts a render after `open` turns true (it is portalled): keep it in state so scrolling waits for it.
|
|
78
|
-
const
|
|
74
|
+
const listRef = useRef(null);
|
|
75
|
+
const [shown, setShown] = useState(false);
|
|
76
|
+
const setList = useCallback((node) => { listRef.current = node; setShown(node !== null); }, []);
|
|
79
77
|
// Keep the active option in view, scrolling only the list.
|
|
80
78
|
useEffect(() => {
|
|
81
|
-
|
|
79
|
+
const list = listRef.current;
|
|
80
|
+
if (!open || !shown || !list || active < 0)
|
|
82
81
|
return;
|
|
83
|
-
const el = list.querySelector(`[data-index="${active}"]`);
|
|
82
|
+
const el = list.querySelector(`[data-index="${String(active)}"]`);
|
|
84
83
|
if (!el)
|
|
85
84
|
return;
|
|
86
85
|
const top = el.offsetTop, bottom = top + el.offsetHeight;
|
|
@@ -88,21 +87,21 @@ function TimeList({ listId, label, times, value, open, active, setActive, onPick
|
|
|
88
87
|
list.scrollTop = top;
|
|
89
88
|
else if (bottom > list.scrollTop + list.clientHeight)
|
|
90
89
|
list.scrollTop = bottom - list.clientHeight;
|
|
91
|
-
}, [open,
|
|
90
|
+
}, [open, shown, active]);
|
|
92
91
|
return (_jsx(Primitive.Portal, { children: _jsx(Primitive.Content, { asChild: true, side: "bottom", align: "start", sideOffset: 4, collisionPadding: 8,
|
|
93
92
|
// Focus stays in the input while the list is open, and wherever people moved it after.
|
|
94
|
-
onOpenAutoFocus: (e) => e.preventDefault(), onCloseAutoFocus: (e) => e.preventDefault(), onEscapeKeyDown: () => {
|
|
95
|
-
|
|
93
|
+
onOpenAutoFocus: (e) => { e.preventDefault(); }, onCloseAutoFocus: (e) => { e.preventDefault(); }, onEscapeKeyDown: () => {
|
|
94
|
+
escapedRef.current = true;
|
|
96
95
|
}, onInteractOutside: (e) => {
|
|
97
96
|
// Pressing the field keeps the list open.
|
|
98
|
-
if (rootRef.current && rootRef.current.contains(e.target))
|
|
97
|
+
if (e.target instanceof Node && rootRef.current && rootRef.current.contains(e.target))
|
|
99
98
|
e.preventDefault();
|
|
100
99
|
}, children: _jsx("ul", { ref: setList, id: listId, role: "listbox", "aria-label": label, className: "vk-select-menu vk-time-menu",
|
|
101
100
|
// Keep focus (and the typed text) in the input when pressing the list.
|
|
102
|
-
onMouseDown: (e) => e.preventDefault(), children: times.map((t, i) => (_jsxs("li", { id: listId + "-" + i, "data-index": i, role: "option", "aria-selected": t.value === value ? "true" : "false", className: cx("vk-select-option", i === active && "vk-select-option-active"), onMouseMove: () => {
|
|
101
|
+
onMouseDown: (e) => { e.preventDefault(); }, children: times.map((t, i) => (_jsxs("li", { id: listId + "-" + String(i), "data-index": i, role: "option", "aria-selected": t.value === value ? "true" : "false", className: cx("vk-select-option", i === active && "vk-select-option-active"), onMouseMove: () => {
|
|
103
102
|
if (i !== active)
|
|
104
103
|
setActive(i);
|
|
105
|
-
}, onClick: () => onPick(t.value), children: [_jsx("span", { className: "vk-time-option", children: t.label }), t.value === value ? _jsx(Icon, { name: "check", size: 16, className: "vk-select-check" }) : null] }, t.value))) }) }) }));
|
|
104
|
+
}, onClick: () => { onPick(t.value); }, children: [_jsx("span", { className: "vk-time-option", children: t.label }), t.value === value ? _jsx(Icon, { name: "check", size: 16, className: "vk-select-check" }) : null] }, t.value))) }) }) }));
|
|
106
105
|
}
|
|
107
106
|
/**
|
|
108
107
|
* A time field: type a time or pick one from a list in steps. The list is a
|
|
@@ -110,7 +109,7 @@ function TimeList({ listId, label, times, value, open, active, setActive, onPick
|
|
|
110
109
|
* (aria-activedescendant). The ref goes to the input.
|
|
111
110
|
*/
|
|
112
111
|
export const TimePicker = forwardRef(function TimePicker(props, ref) {
|
|
113
|
-
const locale =
|
|
112
|
+
const { locale, messages } = useLocale(props.locale);
|
|
114
113
|
const from = parseTime(props.min || "00:00"), to = parseTime(props.max || "23:59");
|
|
115
114
|
const times = timeOptions(props.step || 30, from, to, locale);
|
|
116
115
|
const { value, text, invalid, type, commit, commitText } = useTimeValue(props, locale, from, to);
|
|
@@ -125,7 +124,7 @@ export const TimePicker = forwardRef(function TimePicker(props, ref) {
|
|
|
125
124
|
const listId = uid + "-list";
|
|
126
125
|
const rootRef = useRef(null);
|
|
127
126
|
// Set when Radix closes the list on Escape, which happens before the input sees the key.
|
|
128
|
-
const
|
|
127
|
+
const escapedRef = useRef(false);
|
|
129
128
|
const setInputRef = useCallback((el) => {
|
|
130
129
|
if (typeof ref === "function")
|
|
131
130
|
ref(el);
|
|
@@ -139,7 +138,7 @@ export const TimePicker = forwardRef(function TimePicker(props, ref) {
|
|
|
139
138
|
return i < 0 ? times.length - 1 : i;
|
|
140
139
|
};
|
|
141
140
|
const openList = () => {
|
|
142
|
-
|
|
141
|
+
escapedRef.current = false;
|
|
143
142
|
setOpen(true);
|
|
144
143
|
setActive(nearest());
|
|
145
144
|
};
|
|
@@ -164,23 +163,26 @@ export const TimePicker = forwardRef(function TimePicker(props, ref) {
|
|
|
164
163
|
}
|
|
165
164
|
else if (e.key === "Enter") {
|
|
166
165
|
e.preventDefault();
|
|
167
|
-
if (open && active >= 0)
|
|
168
|
-
|
|
166
|
+
if (open && active >= 0) {
|
|
167
|
+
const option = times[active];
|
|
168
|
+
if (option)
|
|
169
|
+
pick(option.value);
|
|
170
|
+
}
|
|
169
171
|
else
|
|
170
172
|
commitText();
|
|
171
173
|
}
|
|
172
174
|
else if (e.key === "Escape") {
|
|
173
|
-
if (open ||
|
|
175
|
+
if (open || escapedRef.current) {
|
|
174
176
|
// Closes the list only, not an enclosing dialog.
|
|
175
177
|
e.preventDefault();
|
|
176
178
|
e.stopPropagation();
|
|
177
179
|
setOpen(false);
|
|
178
180
|
}
|
|
179
|
-
|
|
181
|
+
escapedRef.current = false;
|
|
180
182
|
}
|
|
181
183
|
};
|
|
182
184
|
const a11y = omit(props, ["value", "defaultValue", "onChange", "step", "min", "max", "locale", "id", "name", "placeholder", "defaultOpen", "className", "disabled", "invalidMessage"]);
|
|
183
|
-
return (_jsx(Primitive.Root, { open: open, onOpenChange: setOpen, children: _jsxs("div", { ref: rootRef, className: cx("vk-select", "vk-timepicker", props.className), "data-state": open ? "open" : "closed", children: [_jsx(Primitive.Anchor, { asChild: true, children: _jsxs("div", { className: "vk-combobox-field", children: [_jsx("input", { ref: setInputRef, id: props.id || uid, type: "text", role: "combobox", autoComplete: "off", className: "vk-input vk-combobox-input", placeholder: props.placeholder || formatTime("09:30", locale), disabled: props.disabled, value: text, "aria-autocomplete": "none", "aria-expanded": open ? "true" : "false", "aria-controls": listId, "aria-activedescendant": open && active >= 0 ? listId + "-" + active : undefined, onChange: (e) => type(e.target.value), onClick: () => {
|
|
185
|
+
return (_jsx(Primitive.Root, { open: open, onOpenChange: setOpen, children: _jsxs("div", { ref: rootRef, className: cx("vk-select", "vk-timepicker", props.className), "data-state": open ? "open" : "closed", children: [_jsx(Primitive.Anchor, { asChild: true, children: _jsxs("div", { className: "vk-combobox-field", children: [_jsx("input", { ref: setInputRef, id: props.id || uid, type: "text", role: "combobox", autoComplete: "off", className: "vk-input vk-combobox-input", placeholder: props.placeholder || formatTime("09:30", locale), disabled: props.disabled, value: text, "aria-autocomplete": "none", "aria-expanded": open ? "true" : "false", "aria-controls": listId, "aria-activedescendant": open && active >= 0 ? listId + "-" + String(active) : undefined, onChange: (e) => { type(e.target.value); }, onClick: () => {
|
|
184
186
|
if (!open)
|
|
185
187
|
openList();
|
|
186
188
|
}, onKeyDown: onKeyDown, onBlur: (e) => {
|
|
@@ -188,5 +190,5 @@ export const TimePicker = forwardRef(function TimePicker(props, ref) {
|
|
|
188
190
|
setOpen(false);
|
|
189
191
|
commitText();
|
|
190
192
|
}
|
|
191
|
-
}, ...a11y, ...invalidAria(invalid, props, uid + "-err") }), _jsx(Icon, { name: "clock", size: 16, className: "vk-select-icon" })] }) }), _jsx(TimeList, { listId: listId, label: props["aria-label"] ||
|
|
193
|
+
}, ...a11y, ...invalidAria(invalid, props, uid + "-err") }), _jsx(Icon, { name: "clock", size: 16, className: "vk-select-icon" })] }) }), _jsx(TimeList, { listId: listId, label: props["aria-label"] || messages.times, times: times, value: value, open: open, active: active, setActive: setActive, onPick: pick, rootRef: rootRef, escapedRef: escapedRef }), invalid ? _jsx(InvalidTime, { id: uid + "-err", message: props.invalidMessage, locale: locale }) : null, props.name ? _jsx("input", { type: "hidden", name: props.name, value: value || "" }) : null] }) }));
|
|
192
194
|
});
|
|
@@ -1,10 +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 { Icon } from "../Icon/Icon.js";
|
|
3
|
-
import {
|
|
5
|
+
import { statusWord } from "../../internal/status.js";
|
|
4
6
|
import { cx } from "../../lib/cx.js";
|
|
5
|
-
/** A status without a word of its own ("primary") is announced as itself. */
|
|
6
|
-
const STATUS_TEXT = STATUS_WORD;
|
|
7
7
|
/** A vertical sequence of events: an invoice's history, an audit log, a delivery's progress. */
|
|
8
8
|
export function Timeline({ items, label, className }) {
|
|
9
|
-
|
|
9
|
+
const { messages } = useLocale();
|
|
10
|
+
return (_jsx("ol", { className: cx("vk-timeline", className), "aria-label": label, children: items.map((it, i) => (_jsxs("li", { className: cx("vk-timeline-item", it.status && "vk-timeline-" + it.status), children: [_jsx("span", { className: "vk-timeline-marker", "aria-hidden": "true", children: it.icon ? _jsx(Icon, { name: it.icon, size: 14 }) : null }), _jsxs("div", { className: "vk-timeline-body", children: [_jsxs("p", { className: "vk-timeline-title", children: [it.title, it.status ? _jsx("span", { className: "vk-sr-only", children: " (" + statusWord(it.status, messages) + ")" }) : null] }), it.description ? _jsx("div", { className: "vk-timeline-description", children: it.description }) : null, it.time ? _jsx("time", { className: "vk-timeline-time", dateTime: it.dateTime, children: it.time }) : null] })] }, (it.dateTime || (typeof it.title === "string" ? it.title : "")) + "#" + String(i)))) }));
|
|
10
11
|
}
|