@vokality/design-system 2.0.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +49 -3
  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 +2 -2
  45. package/dist/components/FileUpload/FileUpload.js +17 -9
  46. package/dist/components/Grid/Grid.d.ts +5 -5
  47. package/dist/components/Grid/Grid.js +1 -1
  48. package/dist/components/Heading/Heading.js +2 -1
  49. package/dist/components/Icon/Icon.js +4 -2
  50. package/dist/components/Inline/Inline.d.ts +7 -7
  51. package/dist/components/LineChart/LineChart.js +17 -15
  52. package/dist/components/LinkProvider/LinkProvider.d.ts +1 -1
  53. package/dist/components/LinkProvider/LinkProvider.js +6 -2
  54. package/dist/components/List/List.js +1 -1
  55. package/dist/components/MediaCard/MediaCard.js +2 -2
  56. package/dist/components/Menu/Menu.js +6 -43
  57. package/dist/components/Menu/entries.d.ts +1 -30
  58. package/dist/components/Menu/entries.js +16 -100
  59. package/dist/components/MultiSelect/MultiSelect.js +43 -34
  60. package/dist/components/NumberInput/NumberInput.js +17 -18
  61. package/dist/components/OtpInput/OtpInput.d.ts +1 -1
  62. package/dist/components/OtpInput/OtpInput.js +10 -67
  63. package/dist/components/PageHeader/PageHeader.js +2 -2
  64. package/dist/components/Pagination/Pagination.js +3 -1
  65. package/dist/components/PasswordInput/PasswordInput.d.ts +1 -1
  66. package/dist/components/PasswordInput/PasswordInput.js +9 -4
  67. package/dist/components/Popover/Popover.d.ts +6 -7
  68. package/dist/components/Popover/Popover.js +2 -19
  69. package/dist/components/Progress/Progress.d.ts +1 -1
  70. package/dist/components/Progress/Progress.js +7 -11
  71. package/dist/components/Radio/Radio.d.ts +4 -2
  72. package/dist/components/RadioGroup/RadioGroup.d.ts +5 -12
  73. package/dist/components/RadioGroup/RadioGroup.js +6 -33
  74. package/dist/components/RichTextEditor/RichTextEditor.d.ts +63 -0
  75. package/dist/components/RichTextEditor/RichTextEditor.js +175 -0
  76. package/dist/components/RichTextEditor/toolbar.d.ts +15 -0
  77. package/dist/components/RichTextEditor/toolbar.js +142 -0
  78. package/dist/components/RichTextEditor/uploads.d.ts +41 -0
  79. package/dist/components/RichTextEditor/uploads.js +124 -0
  80. package/dist/components/SearchInput/SearchInput.js +4 -2
  81. package/dist/components/SectionHeader/SectionHeader.js +1 -3
  82. package/dist/components/SegmentedControl/SegmentedControl.js +2 -12
  83. package/dist/components/Select/Select.d.ts +15 -16
  84. package/dist/components/Select/Select.js +11 -252
  85. package/dist/components/Slider/Slider.js +11 -21
  86. package/dist/components/Sparkline/Sparkline.js +8 -3
  87. package/dist/components/Spinner/Spinner.js +5 -2
  88. package/dist/components/Stack/Stack.d.ts +5 -5
  89. package/dist/components/Stat/Stat.js +6 -3
  90. package/dist/components/Steps/Steps.js +6 -3
  91. package/dist/components/Switch/Switch.d.ts +7 -7
  92. package/dist/components/Switch/Switch.js +4 -10
  93. package/dist/components/Table/Table.js +38 -19
  94. package/dist/components/Tabs/Tabs.js +2 -22
  95. package/dist/components/Tag/Tag.js +3 -1
  96. package/dist/components/Text/Text.d.ts +1 -1
  97. package/dist/components/TileGrid/TileGrid.js +1 -1
  98. package/dist/components/TimePicker/TimePicker.js +35 -33
  99. package/dist/components/Timeline/Timeline.js +5 -4
  100. package/dist/components/Toaster/Toaster.js +21 -17
  101. package/dist/components/Tooltip/Tooltip.d.ts +6 -6
  102. package/dist/components/Tooltip/Tooltip.js +3 -17
  103. package/dist/components/TreeView/TreeView.js +15 -12
  104. package/dist/components.css +179 -8
  105. package/dist/hooks/useTheme.js +6 -6
  106. package/dist/icons/message-circle.svg +1 -0
  107. package/dist/internal/CharCount.js +3 -1
  108. package/dist/internal/choice.d.ts +10 -48
  109. package/dist/internal/choice.js +8 -96
  110. package/dist/internal/options.d.ts +10 -5
  111. package/dist/internal/options.js +25 -11
  112. package/dist/internal/status.d.ts +3 -2
  113. package/dist/internal/status.js +10 -2
  114. package/dist/internal/useScrollActive.js +2 -2
  115. package/dist/internal/useToday.d.ts +3 -0
  116. package/dist/internal/useToday.js +42 -0
  117. package/dist/lib/dates.js +25 -15
  118. package/dist/lib/format.js +11 -8
  119. package/dist/lib/icons.d.ts +5 -0
  120. package/dist/lib/icons.js +2 -0
  121. package/dist/lib/math.js +17 -5
  122. package/dist/lib/rich-text.d.ts +13 -0
  123. package/dist/lib/rich-text.js +62 -0
  124. package/dist/lib/space.d.ts +1 -2
  125. package/dist/lib/space.js +4 -1
  126. package/dist/lib/text.js +1 -1
  127. package/dist/lib/theme.js +1 -1
  128. package/dist/localization.d.ts +166 -0
  129. package/dist/localization.js +142 -0
  130. package/dist/vokality.css +179 -8
  131. package/dist/vokality.iife.js +35986 -9685
  132. package/docs/brand.md +6 -3
  133. package/docs/components/AppShell/README.md +1 -1
  134. package/docs/components/BarChart/README.md +1 -0
  135. package/docs/components/ChatInbox/README.md +41 -0
  136. package/docs/components/ChatWidget/README.md +47 -0
  137. package/docs/components/Checkbox/README.md +7 -3
  138. package/docs/components/ContextMenu/README.md +7 -3
  139. package/docs/components/Dialog/README.md +9 -4
  140. package/docs/components/Drawer/README.md +1 -1
  141. package/docs/components/Field/README.md +1 -1
  142. package/docs/components/Fieldset/README.md +2 -2
  143. package/docs/components/LineChart/README.md +1 -0
  144. package/docs/components/LocaleProvider/README.md +48 -0
  145. package/docs/components/Menu/README.md +13 -8
  146. package/docs/components/OtpInput/README.md +9 -5
  147. package/docs/components/PasswordInput/README.md +11 -2
  148. package/docs/components/Popover/README.md +6 -3
  149. package/docs/components/Progress/README.md +3 -1
  150. package/docs/components/RadioGroup/README.md +5 -2
  151. package/docs/components/RichTextEditor/README.md +84 -0
  152. package/docs/components/SegmentedControl/README.md +2 -0
  153. package/docs/components/Select/README.md +13 -17
  154. package/docs/components/Skeleton/README.md +1 -1
  155. package/docs/components/Slider/README.md +4 -2
  156. package/docs/components/Steps/README.md +1 -1
  157. package/docs/components/Switch/README.md +5 -2
  158. package/docs/components/Tabs/README.md +4 -2
  159. package/docs/components/Toaster/README.md +3 -1
  160. package/docs/components/Tooltip/README.md +5 -3
  161. package/package.json +49 -5
