@vokality/design-system 2.0.0 → 3.0.1

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 (164) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/README.md +63 -3
  3. package/bin/vokality-skill.mjs +68 -0
  4. package/dist/browser.d.ts +13 -0
  5. package/dist/browser.js +7 -0
  6. package/dist/charts/chart.d.ts +6 -5
  7. package/dist/charts/chart.js +44 -25
  8. package/dist/chat.d.ts +54 -0
  9. package/dist/chat.js +1 -0
  10. package/dist/components/Accordion/Accordion.js +1 -1
  11. package/dist/components/Alert/Alert.js +5 -2
  12. package/dist/components/AppShell/AppShell.js +10 -14
  13. package/dist/components/Avatar/Avatar.js +2 -2
  14. package/dist/components/AvatarGroup/AvatarGroup.js +2 -2
  15. package/dist/components/BarChart/BarChart.js +17 -15
  16. package/dist/components/Breadcrumbs/Breadcrumbs.js +6 -3
  17. package/dist/components/Calendar/Calendar.js +6 -5
  18. package/dist/components/Card/Card.js +2 -3
  19. package/dist/components/ChatInbox/ChatInbox.d.ts +11 -0
  20. package/dist/components/ChatInbox/ChatInbox.js +49 -0
  21. package/dist/components/ChatPanel/ChatPanel.d.ts +3 -0
  22. package/dist/components/ChatPanel/ChatPanel.js +13 -0
  23. package/dist/components/ChatPanel/composer.d.ts +5 -0
  24. package/dist/components/ChatPanel/composer.js +32 -0
  25. package/dist/components/ChatPanel/transcript.d.ts +13 -0
  26. package/dist/components/ChatPanel/transcript.js +39 -0
  27. package/dist/components/ChatWidget/ChatWidget.d.ts +12 -0
  28. package/dist/components/ChatWidget/ChatWidget.js +42 -0
  29. package/dist/components/Checkbox/Checkbox.d.ts +5 -10
  30. package/dist/components/Checkbox/Checkbox.js +5 -19
  31. package/dist/components/CodeBlock/CodeBlock.js +19 -5
  32. package/dist/components/Combobox/Combobox.js +22 -15
  33. package/dist/components/Combobox/ListPanel.js +20 -9
  34. package/dist/components/CommandPalette/CommandPalette.js +33 -14
  35. package/dist/components/ContextMenu/ContextMenu.d.ts +2 -2
  36. package/dist/components/ContextMenu/ContextMenu.js +5 -50
  37. package/dist/components/DatePicker/DatePicker.js +35 -29
  38. package/dist/components/DescriptionList/DescriptionList.js +1 -1
  39. package/dist/components/Dialog/Dialog.d.ts +24 -7
  40. package/dist/components/Dialog/Dialog.js +30 -41
  41. package/dist/components/Drawer/Drawer.d.ts +4 -2
  42. package/dist/components/EmptyState/EmptyState.js +2 -2
  43. package/dist/components/ErrorSummary/ErrorSummary.js +5 -3
  44. package/dist/components/FaqList/FaqList.js +1 -1
  45. package/dist/components/Field/Field.js +2 -2
  46. package/dist/components/FileUpload/FileUpload.js +17 -9
  47. package/dist/components/Grid/Grid.d.ts +5 -5
  48. package/dist/components/Grid/Grid.js +1 -1
  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 +7 -7
  52. package/dist/components/LineChart/LineChart.js +17 -15
  53. package/dist/components/LinkProvider/LinkProvider.d.ts +1 -1
  54. package/dist/components/LinkProvider/LinkProvider.js +6 -2
  55. package/dist/components/List/List.js +1 -1
  56. package/dist/components/MediaCard/MediaCard.js +2 -2
  57. package/dist/components/Menu/Menu.js +6 -43
  58. package/dist/components/Menu/entries.d.ts +1 -30
  59. package/dist/components/Menu/entries.js +16 -100
  60. package/dist/components/MultiSelect/MultiSelect.js +43 -34
  61. package/dist/components/NumberInput/NumberInput.js +17 -18
  62. package/dist/components/OtpInput/OtpInput.d.ts +1 -1
  63. package/dist/components/OtpInput/OtpInput.js +10 -67
  64. package/dist/components/PageHeader/PageHeader.js +2 -2
  65. package/dist/components/Pagination/Pagination.js +3 -1
  66. package/dist/components/PasswordInput/PasswordInput.d.ts +1 -1
  67. package/dist/components/PasswordInput/PasswordInput.js +9 -4
  68. package/dist/components/Popover/Popover.d.ts +6 -7
  69. package/dist/components/Popover/Popover.js +2 -19
  70. package/dist/components/Progress/Progress.d.ts +1 -1
  71. package/dist/components/Progress/Progress.js +7 -11
  72. package/dist/components/Radio/Radio.d.ts +4 -2
  73. package/dist/components/RadioGroup/RadioGroup.d.ts +5 -12
  74. package/dist/components/RadioGroup/RadioGroup.js +6 -33
  75. package/dist/components/RichTextEditor/RichTextEditor.d.ts +63 -0
  76. package/dist/components/RichTextEditor/RichTextEditor.js +175 -0
  77. package/dist/components/RichTextEditor/toolbar.d.ts +15 -0
  78. package/dist/components/RichTextEditor/toolbar.js +142 -0
  79. package/dist/components/RichTextEditor/uploads.d.ts +41 -0
  80. package/dist/components/RichTextEditor/uploads.js +124 -0
  81. package/dist/components/SearchInput/SearchInput.js +4 -2
  82. package/dist/components/SectionHeader/SectionHeader.js +1 -3
  83. package/dist/components/SegmentedControl/SegmentedControl.js +2 -12
  84. package/dist/components/Select/Select.d.ts +15 -16
  85. package/dist/components/Select/Select.js +11 -252
  86. package/dist/components/Slider/Slider.js +11 -21
  87. package/dist/components/Sparkline/Sparkline.js +8 -3
  88. package/dist/components/Spinner/Spinner.js +5 -2
  89. package/dist/components/Stack/Stack.d.ts +5 -5
  90. package/dist/components/Stat/Stat.js +6 -3
  91. package/dist/components/Steps/Steps.js +6 -3
  92. package/dist/components/Switch/Switch.d.ts +7 -7
  93. package/dist/components/Switch/Switch.js +4 -10
  94. package/dist/components/Table/Table.js +38 -19
  95. package/dist/components/Tabs/Tabs.js +2 -22
  96. package/dist/components/Tag/Tag.js +3 -1
  97. package/dist/components/Text/Text.d.ts +1 -1
  98. package/dist/components/TileGrid/TileGrid.js +1 -1
  99. package/dist/components/TimePicker/TimePicker.js +35 -33
  100. package/dist/components/Timeline/Timeline.js +5 -4
  101. package/dist/components/Toaster/Toaster.js +21 -17
  102. package/dist/components/Tooltip/Tooltip.d.ts +6 -6
  103. package/dist/components/Tooltip/Tooltip.js +3 -17
  104. package/dist/components/TreeView/TreeView.js +15 -12
  105. package/dist/components.css +179 -8
  106. package/dist/hooks/useTheme.js +6 -6
  107. package/dist/icons/message-circle.svg +1 -0
  108. package/dist/internal/CharCount.js +3 -1
  109. package/dist/internal/choice.d.ts +10 -48
  110. package/dist/internal/choice.js +8 -96
  111. package/dist/internal/options.d.ts +10 -5
  112. package/dist/internal/options.js +25 -11
  113. package/dist/internal/status.d.ts +3 -2
  114. package/dist/internal/status.js +10 -2
  115. package/dist/internal/useScrollActive.js +2 -2
  116. package/dist/internal/useToday.d.ts +3 -0
  117. package/dist/internal/useToday.js +42 -0
  118. package/dist/lib/dates.js +25 -15
  119. package/dist/lib/format.js +11 -8
  120. package/dist/lib/icons.d.ts +5 -0
  121. package/dist/lib/icons.js +2 -0
  122. package/dist/lib/math.js +17 -5
  123. package/dist/lib/rich-text.d.ts +13 -0
  124. package/dist/lib/rich-text.js +62 -0
  125. package/dist/lib/space.d.ts +1 -2
  126. package/dist/lib/space.js +4 -1
  127. package/dist/lib/text.js +1 -1
  128. package/dist/lib/theme.js +1 -1
  129. package/dist/localization.d.ts +166 -0
  130. package/dist/localization.js +142 -0
  131. package/dist/vokality.css +179 -8
  132. package/dist/vokality.iife.js +35986 -9685
  133. package/docs/brand.md +6 -3
  134. package/docs/components/AppShell/README.md +1 -1
  135. package/docs/components/BarChart/README.md +1 -0
  136. package/docs/components/ChatInbox/README.md +41 -0
  137. package/docs/components/ChatWidget/README.md +47 -0
  138. package/docs/components/Checkbox/README.md +7 -3
  139. package/docs/components/ContextMenu/README.md +7 -3
  140. package/docs/components/Dialog/README.md +9 -4
  141. package/docs/components/Drawer/README.md +1 -1
  142. package/docs/components/Field/README.md +1 -1
  143. package/docs/components/Fieldset/README.md +2 -2
  144. package/docs/components/LineChart/README.md +1 -0
  145. package/docs/components/LocaleProvider/README.md +48 -0
  146. package/docs/components/Menu/README.md +13 -8
  147. package/docs/components/OtpInput/README.md +9 -5
  148. package/docs/components/PasswordInput/README.md +11 -2
  149. package/docs/components/Popover/README.md +6 -3
  150. package/docs/components/Progress/README.md +3 -1
  151. package/docs/components/RadioGroup/README.md +5 -2
  152. package/docs/components/RichTextEditor/README.md +84 -0
  153. package/docs/components/SegmentedControl/README.md +2 -0
  154. package/docs/components/Select/README.md +13 -17
  155. package/docs/components/Skeleton/README.md +1 -1
  156. package/docs/components/Slider/README.md +4 -2
  157. package/docs/components/Steps/README.md +1 -1
  158. package/docs/components/Switch/README.md +5 -2
  159. package/docs/components/Tabs/README.md +4 -2
  160. package/docs/components/Toaster/README.md +3 -1
  161. package/docs/components/Tooltip/README.md +5 -3
  162. package/package.json +55 -6
  163. package/skills/vokality-design-system/SKILL.md +55 -0
  164. package/skills/vokality-design-system/references/examples.tsx +103 -0
