@vokality/design-system 1.3.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/README.md +51 -5
  3. package/dist/browser.d.ts +13 -0
  4. package/dist/browser.js +7 -0
  5. package/dist/charts/chart.d.ts +6 -5
  6. package/dist/charts/chart.js +44 -25
  7. package/dist/chat.d.ts +54 -0
  8. package/dist/chat.js +1 -0
  9. package/dist/components/Accordion/Accordion.js +1 -1
  10. package/dist/components/Alert/Alert.js +5 -2
  11. package/dist/components/AppShell/AppShell.js +10 -14
  12. package/dist/components/Avatar/Avatar.js +2 -2
  13. package/dist/components/AvatarGroup/AvatarGroup.js +2 -2
  14. package/dist/components/BarChart/BarChart.js +17 -15
  15. package/dist/components/Breadcrumbs/Breadcrumbs.js +6 -3
  16. package/dist/components/Calendar/Calendar.js +6 -5
  17. package/dist/components/Card/Card.js +2 -3
  18. package/dist/components/ChatInbox/ChatInbox.d.ts +11 -0
  19. package/dist/components/ChatInbox/ChatInbox.js +49 -0
  20. package/dist/components/ChatPanel/ChatPanel.d.ts +3 -0
  21. package/dist/components/ChatPanel/ChatPanel.js +13 -0
  22. package/dist/components/ChatPanel/composer.d.ts +5 -0
  23. package/dist/components/ChatPanel/composer.js +32 -0
  24. package/dist/components/ChatPanel/transcript.d.ts +13 -0
  25. package/dist/components/ChatPanel/transcript.js +39 -0
  26. package/dist/components/ChatWidget/ChatWidget.d.ts +12 -0
  27. package/dist/components/ChatWidget/ChatWidget.js +42 -0
  28. package/dist/components/Checkbox/Checkbox.d.ts +5 -10
  29. package/dist/components/Checkbox/Checkbox.js +5 -19
  30. package/dist/components/CodeBlock/CodeBlock.js +19 -5
  31. package/dist/components/Combobox/Combobox.js +22 -15
  32. package/dist/components/Combobox/ListPanel.js +20 -9
  33. package/dist/components/CommandPalette/CommandPalette.js +33 -14
  34. package/dist/components/ContextMenu/ContextMenu.d.ts +2 -2
  35. package/dist/components/ContextMenu/ContextMenu.js +5 -50
  36. package/dist/components/DatePicker/DatePicker.js +35 -29
  37. package/dist/components/DescriptionList/DescriptionList.js +1 -1
  38. package/dist/components/Dialog/Dialog.d.ts +24 -7
  39. package/dist/components/Dialog/Dialog.js +30 -41
  40. package/dist/components/Drawer/Drawer.d.ts +4 -2
  41. package/dist/components/EmptyState/EmptyState.js +2 -2
  42. package/dist/components/ErrorSummary/ErrorSummary.js +5 -3
  43. package/dist/components/FaqList/FaqList.js +1 -1
  44. package/dist/components/Field/Field.js +4 -4
  45. package/dist/components/Fieldset/Fieldset.js +3 -3
  46. package/dist/components/FileUpload/FileUpload.js +17 -9
  47. package/dist/components/Grid/Grid.d.ts +867 -5
  48. package/dist/components/Grid/Grid.js +3 -4
  49. package/dist/components/Heading/Heading.js +2 -1
  50. package/dist/components/Icon/Icon.js +4 -2
  51. package/dist/components/Inline/Inline.d.ts +867 -5
  52. package/dist/components/Inline/Inline.js +2 -3
  53. package/dist/components/LineChart/LineChart.js +17 -15
  54. package/dist/components/LinkProvider/LinkProvider.d.ts +1 -1
  55. package/dist/components/LinkProvider/LinkProvider.js +6 -2
  56. package/dist/components/List/List.js +1 -1
  57. package/dist/components/MediaCard/MediaCard.js +2 -2
  58. package/dist/components/Menu/Menu.js +6 -43
  59. package/dist/components/Menu/entries.d.ts +1 -30
  60. package/dist/components/Menu/entries.js +16 -100
  61. package/dist/components/MultiSelect/MultiSelect.js +43 -34
  62. package/dist/components/NumberInput/NumberInput.js +17 -18
  63. package/dist/components/OtpInput/OtpInput.d.ts +1 -1
  64. package/dist/components/OtpInput/OtpInput.js +10 -67
  65. package/dist/components/PageHeader/PageHeader.js +2 -2
  66. package/dist/components/Pagination/Pagination.js +3 -1
  67. package/dist/components/PasswordInput/PasswordInput.d.ts +1 -1
  68. package/dist/components/PasswordInput/PasswordInput.js +9 -4
  69. package/dist/components/Popover/Popover.d.ts +6 -7
  70. package/dist/components/Popover/Popover.js +2 -19
  71. package/dist/components/Progress/Progress.d.ts +1 -1
  72. package/dist/components/Progress/Progress.js +7 -11
  73. package/dist/components/Radio/Radio.d.ts +4 -2
  74. package/dist/components/RadioGroup/RadioGroup.d.ts +5 -12
  75. package/dist/components/RadioGroup/RadioGroup.js +6 -33
  76. package/dist/components/RichTextEditor/RichTextEditor.d.ts +63 -0
  77. package/dist/components/RichTextEditor/RichTextEditor.js +175 -0
  78. package/dist/components/RichTextEditor/toolbar.d.ts +15 -0
  79. package/dist/components/RichTextEditor/toolbar.js +142 -0
  80. package/dist/components/RichTextEditor/uploads.d.ts +41 -0
  81. package/dist/components/RichTextEditor/uploads.js +124 -0
  82. package/dist/components/SearchInput/SearchInput.js +4 -2
  83. package/dist/components/SectionHeader/SectionHeader.js +1 -3
  84. package/dist/components/SegmentedControl/SegmentedControl.js +2 -12
  85. package/dist/components/Select/Select.d.ts +15 -16
  86. package/dist/components/Select/Select.js +11 -252
  87. package/dist/components/Slider/Slider.js +11 -21
  88. package/dist/components/Sparkline/Sparkline.js +8 -3
  89. package/dist/components/Spinner/Spinner.js +5 -2
  90. package/dist/components/Stack/Stack.d.ts +867 -5
  91. package/dist/components/Stack/Stack.js +2 -3
  92. package/dist/components/Stat/Stat.js +6 -3
  93. package/dist/components/Steps/Steps.js +6 -3
  94. package/dist/components/Switch/Switch.d.ts +7 -7
  95. package/dist/components/Switch/Switch.js +4 -10
  96. package/dist/components/Table/Table.js +38 -19
  97. package/dist/components/Tabs/Tabs.js +2 -22
  98. package/dist/components/Tag/Tag.js +3 -1
  99. package/dist/components/Text/Text.d.ts +9 -5
  100. package/dist/components/Text/Text.js +3 -4
  101. package/dist/components/TileGrid/TileGrid.js +1 -1
  102. package/dist/components/TimePicker/TimePicker.js +35 -33
  103. package/dist/components/Timeline/Timeline.js +5 -4
  104. package/dist/components/Toaster/Toaster.js +21 -17
  105. package/dist/components/Tooltip/Tooltip.d.ts +6 -6
  106. package/dist/components/Tooltip/Tooltip.js +3 -17
  107. package/dist/components/TreeView/TreeView.js +15 -12
  108. package/dist/components.css +281 -60
  109. package/dist/hooks/useTheme.js +6 -6
  110. package/dist/icons/message-circle.svg +1 -0
  111. package/dist/internal/CharCount.js +3 -1
  112. package/dist/internal/choice.d.ts +10 -48
  113. package/dist/internal/choice.js +8 -96
  114. package/dist/internal/describedBy.d.ts +3 -0
  115. package/dist/internal/describedBy.js +4 -0
  116. package/dist/internal/options.d.ts +10 -5
  117. package/dist/internal/options.js +25 -11
  118. package/dist/internal/status.d.ts +3 -2
  119. package/dist/internal/status.js +10 -2
  120. package/dist/internal/useScrollActive.js +2 -2
  121. package/dist/internal/useToday.d.ts +3 -0
  122. package/dist/internal/useToday.js +42 -0
  123. package/dist/lib/dates.js +25 -15
  124. package/dist/lib/format.js +11 -8
  125. package/dist/lib/icons.d.ts +5 -0
  126. package/dist/lib/icons.js +2 -0
  127. package/dist/lib/math.js +17 -5
  128. package/dist/lib/rich-text.d.ts +13 -0
  129. package/dist/lib/rich-text.js +62 -0
  130. package/dist/lib/space.d.ts +1 -2
  131. package/dist/lib/space.js +4 -1
  132. package/dist/lib/text.js +1 -1
  133. package/dist/lib/theme.js +1 -1
  134. package/dist/localization.d.ts +166 -0
  135. package/dist/localization.js +142 -0
  136. package/dist/tokens.css +2 -0
  137. package/dist/tokens.dtcg.json +10 -0
  138. package/dist/tokens.json +10 -0
  139. package/dist/types.d.ts +6 -1
  140. package/dist/vokality.css +283 -60
  141. package/dist/vokality.iife.js +35981 -9698
  142. package/docs/brand.md +8 -5
  143. package/docs/components/AppShell/README.md +1 -1
  144. package/docs/components/Badge/README.md +1 -1
  145. package/docs/components/BarChart/README.md +1 -0
  146. package/docs/components/Button/README.md +4 -2
  147. package/docs/components/ChatInbox/README.md +41 -0
  148. package/docs/components/ChatWidget/README.md +47 -0
  149. package/docs/components/Checkbox/README.md +7 -3
  150. package/docs/components/ContextMenu/README.md +7 -3
  151. package/docs/components/Dialog/README.md +9 -4
  152. package/docs/components/Drawer/README.md +1 -1
  153. package/docs/components/Field/README.md +1 -1
  154. package/docs/components/Fieldset/README.md +2 -2
  155. package/docs/components/Inline/README.md +1 -1
  156. package/docs/components/LineChart/README.md +1 -0
  157. package/docs/components/LocaleProvider/README.md +48 -0
  158. package/docs/components/Menu/README.md +13 -8
  159. package/docs/components/OtpInput/README.md +9 -5
  160. package/docs/components/PasswordInput/README.md +11 -2
  161. package/docs/components/Popover/README.md +6 -3
  162. package/docs/components/Progress/README.md +3 -1
  163. package/docs/components/RadioGroup/README.md +5 -2
  164. package/docs/components/RichTextEditor/README.md +84 -0
  165. package/docs/components/SegmentedControl/README.md +2 -0
  166. package/docs/components/Select/README.md +13 -17
  167. package/docs/components/Skeleton/README.md +1 -1
  168. package/docs/components/Slider/README.md +4 -2
  169. package/docs/components/Steps/README.md +1 -1
  170. package/docs/components/Switch/README.md +5 -2
  171. package/docs/components/Tabs/README.md +4 -2
  172. package/docs/components/Text/README.md +1 -1
  173. package/docs/components/Toaster/README.md +3 -1
  174. package/docs/components/Tooltip/README.md +5 -3
  175. package/package.json +49 -5