@@ -1,11 +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 { useEffect, useRef, useState } from "react";
4
5
  import { IconButton } from "../IconButton/IconButton.js";
5
6
  import { useUid } from "../../internal/useUid.js";
7
+ import { useToday } from "../../internal/useToday.js";
6
8
  import { cx } from "../../lib/cx.js";
7
9
  import { addDays, addMonths, clampDate, parseISO, sameDay, toISO } from "../../lib/dates.js";
8
- import { resolveLocale } from "../../lib/format.js";
9
10
  import { dateFormat } from "../../lib/intl.js";
10
11
  /** Days from the start of the week to d. */
11
12
  const weekday = (d, weekStart) => (d.getDay() - weekStart + 7) % 7;
@@ -66,15 +67,15 @@ function dayLook({ date: d, focus, today, range, selStart, selEnd, rangeEnd }) {
66
67
  function DayCell(props) {
67
68
  const { date: d, onPick, onHover } = props;
68
69
  const look = dayLook(props);
69
- return (_jsx("td", { role: "gridcell", "aria-selected": look.selected ? "true" : "false", className: look.cellClass, children: _jsx("button", { type: "button", "data-date": toISO(d), tabIndex: sameDay(d, props.focus) ? 0 : -1, className: look.dayClass, "aria-label": props.label, "aria-current": look.isToday ? "date" : undefined, "aria-disabled": props.disabled ? "true" : undefined, onClick: () => onPick(d), onMouseEnter: onHover ? () => onHover(d) : undefined, children: d.getDate() }) }));
70
+ return (_jsx("td", { role: "gridcell", "aria-selected": look.selected ? "true" : "false", className: look.cellClass, children: _jsx("button", { type: "button", "data-date": toISO(d), tabIndex: sameDay(d, props.focus) ? 0 : -1, className: look.dayClass, "aria-label": props.label, "aria-current": look.isToday ? "date" : undefined, "aria-disabled": props.disabled ? "true" : undefined, onClick: () => { onPick(d); }, onMouseEnter: onHover ? () => { onHover(d); } : undefined, children: d.getDate() }) }));
70
71
  }
71
72
  /** Month grid for a date or a range (WAI-ARIA grid). */
72
73
  export function Calendar(props) {
74
+ const { locale, messages } = useLocale(props.locale);
73
75
  const range = props.mode === "range";
74
- const locale = resolveLocale(props.locale);
75
76
  const weekStart = props.weekStartsOn == null ? 0 : props.weekStartsOn;
76
77
  const min = parseISO(props.min), max = parseISO(props.max);
77
- const today = parseISO(props.today) || parseISO(toISO(new Date()));
78
+ const today = useToday(props.today);
78
79
  const { selStart, selEnd, select } = useSelection(props, range);
79
80
  const [focus, setFocus] = useState(() => clampDate(selStart || parseISO(props.defaultMonth) || today, min, max));
80
81
  const [hover, setHover] = useState(null);
@@ -140,5 +141,5 @@ export function Calendar(props) {
140
141
  }
141
142
  rows.push(_jsx("tr", { children: cells }, r));
142
143
  }
143
- return (_jsxs("div", { className: cx("vk-calendar", props.className), children: [_jsxs("div", { className: "vk-calendar-header", children: [_jsx(IconButton, { icon: "chevron-left", label: "Previous month", disabled: min !== null && prevMonthEnd < min, onClick: () => moveTo(addMonths(focus, -1), false) }), _jsx("h2", { id: titleId, className: "vk-calendar-title", "aria-live": "polite", children: title }), _jsx(IconButton, { icon: "chevron-right", label: "Next month", disabled: max !== null && nextMonthStart > max, onClick: () => moveTo(addMonths(focus, 1), false) })] }), _jsxs("table", { ref: gridRef, role: "grid", className: "vk-calendar-grid", "aria-labelledby": titleId, onKeyDown: onKeyDown, onMouseLeave: () => setHover(null), children: [_jsx("thead", { children: _jsx("tr", { children: head }) }), _jsx("tbody", { children: rows })] })] }));
144
+ return (_jsxs("div", { className: cx("vk-calendar", props.className), children: [_jsxs("div", { className: "vk-calendar-header", children: [_jsx(IconButton, { icon: "chevron-left", label: messages.previousMonth, disabled: min !== null && prevMonthEnd < min, onClick: () => { moveTo(addMonths(focus, -1), false); } }), _jsx("h2", { id: titleId, className: "vk-calendar-title", "aria-live": "polite", children: title }), _jsx(IconButton, { icon: "chevron-right", label: messages.nextMonth, disabled: max !== null && nextMonthStart > max, onClick: () => { moveTo(addMonths(focus, 1), false); } })] }), _jsxs("table", { ref: gridRef, role: "grid", className: "vk-calendar-grid", "aria-labelledby": titleId, onKeyDown: onKeyDown, onMouseLeave: () => { setHover(null); }, children: [_jsx("thead", { children: _jsx("tr", { children: head }) }), _jsx("tbody", { children: rows })] })] }));
144
145
  }
@@ -1,11 +1,10 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { createElement } from "react";
2
3
  import { cx } from "../../lib/cx.js";
3
4
  import { pad, para } from "../../lib/text.js";
4
5
  /** Outlined panel for a feature, plan, step or summary. */
