@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,53 +1,42 @@
1
1
  "use client";
2
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { useRef } from "react";
2
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useLocale } from "../../localization.js";
4
+ import { createElement } from "react";
4
5
  import { AlertDialog, Dialog as Primitive } from "radix-ui";
5
6
  import { IconButton } from "../IconButton/IconButton.js";
6
- import { focusables } from "../../internal/focusables.js";
7
- import { useIsoLayoutEffect } from "../../internal/useIsoLayoutEffect.js";
8
7
  import { cx } from "../../lib/cx.js";
9
8
  import { para } from "../../lib/text.js";
10
9
  /**
11
10
  * Modal dialog (Radix Dialog; Radix AlertDialog for `role="alertdialog"`): focus moves in and is
12
- * trapped, the page behind is inert and can't scroll, and closing returns focus to the opener.
11
+ * trapped, the page behind is inert and can't scroll, and closing returns focus to its Radix Trigger.
13
12
  */
14
13
  export function Dialog(props) {
15
- const { open, title, description, children, footer, size, role, closeLabel, className, side } = props;
14
+ const { open, defaultOpen, onOpenChange, onClose, trigger, children, size, role, className, side } = props;
16
15
  const alert = role === "alertdialog";
17
16
  // The same Radix parts either way; AlertDialog also ignores outside presses.
18
- const P = (alert ? AlertDialog : Primitive);
19
- const panelRef = useRef(null);
20
- const restoreRef = useRef(null);
21
- const dismissible = props.dismissible !== false && !alert;
22
- const closeOnBackdrop = dismissible && props.closeOnBackdrop !== false;
23
- // Handlers read the latest onClose.
24
- const onCloseRef = useRef(props.onClose);
25
- useIsoLayoutEffect(() => { onCloseRef.current = props.onClose; });
26
- // There is no Radix trigger: remember what had focus when the dialog opened, to return to it.
27
- useIsoLayoutEffect(() => {
28
- if (open)
29
- restoreRef.current = document.activeElement;
30
- }, [open]);
31
- const Description = para(description);
32
- return (_jsx(P.Root, { open: open, onOpenChange: (next) => { if (!next)
33
- onCloseRef.current?.(); }, children: _jsx(P.Portal, { children: _jsx(P.Overlay, { className: cx("vk-overlay", side ? "vk-overlay-drawer" : null), children: _jsxs(P.Content, { ref: panelRef, "aria-modal": "true", className: cx("vk-dialog", side ? "vk-drawer vk-drawer-" + side : "vk-dialog-" + (size || "md"), className), onOpenAutoFocus: (e) => {
34
- // The first field in the body (or [data-autofocus]), else the first footer button, else the panel.
35
- e.preventDefault();
36
- const panel = panelRef.current;
37
- if (!panel)
38
- return;
39
- const target = panel.querySelector("[data-autofocus]") || focusables(panel.querySelector(".vk-dialog-body"))[0] || focusables(panel.querySelector(".vk-dialog-footer"))[0] || panel;
40
- target.focus();
41
- }, onCloseAutoFocus: (e) => {
42
- e.preventDefault();
43
- const r = restoreRef.current;
44
- if (r && r.focus && document.contains(r))
45
- r.focus();
46
- }, onEscapeKeyDown: (e) => { if (!dismissible)
47
- e.preventDefault(); }, onPointerDownOutside: (e) => { if (!closeOnBackdrop)
48
- e.preventDefault(); }, children: [_jsxs("div", { className: "vk-dialog-header", children: [_jsxs("div", { className: "vk-dialog-heading", children: [_jsx(P.Title, { className: "vk-dialog-title", children: title }), description
49
- ? _jsx(P.Description, { asChild: true, children: _jsx(Description, { className: "vk-dialog-description", children: description }) })
50
- : null] }), dismissible
51
- ? _jsx(P.Close, { asChild: true, children: _jsx(IconButton, { icon: "x", label: closeLabel || "Close", className: "vk-dialog-close" }) })
52
- : null] }), children ? _jsx("div", { className: "vk-dialog-body", children: children }) : null, footer ? _jsx("div", { className: "vk-dialog-footer", children: footer }) : null] }) }) }) }));
17
+ const P = alert ? AlertDialog : Primitive;
18
+ const content = (_jsxs(_Fragment, { children: [_jsx(DialogHeader, { ...props }), children ? _jsx("div", { className: "vk-dialog-body", children: children }) : null, _jsx(DialogFooter, { ...props })] }));
19
+ const contentClass = cx("vk-dialog", side ? "vk-drawer vk-drawer-" + side : "vk-dialog-" + (size || "md"), className);
20
+ return (_jsxs(P.Root, { open: open, defaultOpen: defaultOpen, onOpenChange: (next) => { onOpenChange?.(next); if (!next)
21
+ onClose?.(); }, children: [trigger ? _jsx(P.Trigger, { asChild: true, children: trigger }) : null, _jsx(P.Portal, { children: _jsx(P.Overlay, { className: cx("vk-overlay", side ? "vk-overlay-drawer" : null), children: props.role === "alertdialog"
22
+ ? _jsx(AlertDialog.Content, { ...props.contentProps, "aria-modal": "true", className: contentClass, children: content })
23
+ : _jsx(Primitive.Content, { ...props.contentProps, "aria-modal": "true", className: contentClass, children: content }) }) })] }));
24
+ }
25
+ /** Styled title, description and native close control; Radix owns all interaction. */
26
+ function DialogHeader({ title, description, role, hideCloseButton, closeLabel }) {
27
+ const { messages } = useLocale();
28
+ const alert = role === "alertdialog";
29
+ const P = alert ? AlertDialog : Primitive;
30
+ return (_jsxs("div", { className: "vk-dialog-header", children: [_jsxs("div", { className: "vk-dialog-heading", children: [_jsx(P.Title, { className: "vk-dialog-title", children: title }), description
31
+ ? _jsx(P.Description, { asChild: true, children: createElement(para(description), { className: "vk-dialog-description" }, description) })
32
+ : null] }), !alert && !hideCloseButton
33
+ ? _jsx(Primitive.Close, { asChild: true, children: _jsx(IconButton, { icon: "x", label: closeLabel || messages.close, className: "vk-dialog-close" }) })
34
+ : null] }));
35
+ }
36
+ /** The footer only composes content and native AlertDialog actions. */
37
+ function DialogFooter(props) {
38
+ const { footer } = props;
39
+ return (footer || (props.role === "alertdialog" && (props.cancel || props.action))
40
+ ? _jsxs("div", { className: "vk-dialog-footer", children: [footer, props.role === "alertdialog" && props.cancel ? _jsx(AlertDialog.Cancel, { asChild: true, children: props.cancel }) : null, props.role === "alertdialog" && props.action ? _jsx(AlertDialog.Action, { asChild: true, children: props.action }) : null] })
41
+ : null);
53
42
  }
