@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.
Files changed (175) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/README.md +51 -5
  3. package/dist/browser.d.ts +13 -0
  4. package/dist/browser.js +7 -0
  5. package/dist/charts/chart.d.ts +6 -5
  6. package/dist/charts/chart.js +44 -25
  7. package/dist/chat.d.ts +54 -0
  8. package/dist/chat.js +1 -0
  9. package/dist/components/Accordion/Accordion.js +1 -1
  10. package/dist/components/Alert/Alert.js +5 -2
  11. package/dist/components/AppShell/AppShell.js +10 -14
  12. package/dist/components/Avatar/Avatar.js +2 -2
  13. package/dist/components/AvatarGroup/AvatarGroup.js +2 -2
  14. package/dist/components/BarChart/BarChart.js +17 -15
  15. package/dist/components/Breadcrumbs/Breadcrumbs.js +6 -3
  16. package/dist/components/Calendar/Calendar.js +6 -5
  17. package/dist/components/Card/Card.js +2 -3
  18. package/dist/components/ChatInbox/ChatInbox.d.ts +11 -0
  19. package/dist/components/ChatInbox/ChatInbox.js +49 -0
  20. package/dist/components/ChatPanel/ChatPanel.d.ts +3 -0
  21. package/dist/components/ChatPanel/ChatPanel.js +13 -0
  22. package/dist/components/ChatPanel/composer.d.ts +5 -0
  23. package/dist/components/ChatPanel/composer.js +32 -0
  24. package/dist/components/ChatPanel/transcript.d.ts +13 -0
  25. package/dist/components/ChatPanel/transcript.js +39 -0
  26. package/dist/components/ChatWidget/ChatWidget.d.ts +12 -0
  27. package/dist/components/ChatWidget/ChatWidget.js +42 -0
  28. package/dist/components/Checkbox/Checkbox.d.ts +5 -10
  29. package/dist/components/Checkbox/Checkbox.js +5 -19
  30. package/dist/components/CodeBlock/CodeBlock.js +19 -5
  31. package/dist/components/Combobox/Combobox.js +22 -15
  32. package/dist/components/Combobox/ListPanel.js +20 -9
  33. package/dist/components/CommandPalette/CommandPalette.js +33 -14
  34. package/dist/components/ContextMenu/ContextMenu.d.ts +2 -2
  35. package/dist/components/ContextMenu/ContextMenu.js +5 -50
  36. package/dist/components/DatePicker/DatePicker.js +35 -29
  37. package/dist/components/DescriptionList/DescriptionList.js +1 -1
  38. package/dist/components/Dialog/Dialog.d.ts +24 -7
  39. package/dist/components/Dialog/Dialog.js +30 -41
  40. package/dist/components/Drawer/Drawer.d.ts +4 -2
  41. package/dist/components/EmptyState/EmptyState.js +2 -2
  42. package/dist/components/ErrorSummary/ErrorSummary.js +5 -3
  43. package/dist/components/FaqList/FaqList.js +1 -1
  44. package/dist/components/Field/Field.js +4 -4
  45. package/dist/components/Fieldset/Fieldset.js +3 -3
  46. package/dist/components/FileUpload/FileUpload.js +17 -9
  47. package/dist/components/Grid/Grid.d.ts +867 -5
  48. package/dist/components/Grid/Grid.js +3 -4
  49. package/dist/components/Heading/Heading.js +2 -1
  50. package/dist/components/Icon/Icon.js +4 -2
  51. package/dist/components/Inline/Inline.d.ts +867 -5
  52. package/dist/components/Inline/Inline.js +2 -3
  53. package/dist/components/LineChart/LineChart.js +17 -15
  54. package/dist/components/LinkProvider/LinkProvider.d.ts +1 -1
  55. package/dist/components/LinkProvider/LinkProvider.js +6 -2
  56. package/dist/components/List/List.js +1 -1
  57. package/dist/components/MediaCard/MediaCard.js +2 -2
  58. package/dist/components/Menu/Menu.js +6 -43
  59. package/dist/components/Menu/entries.d.ts +1 -30
  60. package/dist/components/Menu/entries.js +16 -100
  61. package/dist/components/MultiSelect/MultiSelect.js +43 -34
  62. package/dist/components/NumberInput/NumberInput.js +17 -18
  63. package/dist/components/OtpInput/OtpInput.d.ts +1 -1
  64. package/dist/components/OtpInput/OtpInput.js +10 -67
  65. package/dist/components/PageHeader/PageHeader.js +2 -2
  66. package/dist/components/Pagination/Pagination.js +3 -1
  67. package/dist/components/PasswordInput/PasswordInput.d.ts +1 -1
  68. package/dist/components/PasswordInput/PasswordInput.js +9 -4
  69. package/dist/components/Popover/Popover.d.ts +6 -7
  70. package/dist/components/Popover/Popover.js +2 -19
  71. package/dist/components/Progress/Progress.d.ts +1 -1
  72. package/dist/components/Progress/Progress.js +7 -11
  73. package/dist/components/Radio/Radio.d.ts +4 -2
  74. package/dist/components/RadioGroup/RadioGroup.d.ts +5 -12
  75. package/dist/components/RadioGroup/RadioGroup.js +6 -33
  76. package/dist/components/RichTextEditor/RichTextEditor.d.ts +63 -0
  77. package/dist/components/RichTextEditor/RichTextEditor.js +175 -0
  78. package/dist/components/RichTextEditor/toolbar.d.ts +15 -0
  79. package/dist/components/RichTextEditor/toolbar.js +142 -0
  80. package/dist/components/RichTextEditor/uploads.d.ts +41 -0
  81. package/dist/components/RichTextEditor/uploads.js +124 -0
  82. package/dist/components/SearchInput/SearchInput.js +4 -2
  83. package/dist/components/SectionHeader/SectionHeader.js +1 -3
  84. package/dist/components/SegmentedControl/SegmentedControl.js +2 -12
  85. package/dist/components/Select/Select.d.ts +15 -16
  86. package/dist/components/Select/Select.js +11 -252
  87. package/dist/components/Slider/Slider.js +11 -21
  88. package/dist/components/Sparkline/Sparkline.js +8 -3
  89. package/dist/components/Spinner/Spinner.js +5 -2
  90. package/dist/components/Stack/Stack.d.ts +867 -5
  91. package/dist/components/Stack/Stack.js +2 -3
  92. package/dist/components/Stat/Stat.js +6 -3
  93. package/dist/components/Steps/Steps.js +6 -3
  94. package/dist/components/Switch/Switch.d.ts +7 -7
  95. package/dist/components/Switch/Switch.js +4 -10
  96. package/dist/components/Table/Table.js +38 -19
  97. package/dist/components/Tabs/Tabs.js +2 -22
  98. package/dist/components/Tag/Tag.js +3 -1
  99. package/dist/components/Text/Text.d.ts +9 -5
  100. package/dist/components/Text/Text.js +3 -4
  101. package/dist/components/TileGrid/TileGrid.js +1 -1
  102. package/dist/components/TimePicker/TimePicker.js +35 -33
  103. package/dist/components/Timeline/Timeline.js +5 -4
  104. package/dist/components/Toaster/Toaster.js +21 -17
  105. package/dist/components/Tooltip/Tooltip.d.ts +6 -6
  106. package/dist/components/Tooltip/Tooltip.js +3 -17
  107. package/dist/components/TreeView/TreeView.js +15 -12
  108. package/dist/components.css +281 -60
  109. package/dist/hooks/useTheme.js +6 -6
  110. package/dist/icons/message-circle.svg +1 -0
  111. package/dist/internal/CharCount.js +3 -1
  112. package/dist/internal/choice.d.ts +10 -48
  113. package/dist/internal/choice.js +8 -96
  114. package/dist/internal/describedBy.d.ts +3 -0
  115. package/dist/internal/describedBy.js +4 -0
  116. package/dist/internal/options.d.ts +10 -5
  117. package/dist/internal/options.js +25 -11
  118. package/dist/internal/status.d.ts +3 -2
  119. package/dist/internal/status.js +10 -2
  120. package/dist/internal/useScrollActive.js +2 -2
  121. package/dist/internal/useToday.d.ts +3 -0
  122. package/dist/internal/useToday.js +42 -0
  123. package/dist/lib/dates.js +25 -15
  124. package/dist/lib/format.js +11 -8
  125. package/dist/lib/icons.d.ts +5 -0
  126. package/dist/lib/icons.js +2 -0
  127. package/dist/lib/math.js +17 -5
  128. package/dist/lib/rich-text.d.ts +13 -0
  129. package/dist/lib/rich-text.js +62 -0
  130. package/dist/lib/space.d.ts +1 -2
  131. package/dist/lib/space.js +4 -1
  132. package/dist/lib/text.js +1 -1
  133. package/dist/lib/theme.js +1 -1
  134. package/dist/localization.d.ts +166 -0
  135. package/dist/localization.js +142 -0
  136. package/dist/tokens.css +2 -0
  137. package/dist/tokens.dtcg.json +10 -0
  138. package/dist/tokens.json +10 -0
  139. package/dist/types.d.ts +6 -1
  140. package/dist/vokality.css +283 -60
  141. package/dist/vokality.iife.js +35981 -9698
  142. package/docs/brand.md +8 -5
  143. package/docs/components/AppShell/README.md +1 -1
  144. package/docs/components/Badge/README.md +1 -1
  145. package/docs/components/BarChart/README.md +1 -0
  146. package/docs/components/Button/README.md +4 -2
  147. package/docs/components/ChatInbox/README.md +41 -0
  148. package/docs/components/ChatWidget/README.md +47 -0
  149. package/docs/components/Checkbox/README.md +7 -3
  150. package/docs/components/ContextMenu/README.md +7 -3
  151. package/docs/components/Dialog/README.md +9 -4
  152. package/docs/components/Drawer/README.md +1 -1
  153. package/docs/components/Field/README.md +1 -1
  154. package/docs/components/Fieldset/README.md +2 -2
  155. package/docs/components/Inline/README.md +1 -1
  156. package/docs/components/LineChart/README.md +1 -0
  157. package/docs/components/LocaleProvider/README.md +48 -0
  158. package/docs/components/Menu/README.md +13 -8
  159. package/docs/components/OtpInput/README.md +9 -5
  160. package/docs/components/PasswordInput/README.md +11 -2
  161. package/docs/components/Popover/README.md +6 -3
  162. package/docs/components/Progress/README.md +3 -1
  163. package/docs/components/RadioGroup/README.md +5 -2
  164. package/docs/components/RichTextEditor/README.md +84 -0
  165. package/docs/components/SegmentedControl/README.md +2 -0
  166. package/docs/components/Select/README.md +13 -17
  167. package/docs/components/Skeleton/README.md +1 -1
  168. package/docs/components/Slider/README.md +4 -2
  169. package/docs/components/Steps/README.md +1 -1
  170. package/docs/components/Switch/README.md +5 -2
  171. package/docs/components/Tabs/README.md +4 -2
  172. package/docs/components/Text/README.md +1 -1
  173. package/docs/components/Toaster/README.md +3 -1
  174. package/docs/components/Tooltip/README.md +5 -3
  175. package/package.json +49 -5