@@ -1,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
  }
@@ -2,21 +2,21 @@
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { cloneElement, isValidElement } from "react";
4
4
  import { Label } from "radix-ui";
5
+ import { describedBy } from "../../internal/describedBy.js";
5
6
  import { useUid } from "../../internal/useUid.js";
6
7
  import { cx } from "../../lib/cx.js";
7
8
  /** Label (Radix Label), hint and error around one control; wires id, aria-describedby and aria-invalid onto the child. */
8
9
  export function Field(props) {
9
10
  const uid = useUid("vk-field");
10
11
  const id = props.id || uid;
11
- const describedBy = [props.hint ? id + "-hint" : null, props.error ? id + "-error" : null].filter(Boolean).join(" ") || undefined;
12
12
  const labelId = id + "-label";
13
13
  const control = isValidElement(props.children)
14
- ? cloneElement(props.children, { id, "aria-labelledby": labelId, "aria-describedby": describedBy, "aria-invalid": props.error ? true : undefined })
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,12 +1,12 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { forwardRef } from "react";
4
+ import { describedBy } from "../../internal/describedBy.js";
4
5
  import { useUid } from "../../internal/useUid.js";
5
6
  import { cx } from "../../lib/cx.js";
6
7
  /** Groups related controls with a native legend and shared instructions. */
7
- export const Fieldset = forwardRef(function Fieldset({ legend, hint, error, children, className, id, "aria-describedby": describedBy, ...rest }, ref) {
8
+ export const Fieldset = forwardRef(function Fieldset({ legend, hint, error, children, className, id, "aria-describedby": existing, ...rest }, ref) {
8
9
  const uid = useUid("vk-fieldset");
9
10
  const groupId = id || uid;
10
- const descriptions = [describedBy, hint ? groupId + "-hint" : null, error ? groupId + "-error" : null].filter(Boolean).join(" ") || undefined;
11
- return (_jsxs("fieldset", { ref: ref, id: groupId, className: cx("vk-fieldset", className), "aria-describedby": descriptions, "aria-invalid": error ? true : undefined, ...rest, children: [_jsx("legend", { className: "vk-fieldset-legend", children: legend }), hint ? _jsx("p", { className: "vk-fieldset-hint", id: groupId + "-hint", children: hint }) : null, _jsx("div", { className: "vk-fieldset-controls", children: children }), error ? _jsx("p", { className: "vk-fieldset-error", id: groupId + "-error", children: error }) : null] }));
11
+ return (_jsxs("fieldset", { ref: ref, id: groupId, className: cx("vk-fieldset", className), "aria-describedby": describedBy(groupId, hint, error, existing), "aria-invalid": error ? true : undefined, ...rest, children: [_jsx("legend", { className: "vk-fieldset-legend", children: legend }), hint ? _jsx("p", { className: "vk-field-hint vk-fieldset-hint", id: groupId + "-hint", children: hint }) : null, _jsx("div", { className: "vk-fieldset-controls", children: children }), error ? _jsx("p", { className: "vk-field-error vk-fieldset-error", id: groupId + "-error", children: error }) : null] }));
12
12
  });
@@ -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
  }