@@ -1,6 +1,8 @@
1
1
  import { type DialogProps } from "../Dialog/Dialog.js";
2
- export interface DrawerProps extends Omit<DialogProps, 'size'> {
2
+ type AsDrawer<Props> = Props extends DialogProps ? Omit<Props, 'size'> & {
3
3
  side?: 'right' | 'left';
4
- }
4
+ } : never;
5
+ export type DrawerProps = AsDrawer<DialogProps>;
5
6
  /** A modal panel that slides in from the side: a Dialog rendered as a sheet. */
6
7
  export declare function Drawer(props: DrawerProps): import("react/jsx-runtime").JSX.Element;
8
+ export {};
@@ -1,10 +1,10 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { createElement } from "react";
2
3
  import { SquareGlyph } from "../SquareGlyph/SquareGlyph.js";
3
4
  import { cx } from "../../lib/cx.js";
4
5
  import { para } from "../../lib/text.js";
5
6
  /** What a list, table or page shows when it has nothing in it yet. */
6
7
  export function EmptyState({ title, children, actions, glyph, headingAs, className }) {
7
8
  const HeadingTag = headingAs || "h3";
8
- const Body = para(children);
9
- return (_jsxs("div", { className: cx("vk-empty", className), children: [_jsxs("div", { className: "vk-empty-glyphs", "aria-hidden": "true", children: [_jsx(SquareGlyph, { children: glyph || "+" }), _jsx("span", { className: "vk-empty-glyph-ghost" }), _jsx("span", { className: "vk-empty-glyph-ghost" })] }), _jsx(HeadingTag, { className: "vk-empty-title", children: title }), children ? _jsx(Body, { className: "vk-empty-text", children: children }) : null, actions ? _jsx("div", { className: "vk-row vk-empty-actions", children: actions }) : null] }));
9
+ return (_jsxs("div", { className: cx("vk-empty", className), children: [_jsxs("div", { className: "vk-empty-glyphs", "aria-hidden": "true", children: [_jsx(SquareGlyph, { children: glyph || "+" }), _jsx("span", { className: "vk-empty-glyph-ghost" }), _jsx("span", { className: "vk-empty-glyph-ghost" })] }), _jsx(HeadingTag, { className: "vk-empty-title", children: title }), children ? createElement(para(children), { className: "vk-empty-text" }, children) : null, actions ? _jsx("div", { className: "vk-row vk-empty-actions", children: actions }) : null] }));
10
10
  }
@@ -1,11 +1,13 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useLocale } from "../../localization.js";
3
4
  import { useEffect, useRef } from "react";
4
5
  import { Icon } from "../Icon/Icon.js";
5
6
  /** A form's problems at the top of the form after a failed submit; each item links to its field. */
6
7
  export function ErrorSummary(props) {
8
+ const { messages } = useLocale();
7
9
  const ref = useRef(null);
8
- const errors = props.errors || [];
10
+ const errors = props.errors;
9
11
  // Focus follows a change in the number of errors, not a change of autoFocus: the effect reads the latest value.
10
12
  const autoFocusRef = useRef(props.autoFocus);
11
13
  useEffect(() => { autoFocusRef.current = props.autoFocus; }, [props.autoFocus]);
@@ -15,13 +17,13 @@ export function ErrorSummary(props) {
15
17
  }, [errors.length]);
16
18
  if (!errors.length)
17
19
  return null;
18
- const title = props.title || (errors.length === 1 ? "Fix 1 problem to continue" : "Fix " + errors.length + " problems to continue");
20
+ const title = props.title || messages.fixProblems(errors.length);
19
21
  return (_jsxs("div", { ref: ref, tabIndex: -1, role: "alert", className: "vk-alert vk-alert-danger vk-error-summary", "aria-labelledby": "vk-errsum-title", children: [_jsx(Icon, { name: "circle-alert", size: 18, className: "vk-alert-icon" }), _jsxs("div", { className: "vk-alert-body", children: [_jsx("p", { id: "vk-errsum-title", className: "vk-alert-title", children: title }), _jsx("ul", { className: "vk-error-summary-list", children: errors.map(({ field, message }) => (_jsx("li", { children: field ? (_jsx("a", { href: "#" + field, className: "vk-link", onClick: (ev) => {
20
22
  const el = document.getElementById(field);
21
23
  if (el) {
22
24
  ev.preventDefault();
23
25
  el.focus();
24
- if (el.scrollIntoView)
26
+ if (typeof Reflect.get(el, "scrollIntoView") === "function")
25
27
  el.scrollIntoView({ block: "center" });
26
28
  }
27
29
  }, children: message })) : (message) }, field || message))) })] })] }));
@@ -2,5 +2,5 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { cx } from "../../lib/cx.js";
3
3
  /** Question-and-answer panels as a description list. */