@@ -1,4 +1,3 @@
1
- import { type FocusEvent, type KeyboardEvent } from "react";
2
1
  import type { DropdownMenu } from "radix-ui";
3
2
  import type { MenuEntry } from "../../types.js";
4
3
  /** The Radix menu parts the entries are built from: DropdownMenu's or ContextMenu's (same shapes). */
@@ -6,35 +5,7 @@ export type MenuParts = Pick<typeof DropdownMenu, "Item" | "CheckboxItem" | "Rad
6
5
  interface MenuEntriesProps {
7
6
  parts: MenuParts;
8
7
  items: MenuEntry[];
9
- /** Runs a plain item's onSelect once the menu has closed and focus has gone back (see useDeferredSelect). */
10
- defer: (run: () => void) => void;
11
8
  }
12
- /**
13
- * Plain items' onSelect runs after the menu has closed and focus is back on the trigger,
14
- * so an action that opens a dialog captures the trigger as its return focus.
15
- * `defer` queues the action; call `flush` from the content's onCloseAutoFocus.
16
- */
17
- export declare function useDeferredSelect(): {
18
- defer: (run: () => void) => void;
19
- flush: () => void;
20
- };
21
- /** Focuses the first or last enabled item of a menu, or the menu itself when none can take focus. */
22
- export declare function focusEdgeItem(content: HTMLElement | null, edge: "first" | "last"): void;
23
- /**
24
- * Radix focuses a menu's content as it opens, and only moves on to the first item when it was
25
- * opened with the keyboard. `arm(edge)` before opening; the content's `onFocus` then moves
26
- * straight to the first (or last) item, however the menu was opened.
27
- */
28
- export declare function useFocusOnOpen(): {
29
- arm: (which: "first" | "last" | null) => void;
30
- onFocus: (e: FocusEvent<HTMLDivElement>) => void;
31
- };
32
- /**
33
- * onKeyDownCapture for a menu's content (root or submenu): ↓ ↑ Home End move focus in the same
34
- * keystroke, wrapping. Radix's roving focus moves it a task later (setTimeout), which lets a
35
- * key that follows at once act on the old item.
36
- */
37
- export declare function moveFocusNow(e: KeyboardEvent<HTMLDivElement>): void;
38
9
  /** Renders MenuEntry[] as Radix menu parts: items, checkbox and radio items, submenus, separators and labels. */
39
- export declare function MenuEntries({ parts: P, items, defer }: MenuEntriesProps): import("react/jsx-runtime").JSX.Element;
10
+ export declare function MenuEntries({ parts: P, items }: MenuEntriesProps): import("react/jsx-runtime").JSX.Element;
40
11
  export {};
@@ -1,92 +1,14 @@
1
1
  "use client";
2
- import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { Fragment, useCallback, useId, useRef, useState } from "react";
2
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { Fragment, useId } from "react";
4
4
  import { Icon } from "../Icon/Icon.js";
5
5
  import { cx } from "../../lib/cx.js";