5
6
  export function Card({ title, children, eyebrow, step, points, footnote, as, titleAs, className }) {
6
7
  const Tag = as || "div";
7
8
  const TitleTag = titleAs || "h3";
8
- const Body = para(children);
9
- const Footnote = para(footnote);
10
- return (_jsxs(Tag, { className: cx("vk-card", className), children: [step != null && _jsx("span", { className: "vk-step-number", "aria-hidden": "true", children: pad(step) }), eyebrow ? _jsx("p", { className: "vk-card-eyebrow", children: eyebrow }) : null, title ? _jsx(TitleTag, { className: "vk-card-title", children: title }) : null, children ? _jsx(Body, { className: "vk-card-body", children: children }) : null, points && points.length ? (_jsx("ul", { className: "vk-card-points", children: points.map((p) => _jsx("li", { children: p }, p)) })) : null, footnote ? _jsx(Footnote, { className: "vk-card-footnote", children: footnote }) : null] }));
9
+ return (_jsxs(Tag, { className: cx("vk-card", className), children: [step != null && _jsx("span", { className: "vk-step-number", "aria-hidden": "true", children: pad(step) }), eyebrow ? _jsx("p", { className: "vk-card-eyebrow", children: eyebrow }) : null, title ? _jsx(TitleTag, { className: "vk-card-title", children: title }) : null, children ? createElement(para(children), { className: "vk-card-body" }, children) : null, points && points.length ? (_jsx("ul", { className: "vk-card-points", children: points.map((p) => _jsx("li", { children: p }, p)) })) : null, footnote ? createElement(para(footnote), { className: "vk-card-footnote" }, footnote) : null] }));
11
10
  }