4
4
  export function FaqList({ items, columns }) {
5
- return (_jsx("dl", { className: cx("vk-faq-list", columns === 2 && "vk-faq-list-2"), children: (items || []).map((item) => (_jsxs("div", { className: "vk-faq-item", children: [_jsx("dt", { className: "vk-faq-question", children: item.question }), _jsx("dd", { className: "vk-faq-answer", children: item.answer })] }, item.question))) }));
5
+ return (_jsx("dl", { className: cx("vk-faq-list", columns === 2 && "vk-faq-list-2"), children: items.map((item) => (_jsxs("div", { className: "vk-faq-item", children: [_jsx("dt", { className: "vk-faq-question", children: item.question }), _jsx("dd", { className: "vk-faq-answer", children: item.answer })] }, item.question))) }));
6
6
  }
@@ -13,10 +13,10 @@ export function Field(props) {
13
13
  const control = isValidElement(props.children)
14
14
  ? cloneElement(props.children, { id, "aria-labelledby": labelId, "aria-describedby": describedBy(id, props.hint, props.error), "aria-invalid": props.error ? true : undefined })
15
15
  : props.children;
16
- // A custom combobox only takes focus from its label; the click is not forwarded to it.
16
+ // A contenteditable editor is not a labelable HTML element.
17
17
  const focusControl = (e) => {
18
18
  const el = document.getElementById(id);
19
- if (el && el.getAttribute("role") === "combobox") {
19
+ if (el?.isContentEditable) {
20
20
  e.preventDefault();
21
21
  el.focus();
22
22
  }
@@ -1,14 +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 { createElement, useRef, useState } from "react";
4
5
  import { Icon } from "../Icon/Icon.js";
5
6
  import { IconButton } from "../IconButton/IconButton.js";
6
7
  import { useUid } from "../../internal/useUid.js";
7
8
  import { cx } from "../../lib/cx.js";
8
- import { formatBytes } from "../../lib/format.js";
9
+ import { formatNumber } from "../../lib/format.js";
9
10
  import { para } from "../../lib/text.js";
10
11
  /** Drop zone with a browse button for attaching files, and a list of the chosen files with sizes and errors. */
11
12
  export function FileUpload(props) {
13
+ const { locale, messages } = useLocale();
14
+ const sizeLabel = (size) => {
15
+ const value = size < 1024 ? size : size < 1048576 ? size / 1024 : size / 1048576;
16
+ const decimals = size >= 1048576 || (size >= 1024 && size < 10240) ? 1 : 0;
17
+ return formatNumber(value, { locale, minimumFractionDigits: decimals, maximumFractionDigits: decimals }) + (size < 1024 ? " B" : size < 1048576 ? " KB" : " MB");
18
+ };
12
19
  const uid = useUid("vk-file");
13
20
  const id = props.id || uid;
14
21
  const [files, setFiles] = useState(props.defaultFiles || []);
@@ -21,27 +28,28 @@ export function FileUpload(props) {
21
28
  };
22
29
  const accept = (list) => {
23
30
  const incoming = Array.from(list, (f) => {
24
- const error = props.maxSize && f.size > props.maxSize ? "Larger than " + formatBytes(props.maxSize) + "." : null;
31
+ const error = props.maxSize && f.size > props.maxSize ? messages.fileTooLarge(sizeLabel(props.maxSize)) : null;
25
32
  return { name: f.name, size: f.size, file: f, error };
26
33
  });
27
34
  update(props.multiple ? files.concat(incoming) : incoming.slice(0, 1));
28
35
  };
29
- const remove = (i) => update(files.filter((_, j) => j !== i));
30
- const Hint = para(props.hint);
36
+ const remove = (i) => { update(files.filter((_, j) => j !== i)); };
31
37
  return (_jsxs("div", { className: cx("vk-upload", props.className), children: [_jsxs("div", { className: cx("vk-dropzone", dragging && "vk-dropzone-active", props.disabled && "vk-dropzone-disabled"), onDragOver: (e) => {
32
38
  if (props.disabled)
33
39
  return;
34
40
  e.preventDefault();
35
41
  setDragging(true);
36
- }, onDragLeave: () => setDragging(false), onDrop: (e) => {
42
+ }, onDragLeave: () => { setDragging(false); }, onDrop: (e) => {
37
43
  e.preventDefault();
38
44
  setDragging(false);
39
45
  if (!props.disabled)
40
46
  accept(e.dataTransfer.files);
41
- }, children: [_jsx(Icon, { name: "upload", className: "vk-dropzone-icon" }), _jsxs("div", { className: "vk-dropzone-text", children: [_jsxs("p", { className: "vk-dropzone-title", children: [props.title || (props.multiple ? "Drop files here" : "Drop a file here"), " or ", _jsx("button", { type: "button", className: "vk-link vk-dropzone-browse", disabled: props.disabled, onClick: () => inputRef.current?.click(), children: "browse" })] }), props.hint ? _jsx(Hint, { className: "vk-dropzone-hint", children: props.hint }) : null] }), _jsx("input", { ref: inputRef, id: id, type: "file", className: "vk-sr-only", tabIndex: -1, accept: props.accept, multiple: props.multiple, disabled: props.disabled, name: props.name, "aria-label": props["aria-label"], "aria-labelledby": props["aria-labelledby"], "aria-describedby": props["aria-describedby"], onChange: (e) => {
47
+ }, children: [_jsx(Icon, { name: "upload", className: "vk-dropzone-icon" }), _jsxs("div", { className: "vk-dropzone-text", children: [_jsxs("p", { className: "vk-dropzone-title", children: [props.title || (props.multiple ? messages.dropFiles : messages.dropFile), messages.or, _jsx("button", { type: "button", className: "vk-link vk-dropzone-browse", disabled: props.disabled, onClick: () => inputRef.current?.click(), children: messages.browse })] }), props.hint ? createElement(para(props.hint), { className: "vk-dropzone-hint" }, props.hint) : null] }), _jsx("input", { ref: inputRef, id: id, type: "file", className: "vk-sr-only", tabIndex: -1, accept: props.accept, multiple: props.multiple, disabled: props.disabled, name: props.name, "aria-label": props["aria-label"], "aria-labelledby": props["aria-labelledby"], "aria-describedby": props["aria-describedby"], onChange: (e) => {
42
48
  // A file input always has a FileList.
43
- accept(e.target.files);
49
+ const chosen = e.target.files;
50
+ if (chosen)
51
+ accept(chosen);
44
52
  // Clear it so choosing the same file again still fires onChange.
45
53
  e.target.value = "";
46
- } })] }), files.length ? (_jsx("ul", { className: "vk-upload-list", children: files.map((f, i) => (_jsxs("li", { className: cx("vk-upload-item", f.error && "vk-upload-item-error"), children: [_jsx(Icon, { name: f.error ? "circle-alert" : "file", size: 16, className: "vk-upload-icon" }), _jsx("span", { className: "vk-upload-name", children: f.name }), f.error ? _jsx("span", { className: "vk-upload-error", children: f.error }) : _jsx("span", { className: "vk-upload-size", children: formatBytes(f.size) }), _jsx(IconButton, { icon: "x", size: 16, label: "Remove " + f.name, onClick: () => remove(i) })] }, f.name + i))) })) : null] }));
54
+ } })] }), files.length ? (_jsx("ul", { className: "vk-upload-list", children: files.map((f, i) => (_jsxs("li", { className: cx("vk-upload-item", f.error && "vk-upload-item-error"), children: [_jsx(Icon, { name: f.error ? "circle-alert" : "file", size: 16, className: "vk-upload-icon" }), _jsx("span", { className: "vk-upload-name", children: f.name }), f.error ? _jsx("span", { className: "vk-upload-error", children: f.file && props.maxSize && f.size > props.maxSize ? messages.fileTooLarge(sizeLabel(props.maxSize)) : f.error }) : _jsx("span", { className: "vk-upload-size", children: sizeLabel(f.size) }), _jsx(IconButton, { icon: "x", size: 16, label: messages.remove(f.name), onClick: () => { remove(i); } })] }, f.name + String(i)))) })) : null] }));
47
55
  }