6
- /**
7
- * Plain items' onSelect runs after the menu has closed and focus is back on the trigger,
8
- * so an action that opens a dialog captures the trigger as its return focus.
9
- * `defer` queues the action; call `flush` from the content's onCloseAutoFocus.
10
- */
11
- export function useDeferredSelect() {
12
- const pending = useRef(null);
13
- const defer = useCallback((run) => { pending.current = run; }, []);
14
- const flush = useCallback(() => {
15
- const run = pending.current;
16
- pending.current = null;
17
- // After Radix has moved focus back (it does so right after the onCloseAutoFocus handlers).
18
- if (run)
19
- queueMicrotask(run);
20
- }, []);
21
- return { defer, flush };
22
- }
23
- /** Focuses the first or last enabled item of a menu, or the menu itself when none can take focus. */
24
- export function focusEdgeItem(content, edge) {
25
- if (!content)
26
- return;
27
- const items = Array.from(content.querySelectorAll('[role^="menuitem"]:not([data-disabled])'));
28
- const target = edge === "last" ? items[items.length - 1] : items[0];
29
- (target || content).focus({ preventScroll: true });
30
- }
31
- /**
32
- * Radix focuses a menu's content as it opens, and only moves on to the first item when it was
33
- * opened with the keyboard. `arm(edge)` before opening; the content's `onFocus` then moves
34
- * straight to the first (or last) item, however the menu was opened.
35
- */
36
- export function useFocusOnOpen() {
37
- const edge = useRef(null);
38
- const arm = useCallback((which) => { edge.current = which; }, []);
39
- const onFocus = useCallback((e) => {
40
- const which = edge.current;
41
- if (!which || e.target !== e.currentTarget)
42
- return;
43
- edge.current = null;
44
- // Skips Radix's own entry focus (composed after this handler), which would pick the first item.
45
- e.preventDefault();
46
- focusEdgeItem(e.currentTarget, which);
47
- }, []);
48
- return { arm, onFocus };
49
- }
50
- const STEP = { ArrowDown: 1, ArrowUp: -1, Home: "first", End: "last", PageUp: "first", PageDown: "last" };
51
- /**
52
- * onKeyDownCapture for a menu's content (root or submenu): ↓ ↑ Home End move focus in the same
53
- * keystroke, wrapping. Radix's roving focus moves it a task later (setTimeout), which lets a
54
- * key that follows at once act on the old item.
55
- */
56
- export function moveFocusNow(e) {
57
- const step = STEP[e.key];
58
- if (step === undefined || e.metaKey || e.ctrlKey || e.altKey || e.shiftKey)
59
- return;
60
- const content = e.currentTarget;
61
- const target = e.target;
62
- // Keys from a submenu bubble through the React tree (portals included); each level handles its own.
63
- if (target.closest('[role="menu"]') !== content)
64
- return;
65
- const items = Array.from(content.querySelectorAll('[role^="menuitem"]:not([data-disabled])'));
66
- if (!items.length)
67
- return;
68
- const at = items.indexOf(target);
69
- let next;
70
- if (step === "first")
71
- next = items[0];
72
- else if (step === "last")
73
- next = items[items.length - 1];
74
- else if (at < 0)
75
- next = step === 1 ? items[0] : items[items.length - 1];
76
- else
77
- next = items[(at + step + items.length) % items.length];
78
- // Prevented, so Radix's own (deferred) handlers for the same key stand down.
79
- e.preventDefault();
80
- next.focus();
81
- }
82
6
  function Body({ icon, label, shortcut, sub }) {
83
7
  return (_jsxs(_Fragment, { children: [icon ? _jsx(Icon, { name: icon, size: 16, className: "vk-menu-item-icon" }) : _jsx("span", { className: "vk-menu-item-icon", "aria-hidden": "true" }), _jsx("span", { className: "vk-menu-item-label", children: label }), shortcut ? _jsx("kbd", { className: "vk-menu-shortcut", children: shortcut }) : null, sub ? _jsx(Icon, { name: "chevron-right", size: 14, className: "vk-menu-sub-icon" }) : null] }));
84
8
  }