@@ -0,0 +1,11 @@
1
+ import { type ReactNode } from "react";
2
+ import type { ChatPanelProps, ChatThread } from "../../chat.js";
3
+ export interface ChatInboxProps extends ChatPanelProps {
4
+ title?: string;
5
+ threads: readonly ChatThread[];
6
+ selectedThreadId: string | null;
7
+ onSelectThread: (threadId: string | null) => void;
8
+ emptySelection?: ReactNode;
9
+ }
10
+ /** Controlled thread selection; CSS handles the narrow-screen list/detail presentation. */
11
+ export declare function ChatInbox({ title, threads, selectedThreadId, onSelectThread, emptySelection, className, ...panel }: ChatInboxProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,49 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { useRef } from "react";
4
+ import { useLocale } from "../../localization.js";
5
+ import { useIsoLayoutEffect } from "../../internal/useIsoLayoutEffect.js";
6
+ import { useUid } from "../../internal/useUid.js";
7
+ import { cx } from "../../lib/cx.js";
8
+ import { formatNumber } from "../../lib/format.js";
9
+ import { Avatar } from "../Avatar/Avatar.js";
10
+ import { IconButton } from "../IconButton/IconButton.js";
11
+ import { ChatPanel } from "../ChatPanel/ChatPanel.js";
12
+ function ThreadList({ threads, selectedId, activeRef, onSelect }) {
13
+ const { locale, messages } = useLocale();
14
+ if (!threads.length)
15
+ return _jsx("div", { className: "vk-chat-empty", children: messages.chat.noThreads });
16
+ return _jsx("ul", { className: "vk-chat-threads", children: threads.map((thread) => _jsx("li", { children: _jsxs("button", { ref: thread.id === selectedId ? activeRef : undefined, type: "button", className: "vk-chat-thread", "aria-current": thread.id === selectedId ? "true" : undefined, disabled: thread.disabled, onClick: () => { onSelect(thread.id); }, children: [_jsx("span", { className: "vk-chat-thread-avatar", children: thread.avatar || _jsx(Avatar, { name: thread.title, decorative: true }) }), _jsxs("span", { className: "vk-chat-thread-text", children: [_jsx("span", { className: "vk-chat-thread-title", children: thread.title }), thread.preview ? _jsx("span", { className: "vk-chat-thread-preview", children: thread.preview }) : null, _jsxs("span", { className: "vk-chat-thread-meta", children: [thread.timestamp, thread.unreadCount && thread.unreadCount > 0 ? _jsx("span", { className: "vk-chat-thread-count", "aria-label": messages.chat.unread(thread.unreadCount), children: formatNumber(thread.unreadCount, { locale }) }) : null] })] })] }) }, thread.id)) });
17
+ }
18
+ /** Controlled thread selection; CSS handles the narrow-screen list/detail presentation. */
19
+ export function ChatInbox({ title, threads, selectedThreadId, onSelectThread, emptySelection, className, ...panel }) {
20
+ const { messages } = useLocale();
21
+ const listTitleId = useUid("vk-chat-threads");
22
+ const selected = threads.find((thread) => thread.id === selectedThreadId);
23
+ const headingRef = useRef(null);
24
+ const activeRef = useRef(null);
25
+ const navigation = useRef(null);
26
+ useIsoLayoutEffect(() => {
27
+ const request = navigation.current;
28
+ if (!request)
29
+ return;
30
+ if ("threadId" in request && request.threadId === selectedThreadId) {
31
+ headingRef.current?.focus();
32
+ navigation.current = null;
33
+ }
34
+ else if ("returnTo" in request && selectedThreadId === null) {
35
+ request.returnTo?.focus();
36
+ navigation.current = null;
37
+ }
38
+ }, [selectedThreadId]);
39
+ const select = (id) => {
40
+ navigation.current = { threadId: id };
41
+ onSelectThread(id);
42
+ };
43
+ const back = () => {
44
+ navigation.current = { returnTo: activeRef.current };
45
+ onSelectThread(null);
46
+ };
47
+ const empty = emptySelection === undefined ? messages.chat.chooseThread : emptySelection;
48
+ return (_jsxs("div", { className: cx("vk-chat-inbox", selected && "vk-chat-inbox-selected", className), children: [_jsxs("section", { className: "vk-chat-inbox-list", "aria-labelledby": listTitleId, children: [_jsx("header", { className: "vk-chat-header", children: _jsx("h2", { id: listTitleId, className: "vk-chat-title", children: title || messages.chat.conversations }) }), _jsx(ThreadList, { threads: threads, selectedId: selectedThreadId, activeRef: activeRef, onSelect: select })] }), _jsx("section", { className: "vk-chat-inbox-detail", "aria-label": selected?.title || messages.chat.messages, children: selected ? _jsxs(_Fragment, { children: [_jsxs("header", { className: "vk-chat-header", children: [_jsx(IconButton, { icon: "chevron-left", label: messages.chat.back, className: "vk-chat-back", onClick: back }), _jsx("h2", { ref: headingRef, tabIndex: -1, className: "vk-chat-title", children: selected.title })] }), _jsx(ChatPanel, { ...panel }, selected.id)] }) : _jsx("div", { className: "vk-chat-empty vk-chat-no-selection", children: empty }) })] }));
49
+ }
@@ -0,0 +1,3 @@
1
+ import type { ChatPanelProps } from "../../chat.js";
2
+ /** Shared transcript, feedback and Markdown composer; no transport or persistence. */
3
+ export declare function ChatPanel(props: ChatPanelProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,13 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useLocale } from "../../localization.js";
4
+ import { cx } from "../../lib/cx.js";
5
+ import { Button } from "../Button/Button.js";
6
+ import { Icon } from "../Icon/Icon.js";
7
+ import { ChatComposer } from "./composer.js";
8
+ import { ChatTranscript } from "./transcript.js";
9
+ /** Shared transcript, feedback and Markdown composer; no transport or persistence. */
10
+ export function ChatPanel(props) {
11
+ const { messages } = useLocale();
12
+ return (_jsxs("div", { className: cx("vk-chat-panel", props.className), children: [_jsx(ChatTranscript, { messages: props.messages, emptyState: props.emptyState, pending: props.pending, error: props.error, label: props["aria-label"], onRetryMessage: props.onRetryMessage }), props.error ? _jsxs("div", { className: "vk-chat-feedback", role: "alert", children: [_jsx(Icon, { name: "circle-alert", size: 16 }), _jsx("div", { children: props.error }), props.onRetry ? _jsx(Button, { type: "button", size: "sm", variant: "ghost", onClick: props.onRetry, children: messages.chat.tryAgain }) : null] }) : null, _jsx(ChatComposer, { options: props.composer })] }));
13
+ }
@@ -0,0 +1,5 @@
1
+ import type { ChatComposerOptions } from "../../chat.js";
2
+ /** Draft state belongs to this form, or to the application when value is supplied. */
3
+ export declare function ChatComposer({ options }: {
4
+ options: ChatComposerOptions;
5
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,32 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useState } from "react";
4
+ import { useLocale } from "../../localization.js";
5
+ import { Field } from "../Field/Field.js";
6
+ import { Button } from "../Button/Button.js";
7
+ import { RichTextEditor } from "../RichTextEditor/RichTextEditor.js";
8
+ /** Draft state belongs to this form, or to the application when value is supplied. */
9
+ export function ChatComposer({ options }) {
10
+ const { messages } = useLocale();
11
+ const [uncontrolled, setUncontrolled] = useState(options.defaultValue || "");
12
+ const controlled = options.value !== undefined;
13
+ const [uploadPending, setUploadPending] = useState(false);
14
+ const draft = options.value ?? uncontrolled;
15
+ const locked = Boolean(options.disabled || options.sending);
16
+ const change = (value) => {
17
+ if (!controlled)
18
+ setUncontrolled(value);
19
+ options.onChange?.(value);
20
+ };
21
+ const submit = (event) => {
22
+ if (event.target !== event.currentTarget)
23
+ return;
24
+ event.preventDefault();
25
+ if (locked || uploadPending || !draft.trim())
26
+ return;
27
+ options.onSend(draft);
28
+ if (!controlled)
29
+ change("");
30
+ };
31
+ return (_jsxs("form", { className: "vk-chat-composer", onSubmit: submit, children: [_jsx(Field, { label: options.label || messages.chat.message, children: _jsx(RichTextEditor, { toolbar: "minimal", value: draft, onChange: change, name: options.name, disabled: locked, placeholder: options.placeholder || messages.chat.placeholder, onUploadAttachment: options.onUploadAttachment, accept: options.accept, maxFileSize: options.maxFileSize, emojiOptions: options.emojiOptions, onUploadError: options.onUploadError, onUploadPendingChange: setUploadPending }) }), _jsx("div", { className: "vk-chat-composer-actions", children: _jsx(Button, { type: "submit", size: "sm", loading: options.sending, loadingLabel: messages.chat.sending, disabled: locked || uploadPending || !draft.trim(), children: options.sendLabel || messages.chat.send }) })] }));
32
+ }
@@ -0,0 +1,13 @@
1
+ import { type ReactNode } from "react";
2
+ import type { ChatMessage } from "../../chat.js";
3
+ interface TranscriptProps {
4
+ messages: readonly ChatMessage[];
5
+ emptyState?: ReactNode;
6
+ pending?: ReactNode;
7
+ error?: ReactNode;
8
+ label?: string;
9
+ onRetryMessage?: (id: string) => void;
10
+ }
11
+ /** A native scrollable log. Follow new messages only while the reader is near its end. */
12
+ export declare function ChatTranscript(props: TranscriptProps): import("react/jsx-runtime").JSX.Element;
13
+ export {};
@@ -0,0 +1,39 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useRef } from "react";
4
+ import { AnimatePresence, LazyMotion, domAnimation, useReducedMotion } from "motion/react";
5
+ import * as m from "motion/react-m";
6
+ import { useLocale } from "../../localization.js";
7
+ import { useIsoLayoutEffect } from "../../internal/useIsoLayoutEffect.js";
8
+ import { Avatar } from "../Avatar/Avatar.js";
9
+ import { Button } from "../Button/Button.js";
10
+ import { Icon } from "../Icon/Icon.js";
11
+ import { cx } from "../../lib/cx.js";
12
+ function MessageDelivery({ message, onRetry }) {
13
+ const { messages } = useLocale();
14
+ if (!message.delivery)
15
+ return null;
16
+ if (message.delivery.state === "pending")
17
+ return _jsxs("span", { className: "vk-chat-delivery", children: [_jsx(Icon, { name: "clock", size: 14 }), messages.chat.sending] });
18
+ return (_jsxs("div", { className: "vk-chat-delivery vk-chat-delivery-failed", children: [_jsx(Icon, { name: "circle-alert", size: 14 }), _jsx("span", { children: message.delivery.error || messages.chat.failed }), onRetry ? _jsx(Button, { type: "button", size: "sm", variant: "ghost", "aria-label": messages.chat.retryMessage(message.author.name), onClick: () => { onRetry(message.id); }, children: messages.chat.retry }) : null] }));
19
+ }
20
+ function MessageItem({ message, onRetry, reducedMotion }) {
21
+ return (_jsxs(m.li, { className: cx("vk-chat-message", "vk-chat-message-" + message.direction), initial: { opacity: 0, y: reducedMotion ? 0 : 4 }, animate: { opacity: 1, y: 0 }, transition: { duration: reducedMotion ? 0 : 0.16, ease: "easeOut" }, children: [_jsx("span", { className: "vk-chat-message-avatar", children: message.author.avatar || _jsx(Avatar, { name: message.author.name, size: 28, decorative: true }) }), _jsxs("div", { className: "vk-chat-message-body", children: [_jsxs("div", { className: "vk-chat-message-meta", children: [_jsx("span", { className: "vk-chat-message-author", children: message.author.name }), message.timestamp ? _jsx("span", { className: "vk-chat-message-time", children: message.timestamp }) : null] }), _jsx("div", { className: "vk-prose vk-chat-message-content", children: message.content }), _jsx(MessageDelivery, { message: message, onRetry: onRetry })] })] }));
22
+ }
23
+ /** A native scrollable log. Follow new messages only while the reader is near its end. */
24
+ export function ChatTranscript(props) {
25
+ const { messages } = useLocale();
26
+ const reducedMotion = useReducedMotion() === true;
27
+ const scrollRef = useRef(null);
28
+ const follow = useRef(true);
29
+ useIsoLayoutEffect(() => {
30
+ const node = scrollRef.current;
31
+ if (node && follow.current)
32
+ node.scrollTop = node.scrollHeight;
33
+ }, [props.messages, props.pending]);
34
+ const empty = props.emptyState === undefined ? messages.chat.empty : props.emptyState;
35
+ return (_jsxs("div", { ref: scrollRef, role: "log", "aria-label": props.label || messages.chat.messages, "aria-live": "polite", "aria-relevant": "additions text", "aria-atomic": "false", tabIndex: 0, className: "vk-chat-transcript", onScroll: (event) => {
36
+ const node = event.currentTarget;
37
+ follow.current = node.scrollHeight - node.scrollTop - node.clientHeight <= 32;
38
+ }, children: [_jsx(LazyMotion, { features: domAnimation, children: _jsx("ol", { className: "vk-chat-messages", children: _jsx(AnimatePresence, { initial: false, children: props.messages.map((message) => _jsx(MessageItem, { message: message, onRetry: props.onRetryMessage, reducedMotion: reducedMotion }, message.id)) }) }) }), !props.messages.length && !props.pending && !props.error ? _jsx("div", { className: "vk-chat-empty", children: empty }) : null, props.pending ? _jsx("div", { className: "vk-chat-pending", role: "status", children: props.pending }) : null] }));
39
+ }
@@ -0,0 +1,12 @@
1
+ import { type ReactNode } from "react";
2
+ import { Popover as Primitive } from "radix-ui";
3
+ import type { ChatPanelProps } from "../../chat.js";
4
+ export interface ChatWidgetProps extends ChatPanelProps, Pick<Primitive.PopoverProps, "open" | "defaultOpen" | "onOpenChange" | "modal"> {
5
+ title: string;
6
+ description?: ReactNode;
7
+ align?: "start" | "end";
8
+ triggerLabel?: string;
9
+ unreadCount?: number;
10
+ }
11
+ /** A floating chat launcher with native Radix Popover focus, state and dismissal. */
12
+ export declare function ChatWidget({ title, description, align, triggerLabel, unreadCount, open, defaultOpen, onOpenChange, modal, className, ...panel }: ChatWidgetProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,42 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useState } from "react";
4
+ import { Popover as Primitive } from "radix-ui";
5
+ import { AnimatePresence, LazyMotion, domAnimation, useReducedMotion } from "motion/react";
6
+ import * as m from "motion/react-m";
7
+ import { useLocale } from "../../localization.js";
8
+ import { useUid } from "../../internal/useUid.js";
9
+ import { formatNumber } from "../../lib/format.js";
10
+ import { cx } from "../../lib/cx.js";
11
+ import { ChatPanel } from "../ChatPanel/ChatPanel.js";
12
+ import { IconButton } from "../IconButton/IconButton.js";
13
+ const MotionIconButton = m.create(IconButton);
14
+ /** Hoist only Radix's public state contract so Motion can retain native content during exit. */
15
+ function useChatOpen({ open, defaultOpen, onOpenChange }) {
16
+ const [localOpen, setLocalOpen] = useState(defaultOpen ?? false);
17
+ return {
18
+ open: open ?? localOpen,
19
+ change: (next) => {
20
+ if (open === undefined)
21
+ setLocalOpen(next);
22
+ onOpenChange?.(next);
23
+ },
24
+ };
25
+ }
26
+ /** Motion retains the native content during exit; Radix still owns its focus scope and position. */
27
+ function WidgetContent({ title, description, align, titleId, panel }) {
28
+ const { messages } = useLocale();
29
+ const reducedMotion = useReducedMotion() === true;
30
+ const descriptionId = titleId + "-description";
31
+ return _jsx(Primitive.Portal, { forceMount: true, children: _jsx(Primitive.Content, { forceMount: true, asChild: true, side: "top", align: align, sideOffset: 12, collisionPadding: 12, "aria-labelledby": titleId, "aria-describedby": description ? descriptionId : undefined, className: "vk-chat-widget-panel", children: _jsxs(m.div, { initial: { opacity: 0, y: reducedMotion ? 0 : 8, scale: reducedMotion ? 1 : 0.99 }, animate: { opacity: 1, y: 0, scale: 1, transition: { duration: reducedMotion ? 0 : 0.2, ease: [0.2, 0.8, 0.2, 1] } }, exit: { opacity: 0, y: reducedMotion ? 0 : 8, scale: reducedMotion ? 1 : 0.99, transition: { duration: reducedMotion ? 0 : 0.12 } }, children: [_jsxs("header", { className: "vk-chat-header", children: [_jsxs("div", { className: "vk-chat-heading", children: [_jsx("h2", { id: titleId, className: "vk-chat-title", children: title }), description ? _jsx("div", { id: descriptionId, className: "vk-chat-description", children: description }) : null] }), _jsx(Primitive.Close, { asChild: true, children: _jsx(IconButton, { icon: "x", label: messages.chat.close }) })] }), _jsx(ChatPanel, { ...panel })] }) }) });
32
+ }
33
+ /** A floating chat launcher with native Radix Popover focus, state and dismissal. */
34
+ export function ChatWidget({ title, description, align = "end", triggerLabel, unreadCount, open, defaultOpen, onOpenChange, modal, className, ...panel }) {
35
+ const { locale, messages } = useLocale();
36
+ const disclosure = useChatOpen({ open, defaultOpen, onOpenChange });
37
+ const reducedMotion = useReducedMotion() === true;
38
+ const titleId = useUid("vk-chat-title");
39
+ const unread = unreadCount && unreadCount > 0 ? messages.chat.unread(unreadCount) : "";
40
+ const label = (triggerLabel || messages.chat.open) + (unread ? ", " + unread : "");
41
+ return (_jsx(LazyMotion, { features: domAnimation, children: _jsxs(Primitive.Root, { open: disclosure.open, onOpenChange: disclosure.change, modal: modal, children: [_jsxs("div", { className: cx("vk-chat-widget-launcher", "vk-chat-widget-" + align, className), children: [_jsx(Primitive.Trigger, { asChild: true, children: _jsx(MotionIconButton, { icon: "message-circle", size: 24, label: label, variant: "outline", className: "vk-chat-widget-trigger", whileHover: reducedMotion ? undefined : { scale: 1.03 }, whileTap: reducedMotion ? undefined : { scale: 0.97 }, transition: { duration: reducedMotion ? 0 : 0.12 } }) }), unreadCount && unreadCount > 0 ? _jsx("span", { className: "vk-chat-unread", "aria-hidden": "true", children: formatNumber(unreadCount, { locale }) }) : null] }), _jsx(AnimatePresence, { initial: false, children: disclosure.open ? _jsx(WidgetContent, { title: title, description: description, align: align, titleId: titleId, panel: panel }) : null })] }) }));
42
+ }
@@ -1,12 +1,7 @@
1
- import { type InputHTMLAttributes, type ReactNode } from "react";
2
- export interface CheckboxProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'type'> {
3
- label: ReactNode;
4
- description?: ReactNode;
5
- indeterminate?: boolean;
6
- hideLabel?: boolean;
1
+ import { type ComponentPropsWithoutRef } from "react";
2
+ import { Checkbox as Primitive } from "radix-ui";
3
+ import { type ChoiceTextProps } from "../../internal/choice.js";
4
+ export interface CheckboxProps extends Omit<ComponentPropsWithoutRef<typeof Primitive.Root>, "asChild" | "children" | "onChange">, ChoiceTextProps {
7
5
  }
8
- /**
9
- * Square checkbox with label and optional description (Radix Checkbox). `onChange` receives a change event whose
10
- * target reads `checked`, `value` and `name` like a native checkbox. The ref is the checkbox control.
11
- */
6
+ /** Styled Radix Checkbox; checked state, callbacks, keyboard and form behavior belong to Radix. */
12
7
  export declare const Checkbox: import("react").ForwardRefExoticComponent<CheckboxProps & import("react").RefAttributes<HTMLButtonElement>>;
@@ -1,24 +1,10 @@
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
4
  import { Checkbox as Primitive } from "radix-ui";
5
- import { checkMark, ChoiceLabel, hiddenLabel, useChoiceToggle } from "../../internal/choice.js";
5
+ import { checkMark, ChoiceLabel, hiddenLabel } from "../../internal/choice.js";
6
6
  import { omit } from "../../lib/omit.js";
7
- /**
8
- * Square checkbox with label and optional description (Radix Checkbox). `onChange` receives a change event whose
9
- * target reads `checked`, `value` and `name` like a native checkbox. The ref is the checkbox control.
10
- */
11
- export const Checkbox = forwardRef(function Checkbox(props, ref) {
12
- const toggle = useChoiceToggle(props);
13
- // As natively, a click clears the indeterminate look until `indeterminate` changes.
14
- const [cleared, setCleared] = useState(false);
15
- const [wasIndeterminate, setWasIndeterminate] = useState(props.indeterminate);
16
- if (wasIndeterminate !== props.indeterminate) {
17
- setWasIndeterminate(props.indeterminate);
18
- setCleared(false);
19
- }
20
- const mixed = Boolean(props.indeterminate) && !cleared;
21
- // Radix owns data-state on the control, so a trigger's data-state (Tooltip, Popover) is not passed on.
22
- const rest = omit(props, ["label", "description", "className", "indeterminate", "hideLabel", "checked", "defaultChecked", "onChange", "onClick", "value", "data-state"]);
23
- return (_jsx(ChoiceLabel, { 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-choice-box", value: props.value == null ? undefined : String(props.value), checked: mixed ? "indeterminate" : toggle.checked, onClick: toggle.onClick, onCheckedChange: () => setCleared(toggle.change()), children: _jsx(Primitive.Indicator, { forceMount: true, asChild: true, children: checkMark(mixed) }) }) }));
7
+ /** Styled Radix Checkbox; checked state, callbacks, keyboard and form behavior belong to Radix. */
8
+ export const Checkbox = forwardRef(function Checkbox({ label, description, hideLabel, className, ...props }, ref) {
9
+ return (_jsx(ChoiceLabel, { 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-choice-box", children: _jsx(Primitive.Indicator, { forceMount: true, asChild: true, children: checkMark() }) }) }));
24
10
  });
@@ -1,12 +1,21 @@
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 { useLocale } from "../../localization.js";
4
+ import { useEffect, useRef, useState } from "react";
4
5
  import { Icon } from "../Icon/Icon.js";
5
6
  import { cx } from "../../lib/cx.js";
6
7
  // Copies the code, or, without clipboard access, selects it so it can be copied by hand.
7
8
  function useCopy(code, preRef) {
8
9
  const [copied, setCopied] = useState(false);
10
+ const timer = useRef();
11
+ const mounted = useRef(false);
12
+ useEffect(() => {
13
+ mounted.current = true;
14
+ return () => { mounted.current = false; clearTimeout(timer.current); };
15
+ }, []);
9
16
  const selectAll = () => {
17
+ if (!mounted.current)
18
+ return;
10
19
  const pre = preRef.current;
11
20
  const sel = window.getSelection();
12
21
  if (!pre || !sel)
@@ -18,8 +27,11 @@ function useCopy(code, preRef) {
18
27
  };
19
28
  const copy = () => {
20
29
  const done = () => {
30
+ if (!mounted.current)
31
+ return;
32
+ clearTimeout(timer.current);
21
33
  setCopied(true);
22
- setTimeout(() => setCopied(false), 1600);
34
+ timer.current = setTimeout(() => { setCopied(false); }, 1600);
23
35
  };
24
36
  try {
25
37
  navigator.clipboard.writeText(code).then(done, selectAll);
@@ -31,13 +43,15 @@ function useCopy(code, preRef) {
31
43
  return { copied, copy };
32
44
  }
33
45
  function CodeBlockHead({ title, showCopy, copied, onCopy }) {
34
- return (_jsxs("figcaption", { className: "vk-codeblock-head", children: [_jsx("span", { className: "vk-codeblock-title", children: title }), showCopy ? (_jsxs("button", { type: "button", className: "vk-codeblock-copy", onClick: onCopy, children: [_jsx(Icon, { name: copied ? "check" : "copy", size: 14 }), _jsx("span", { "aria-live": "polite", children: copied ? "Copied" : "Copy" })] })) : null] }));
46
+ const { messages } = useLocale();
47
+ return (_jsxs("figcaption", { className: "vk-codeblock-head", children: [_jsx("span", { className: "vk-codeblock-title", children: title }), showCopy ? (_jsxs("button", { type: "button", className: "vk-codeblock-copy", onClick: onCopy, children: [_jsx(Icon, { name: copied ? "check" : "copy", size: 14 }), _jsx("span", { "aria-live": "polite", children: copied ? messages.copied : messages.copy })] })) : null] }));
35
48
  }
36
49
  /** A block of code or terminal output with a title, an optional line-number gutter and a copy button. */
37
50
  export function CodeBlock({ code, title, language, lineNumbers, copy: showCopy, className }) {
51
+ const { messages } = useLocale();
38
52
  const preRef = useRef(null);
39
53
  const { copied, copy } = useCopy(code, preRef);
40
- const lines = String(code || "").replace(/\n$/, "").split("\n");
54
+ const lines = code.replace(/\n$/, "").split("\n");
41
55
  const canCopy = showCopy !== false;
42
- return (_jsxs("figure", { className: cx("vk-codeblock", className), children: [title || language || canCopy ? (_jsx(CodeBlockHead, { title: title || language, showCopy: canCopy, copied: copied, onCopy: copy })) : null, _jsx("pre", { ref: preRef, className: cx("vk-codeblock-pre", lineNumbers && "vk-codeblock-numbered"), tabIndex: 0, "aria-label": title || (language ? language + " code" : "Code"), children: _jsx("code", { children: lineNumbers ? lines.map((l, i) => _jsx("span", { className: "vk-code-line", children: l + "\n" }, i)) : lines.join("\n") }) })] }));
56
+ return (_jsxs("figure", { className: cx("vk-codeblock", className), children: [title || language || canCopy ? (_jsx(CodeBlockHead, { title: title || language, showCopy: canCopy, copied: copied, onCopy: copy })) : null, _jsx("pre", { ref: preRef, className: cx("vk-codeblock-pre", lineNumbers && "vk-codeblock-numbered"), tabIndex: 0, "aria-label": title || (language ? messages.languageCode(language) : messages.code), children: _jsx("code", { children: lineNumbers ? lines.map((l, i) => _jsx("span", { className: "vk-code-line", children: l + "\n" }, i)) : lines.join("\n") }) })] }));
43
57
  }
@@ -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 { useEffect, useRef, useState } from "react";
4
5
  import { Popover } from "radix-ui";
5
6
  import { Icon } from "../Icon/Icon.js";
@@ -19,25 +20,27 @@ function optionWithValue(options, value) {
19
20
  }
20
21
  /** The end of the field: a clear button while there is text, else the chevron. */
21
22
  function FieldEnd({ clearable, clearLabel, onClear }) {
23
+ const { messages } = useLocale();
22
24
  if (!clearable)
23
25
  return _jsx(Icon, { name: "chevron-down", className: "vk-select-icon" });
24
- return (_jsx("button", { type: "button", tabIndex: -1, className: "vk-field-clear", "aria-label": clearLabel || "Clear", onMouseDown: (e) => e.preventDefault(), onClick: onClear, children: _jsx(Icon, { name: "x", size: 16 }) }));
26
+ return (_jsx("button", { type: "button", tabIndex: -1, className: "vk-field-clear", "aria-label": clearLabel || messages.clear, onMouseDown: (e) => { e.preventDefault(); }, onClick: onClear, children: _jsx(Icon, { name: "x", size: 16 }) }));
25
27
  }
26
28
  /** The popup, which ListPanel makes the Radix content (so a plain element, not a component): a <ul> listbox, or a <div> status when nothing matches. */
27
29
  function optionList({ listId, options, value, active, setActive, query, onPick, emptyText, ...labels }) {
28
30
  if (!options.length) {
29
- return (_jsx("div", { id: listId, className: "vk-select-menu vk-select-empty", role: "status", children: emptyText || "No matches for “" + query + "”" }));
31
+ return (_jsx("div", { id: listId, className: "vk-select-menu vk-select-empty", role: "status", children: emptyText }));
30
32
  }
31
33
  return (_jsx("ul", { id: listId, role: "listbox", className: "vk-select-menu", "aria-labelledby": labels["aria-labelledby"], "aria-label": labels["aria-label"], children: options.map((o, i) => {
32
34
  const isSel = o.value === value;
33
- return (_jsxs("li", { id: listId + "-" + i, "data-index": i, role: "option", "aria-selected": isSel ? "true" : "false", "aria-disabled": o.disabled ? "true" : undefined, className: cx("vk-select-option", i === active && "vk-select-option-active"), onMouseDown: (e) => e.preventDefault(), onMouseMove: () => {
35
+ return (_jsxs("li", { id: listId + "-" + String(i), "data-index": i, role: "option", "aria-selected": isSel ? "true" : "false", "aria-disabled": o.disabled ? "true" : undefined, className: cx("vk-select-option", i === active && "vk-select-option-active"), onMouseDown: (e) => { e.preventDefault(); }, onMouseMove: () => {
34
36
  if (!o.disabled && i !== active)
35
37
  setActive(i);
36
- }, onClick: () => onPick(o), children: [_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] }), isSel ? _jsx(Icon, { name: "check", size: 16, className: "vk-select-check" }) : null] }, o.value));
38
+ }, onClick: () => { onPick(o); }, children: [_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] }), isSel ? _jsx(Icon, { name: "check", size: 16, className: "vk-select-check" }) : null] }, o.value));
37
39
  }) }));
38
40
  }
39
41
  /** Searchable single select (WAI-ARIA combobox, list autocomplete). The list is a Radix Popover anchored to the field. */
40
42
  export function Combobox(props) {
43
+ const { messages } = useLocale();
41
44
  const options = normalizeOptions(props.options);
42
45
  const base = useUid("vk-combo");
43
46
  const inputId = props.id || base + "-input";
@@ -46,7 +49,7 @@ export function Combobox(props) {
46
49
  const [uncontrolledValue, setUncontrolledValue] = useState(props.defaultValue !== undefined ? props.defaultValue : null);
47
50
  const value = controlled ? props.value : uncontrolledValue;
48
51
  const selected = optionWithValue(options, value);
49
- const selectedLabel = selected ? String(selected.label) : "";
52
+ const selectedLabel = selected ? selected.label : "";
50
53
  const [text, setText] = useState(selectedLabel);
51
54
  const [query, setQuery] = useState("");
52
55
  const [open, setOpen] = useState(Boolean(props.defaultOpen));
@@ -82,7 +85,7 @@ export function Combobox(props) {
82
85
  if (!o || o.disabled)
83
86
  return;
84
87
  setValue(o);
85
- setText(String(o.label));
88
+ setText(o.label);
86
89
  setQuery("");
87
90
  close();
88
91
  };
@@ -93,25 +96,29 @@ export function Combobox(props) {
93
96
  setActive(i);
94
97
  };
95
98
  const selectedIn = (list) => {
96
- for (let i = 0; i < list.length; i++)
97
- if (list[i].value === value && !list[i].disabled)
98
- return i;
99
+ for (const [index, option] of list.entries())
100
+ if (option.value === value && !option.disabled)
101
+ return index;
99
102
  return nextEnabled(list, 0, 1);
100
103
  };
101
104
  const onKeyDown = (e) => {
102
105
  const key = e.key;
103
106
  if (key === "ArrowDown") {
104
107
  e.preventDefault();
105
- if (!open)
106
- return openAt(e.altKey ? -1 : selectedIn(filtered));
108
+ if (!open) {
109
+ openAt(e.altKey ? -1 : selectedIn(filtered));
110
+ return;
111
+ }
107
112
  const n = nextEnabled(filtered, active + 1, 1);
108
113
  if (n >= 0)
109
114
  setActive(n);
110
115
  }
111
116
  else if (key === "ArrowUp") {
112
117
  e.preventDefault();
113
- if (!open)
114
- return openAt(nextEnabled(filtered, filtered.length - 1, -1));
118
+ if (!open) {
119
+ openAt(nextEnabled(filtered, filtered.length - 1, -1));
120
+ return;
121
+ }
115
122
  const p = nextEnabled(filtered, active - 1, -1);
116
123
  if (p >= 0)
117
124
  setActive(p);
@@ -143,7 +150,7 @@ export function Combobox(props) {
143
150
  }
144
151
  };
145
152
  const a11y = omit(props, ["options", "placeholder", "className", "value", "defaultValue", "onChange", "disabled", "name", "id", "defaultOpen", "emptyText", "icon", "required", "clearLabel"]);
146
- const input = (_jsx("input", { ref: inputRef, id: inputId, type: "text", role: "combobox", autoComplete: "off", spellCheck: false, className: cx("vk-input", "vk-combobox-input", props.icon === "search" && "vk-has-lead"), placeholder: props.placeholder, disabled: props.disabled, required: props.required, "aria-autocomplete": "list", "aria-expanded": open ? "true" : "false", "aria-controls": listId, "aria-activedescendant": open && active >= 0 ? listId + "-" + active : undefined, value: text, onChange: (e) => {
153
+ const input = (_jsx("input", { ref: inputRef, id: inputId, type: "text", role: "combobox", autoComplete: "off", spellCheck: false, className: cx("vk-input", "vk-combobox-input", props.icon === "search" && "vk-has-lead"), placeholder: props.placeholder, disabled: props.disabled, required: props.required, "aria-autocomplete": "list", "aria-expanded": open ? "true" : "false", "aria-controls": listId, "aria-activedescendant": open && active >= 0 ? listId + "-" + String(active) : undefined, value: text, onChange: (e) => {
147
154
  const v = e.target.value;
148
155
  setText(v);
149
156
  setQuery(v);
@@ -181,7 +188,7 @@ export function Combobox(props) {
181
188
  setActive,
182
189
  query,
183
190
  onPick: commit,
184
- emptyText: props.emptyText,
191
+ emptyText: props.emptyText || messages.noMatches(query),
185
192
  "aria-label": props["aria-label"],
186
193
  "aria-labelledby": props["aria-labelledby"],
187
194
  }) }), props.name ? _jsx("input", { type: "hidden", name: props.name, value: value ?? "" }) : null] }) }));
@@ -20,7 +20,7 @@ const PANEL_STYLE = {
20
20
  "--vk-float-max": "max(96px, var(--radix-popper-available-height))",
21
21
  };
22
22
  const inside = (root, target) => Boolean(root.current && target instanceof Node && root.current.contains(target));
23
- const prevent = (e) => e.preventDefault();
23
+ const prevent = (e) => { e.preventDefault(); };
24
24
  /**
25
25
  * The listbox panel of Combobox and MultiSelect: Radix Popover content, portalled to the body and
26
26
  * placed 4px from the field (Popover.Anchor), at least as wide, flipping above when there's no room.
@@ -55,15 +55,26 @@ export function ListPanel({ rootRef, active, children }) {
55
55
  const node = nodeRef.current;
56
56
  if (!shown || !node || active < 0)
57
57
  return;
58
- const el = node.querySelector(`[data-index="${active}"]`);
58
+ const el = node.querySelector(`[data-index="${String(active)}"]`);
59
59
  if (!el)
60
60
  return;
61
- // Scroll the list only (scrollIntoView could also scroll the page).
62
- const top = el.offsetTop, bottom = top + el.offsetHeight;
63
- if (top < node.scrollTop)
64
- node.scrollTop = top;
65
- else if (bottom > node.scrollTop + node.clientHeight)
66
- node.scrollTop = bottom - node.clientHeight;
61
+ const reveal = () => {
62
+ // Scroll the list only (scrollIntoView could also scroll the page).
63
+ const top = el.offsetTop, bottom = top + el.offsetHeight;
64
+ if (top < node.scrollTop)
65
+ node.scrollTop = top;
66
+ else if (bottom > node.scrollTop + node.clientHeight)
67
+ node.scrollTop = bottom - node.clientHeight;
68
+ };
69
+ reveal();
70
+ // Radix measures and caps the panel after it mounts, and again when the viewport changes.
71
+ // Keep the active option visible as that available space or its text dimensions change.
72
+ if (typeof ResizeObserver === "undefined")
73
+ return;
74
+ const observer = new ResizeObserver(reveal);
75
+ observer.observe(node);
76
+ observer.observe(el);
77
+ return () => { observer.disconnect(); };
67
78
  }, [shown, active]);
68
79
  return (_jsx(Primitive.Portal, { children: _jsx(Primitive.Content, { asChild: true, ref: ref, side: "bottom", align: "start", sideOffset: 4, collisionPadding: 8, onOpenAutoFocus: prevent, onCloseAutoFocus: prevent,
69
80
  // The input handles its own Escape (close, then clear); Radix dismisses only from elsewhere.
@@ -71,5 +82,5 @@ export function ListPanel({ rootRef, active, children }) {
71
82
  e.preventDefault(); }, onInteractOutside: (e) => { if (ours(e.target))
72
83
  e.preventDefault(); },
73
84
  // Keep focus in the input when the panel itself is pressed.
74
- onMouseDown: (e) => e.preventDefault(), tabIndex: undefined, style: PANEL_STYLE, children: children }) }));
85
+ onMouseDown: (e) => { e.preventDefault(); }, tabIndex: undefined, style: PANEL_STYLE, children: children }) }));
75
86
  }