@@ -1,8 +1,7 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
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
- const Tag = as || "div";
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", spoken: "Up " },
6
- down: { icon: "arrow-down", spoken: "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 ? dir.spoken : "" }), _jsx("span", { children: delta }), deltaContext ? _jsx("span", { className: "vk-stat-context", children: " " + deltaContext }) : null] }));
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 steps = stepsProp || [];
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 || "Progress", children: steps.map((s, i) => {
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" ? " (completed)" : state === "current" ? " (current step)" : "" }), s.description ? _jsx("span", { className: "vk-step-description", children: s.description }) : null] })] }, (typeof s.label === "string" ? s.label : "") + "#" + i));
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 { CheckboxProps } from "../Checkbox/Checkbox.js";
2
- export type SwitchProps = CheckboxProps;
3
- /**
4
- * Square on/off toggle for settings that apply immediately (Radix Switch: a button with role=switch). `onChange`
5
- * receives a change event whose target reads `checked`, `value` and `name` like a native checkbox. The ref is the switch.
6
- */
7
- export declare const Switch: import("react").ForwardRefExoticComponent<CheckboxProps & import("react").RefAttributes<HTMLButtonElement>>;
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, useChoiceToggle } from "../../internal/choice.js";
5
+ import { ChoiceLabel, hiddenLabel } from "../../internal/choice.js";
6
6
  import { omit } from "../../lib/omit.js";
7
- /**
8
- * Square on/off toggle for settings that apply immediately (Radix Switch: a button with role=switch). `onChange`
9
- * receives a change event whose target reads `checked`, `value` and `name` like a native checkbox. The ref is the switch.
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 { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { useState } from "react";
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[key];
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 != null ? k : i;
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), undefined, { numeric: true });
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
- return (_jsxs("tr", { children: [expandable ? (_jsx("th", { className: "vk-td-select", scope: "col", children: _jsx("span", { className: "vk-sr-only", children: expandColumnLabel || "Details" }) })) : null, selectable ? (_jsx("th", { className: "vk-td-select", scope: "col", children: _jsx(Checkbox, { label: selectAllLabel || "Select all rows", hideLabel: true, checked: allKeys.length > 0 && selCount === allKeys.length, indeterminate: selCount > 0 && selCount < allKeys.length, onChange: onSelectAll }) })) : null, columns.map((c) => _jsx(TableHeaderCell, { column: c, sort: sort, onSort: onSort }, c.key))] }));
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
- 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-" + k, "aria-label": (isOpen ? "Hide details for " : "Show details for ") + name, onClick: onToggle, children: _jsx(Icon, { name: "chevron-right", size: 14, className: cx("vk-tree-caret", isOpen && "vk-tree-caret-open") }) }) }));
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 ? String(isSel) : undefined, className: cx(isSel && "vk-tr-selected", isOpen && "vk-tr-open"), children: [renderExpanded ? _jsx(RowToggleCell, { rowKey: k, name: label != null ? label.replace(/^Select /, "") : "row " + (i + 1), isOpen: isOpen, onToggle: onToggleOpen }) : null, selectable ? (_jsx("td", { className: "vk-td-select", children: _jsx(Checkbox, { label: label != null ? label : "Select row " + (i + 1), hideLabel: true, checked: isSel, onChange: onToggleSelect }) })) : null, _jsx(TableCells, { row: r, columns: columns, rowHeader: rowHeader })] }), renderExpanded && isOpen ? (_jsx("tr", { id: "vk-row-" + k, className: "vk-tr-expanded", children: _jsx("td", { colSpan: colCount, children: renderExpanded(r) }) })) : null] }));
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 + "–" + to + " of " + total });
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 || "Nothing to show yet." }) });
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
- const controlled = valueProp !== undefined;
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
- 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 || "Remove " + (typeof children === "string" ? children : ""), onMouseDown: (e) => e.preventDefault(), onClick: onRemove, children: _jsx(Icon, { name: "x", size: 12 }) })) : null] }));
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 type { HTMLAttributes, ReactNode } from "react";
2
- import type { AsProp } from "../../types.js";
3
- export interface TextProps extends AsProp, HTMLAttributes<Element> {
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
- wrap?: "normal" | "anywhere";
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, wrap, truncate, weight, children, className, ...rest }: TextProps): import("react/jsx-runtime").JSX.Element;
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 { jsx as _jsx } from "react/jsx-runtime";
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, wrap, truncate, weight, children, className, ...rest }) {
5
- const Tag = as || "p";
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: (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))) })] }));
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 [text, setText] = useState(() => formatTime(value, locale));
37
- const [invalid, setInvalid] = useState(false);
38
- useEffect(() => {
39
- setText(formatTime(value, locale));
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
- setText(formatTime(v, locale));
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
- setInvalid(true);
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
- return _jsx("span", { id: id, className: "vk-field-error vk-inline-error", children: message || "Enter a time like " + formatTime("14:30", locale) + "." });
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, escaped }) {
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 [list, setList] = useState(null);
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
- if (!open || !list || active < 0)
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, list, active]);
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
- escaped.current = true;
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 = resolveLocale(props.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 escaped = useRef(false);
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
- escaped.current = false;
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
- pick(times[active].value);
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 || escaped.current) {
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
- escaped.current = false;
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"] || "Times", times: times, value: value, open: open, active: active, setActive: setActive, onPick: pick, rootRef: rootRef, escaped: escaped }), invalid ? _jsx(InvalidTime, { id: uid + "-err", message: props.invalidMessage, locale: locale }) : null, props.name ? _jsx("input", { type: "hidden", name: props.name, value: value || "" }) : null] }) }));
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 { STATUS_WORD } from "../../internal/status.js";
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
- 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: " (" + (STATUS_TEXT[it.status] || it.status) + ")" }) : 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 : "")) + "#" + i))) }));
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
  }