85
- /** A submenu. Esc closes just this level and goes back to its item, like ← (Radix would close every level). */
86
- function SubEntry({ parts: P, entry, items, defer }) {
87
- const [open, setOpen] = useState(false);
88
- const triggerRef = useRef(null);
89
- return (_jsxs(P.Sub, { open: open, onOpenChange: setOpen, children: [_jsx(P.SubTrigger, { ref: triggerRef, className: cx("vk-menu-item", entry.danger ? "vk-menu-item-danger" : null), disabled: entry.disabled, textValue: entry.label, children: _jsx(Body, { icon: entry.icon, label: entry.label, shortcut: entry.shortcut, sub: true }) }), _jsx(P.Portal, { children: _jsx(P.SubContent, { className: "vk-menu vk-menu-sub", sideOffset: -4, alignOffset: -5, collisionPadding: 8, loop: true, onKeyDownCapture: moveFocusNow, onEscapeKeyDown: (e) => { e.preventDefault(); setOpen(false); triggerRef.current?.focus(); }, children: _jsx(MenuEntries, { parts: P, items: items, defer: defer }) }) })] }));
9
+ /** The primitive owns submenu opening, keyboard navigation and dismissal. */
10
+ function SubEntry({ parts: P, entry, items }) {
11
+ return (_jsxs(P.Sub, { children: [_jsx(P.SubTrigger, { className: cx("vk-menu-item", entry.danger ? "vk-menu-item-danger" : null), disabled: entry.disabled, textValue: entry.label, children: _jsx(Body, { icon: entry.icon, label: entry.label, shortcut: entry.shortcut, sub: true }) }), _jsx(P.Portal, { children: _jsx(P.SubContent, { className: "vk-menu vk-menu-sub", sideOffset: -4, alignOffset: -5, collisionPadding: 8, children: _jsx(MenuEntries, { parts: P, items: items }) }) })] }));
90
12
  }
91
13
  /** Splits entries into single entries and runs of consecutive radio entries. */
92
14
  function segments(items) {
@@ -107,40 +29,34 @@ function segments(items) {
107
29
  /** Consecutive radio entries as one group; `start` is the first one's index in the menu. */
108
30
  function RadioRun({ parts: P, run, start, labelledBy }) {
109
31
  const checked = run.findIndex((r) => r.checked);
110
- return (_jsx(P.RadioGroup, { value: checked >= 0 ? String(start + checked) : "", "aria-labelledby": labelledBy, children: run.map((r, k) => (_jsxs(P.RadioItem, { value: String(start + k), className: "vk-menu-item", disabled: r.disabled, textValue: r.label,
111
- // Choosing a radio item keeps the menu open.
112
- onSelect: (e) => { e.preventDefault(); r.onSelect?.(); }, children: [_jsx("span", { className: "vk-menu-item-icon vk-menu-check", "aria-hidden": "true", children: _jsx(P.ItemIndicator, { asChild: true, children: _jsx("span", { className: "vk-choice-dot vk-menu-dot" }) }) }), _jsx("span", { className: "vk-menu-item-label", children: r.label })] }, k + ":" + r.label))) }));
32
+ return (_jsx(P.RadioGroup, { value: checked >= 0 ? String(start + checked) : "", "aria-labelledby": labelledBy, children: run.map((r, k) => (_jsxs(P.RadioItem, { value: String(start + k), className: "vk-menu-item", disabled: r.disabled, textValue: r.label, onSelect: r.onSelect, children: [_jsx("span", { className: "vk-menu-item-icon vk-menu-check", "aria-hidden": "true", children: _jsx(P.ItemIndicator, { asChild: true, children: _jsx("span", { className: "vk-choice-dot vk-menu-dot" }) }) }), _jsx("span", { className: "vk-menu-item-label", children: r.label })] }, String(k) + ":" + r.label))) }));
113
33
  }
114
34
  function CheckboxItem({ parts: P, entry: it }) {
115
- return (_jsxs(P.CheckboxItem, { className: "vk-menu-item", checked: it.checked, disabled: it.disabled, textValue: it.label,
116
- // Keeps the menu open; onCheckedChange first, then onSelect (Radix's own onCheckedChange is unused).
117
- onSelect: (e) => { e.preventDefault(); it.onCheckedChange?.(!it.checked); it.onSelect?.(); }, children: [_jsx("span", { className: "vk-menu-item-icon vk-menu-check", "aria-hidden": "true", children: _jsx(P.ItemIndicator, { className: "vk-menu-indicator", children: _jsx(Icon, { name: "check", size: 16 }) }) }), _jsx("span", { className: "vk-menu-item-label", children: it.label })] }));
35
+ return (_jsxs(P.CheckboxItem, { className: "vk-menu-item", checked: it.checked, disabled: it.disabled, textValue: it.label, onCheckedChange: it.onCheckedChange, onSelect: it.onSelect, children: [_jsx("span", { className: "vk-menu-item-icon vk-menu-check", "aria-hidden": "true", children: _jsx(P.ItemIndicator, { className: "vk-menu-indicator", children: _jsx(Icon, { name: "check", size: 16 }) }) }), _jsx("span", { className: "vk-menu-item-label", children: it.label })] }));
118
36
  }
119
- function PlainItem({ parts: P, entry: it, defer }) {
120
- const onSelect = it.onSelect;
121
- return (_jsx(P.Item, { className: cx("vk-menu-item", it.danger ? "vk-menu-item-danger" : null), disabled: it.disabled, textValue: it.label, onSelect: () => { if (onSelect)
122
- defer(() => onSelect()); }, children: _jsx(Body, { icon: it.icon, label: it.label, shortcut: it.shortcut }) }));
37
+ function PlainItem({ parts: P, entry: it }) {
38
+ return (_jsx(P.Item, { className: cx("vk-menu-item", it.danger ? "vk-menu-item-danger" : null), disabled: it.disabled, textValue: it.label, onSelect: it.onSelect, children: _jsx(Body, { icon: it.icon, label: it.label, shortcut: it.shortcut }) }));
123
39
  }
124
40
  /** Renders MenuEntry[] as Radix menu parts: items, checkbox and radio items, submenus, separators and labels. */
125
- export function MenuEntries({ parts: P, items, defer }) {
41
+ export function MenuEntries({ parts: P, items }) {
126
42
  const uid = useId();
127
43
  return (_jsx(Fragment, { children: segments(items).map((s) => {
128
- const first = items[s.at];
129
- const key = s.at + ":" + ("label" in first ? first.label : first.type);
44
+ const first = "run" in s ? s.run[0] : s.entry;
45
+ const key = String(s.at) + ":" + ("label" in first ? first.label : first.type);
130
46
  if ("run" in s) {
131
47
  // A label right before a radio group names it.
132
48
  const prev = items[s.at - 1];
133
- return _jsx(RadioRun, { parts: P, run: s.run, start: s.at, labelledBy: prev && prev.type === "label" ? uid + "-l" + (s.at - 1) : undefined }, key);
49
+ return _jsx(RadioRun, { parts: P, run: s.run, start: s.at, labelledBy: prev?.type === "label" ? uid + "-l" + String(s.at - 1) : undefined }, key);
134
50
  }
135
51
  const it = s.entry;
136
52
  if (it.type === "separator")
137
53
  return _jsx(P.Separator, { className: "vk-menu-separator" }, key);
138
54
  if (it.type === "label")
139
- return _jsx(P.Label, { id: uid + "-l" + s.at, className: "vk-menu-label", children: it.label }, key);
55
+ return _jsx(P.Label, { id: uid + "-l" + String(s.at), className: "vk-menu-label", children: it.label }, key);
140
56
  if (it.type === "checkbox")
141
57
  return _jsx(CheckboxItem, { parts: P, entry: it }, key);
142
58
  if (it.items)
143
- return _jsx(SubEntry, { parts: P, entry: it, items: it.items, defer: defer }, key);
144
- return _jsx(PlainItem, { parts: P, entry: it, defer: defer }, key);
59
+ return _jsx(SubEntry, { parts: P, entry: it, items: it.items }, key);
60
+ return _jsx(PlainItem, { parts: P, entry: it }, key);
145
61
  }) }));
146
62
  }
@@ -1,5 +1,6 @@
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 { useRef, useState } from "react";
4
5
  import { Popover } from "radix-ui";
5
6
  import { ListPanel } from "../Combobox/ListPanel.js";
@@ -13,14 +14,14 @@ import { omit } from "../../lib/omit.js";
13
14
  /** The popup, which ListPanel makes the Radix content (so a plain element, not a component): a <ul> listbox of checkable options, or a <div> status when nothing matches. */
14
15
  function optionList({ listId, options, values, max, active, setActive, query, onToggle, emptyText, ...labels }) {
15
16
  if (!options.length) {
16
- return (_jsx("div", { id: listId, className: "vk-select-menu vk-select-empty", role: "status", children: emptyText || "No matches for “" + query + "”" }));
17
+ return (_jsx("div", { id: listId, className: "vk-select-menu vk-select-empty", role: "status", children: emptyText }));
17
18
  }
18
19
  const chosen = new Set(values);
19
20
  const atMax = Boolean(max && values.length >= max);
20
21
  return (_jsx("ul", { id: listId, role: "listbox", "aria-multiselectable": "true", className: "vk-select-menu", "aria-labelledby": labels["aria-labelledby"], "aria-label": labels["aria-label"], children: options.map((o, i) => {
21
22
  const isSel = chosen.has(o.value);
22
23
  const blocked = o.disabled || (!isSel && atMax);
23
- return (_jsxs("li", { id: listId + "-" + i, "data-index": i, role: "option", "aria-selected": isSel ? "true" : "false", "aria-disabled": blocked ? "true" : undefined, className: cx("vk-select-option", "vk-multi-option", i === active && "vk-select-option-active"), onMouseDown: (e) => e.preventDefault(), onMouseMove: () => {
24
+ return (_jsxs("li", { id: listId + "-" + String(i), "data-index": i, role: "option", "aria-selected": isSel ? "true" : "false", "aria-disabled": blocked ? "true" : undefined, className: cx("vk-select-option", "vk-multi-option", i === active && "vk-select-option-active"), onMouseDown: (e) => { e.preventDefault(); }, onMouseMove: () => {
24
25
  if (!o.disabled && i !== active)
25
26
  setActive(i);
26
27
  }, onClick: () => {
@@ -29,15 +30,36 @@ function optionList({ listId, options, values, max, active, setActive, query, on
29
30
  }, children: [_jsx("span", { className: "vk-choice-box vk-multi-box", "aria-hidden": "true", children: _jsx("svg", { className: "vk-choice-mark", viewBox: "0 0 16 16", width: 12, height: 12, fill: "none", children: _jsx("path", { d: CHECK_PATH, stroke: "currentColor", strokeWidth: 2, strokeLinecap: "square" }) }) }), _jsxs("span", { className: "vk-select-option-text", children: [_jsx("span", { children: highlight(o.label, query) }), o.description ? _jsx("span", { className: "vk-select-option-description", children: o.description }) : null] })] }, o.value));
30
31
  }) }));
31
32
  }
33
+ /** Selection owns controlled/default values and enforces the maximum independently of popup navigation. */
34
+ function useMultiSelection(props, options) {
35
+ const controlled = props.value !== undefined;
36
+ const [uncontrolled, setUncontrolled] = useState(props.defaultValue || []);
37
+ const values = controlled ? props.value || [] : uncontrolled;
38
+ const set = (next) => {
39
+ if (!controlled)
40
+ setUncontrolled(next);
41
+ props.onChange?.(next);
42
+ };
43
+ const toggle = (option) => {
44
+ if (!option || option.disabled)
45
+ return;
46
+ const chosen = values.includes(option.value);
47
+ if (!chosen && props.max && values.length >= props.max)
48
+ return;
49
+ set(chosen ? values.filter((value) => value !== option.value) : values.concat(option.value));
50
+ };
51
+ const remove = (value) => { set(values.filter((item) => item !== value)); };
52
+ const optionForValue = (value) => options.find((option) => option.value === value) || { value, label: value };
53
+ return { values, toggle, remove, optionForValue };
54
+ }
32
55
  /** Pick several options; chosen values show as removable tags, typing filters. The list is a Radix Popover anchored to the field. */
33
56
  export function MultiSelect(props) {
57
+ const { messages } = useLocale();
34
58
  const options = normalizeOptions(props.options);
35
59
  const base = useUid("vk-multi");
36
60
  const inputId = props.id || base + "-input";
37
61
  const listId = base + "-list";
38
- const controlled = props.value !== undefined;
39
- const [uncontrolledValues, setUncontrolledValues] = useState(props.defaultValue || []);
40
- const values = controlled ? props.value || [] : uncontrolledValues;
62
+ const { values, toggle, remove: removeValue, optionForValue } = useMultiSelection(props, options);
41
63
  const [query, setQuery] = useState("");
42
64
  const [open, setOpen] = useState(Boolean(props.defaultOpen));
43
65
  const [active, setActive] = useState(props.defaultOpen ? 0 : -1);
@@ -49,27 +71,8 @@ export function MultiSelect(props) {
49
71
  setActive(-1);
50
72
  setQuery("");
51
73
  };
52
- const byValue = (v) => {
53
- for (let i = 0; i < options.length; i++)
54
- if (options[i].value === v)
55
- return options[i];
56
- return { value: v, label: v };
57
- };
58
- const setValues = (next) => {
59
- if (!controlled)
60
- setUncontrolledValues(next);
61
- props.onChange?.(next);
62
- };
63
- const toggle = (o) => {
64
- if (!o || o.disabled)
65
- return;
66
- const has = values.indexOf(o.value) >= 0;
67
- if (!has && props.max && values.length >= props.max)
68
- return;
69
- setValues(has ? values.filter((v) => v !== o.value) : values.concat([o.value]));
70
- };
71
74
  const remove = (v) => {
72
- setValues(values.filter((x) => x !== v));
75
+ removeValue(v);
73
76
  inputRef.current?.focus();
74
77
  };
75
78
  const openAt = (i) => {
@@ -82,16 +85,20 @@ export function MultiSelect(props) {
82
85
  const key = e.key;
83
86
  if (key === "ArrowDown") {
84
87
  e.preventDefault();
85
- if (!open)
86
- return openAt(nextEnabled(filtered, 0, 1));
88
+ if (!open) {
89
+ openAt(nextEnabled(filtered, 0, 1));
90
+ return;
91
+ }
87
92
  const n = nextEnabled(filtered, active + 1, 1);
88
93
  if (n >= 0)
89
94
  setActive(n);
90
95
  }
91
96
  else if (key === "ArrowUp") {
92
97
  e.preventDefault();
93
- if (!open)
94
- return openAt(nextEnabled(filtered, filtered.length - 1, -1));
98
+ if (!open) {
99
+ openAt(nextEnabled(filtered, filtered.length - 1, -1));
100
+ return;
101
+ }
95
102
  const p = nextEnabled(filtered, active - 1, -1);
96
103
  if (p >= 0)
97
104
  setActive(p);
@@ -117,7 +124,9 @@ export function MultiSelect(props) {
117
124
  }
118
125
  }
119
126
  else if (key === "Backspace" && !query && values.length) {
120
- remove(values[values.length - 1]);
127
+ const last = values[values.length - 1];
128
+ if (last !== undefined)
129
+ remove(last);
121
130
  }
122
131
  else if (key === "Tab") {
123
132
  close();
@@ -140,9 +149,9 @@ export function MultiSelect(props) {
140
149
  if (!open)
141
150
  openAt(nextEnabled(filtered, 0, 1));
142
151
  }, children: [values.map((v) => {
143
- const o = byValue(v);
144
- return (_jsx(Tag, { removeTabIndex: -1, removeLabel: "Remove " + o.label, onRemove: props.disabled ? undefined : () => remove(v), children: o.label }, v));
145
- }), _jsx("input", { ref: inputRef, id: inputId, type: "text", role: "combobox", autoComplete: "off", spellCheck: false, className: cx("vk-multiselect-input", values.length > 0 && "vk-multiselect-input-compact"), placeholder: values.length ? "" : props.placeholder, disabled: props.disabled, "aria-autocomplete": "list", "aria-expanded": open ? "true" : "false", "aria-controls": listId, "aria-activedescendant": open && active >= 0 ? listId + "-" + active : undefined, "aria-required": props.required ? "true" : undefined, value: query, onChange: (e) => {
152
+ const o = optionForValue(v);
153
+ return (_jsx(Tag, { removeTabIndex: -1, removeLabel: messages.remove(o.label), onRemove: props.disabled ? undefined : () => { remove(v); }, children: o.label }, v));
154
+ }), _jsx("input", { ref: inputRef, id: inputId, type: "text", role: "combobox", autoComplete: "off", spellCheck: false, className: cx("vk-multiselect-input", values.length > 0 && "vk-multiselect-input-compact"), placeholder: values.length ? "" : props.placeholder, disabled: props.disabled, "aria-autocomplete": "list", "aria-expanded": open ? "true" : "false", "aria-controls": listId, "aria-activedescendant": open && active >= 0 ? listId + "-" + String(active) : undefined, "aria-required": props.required ? "true" : undefined, value: query, onChange: (e) => {
146
155
  const v = e.target.value;
147
156
  setQuery(v);
148
157
  const list = options.filter((o) => matches(o, v));
@@ -159,7 +168,7 @@ export function MultiSelect(props) {
159
168
  setActive,
160
169
  query,
161
170
  onToggle: toggle,
162
- emptyText: props.emptyText,
171
+ emptyText: props.emptyText || messages.noMatches(query),
163
172
  "aria-label": props["aria-label"],
164
173
  "aria-labelledby": props["aria-labelledby"],
165
174
  }) }), props.name ? values.map((v) => _jsx("input", { type: "hidden", name: props.name, value: v }, v)) : null] }) }));
@@ -1,6 +1,7 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { forwardRef, useEffect, useRef, useState } from "react";
3
+ import { useLocale } from "../../localization.js";
4
+ import { forwardRef, useState } from "react";
4
5
  import { Icon } from "../Icon/Icon.js";
5
6
  import { Input } from "../Input/Input.js";
6
7
  import { cx } from "../../lib/cx.js";
@@ -12,13 +13,9 @@ export const NumberInput = forwardRef(function NumberInput(props, ref) {
12
13
  const controlled = props.value !== undefined;
13
14
  const [internal, setInternal] = useState(props.defaultValue != null ? props.defaultValue : null);
14
15
  const value = props.value !== undefined ? props.value : internal;
15
- // The text being typed, which may not be a number yet ("-", "1.").
16
- const [text, setText] = useState(value == null ? "" : String(value));
17
- const editing = useRef(false);
18
- useEffect(() => {
19
- if (!editing.current)
20
- setText(value == null ? "" : String(value));
21
- }, [value]);
16
+ // Preserve partial input only while it still describes the current value.
17
+ const [draft, setDraft] = useState(null);
18
+ const text = draft && draft.value === value ? draft.text : value == null ? "" : String(value);
22
19
  const decimals = (String(step).split(".")[1] || "").length;
23
20
  const clamp = (n) => {
24
21
  if (min != null && n < min)
@@ -31,26 +28,27 @@ export const NumberInput = forwardRef(function NumberInput(props, ref) {
31
28
  const next = n == null || isNaN(n) ? null : clamp(n);
32
29
  if (!controlled)
33
30
  setInternal(next);
34
- setText(next == null ? "" : String(next));
31
+ setDraft(null);
35
32
  props.onChange?.(next);
36
33
  };
37
34
  // From empty, a step counts from min (or 0).
38
- const bump = (d) => set((value ?? min ?? 0) + d);
35
+ const bump = (d) => { set((value ?? min ?? 0) + d); };
39
36
  const rest = omit(props, ["value", "defaultValue", "onChange", "min", "max", "step", "decrementLabel", "incrementLabel", "suffix", "prefix", "className"]);
40
37
  return (_jsx(Input, { ...rest, ref: ref, className: cx("vk-number", props.className), inputMode: decimals ? "decimal" : "numeric", role: "spinbutton", "aria-valuenow": value ?? undefined, "aria-valuemin": min, "aria-valuemax": max, autoComplete: "off", value: text, prefix: props.prefix, onChange: (e) => {
41
- editing.current = true;
42
- const raw = e.target.value.replace(",", ".");
43
- setText(e.target.value);
44
- if (raw === "" || raw === "-")
38
+ const nextText = e.target.value;
39
+ const raw = nextText.replace(",", ".");
40
+ if (raw === "" || raw === "-") {
41
+ setDraft({ text: nextText, value });
45
42
  return;
43
+ }
46
44
  const n = Number(raw);
47
- if (!isNaN(n)) {
45
+ setDraft({ text: nextText, value: Number.isNaN(n) ? value : n });
46
+ if (!Number.isNaN(n)) {
48
47
  if (!controlled)
49
48
  setInternal(n);
50
49
  props.onChange?.(n);
51
50
  }
52
51
  }, onBlur: (e) => {
53
- editing.current = false;
54
52
  const raw = text.replace(",", ".");
55
53
  set(raw === "" ? null : Number(raw));
56
54
  props.onBlur?.(e);
@@ -80,11 +78,12 @@ export const NumberInput = forwardRef(function NumberInput(props, ref) {
80
78
  e.preventDefault();
81
79
  set(max);
82
80
  }
83
- }, suffix: _jsx(Stepper, { unit: props.suffix, value: value, min: min, max: max, disabled: props.disabled, decrementLabel: props.decrementLabel, incrementLabel: props.incrementLabel, onStep: (dir) => bump(dir * step) }) }));
81
+ }, suffix: _jsx(Stepper, { unit: props.suffix, value: value, min: min, max: max, disabled: props.disabled, decrementLabel: props.decrementLabel, incrementLabel: props.incrementLabel, onStep: (dir) => { bump(dir * step); } }) }));
84
82
  });
85
83
  // The unit and the − and + buttons; each button is disabled at its end of the range.
86
84
  function Stepper({ unit, value, min, max, disabled, decrementLabel, incrementLabel, onStep }) {
85
+ const { messages } = useLocale();
87
86
  const atMin = min != null && value != null && value <= min;
88
87
  const atMax = max != null && value != null && value >= max;
89
- return (_jsxs("span", { className: "vk-stepper", children: [unit ? _jsx("span", { className: "vk-stepper-unit", "aria-hidden": "true", children: unit }) : null, _jsx("button", { type: "button", tabIndex: -1, className: "vk-stepper-btn", "aria-label": decrementLabel || "Decrease", disabled: disabled || atMin, onClick: () => onStep(-1), children: _jsx(Icon, { name: "minus", size: 14 }) }), _jsx("button", { type: "button", tabIndex: -1, className: "vk-stepper-btn", "aria-label": incrementLabel || "Increase", disabled: disabled || atMax, onClick: () => onStep(1), children: _jsx(Icon, { name: "plus", size: 14 }) })] }));
88
+ return (_jsxs("span", { className: "vk-stepper", children: [unit ? _jsx("span", { className: "vk-stepper-unit", "aria-hidden": "true", children: unit }) : null, _jsx("button", { type: "button", tabIndex: -1, className: "vk-stepper-btn", "aria-label": decrementLabel || messages.decrease, disabled: disabled || atMin, onClick: () => { onStep(-1); }, children: _jsx(Icon, { name: "minus", size: 14 }) }), _jsx("button", { type: "button", tabIndex: -1, className: "vk-stepper-btn", "aria-label": incrementLabel || messages.increase, disabled: disabled || atMax, onClick: () => { onStep(1); }, children: _jsx(Icon, { name: "plus", size: 14 }) })] }));
90
89
  }
@@ -15,5 +15,5 @@ export interface OtpInputProps {
15
15
  'aria-describedby'?: string;
16
16
  'aria-invalid'?: boolean;
17
17
  }
18
- /** One box per character of a one-time code; typing advances, Backspace goes back, a paste fills them all. */
18
+ /** Styled Radix OTP fields; the primitive owns validation, paste, navigation, focus and form data. */
19
19
  export declare function OtpInput(props: OtpInputProps): import("react/jsx-runtime").JSX.Element;
@@ -1,75 +1,18 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { useRef, useState } from "react";
3
+ import { unstable_OneTimePasswordField as Primitive } from "radix-ui";
4
+ import { useLocale } from "../../localization.js";
4
5
  import { useUid } from "../../internal/useUid.js";
5
6
  import { cx } from "../../lib/cx.js";
6
- /** One character box: typing advances, Backspace goes back, the arrows move, a paste fills them all. */
7
- function OtpBox({ index: i, length, value, pattern, firstId, props, boxRef, set, focus }) {
8
- const first = i === 0;
9
- return (_jsx("input", { ref: boxRef, id: first ? firstId : undefined, className: "vk-input vk-otp-box", inputMode: props.numeric === false ? "text" : "numeric", autoComplete: first ? "one-time-code" : "off", maxLength: 1, value: value[i] || "", disabled: props.disabled, "aria-label": (props.label || "Digit") + " " + (i + 1) + " of " + length, "aria-invalid": props["aria-invalid"], "aria-describedby": first ? props["aria-describedby"] : undefined, onFocus: (e) => e.target.select(), onChange: (e) => {
10
- const ch = e.target.value.slice(-1);
11
- if (ch && !pattern.test(ch))
12
- return;
13
- const arr = value.split("");
14
- while (arr.length < i)
15
- arr.push("");
16
- arr[i] = ch;
17
- set(arr.join("").replace(/\s+$/, ""));
18
- if (ch)
19
- focus(i + 1);
20
- }, onKeyDown: (e) => {
21
- if (e.key === "Backspace" && !value[i]) {
22
- e.preventDefault();
23
- const arr = value.split("");
24
- arr[i - 1] = "";
25
- set(arr.join(""));
26
- focus(i - 1);
27
- }
28
- else if (e.key === "ArrowLeft") {
29
- e.preventDefault();
30
- focus(i - 1);
31
- }
32
- else if (e.key === "ArrowRight") {
33
- e.preventDefault();
34
- focus(i + 1);
35
- }
36
- }, onPaste: (e) => {
37
- const text = (e.clipboardData.getData("text") || "").split("").filter((c) => pattern.test(c)).join("");
38
- if (!text)
39
- return;
40
- e.preventDefault();
41
- set(text);
42
- focus(Math.min(text.length, length - 1));
43
- } }));
44
- }
45
- /** One box per character of a one-time code; typing advances, Backspace goes back, a paste fills them all. */
7
+ /** Styled Radix OTP fields; the primitive owns validation, paste, navigation, focus and form data. */
46
8
  export function OtpInput(props) {
9
+ const { messages } = useLocale();
47
10
  const length = props.length || 6;
48
- const [uncontrolled, setUncontrolled] = useState(() => (props.defaultValue || "").slice(0, length));
49
- const value = props.value !== undefined ? props.value : uncontrolled;
50
- const refs = useRef([]);
51
11
  const uid = useUid("vk-otp");
52
- const pattern = props.numeric === false ? /[^\s]/ : /\d/;
53
- const set = (next) => {
54
- const v = next.slice(0, length);
55
- if (props.value === undefined)
56
- setUncontrolled(v);
57
- props.onChange?.(v);
58
- if (v.length === length)
59
- props.onComplete?.(v);
60
- };
61
- const focus = (i) => {
62
- const el = refs.current[Math.max(0, Math.min(length - 1, i))];
63
- if (el) {
64
- el.focus();
65
- el.select();
66
- }
67
- };
68
- const boxes = [];
69
- for (let i = 0; i < length; i++) {
70
- boxes.push(_jsx(OtpBox, { index: i, length: length, value: value, pattern: pattern, firstId: props.id || uid, props: props, boxRef: (el) => {
71
- refs.current[i] = el;
72
- }, set: set, focus: focus }, i));
73
- }
74
- return (_jsxs("div", { role: "group", className: cx("vk-otp", props.className), "aria-labelledby": props["aria-labelledby"], "aria-label": props["aria-labelledby"] ? undefined : props["aria-label"] || "One-time code", children: [boxes, props.name ? _jsx("input", { type: "hidden", name: props.name, value: value }) : null] }));
12
+ const style = { "--vk-otp-length": length };
13
+ return (_jsxs(Primitive.Root, { className: cx("vk-otp", props.className), style: style, value: props.value, defaultValue: props.defaultValue, onValueChange: (code) => {
14
+ props.onChange?.(code);
15
+ if (code.length === length)
16
+ props.onComplete?.(code);
17
+ }, validationType: props.numeric === false ? "none" : "numeric", name: props.disabled ? undefined : props.name, disabled: props.disabled, "aria-labelledby": props["aria-labelledby"], "aria-label": props["aria-labelledby"] ? undefined : props["aria-label"] || messages.oneTimeCode, children: [Array.from({ length }, (_, index) => (_jsx(Primitive.Input, { index: index, id: index === 0 ? props.id || uid : undefined, className: "vk-input vk-otp-box", "aria-label": messages.digitPosition(props.label || messages.digit, index + 1, length), "aria-invalid": props["aria-invalid"], "aria-describedby": index === 0 ? props["aria-describedby"] : undefined }, index))), _jsx(Primitive.HiddenInput, {})] }));
75
18
  }
@@ -1,4 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { createElement } from "react";
2
3
  import { Badge } from "../Badge/Badge.js";
3
4
  import { Breadcrumbs } from "../Breadcrumbs/Breadcrumbs.js";
4
5
  import { cx } from "../../lib/cx.js";
@@ -6,6 +7,5 @@ import { para } from "../../lib/text.js";
6
7
  /** The top of a page inside an app: breadcrumbs, the page title, a description and the page's main actions. */
7
8
  export function PageHeader({ title, description, eyebrow, breadcrumbs, actions, badge, badgeTone, divider, headingAs, children, className }) {
8
9
  const Heading = headingAs || "h1";
9
- const Description = para(description);
10
- return (_jsxs("header", { className: cx("vk-page-header", divider ? "vk-page-header-divider" : null, className), children: [breadcrumbs ? _jsx(Breadcrumbs, { items: breadcrumbs }) : null, _jsxs("div", { className: "vk-page-header-row", children: [_jsxs("div", { className: "vk-page-header-text", children: [eyebrow ? _jsx("p", { className: "vk-page-header-eyebrow", children: eyebrow }) : null, _jsxs(Heading, { className: "vk-page-header-title", children: [title, badge ? _jsx(Badge, { tone: badgeTone, children: badge }) : null] }), description ? _jsx(Description, { className: "vk-page-header-description", children: description }) : null] }), actions ? _jsx("div", { className: "vk-page-header-actions", children: actions }) : null] }), children] }));
10
+ return (_jsxs("header", { className: cx("vk-page-header", divider ? "vk-page-header-divider" : null, className), children: [breadcrumbs ? _jsx(Breadcrumbs, { items: breadcrumbs }) : null, _jsxs("div", { className: "vk-page-header-row", children: [_jsxs("div", { className: "vk-page-header-text", children: [eyebrow ? _jsx("p", { className: "vk-page-header-eyebrow", children: eyebrow }) : null, _jsxs(Heading, { className: "vk-page-header-title", children: [title, badge ? _jsx(Badge, { tone: badgeTone, children: badge }) : null] }), description ? createElement(para(description), { className: "vk-page-header-description" }, description) : null] }), actions ? _jsx("div", { className: "vk-page-header-actions", children: actions }) : null] }), children] }));
11
11
  }
@@ -1,11 +1,13 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useLocale } from "../../localization.js";
3
4
  import { useState } from "react";
4
5
  import { Icon } from "../Icon/Icon.js";
5
6
  import { cx } from "../../lib/cx.js";
6
7
  import { pageList } from "../../lib/math.js";
7
8
  /** Moves through a long list one page at a time, with an optional summary of what's shown. */
8
9
  export function Pagination({ pageCount, page: pageProp, defaultPage, onChange, siblings, summary, previousLabel, nextLabel, label, className }) {
10
+ const { messages } = useLocale();
9
11
  const count = Math.max(1, pageCount || 1);
10
12
  const controlled = pageProp !== undefined;
11
13
  const [internal, setInternal] = useState(defaultPage || 1);
@@ -18,5 +20,5 @@ export function Pagination({ pageCount, page: pageProp, defaultPage, onChange, s
18
20
  onChange?.(p);
19
21
  };
20
22
  const pages = pageList(page, count, siblings ?? 1);
21
- return (_jsxs("nav", { "aria-label": label || "Pagination", className: cx("vk-pagination", className), children: [summary ? _jsx("p", { className: "vk-pagination-summary", children: summary }) : null, _jsxs("ul", { className: "vk-pagination-list", children: [_jsx("li", { children: _jsxs("button", { type: "button", className: "vk-page vk-page-step", disabled: page === 1, onClick: () => go(page - 1), children: [_jsx(Icon, { name: "chevron-left" }), _jsx("span", { children: previousLabel || "Previous" })] }) }), pages.map((p) => typeof p === "string" ? (_jsx("li", { className: "vk-page-gap", "aria-hidden": "true", children: "…" }, p)) : (_jsx("li", { children: _jsx("button", { type: "button", className: "vk-page", "aria-current": p === page ? "page" : undefined, "aria-label": "Page " + p, onClick: () => go(p), children: p }) }, p))), _jsx("li", { children: _jsxs("button", { type: "button", className: "vk-page vk-page-step", disabled: page === count, onClick: () => go(page + 1), children: [_jsx("span", { children: nextLabel || "Next" }), _jsx(Icon, { name: "chevron-right" })] }) })] })] }));
23
+ return (_jsxs("nav", { "aria-label": label || messages.pagination, className: cx("vk-pagination", className), children: [summary ? _jsx("p", { className: "vk-pagination-summary", children: summary }) : null, _jsxs("ul", { className: "vk-pagination-list", children: [_jsx("li", { children: _jsxs("button", { type: "button", className: "vk-page vk-page-step", disabled: page === 1, onClick: () => { go(page - 1); }, children: [_jsx(Icon, { name: "chevron-left" }), _jsx("span", { children: previousLabel || messages.previous })] }) }), pages.map((p) => typeof p === "string" ? (_jsx("li", { className: "vk-page-gap", "aria-hidden": "true", children: "…" }, p)) : (_jsx("li", { children: _jsx("button", { type: "button", className: "vk-page", "aria-current": p === page ? "page" : undefined, "aria-label": messages.page(p), onClick: () => { go(p); }, children: p }) }, p))), _jsx("li", { children: _jsxs("button", { type: "button", className: "vk-page vk-page-step", disabled: page === count, onClick: () => { go(page + 1); }, children: [_jsx("span", { children: nextLabel || messages.next }), _jsx(Icon, { name: "chevron-right" })] }) })] })] }));
22
24
  }
@@ -3,5 +3,5 @@ export interface PasswordInputProps extends Omit<InputProps, 'type' | 'suffix'>
3
3
  showLabel?: string;
4
4
  hideLabel?: string;
5
5
  }
6
- /** Password field with a Show/Hide button, so people can check what they typed. The ref is the <input>. */
6
+ /** Styled Radix password toggle; the primitive owns visibility, selection and focus. The ref is the input. */
7
7
  export declare const PasswordInput: import("react").ForwardRefExoticComponent<PasswordInputProps & import("react").RefAttributes<HTMLInputElement>>;
@@ -1,11 +1,16 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- import { forwardRef, useState } from "react";
3
+ import { forwardRef } from "react";
4
+ import { unstable_PasswordToggleField as Primitive } from "radix-ui";
5
+ import { useLocale } from "../../localization.js";
6
+ import { useUid } from "../../internal/useUid.js";
4
7
  import { Input } from "../Input/Input.js";
5
8
  import { omit } from "../../lib/omit.js";
6
- /** Password field with a Show/Hide button, so people can check what they typed. The ref is the <input>. */
9
+ /** Styled Radix password toggle; the primitive owns visibility, selection and focus. The ref is the input. */
7
10
  export const PasswordInput = forwardRef(function PasswordInput(props, ref) {
8
- const [shown, setShown] = useState(false);
11
+ const { messages } = useLocale();
12
+ const uid = useUid("vk-password");
13
+ const id = props.id || uid;
9
14
  const rest = omit(props, ["showLabel", "hideLabel"]);
10
- return (_jsx(Input, { autoComplete: "current-password", spellCheck: false, ...rest, ref: ref, type: shown ? "text" : "password", suffix: _jsx("button", { type: "button", className: "vk-affix-button", "aria-pressed": shown ? "true" : "false", disabled: props.disabled, onClick: () => setShown(!shown), children: shown ? props.hideLabel || "Hide" : props.showLabel || "Show" }) }));
15
+ return (_jsx(Primitive.Root, { children: _jsx(Primitive.Input, { asChild: true, id: id, children: _jsx(Input, { ...rest, ref: ref, suffix: _jsx(Primitive.Slot, { render: ({ visible }) => (_jsx(Primitive.Toggle, { id: id + "-toggle", "aria-controls": id, className: "vk-affix-button", "aria-pressed": visible, "aria-label": visible ? props.hideLabel || messages.hidePassword : props.showLabel || messages.showPassword, disabled: props.disabled, children: visible ? props.hideLabel || messages.hidePassword : props.showLabel || messages.showPassword })) }) }) }) }));
11
16
  });
@@ -1,6 +1,7 @@
1
- import { type ReactNode } from "react";
1
+ import type { ReactElement, ReactNode } from "react";
2
+ import { Popover as Primitive } from "radix-ui";
2
3
  import type { IconName } from "../../types.js";
3
- export interface PopoverProps {
4
+ export interface PopoverProps extends Pick<Primitive.PopoverProps, 'open' | 'defaultOpen' | 'onOpenChange' | 'modal'> {
4
5
  label: string;
5
6
  title?: string;
6
7
  icon?: IconName;
@@ -8,11 +9,9 @@ export interface PopoverProps {
8
9
  size?: 'sm';
9
10
  align?: 'start' | 'end';
10
11
  width?: string;
11
- defaultOpen?: boolean;
12
- children: ReactNode | ((api: {
13
- close: () => void;
14
- }) => ReactNode);
12
+ children: ReactNode;
13
+ close?: ReactElement;
15
14
  className?: string;
16
15
  }
17
16
  /** Non-modal panel attached to a button (Radix Popover). */
18
- export declare function Popover({ label, title, icon, variant, size, align, width, defaultOpen, children, className }: PopoverProps): import("react/jsx-runtime").JSX.Element;
17
+ export declare function Popover({ label, title, icon, variant, size, align, width, open, defaultOpen, onOpenChange, modal, children, close, className }: PopoverProps): import("react/jsx-runtime").JSX.Element;