@@ -1,9 +1,9 @@
1
1
  import { type CSSProperties, type ReactNode } from "react";
2
- import type { ElementTag, PolymorphicProps, SpaceStep } from "../../types.js";
2
+ import type { ElementTag, PolymorphicProps } from "../../types.js";
3
3
  export interface GridOwnProps {
4
4
  columns?: number;
5
5
  min?: string;
6
- gap?: SpaceStep | string;
6
+ gap?: string;
7
7
  children?: ReactNode;
8
8
  className?: string;
9
9
  style?: CSSProperties;
@@ -181,6 +181,7 @@ export declare function Grid<T extends ElementTag = "div">({ as, columns, min, g
181
181
  gridRowEnd?: import("csstype").Property.GridRowEnd | undefined;
182
182
  gridRowStart?: import("csstype").Property.GridRowStart | undefined;
183
183
  gridTemplateAreas?: import("csstype").Property.GridTemplateAreas | undefined;
184
+ gridTemplateColumns: import("csstype").Property.GridTemplateColumns<string | number>;
184
185
  gridTemplateRows?: import("csstype").Property.GridTemplateRows<string | number> | undefined;
185
186
  hangingPunctuation?: import("csstype").Property.HangingPunctuation | undefined;
186
187
  height?: import("csstype").Property.Height<string | number> | undefined;
@@ -468,6 +469,7 @@ export declare function Grid<T extends ElementTag = "div">({ as, columns, min, g
468
469
  flex?: import("csstype").Property.Flex<string | number> | undefined;
469
470
  flexFlow?: import("csstype").Property.FlexFlow | undefined;
470
471
  font?: import("csstype").Property.Font | undefined;
472
+ gap: import("csstype").Property.Gap<string | number>;
471
473
  grid?: import("csstype").Property.Grid | undefined;
472
474
  gridArea?: import("csstype").Property.GridArea | undefined;
473
475
  gridColumn?: import("csstype").Property.GridColumn | undefined;
@@ -868,7 +870,5 @@ export declare function Grid<T extends ElementTag = "div">({ as, columns, min, g
868
870
  colorInterpolation?: import("csstype").Property.ColorInterpolation | undefined;
869
871
  colorRendering?: import("csstype").Property.ColorRendering | undefined;
870
872
  glyphOrientationVertical?: import("csstype").Property.GlyphOrientationVertical | undefined;
871
- gap: import("csstype").Property.Gap<string | number>;
872
- gridTemplateColumns: import("csstype").Property.GridTemplateColumns<string | number>;
873
873
  };
874
- } & Omit<GridProps<T>, "as" | "children" | "className" | "columns" | "gap" | "min" | "style">, string | import("react").JSXElementConstructor<any>>;
874
+ } & Omit<GridProps<T>, "min" | "columns" | "gap" | "style" | "className" | "children" | "as">, string | import("react").JSXElementConstructor<any>>;
@@ -4,6 +4,6 @@ import { space } from "../../lib/space.js";
4
4
  /** A responsive grid: a fixed number of columns, or as many columns of at least `min` width as fit. */
5
5
  export function Grid({ as, columns, min, gap, children, className, style, ...rest }) {
6
6
  const fixed = typeof columns === "number";
7
- const template = fixed ? "repeat(" + columns + ", minmax(0, 1fr))" : "repeat(auto-fit, minmax(min(" + (min || "16rem") + ", 100%), 1fr))";
7
+ const template = fixed ? "repeat(" + String(columns) + ", minmax(0, 1fr))" : "repeat(auto-fit, minmax(min(" + (min || "16rem") + ", 100%), 1fr))";
8
8
  return createElement(as || "div", { className: cx("vk-layout-grid", fixed ? "vk-layout-grid-fixed" : null, className), style: { gap: space(gap, "lg"), gridTemplateColumns: template, ...style }, ...rest }, children);
9
9
  }
@@ -6,6 +6,7 @@ export const HEADING_SIZE = { 1: "heading-1", 2: "heading-2", 3: "title", 4: "ti
6
6
  export function Heading({ level: levelProp, size, id, children, className }) {
7
7
  const level = levelProp || 2;
8
8
  const style = size || HEADING_SIZE[level];
9
- const Tag = `h${level}`;
9
+ const tags = { 1: "h1", 2: "h2", 3: "h3", 4: "h4" };
10
+ const Tag = tags[level];
10
11
  return _jsx(Tag, { id: id, className: cx("vk-heading", "vk-text-" + style, className), children: children });
11
12
  }
@@ -1,9 +1,11 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { cx } from "../../lib/cx.js";
3
3
  import { ICONS } from "../../lib/icons.js";
4
+ // Lookup remains optional at the runtime boundary for untyped consumers.
5
+ const definitions = ICONS;
4
6
  /** Lucide outline icon, stroke currentColor. */
5
7
  export function Icon({ name, size, className }) {
6
- const def = ICONS[name];
8
+ const def = definitions[name];
7
9
  if (!def)
8
10
  return null;
9
11
  const px = size || def.size;
@@ -11,7 +13,7 @@ export function Icon({ name, size, className }) {
11
13
  const circles = def.circle ? (Array.isArray(def.circle) ? def.circle : [def.circle]) : [];
12
14
  const kids = [
13
15
  ...def.d.map((d, i) => _jsx("path", { d: d, ...common }, i)),
14
- ...circles.map((c, i) => _jsx("circle", { ...c, ...common }, "c" + i)),
16
+ ...circles.map((c, i) => _jsx("circle", { ...c, ...common }, "c" + String(i))),
15
17
  ];
16
18
  return (_jsx("svg", { className: cx("vk-icon", className), viewBox: "0 0 24 24", width: px, height: px, fill: "none", "aria-hidden": "true", children: kids }));
17
19
  }
@@ -1,7 +1,7 @@
1
1
  import { type CSSProperties, type ReactNode } from "react";
2
- import type { ElementTag, PolymorphicProps, SpaceStep } from "../../types.js";
2
+ import type { ElementTag, PolymorphicProps } from "../../types.js";
3
3
  export interface InlineOwnProps {
4
- gap?: SpaceStep | string;
4
+ gap?: string;
5
5
  align?: CSSProperties['alignItems'];
6
6
  justify?: CSSProperties['justifyContent'];
7
7
  wrap?: boolean;
@@ -16,6 +16,7 @@ export declare function Inline<T extends ElementTag = "div">({ as, gap, align, j
16
16
  style: {
17
17
  accentColor?: import("csstype").Property.AccentColor | undefined;
18
18
  alignContent?: import("csstype").Property.AlignContent | undefined;
19
+ alignItems: import("csstype").Property.AlignItems;
19
20
  alignSelf?: import("csstype").Property.AlignSelf | undefined;
20
21
  alignTracks?: import("csstype").Property.AlignTracks | undefined;
21
22
  alignmentBaseline?: import("csstype").Property.AlignmentBaseline | undefined;
@@ -142,6 +143,7 @@ export declare function Inline<T extends ElementTag = "div">({ as, gap, align, j
142
143
  flexDirection?: import("csstype").Property.FlexDirection | undefined;
143
144
  flexGrow?: import("csstype").Property.FlexGrow | undefined;
144
145
  flexShrink?: import("csstype").Property.FlexShrink | undefined;
146
+ flexWrap: string;
145
147
  float?: import("csstype").Property.Float | undefined;
146
148
  floodColor?: import("csstype").Property.FloodColor | undefined;
147
149
  floodOpacity?: import("csstype").Property.FloodOpacity | undefined;
@@ -199,6 +201,7 @@ export declare function Inline<T extends ElementTag = "div">({ as, gap, align, j
199
201
  insetInlineStart?: import("csstype").Property.InsetInlineStart<string | number> | undefined;
200
202
  interpolateSize?: import("csstype").Property.InterpolateSize | undefined;
201
203
  isolation?: import("csstype").Property.Isolation | undefined;
204
+ justifyContent: import("csstype").Property.JustifyContent | undefined;
202
205
  justifyItems?: import("csstype").Property.JustifyItems | undefined;
203
206
  justifySelf?: import("csstype").Property.JustifySelf | undefined;
204
207
  justifyTracks?: import("csstype").Property.JustifyTracks | undefined;
@@ -467,6 +470,7 @@ export declare function Inline<T extends ElementTag = "div">({ as, gap, align, j
467
470
  flex?: import("csstype").Property.Flex<string | number> | undefined;
468
471
  flexFlow?: import("csstype").Property.FlexFlow | undefined;
469
472
  font?: import("csstype").Property.Font | undefined;
473
+ gap: import("csstype").Property.Gap<string | number>;
470
474
  grid?: import("csstype").Property.Grid | undefined;
471
475
  gridArea?: import("csstype").Property.GridArea | undefined;
472
476
  gridColumn?: import("csstype").Property.GridColumn | undefined;
@@ -867,9 +871,5 @@ export declare function Inline<T extends ElementTag = "div">({ as, gap, align, j
867
871
  colorInterpolation?: import("csstype").Property.ColorInterpolation | undefined;
868
872
  colorRendering?: import("csstype").Property.ColorRendering | undefined;
869
873
  glyphOrientationVertical?: import("csstype").Property.GlyphOrientationVertical | undefined;
870
- gap: import("csstype").Property.Gap<string | number>;
871
- alignItems: import("csstype").Property.AlignItems;
872
- justifyContent: import("csstype").Property.JustifyContent | undefined;
873
- flexWrap: string;
874
874
  };
875
- } & Omit<InlineProps<T>, "align" | "as" | "children" | "className" | "gap" | "justify" | "style" | "wrap">, string | import("react").JSXElementConstructor<any>>;
875
+ } & Omit<InlineProps<T>, "gap" | "style" | "className" | "children" | "wrap" | "justify" | "as" | "align">, string | import("react").JSXElementConstructor<any>>;
@@ -1,44 +1,46 @@
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 { ChartFrame, cellLabel, cellNumber, chartKeys, chartTooltip, seriesColor, useChart } from "../../charts/chart.js";
4
5
  import { niceTicks } from "../../lib/math.js";
5
6
  /** Lines for change over time: one to four series, each labeled directly at its end. */
6
7
  export function LineChart(props) {
7
- const c = useChart(props);
8
- const data = props.data || [];
8
+ const { messages } = useLocale(props.locale);
9
+ const { setPlotElement, width, active, setActive, fmt, series, xKey } = useChart(props);
10
+ const data = props.data;
9
11
  const height = props.height || 240;
10
- const label = c.series.length <= 4 && props.directLabels !== false;
12
+ const label = series.length <= 4 && props.directLabels !== false;
11
13
  const pad = { top: 12, right: label ? 96 : 12, bottom: 28, left: 48 };
12
14
  let max = 0;
13
15
  for (const d of data)
14
- for (const s of c.series)
16
+ for (const s of series)
15
17
  max = Math.max(max, cellNumber(d, s.key));
16
- const ticks = niceTicks(max, 4), top = ticks[ticks.length - 1];
17
- const plotW = Math.max(10, c.width - pad.left - pad.right), plotH = height - pad.top - pad.bottom;
18
+ const ticks = niceTicks(max, 4), top = ticks.at(-1) ?? 1;
19
+ const plotW = Math.max(10, width - pad.left - pad.right), plotH = height - pad.top - pad.bottom;
18
20
  const x = (i) => pad.left + (data.length < 2 ? plotW / 2 : (plotW * i) / (data.length - 1));
19
21
  const y = (v) => pad.top + plotH - (v / top) * plotH;
20
- const fmtTick = props.tickFormat || c.fmt;
22
+ const fmtTick = props.tickFormat || fmt;
21
23
  // Label every nth point so x labels stay about 72px apart.
22
24
  const every = Math.max(1, Math.ceil(data.length / Math.max(2, Math.floor(plotW / 72))));
23
- const view = { ...props, data, series: c.series, format: c.fmt, xKey: c.xKey };
25
+ const view = { ...props, data, series, format: fmt, xKey };
24
26
  const lastY = [];
25
27
  const onMouseMove = (e) => {
26
28
  const r = e.currentTarget.getBoundingClientRect(), px = e.clientX - r.left;
27
29
  const i = Math.round(((px - pad.left) / plotW) * (data.length - 1));
28
- c.setActive(Math.max(0, Math.min(data.length - 1, i)));
30
+ setActive(Math.max(0, Math.min(data.length - 1, i)));
29
31
  };
30
- return (_jsx(ChartFrame, { ...view, children: _jsxs("div", { ref: c.ref, className: "vk-chart-plot", tabIndex: 0, role: "img", "aria-label": (props.title || "Line chart") + ". Use the arrow keys to read each value.", onKeyDown: chartKeys(c, data.length), onMouseLeave: () => c.setActive(null), onBlur: () => c.setActive(null), onMouseMove: onMouseMove, children: [_jsxs("svg", { width: c.width, height: height, viewBox: "0 0 " + c.width + " " + height, "aria-hidden": "true", className: "vk-chart-svg", children: [ticks.map((t) => (_jsxs("g", { children: [_jsx("line", { x1: pad.left, x2: pad.left + plotW, y1: y(t), y2: y(t), className: t === 0 ? "vk-chart-baseline" : "vk-chart-grid" }), _jsx("text", { x: pad.left - 8, y: y(t), dy: "0.32em", textAnchor: "end", className: "vk-chart-tick", children: fmtTick(t) })] }, t))), data.map((d, i) => i % every === 0 || i === data.length - 1 ? _jsx("text", { x: x(i), y: height - 8, textAnchor: i === 0 ? "start" : i === data.length - 1 ? "end" : "middle", className: "vk-chart-tick", children: cellLabel(d, c.xKey) }, "x" + i) : null), c.active != null ? _jsx("line", { x1: x(c.active), x2: x(c.active), y1: pad.top, y2: pad.top + plotH, className: "vk-chart-crosshair" }) : null, c.series.map((s, si) => {
31
- const pts = data.map((d, i) => x(i) + "," + y(cellNumber(d, s.key))).join(" ");
32
+ return (_jsx(ChartFrame, { ...view, children: _jsxs("div", { ref: setPlotElement, className: "vk-chart-plot", tabIndex: 0, role: "img", "aria-label": messages.chartInstructions(props.title || messages.lineChart), onKeyDown: chartKeys({ active, setActive }, data.length), onMouseLeave: () => { setActive(null); }, onBlur: () => { setActive(null); }, onMouseMove: onMouseMove, children: [_jsxs("svg", { width: width, height: height, viewBox: `0 0 ${String(width)} ${String(height)}`, "aria-hidden": "true", className: "vk-chart-svg", children: [ticks.map((t) => (_jsxs("g", { children: [_jsx("line", { x1: pad.left, x2: pad.left + plotW, y1: y(t), y2: y(t), className: t === 0 ? "vk-chart-baseline" : "vk-chart-grid" }), _jsx("text", { x: pad.left - 8, y: y(t), dy: "0.32em", textAnchor: "end", className: "vk-chart-tick", children: fmtTick(t) })] }, t))), data.map((d, i) => i % every === 0 || i === data.length - 1 ? _jsx("text", { x: x(i), y: height - 8, textAnchor: i === 0 ? "start" : i === data.length - 1 ? "end" : "middle", className: "vk-chart-tick", children: cellLabel(d, xKey) }, `x${String(i)}`) : null), active != null ? _jsx("line", { x1: x(active), x2: x(active), y1: pad.top, y2: pad.top + plotH, className: "vk-chart-crosshair" }) : null, series.map((s, si) => {
33
+ const pts = data.map((d, i) => `${String(x(i))},${String(y(cellNumber(d, s.key)))}`).join(" ");
32
34
  return _jsx("polyline", { points: pts, fill: "none", stroke: seriesColor(si), strokeWidth: 2, strokeLinejoin: "round", strokeLinecap: "round" }, s.key);
33
- }), c.series.map((s, si) => {
35
+ }), series.map((s, si) => {
34
36
  // A point on each line at the active row, or at the last one.
35
- const i = c.active == null ? data.length - 1 : c.active;
37
+ const i = active == null ? data.length - 1 : active;
36
38
  const d = data[i];
37
39
  if (!d)
38
40
  return null;
39
41
  return _jsx("circle", { cx: x(i), cy: y(cellNumber(d, s.key)), r: 4, fill: seriesColor(si), className: "vk-chart-point" }, "p" + s.key);
40
42
  }), label
41
- ? c.series.map((s) => {
43
+ ? series.map((s) => {
42
44
  const d = data[data.length - 1];
43
45
  if (!d)
44
46
  return null;
@@ -49,5 +51,5 @@ export function LineChart(props) {
49
51
  lastY.push(ly);
50
52
  return _jsx("text", { x: x(data.length - 1) + 10, y: ly, dy: "0.32em", className: "vk-chart-direct", children: s.label }, "l" + s.key);
51
53
  })
52
- : null] }), chartTooltip(view, c.active, c.active == null ? 0 : x(c.active), c.width)] }) }));
54
+ : null] }), chartTooltip(view, active, active == null ? 0 : x(active), width)] }) }));
53
55
  }
@@ -4,7 +4,7 @@ export type LinkComponent = ElementType<{
4
4
  href: string;
5
5
  className?: string;
6
6
  children?: ReactNode;
7
- } & Record<string, unknown>>;
7
+ } & Record<string, unknown>, "a">;
8
8
  export interface LinkProviderProps {
9
9
  component: LinkComponent;
10
10
  children?: ReactNode;
@@ -8,14 +8,18 @@ export const LinkContext = createContext(null);
8
8
  * Hash, external, mailto: and tel: links, and links with target or download, stay plain <a>.
9
9
  */
10
10
  export function LinkProvider({ component, children }) {
11
- return _jsx(LinkContext.Provider, { value: component || null, children: children });
11
+ return _jsx(LinkContext.Provider, { value: component, children: children });
12
12
  }
13
13
  /** Hash links, links with a scheme (https:, mailto:, tel:) and protocol-relative links. */
14
14
  export const PLAIN_HREF = /^(#|[a-z][a-z0-9+.-]*:|\/\/)/i;
15
+ /** The router adapter is an existing component type supplied by the provider. */
16
+ const RouterAnchor = forwardRef(function RouterAnchor({ component: Component, href, ...props }, ref) {
17
+ return _jsx(Component, { ...props, href: href, ref: ref });
18
+ });
15
19
  /** The <a> behind every link in the system: the LinkProvider's component for internal links, else a plain <a>. */
16
20
  export const Anchor = forwardRef(function Anchor(props, ref) {
17
21
  const Comp = useContext(LinkContext);
18
22
  if (!Comp || typeof props.href !== "string" || PLAIN_HREF.test(props.href) || props.target || props.download)
19
23
  return _jsx("a", { ref: ref, ...props });
20
- return _jsx(Comp, { ref: ref, ...props });
24
+ return _jsx(RouterAnchor, { component: Comp, ...props, href: props.href, ref: ref });
21
25
  });
@@ -1,4 +1,4 @@
1
- import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { Anchor } from "../LinkProvider/LinkProvider.js";
3
3
  import { cx } from "../../lib/cx.js";
4
4
  /** Rows of records: people, files, notifications, recent items. */
@@ -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 { Icon } from "../Icon/Icon.js";
4
5
  import { Anchor } from "../LinkProvider/LinkProvider.js";
@@ -6,8 +7,7 @@ import { cx } from "../../lib/cx.js";
6
7
  import { para } from "../../lib/text.js";
7
8
  // The text under the image.
8
9
  function MediaCardBody({ title, eyebrow, meta, description, badge, href, linkLabel, outlined }) {
9
- const Description = para(description);
10
- return (_jsxs("div", { className: "vk-media-card-body", children: [eyebrow ? _jsx("span", { className: "vk-card-eyebrow", children: eyebrow }) : null, _jsxs("span", { className: cx(outlined ? "vk-card-title" : "vk-media-card-title", "vk-media-title-row"), children: [title, badge ? _jsx(Badge, { children: badge }) : null] }), meta ? _jsx("span", { className: "vk-media-card-meta", children: meta }) : null, description ? (_jsx(Description, { className: outlined ? "vk-card-body" : "vk-media-card-services", children: description })) : null, href && linkLabel ? (_jsxs("span", { className: "vk-media-card-link", children: [_jsx("span", { children: linkLabel }), _jsx(Icon, { name: "arrow-up-right", className: "vk-media-card-arrow" })] })) : null] }));
10
+ return (_jsxs("div", { className: "vk-media-card-body", children: [eyebrow ? _jsx("span", { className: "vk-card-eyebrow", children: eyebrow }) : null, _jsxs("span", { className: cx(outlined ? "vk-card-title" : "vk-media-card-title", "vk-media-title-row"), children: [title, badge ? _jsx(Badge, { children: badge }) : null] }), meta ? _jsx("span", { className: "vk-media-card-meta", children: meta }) : null, description ? (createElement(para(description), { className: outlined ? "vk-card-body" : "vk-media-card-services" }, description)) : null, href && linkLabel ? (_jsxs("span", { className: "vk-media-card-link", children: [_jsx("span", { children: linkLabel }), _jsx(Icon, { name: "arrow-up-right", className: "vk-media-card-arrow" })] })) : null] }));
11
11
  }
12
12
  // With an href the whole card is one link; external links open in a new tab.
13
13
  function MediaCardWrap({ href, children }) {
@@ -1,53 +1,16 @@
1
1
  "use client";
2
- import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { useRef, useState } from "react";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { useLocale } from "../../localization.js";
4
4
  import { DropdownMenu as Primitive } from "radix-ui";
5
5
  import { Icon } from "../Icon/Icon.js";
6
- import { focusables } from "../../internal/focusables.js";
7
6
  import { cx } from "../../lib/cx.js";
8
- import { MenuEntries, useDeferredSelect, useFocusOnOpen, moveFocusNow } from "./entries.js";
7
+ import { MenuEntries } from "./entries.js";
9
8
  /** Menu button (WAI-ARIA), built on Radix DropdownMenu. */
10
9
  export function Menu({ items, label, icon, triggerLabel, variant, size, align, disabled, className }) {
11
- const [open, setOpen] = useState(false);
12
- // Which item takes focus as the menu opens: the last one after ↑ on the trigger, else the first.
13
- const openWith = useRef("first");
14
- // Set when Tab closed the menu: focus moves on from the trigger in that direction.
15
- const tabOut = useRef(0);
16
- const triggerRef = useRef(null);
17
- const { defer, flush } = useDeferredSelect();
18
- const { arm, onFocus } = useFocusOnOpen();
19
- const onOpenChange = (next) => {
20
- arm(next ? openWith.current : null);
21
- setOpen(next);
22
- };
10
+ const { messages } = useLocale();
23
11
  // An icon with no label makes an icon button, named by triggerLabel.
24
12
  const iconOnly = label ? undefined : icon;
25
- return (_jsx("div", { className: cx("vk-menu-root", className), children: _jsxs(Primitive.Root, { open: open, onOpenChange: onOpenChange, modal: false, children: [_jsx(Primitive.Trigger, { ref: triggerRef, disabled: disabled, className: iconOnly ? "vk-icon-btn vk-icon-btn-" + (variant || "ghost") : cx("vk-btn", "vk-btn-" + (variant || "outline"), size === "sm" ? "vk-btn-sm" : null), "aria-label": iconOnly ? triggerLabel || "More actions" : undefined, title: iconOnly ? triggerLabel || "More actions" : undefined, onPointerDown: () => { openWith.current = "first"; }, onKeyDown: (e) => {
26
- openWith.current = "first";
27
- if (e.key === "ArrowUp" && !disabled) {
28
- e.preventDefault();
29
- openWith.current = "last";
30
- onOpenChange(true);
31
- }
32
- }, children: iconOnly
13
+ return (_jsx("div", { className: cx("vk-menu-root", className), children: _jsxs(Primitive.Root, { children: [_jsx(Primitive.Trigger, { disabled: disabled, className: iconOnly ? "vk-icon-btn vk-icon-btn-" + (variant || "ghost") : cx("vk-btn", "vk-btn-" + (variant || "outline"), size === "sm" ? "vk-btn-sm" : null), "aria-label": iconOnly ? triggerLabel || messages.moreActions : undefined, title: iconOnly ? triggerLabel || messages.moreActions : undefined, children: iconOnly
33
14
  ? _jsx(Icon, { name: iconOnly })
34
- : _jsxs(_Fragment, { children: [_jsxs("span", { className: "vk-btn-label", children: [icon ? _jsx(Icon, { name: icon, size: 16, className: "vk-menu-trigger-icon" }) : null, label] }), _jsx("span", { className: "vk-btn-glyph", "aria-hidden": "true", children: _jsx(Icon, { name: "chevron-down", size: 14 }) })] }) }), _jsx(Primitive.Portal, { children: _jsx(Primitive.Content, { className: "vk-menu", side: "bottom", align: align === "end" ? "end" : "start", sideOffset: 4, collisionPadding: 8, loop: true, onFocus: onFocus, onKeyDownCapture: moveFocusNow, onCloseAutoFocus: (e) => {
35
- const dir = tabOut.current;
36
- tabOut.current = 0;
37
- if (dir) {
38
- // Tab closes the menu and moves on from the trigger, as if focus had stayed there.
39
- e.preventDefault();
40
- const trigger = triggerRef.current;
41
- const list = focusables(document.body);
42
- const at = trigger ? list.indexOf(trigger) : -1;
43
- (list[at + dir] || trigger)?.focus();
44
- }
45
- flush();
46
- }, onKeyDown: (e) => {
47
- if (e.key === "Tab") {
48
- e.preventDefault();
49
- tabOut.current = e.shiftKey ? -1 : 1;
50
- onOpenChange(false);
51
- }
52
- }, children: _jsx(MenuEntries, { parts: Primitive, items: items || [], defer: defer }) }) })] }) }));
15
+ : _jsxs(_Fragment, { children: [_jsxs("span", { className: "vk-btn-label", children: [icon ? _jsx(Icon, { name: icon, size: 16, className: "vk-menu-trigger-icon" }) : null, label] }), _jsx("span", { className: "vk-btn-glyph", "aria-hidden": "true", children: _jsx(Icon, { name: "chevron-down", size: 14 }) })] }) }), _jsx(Primitive.Portal, { children: _jsx(Primitive.Content, { className: "vk-menu", side: "bottom", align: align === "end" ? "end" : "start", sideOffset: 4, collisionPadding: 8, children: _jsx(MenuEntries, { parts: Primitive, items: items }) }) })] }) }));
53
16
  }