@vokality/design-system 0.0.0-stage → 1.2.2
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.
- package/CHANGELOG.md +92 -0
- package/README.md +134 -2
- package/dist/charts/chart.d.ts +52 -0
- package/dist/charts/chart.js +108 -0
- package/dist/components/Accordion/Accordion.d.ts +15 -0
- package/dist/components/Accordion/Accordion.js +16 -0
- package/dist/components/Alert/Alert.d.ts +14 -0
- package/dist/components/Alert/Alert.js +12 -0
- package/dist/components/AppShell/AppShell.d.ts +21 -0
- package/dist/components/AppShell/AppShell.js +48 -0
- package/dist/components/Avatar/Avatar.d.ts +11 -0
- package/dist/components/Avatar/Avatar.js +19 -0
- package/dist/components/AvatarGroup/AvatarGroup.d.ts +11 -0
- package/dist/components/AvatarGroup/AvatarGroup.js +13 -0
- package/dist/components/Badge/Badge.d.ts +9 -0
- package/dist/components/Badge/Badge.js +6 -0
- package/dist/components/BarChart/BarChart.d.ts +7 -0
- package/dist/components/BarChart/BarChart.js +45 -0
- package/dist/components/Breadcrumbs/Breadcrumbs.d.ts +11 -0
- package/dist/components/Breadcrumbs/Breadcrumbs.js +11 -0
- package/dist/components/Button/Button.d.ts +17 -0
- package/dist/components/Button/Button.js +23 -0
- package/dist/components/Calendar/Calendar.d.ts +21 -0
- package/dist/components/Calendar/Calendar.js +144 -0
- package/dist/components/Card/Card.d.ts +16 -0
- package/dist/components/Card/Card.js +11 -0
- package/dist/components/Checkbox/Checkbox.d.ts +12 -0
- package/dist/components/Checkbox/Checkbox.js +24 -0
- package/dist/components/Code/Code.d.ts +7 -0
- package/dist/components/Code/Code.js +6 -0
- package/dist/components/CodeBlock/CodeBlock.d.ts +10 -0
- package/dist/components/CodeBlock/CodeBlock.js +43 -0
- package/dist/components/Combobox/Combobox.d.ts +23 -0
- package/dist/components/Combobox/Combobox.js +188 -0
- package/dist/components/Combobox/ListPanel.d.ts +16 -0
- package/dist/components/Combobox/ListPanel.js +75 -0
- package/dist/components/CommandPalette/CommandPalette.d.ts +23 -0
- package/dist/components/CommandPalette/CommandPalette.js +86 -0
- package/dist/components/Container/Container.d.ts +10 -0
- package/dist/components/Container/Container.js +7 -0
- package/dist/components/ContextMenu/ContextMenu.d.ts +11 -0
- package/dist/components/ContextMenu/ContextMenu.js +56 -0
- package/dist/components/DatePicker/DatePicker.d.ts +25 -0
- package/dist/components/DatePicker/DatePicker.js +198 -0
- package/dist/components/DescriptionList/DescriptionList.d.ts +12 -0
- package/dist/components/DescriptionList/DescriptionList.js +6 -0
- package/dist/components/Dialog/Dialog.d.ts +23 -0
- package/dist/components/Dialog/Dialog.js +53 -0
- package/dist/components/Divider/Divider.d.ts +6 -0
- package/dist/components/Divider/Divider.js +10 -0
- package/dist/components/Drawer/Drawer.d.ts +6 -0
- package/dist/components/Drawer/Drawer.js +6 -0
- package/dist/components/EmptyState/EmptyState.d.ts +11 -0
- package/dist/components/EmptyState/EmptyState.js +10 -0
- package/dist/components/ErrorSummary/ErrorSummary.d.ts +10 -0
- package/dist/components/ErrorSummary/ErrorSummary.js +28 -0
- package/dist/components/FaqList/FaqList.d.ts +10 -0
- package/dist/components/FaqList/FaqList.js +6 -0
- package/dist/components/Field/Field.d.ts +12 -0
- package/dist/components/Field/Field.js +25 -0
- package/dist/components/Figure/Figure.d.ts +11 -0
- package/dist/components/Figure/Figure.js +6 -0
- package/dist/components/FileUpload/FileUpload.d.ts +25 -0
- package/dist/components/FileUpload/FileUpload.js +47 -0
- package/dist/components/Grid/Grid.d.ts +12 -0
- package/dist/components/Grid/Grid.js +10 -0
- package/dist/components/HatchDivider/HatchDivider.d.ts +2 -0
- package/dist/components/HatchDivider/HatchDivider.js +5 -0
- package/dist/components/Heading/Heading.d.ts +12 -0
- package/dist/components/Heading/Heading.js +11 -0
- package/dist/components/Icon/Icon.d.ts +8 -0
- package/dist/components/Icon/Icon.js +17 -0
- package/dist/components/IconButton/IconButton.d.ts +11 -0
- package/dist/components/IconButton/IconButton.js +16 -0
- package/dist/components/Inline/Inline.d.ts +13 -0
- package/dist/components/Inline/Inline.js +8 -0
- package/dist/components/Input/Input.d.ts +10 -0
- package/dist/components/Input/Input.js +25 -0
- package/dist/components/Kbd/Kbd.d.ts +7 -0
- package/dist/components/Kbd/Kbd.js +6 -0
- package/dist/components/LineChart/LineChart.d.ts +7 -0
- package/dist/components/LineChart/LineChart.js +53 -0
- package/dist/components/Link/Link.d.ts +7 -0
- package/dist/components/Link/Link.js +12 -0
- package/dist/components/LinkProvider/LinkProvider.d.ts +22 -0
- package/dist/components/LinkProvider/LinkProvider.js +21 -0
- package/dist/components/List/List.d.ts +24 -0
- package/dist/components/List/List.js +24 -0
- package/dist/components/MediaCard/MediaCard.d.ts +19 -0
- package/dist/components/MediaCard/MediaCard.js +25 -0
- package/dist/components/Menu/Menu.d.ts +14 -0
- package/dist/components/Menu/Menu.js +53 -0
- package/dist/components/Menu/entries.d.ts +40 -0
- package/dist/components/Menu/entries.js +146 -0
- package/dist/components/MultiSelect/MultiSelect.d.ts +24 -0
- package/dist/components/MultiSelect/MultiSelect.js +166 -0
- package/dist/components/NavList/NavList.d.ts +19 -0
- package/dist/components/NavList/NavList.js +10 -0
- package/dist/components/NumberInput/NumberInput.d.ts +13 -0
- package/dist/components/NumberInput/NumberInput.js +90 -0
- package/dist/components/OtpInput/OtpInput.d.ts +19 -0
- package/dist/components/OtpInput/OtpInput.js +75 -0
- package/dist/components/PageHeader/PageHeader.d.ts +18 -0
- package/dist/components/PageHeader/PageHeader.js +11 -0
- package/dist/components/Pagination/Pagination.d.ts +15 -0
- package/dist/components/Pagination/Pagination.js +22 -0
- package/dist/components/PasswordInput/PasswordInput.d.ts +7 -0
- package/dist/components/PasswordInput/PasswordInput.js +11 -0
- package/dist/components/Popover/Popover.d.ts +18 -0
- package/dist/components/Popover/Popover.js +26 -0
- package/dist/components/Progress/Progress.d.ts +13 -0
- package/dist/components/Progress/Progress.js +24 -0
- package/dist/components/Prose/Prose.d.ts +8 -0
- package/dist/components/Prose/Prose.js +7 -0
- package/dist/components/Quote/Quote.d.ts +10 -0
- package/dist/components/Quote/Quote.js +7 -0
- package/dist/components/Radio/Radio.d.ts +7 -0
- package/dist/components/Radio/Radio.js +9 -0
- package/dist/components/RadioGroup/RadioGroup.d.ts +21 -0
- package/dist/components/RadioGroup/RadioGroup.js +41 -0
- package/dist/components/SearchInput/SearchInput.d.ts +10 -0
- package/dist/components/SearchInput/SearchInput.js +39 -0
- package/dist/components/SectionHeader/SectionHeader.d.ts +10 -0
- package/dist/components/SectionHeader/SectionHeader.js +9 -0
- package/dist/components/SegmentedControl/SegmentedControl.d.ts +19 -0
- package/dist/components/SegmentedControl/SegmentedControl.js +21 -0
- package/dist/components/Select/Select.d.ts +26 -0
- package/dist/components/Select/Select.js +262 -0
- package/dist/components/Skeleton/Skeleton.d.ts +8 -0
- package/dist/components/Skeleton/Skeleton.js +13 -0
- package/dist/components/Slider/Slider.d.ts +21 -0
- package/dist/components/Slider/Slider.js +43 -0
- package/dist/components/Sparkline/Sparkline.d.ts +11 -0
- package/dist/components/Sparkline/Sparkline.js +15 -0
- package/dist/components/Spinner/Spinner.d.ts +8 -0
- package/dist/components/Spinner/Spinner.js +8 -0
- package/dist/components/SquareGlyph/SquareGlyph.d.ts +7 -0
- package/dist/components/SquareGlyph/SquareGlyph.js +6 -0
- package/dist/components/Stack/Stack.d.ts +11 -0
- package/dist/components/Stack/Stack.js +8 -0
- package/dist/components/Stat/Stat.d.ts +13 -0
- package/dist/components/Stat/Stat.js +22 -0
- package/dist/components/Steps/Steps.d.ts +13 -0
- package/dist/components/Steps/Steps.js +13 -0
- package/dist/components/Switch/Switch.d.ts +7 -0
- package/dist/components/Switch/Switch.js +16 -0
- package/dist/components/Table/Table.d.ts +48 -0
- package/dist/components/Table/Table.js +144 -0
- package/dist/components/Tabs/Tabs.d.ts +19 -0
- package/dist/components/Tabs/Tabs.js +29 -0
- package/dist/components/Tag/Tag.d.ts +12 -0
- package/dist/components/Tag/Tag.js +8 -0
- package/dist/components/Text/Text.d.ts +10 -0
- package/dist/components/Text/Text.js +7 -0
- package/dist/components/Textarea/Textarea.d.ts +6 -0
- package/dist/components/Textarea/Textarea.js +17 -0
- package/dist/components/ThemeScript/ThemeScript.d.ts +7 -0
- package/dist/components/ThemeScript/ThemeScript.js +9 -0
- package/dist/components/TileGrid/TileGrid.d.ts +13 -0
- package/dist/components/TileGrid/TileGrid.js +8 -0
- package/dist/components/TimePicker/TimePicker.d.ts +28 -0
- package/dist/components/TimePicker/TimePicker.js +192 -0
- package/dist/components/Timeline/Timeline.d.ts +16 -0
- package/dist/components/Timeline/Timeline.js +10 -0
- package/dist/components/Toaster/Toaster.d.ts +50 -0
- package/dist/components/Toaster/Toaster.js +63 -0
- package/dist/components/Tooltip/Tooltip.d.ts +11 -0
- package/dist/components/Tooltip/Tooltip.js +21 -0
- package/dist/components/TreeView/TreeView.d.ts +30 -0
- package/dist/components/TreeView/TreeView.js +127 -0
- package/dist/components.css +1798 -0
- package/dist/fonts/FONT-NOTICES.txt +20 -0
- package/dist/fonts/IBMPlexSans-Latin.woff2 +0 -0
- package/dist/fonts/IBMPlexSans-OFL.txt +93 -0
- package/dist/fonts/Manrope-Latin.woff2 +0 -0
- package/dist/fonts/Manrope-OFL.txt +93 -0
- package/dist/fonts/SpaceGrotesk-Latin.woff2 +0 -0
- package/dist/fonts/SpaceGrotesk-OFL.txt +93 -0
- package/dist/fonts.css +23 -0
- package/dist/hooks/useTheme.d.ts +16 -0
- package/dist/hooks/useTheme.js +82 -0
- package/dist/icons/arrow-down.svg +1 -0
- package/dist/icons/arrow-up-right.svg +1 -0
- package/dist/icons/arrow-up.svg +1 -0
- package/dist/icons/calendar.svg +1 -0
- package/dist/icons/chart.svg +1 -0
- package/dist/icons/check.svg +1 -0
- package/dist/icons/chevron-down.svg +1 -0
- package/dist/icons/chevron-left.svg +1 -0
- package/dist/icons/chevron-right.svg +1 -0
- package/dist/icons/chevrons-up-down.svg +1 -0
- package/dist/icons/circle-alert.svg +1 -0
- package/dist/icons/circle-check.svg +1 -0
- package/dist/icons/clock.svg +1 -0
- package/dist/icons/copy.svg +1 -0
- package/dist/icons/ellipsis.svg +1 -0
- package/dist/icons/file.svg +1 -0
- package/dist/icons/folder.svg +1 -0
- package/dist/icons/home.svg +1 -0
- package/dist/icons/info.svg +1 -0
- package/dist/icons/map-pin.svg +1 -0
- package/dist/icons/menu.svg +1 -0
- package/dist/icons/minus.svg +1 -0
- package/dist/icons/pencil.svg +1 -0
- package/dist/icons/phone.svg +1 -0
- package/dist/icons/plus.svg +1 -0
- package/dist/icons/quote.svg +1 -0
- package/dist/icons/search.svg +1 -0
- package/dist/icons/sidebar.svg +1 -0
- package/dist/icons/trash.svg +1 -0
- package/dist/icons/triangle-alert.svg +1 -0
- package/dist/icons/upload.svg +1 -0
- package/dist/icons/users.svg +1 -0
- package/dist/icons/x.svg +1 -0
- package/dist/index.d.ts +178 -0
- package/dist/index.js +93 -0
- package/dist/internal/CharCount.d.ts +17 -0
- package/dist/internal/CharCount.js +23 -0
- package/dist/internal/choice.d.ts +65 -0
- package/dist/internal/choice.js +111 -0
- package/dist/internal/focusables.d.ts +3 -0
- package/dist/internal/focusables.js +8 -0
- package/dist/internal/options.d.ts +15 -0
- package/dist/internal/options.js +30 -0
- package/dist/internal/status.d.ts +6 -0
- package/dist/internal/status.js +5 -0
- package/dist/internal/useIsoLayoutEffect.d.ts +3 -0
- package/dist/internal/useIsoLayoutEffect.js +4 -0
- package/dist/internal/useScrollActive.d.ts +3 -0
- package/dist/internal/useScrollActive.js +12 -0
- package/dist/internal/useUid.d.ts +2 -0
- package/dist/internal/useUid.js +6 -0
- package/dist/lib/cx.d.ts +2 -0
- package/dist/lib/cx.js +4 -0
- package/dist/lib/dates.d.ts +10 -0
- package/dist/lib/dates.js +107 -0
- package/dist/lib/format.d.ts +15 -0
- package/dist/lib/format.js +50 -0
- package/dist/lib/icons.d.ts +220 -0
- package/dist/lib/icons.js +54 -0
- package/dist/lib/intl.d.ts +4 -0
- package/dist/lib/intl.js +19 -0
- package/dist/lib/math.d.ts +5 -0
- package/dist/lib/math.js +36 -0
- package/dist/lib/omit.d.ts +2 -0
- package/dist/lib/omit.js +10 -0
- package/dist/lib/space.d.ts +4 -0
- package/dist/lib/space.js +9 -0
- package/dist/lib/text.d.ts +8 -0
- package/dist/lib/text.js +12 -0
- package/dist/lib/theme.d.ts +16 -0
- package/dist/lib/theme.js +14 -0
- package/dist/lib/utils.d.ts +17 -0
- package/dist/lib/utils.js +5 -0
- package/dist/tailwind.css +110 -0
- package/dist/tokens.css +316 -0
- package/dist/tokens.dtcg.json +1606 -0
- package/dist/tokens.json +1217 -0
- package/dist/types.d.ts +67 -0
- package/dist/types.js +1 -0
- package/dist/vokality.css +2139 -0
- package/dist/vokality.iife.js +19408 -0
- package/docs/brand.md +163 -0
- package/docs/components/Accordion/README.md +24 -0
- package/docs/components/Alert/README.md +31 -0
- package/docs/components/AppShell/README.md +20 -0
- package/docs/components/Avatar/README.md +17 -0
- package/docs/components/AvatarGroup/README.md +12 -0
- package/docs/components/Badge/README.md +24 -0
- package/docs/components/BarChart/README.md +30 -0
- package/docs/components/Breadcrumbs/README.md +16 -0
- package/docs/components/Button/README.md +43 -0
- package/docs/components/Calendar/README.md +43 -0
- package/docs/components/Card/README.md +16 -0
- package/docs/components/Checkbox/README.md +30 -0
- package/docs/components/Code/README.md +9 -0
- package/docs/components/CodeBlock/README.md +15 -0
- package/docs/components/Combobox/README.md +43 -0
- package/docs/components/CommandPalette/README.md +20 -0
- package/docs/components/Container/README.md +10 -0
- package/docs/components/ContextMenu/README.md +13 -0
- package/docs/components/Dashboard/README.md +12 -0
- package/docs/components/DatePicker/README.md +34 -0
- package/docs/components/DescriptionList/README.md +18 -0
- package/docs/components/Dialog/README.md +28 -0
- package/docs/components/Divider/README.md +15 -0
- package/docs/components/Drawer/README.md +16 -0
- package/docs/components/EmptyState/README.md +17 -0
- package/docs/components/ErrorPage/README.md +11 -0
- package/docs/components/ErrorSummary/README.md +16 -0
- package/docs/components/FaqList/README.md +11 -0
- package/docs/components/Field/README.md +27 -0
- package/docs/components/Figure/README.md +9 -0
- package/docs/components/FileUpload/README.md +20 -0
- package/docs/components/FormPage/README.md +11 -0
- package/docs/components/Grid/README.md +11 -0
- package/docs/components/HatchDivider/README.md +10 -0
- package/docs/components/Heading/README.md +10 -0
- package/docs/components/Icon/README.md +23 -0
- package/docs/components/IconButton/README.md +28 -0
- package/docs/components/Inline/README.md +9 -0
- package/docs/components/Input/README.md +31 -0
- package/docs/components/Kbd/README.md +13 -0
- package/docs/components/LineChart/README.md +27 -0
- package/docs/components/Link/README.md +31 -0
- package/docs/components/List/README.md +21 -0
- package/docs/components/ListDetail/README.md +11 -0
- package/docs/components/MediaCard/README.md +16 -0
- package/docs/components/Menu/README.md +45 -0
- package/docs/components/MultiSelect/README.md +41 -0
- package/docs/components/NavList/README.md +21 -0
- package/docs/components/NumberInput/README.md +19 -0
- package/docs/components/OtpInput/README.md +17 -0
- package/docs/components/PageHeader/README.md +17 -0
- package/docs/components/Pagination/README.md +22 -0
- package/docs/components/PasswordInput/README.md +13 -0
- package/docs/components/Popover/README.md +23 -0
- package/docs/components/Progress/README.md +19 -0
- package/docs/components/Prose/README.md +12 -0
- package/docs/components/Quote/README.md +13 -0
- package/docs/components/Radio/README.md +25 -0
- package/docs/components/RadioGroup/README.md +23 -0
- package/docs/components/SearchInput/README.md +23 -0
- package/docs/components/SectionHeader/README.md +14 -0
- package/docs/components/SegmentedControl/README.md +19 -0
- package/docs/components/Select/README.md +52 -0
- package/docs/components/SettingsPage/README.md +11 -0
- package/docs/components/SignIn/README.md +11 -0
- package/docs/components/Skeleton/README.md +16 -0
- package/docs/components/Slider/README.md +22 -0
- package/docs/components/Sparkline/README.md +13 -0
- package/docs/components/Spinner/README.md +16 -0
- package/docs/components/SquareGlyph/README.md +18 -0
- package/docs/components/Stack/README.md +11 -0
- package/docs/components/Stat/README.md +20 -0
- package/docs/components/Steps/README.md +22 -0
- package/docs/components/Switch/README.md +27 -0
- package/docs/components/Table/README.md +35 -0
- package/docs/components/Tabs/README.md +26 -0
- package/docs/components/Tag/README.md +21 -0
- package/docs/components/Text/README.md +11 -0
- package/docs/components/Textarea/README.md +20 -0
- package/docs/components/ThemeScript/README.md +47 -0
- package/docs/components/TileGrid/README.md +12 -0
- package/docs/components/TimePicker/README.md +19 -0
- package/docs/components/Timeline/README.md +12 -0
- package/docs/components/Toaster/README.md +34 -0
- package/docs/components/Tooltip/README.md +23 -0
- package/docs/components/TreeView/README.md +15 -0
- package/package.json +76 -4
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { forwardRef, useEffect, useRef, useState } from "react";
|
|
4
|
+
import { Icon } from "../Icon/Icon.js";
|
|
5
|
+
import { Input } from "../Input/Input.js";
|
|
6
|
+
import { cx } from "../../lib/cx.js";
|
|
7
|
+
import { omit } from "../../lib/omit.js";
|
|
8
|
+
/** Field for whole or decimal numbers, with − and + buttons and arrow-key steps. The ref is the <input>. */
|
|
9
|
+
export const NumberInput = forwardRef(function NumberInput(props, ref) {
|
|
10
|
+
const { min, max } = props;
|
|
11
|
+
const step = props.step || 1;
|
|
12
|
+
const controlled = props.value !== undefined;
|
|
13
|
+
const [internal, setInternal] = useState(props.defaultValue != null ? props.defaultValue : null);
|
|
14
|
+
const value = props.value !== undefined ? props.value : internal;
|
|
15
|
+
// The text being typed, which may not be a number yet ("-", "1.").
|
|
16
|
+
const [text, setText] = useState(value == null ? "" : String(value));
|
|
17
|
+
const editing = useRef(false);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (!editing.current)
|
|
20
|
+
setText(value == null ? "" : String(value));
|
|
21
|
+
}, [value]);
|
|
22
|
+
const decimals = (String(step).split(".")[1] || "").length;
|
|
23
|
+
const clamp = (n) => {
|
|
24
|
+
if (min != null && n < min)
|
|
25
|
+
n = min;
|
|
26
|
+
if (max != null && n > max)
|
|
27
|
+
n = max;
|
|
28
|
+
return +n.toFixed(decimals);
|
|
29
|
+
};
|
|
30
|
+
const set = (n) => {
|
|
31
|
+
const next = n == null || isNaN(n) ? null : clamp(n);
|
|
32
|
+
if (!controlled)
|
|
33
|
+
setInternal(next);
|
|
34
|
+
setText(next == null ? "" : String(next));
|
|
35
|
+
props.onChange?.(next);
|
|
36
|
+
};
|
|
37
|
+
// From empty, a step counts from min (or 0).
|
|
38
|
+
const bump = (d) => set((value ?? min ?? 0) + d);
|
|
39
|
+
const rest = omit(props, ["value", "defaultValue", "onChange", "min", "max", "step", "decrementLabel", "incrementLabel", "suffix", "prefix", "className"]);
|
|
40
|
+
return (_jsx(Input, { ...rest, ref: ref, className: cx("vk-number", props.className), inputMode: decimals ? "decimal" : "numeric", role: "spinbutton", "aria-valuenow": value ?? undefined, "aria-valuemin": min, "aria-valuemax": max, autoComplete: "off", value: text, prefix: props.prefix, onChange: (e) => {
|
|
41
|
+
editing.current = true;
|
|
42
|
+
const raw = e.target.value.replace(",", ".");
|
|
43
|
+
setText(e.target.value);
|
|
44
|
+
if (raw === "" || raw === "-")
|
|
45
|
+
return;
|
|
46
|
+
const n = Number(raw);
|
|
47
|
+
if (!isNaN(n)) {
|
|
48
|
+
if (!controlled)
|
|
49
|
+
setInternal(n);
|
|
50
|
+
props.onChange?.(n);
|
|
51
|
+
}
|
|
52
|
+
}, onBlur: (e) => {
|
|
53
|
+
editing.current = false;
|
|
54
|
+
const raw = text.replace(",", ".");
|
|
55
|
+
set(raw === "" ? null : Number(raw));
|
|
56
|
+
props.onBlur?.(e);
|
|
57
|
+
}, onKeyDown: (e) => {
|
|
58
|
+
const k = e.key;
|
|
59
|
+
if (k === "ArrowUp") {
|
|
60
|
+
e.preventDefault();
|
|
61
|
+
bump(step);
|
|
62
|
+
}
|
|
63
|
+
else if (k === "ArrowDown") {
|
|
64
|
+
e.preventDefault();
|
|
65
|
+
bump(-step);
|
|
66
|
+
}
|
|
67
|
+
else if (k === "PageUp") {
|
|
68
|
+
e.preventDefault();
|
|
69
|
+
bump(step * 10);
|
|
70
|
+
}
|
|
71
|
+
else if (k === "PageDown") {
|
|
72
|
+
e.preventDefault();
|
|
73
|
+
bump(-step * 10);
|
|
74
|
+
}
|
|
75
|
+
else if (k === "Home" && min != null) {
|
|
76
|
+
e.preventDefault();
|
|
77
|
+
set(min);
|
|
78
|
+
}
|
|
79
|
+
else if (k === "End" && max != null) {
|
|
80
|
+
e.preventDefault();
|
|
81
|
+
set(max);
|
|
82
|
+
}
|
|
83
|
+
}, suffix: _jsx(Stepper, { unit: props.suffix, value: value, min: min, max: max, disabled: props.disabled, decrementLabel: props.decrementLabel, incrementLabel: props.incrementLabel, onStep: (dir) => bump(dir * step) }) }));
|
|
84
|
+
});
|
|
85
|
+
// The unit and the − and + buttons; each button is disabled at its end of the range.
|
|
86
|
+
function Stepper({ unit, value, min, max, disabled, decrementLabel, incrementLabel, onStep }) {
|
|
87
|
+
const atMin = min != null && value != null && value <= min;
|
|
88
|
+
const atMax = max != null && value != null && value >= max;
|
|
89
|
+
return (_jsxs("span", { className: "vk-stepper", children: [unit ? _jsx("span", { className: "vk-stepper-unit", "aria-hidden": "true", children: unit }) : null, _jsx("button", { type: "button", tabIndex: -1, className: "vk-stepper-btn", "aria-label": decrementLabel || "Decrease", disabled: disabled || atMin, onClick: () => onStep(-1), children: _jsx(Icon, { name: "minus", size: 14 }) }), _jsx("button", { type: "button", tabIndex: -1, className: "vk-stepper-btn", "aria-label": incrementLabel || "Increase", disabled: disabled || atMax, onClick: () => onStep(1), children: _jsx(Icon, { name: "plus", size: 14 }) })] }));
|
|
90
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface OtpInputProps {
|
|
2
|
+
length?: number;
|
|
3
|
+
value?: string;
|
|
4
|
+
defaultValue?: string;
|
|
5
|
+
onChange?: (code: string) => void;
|
|
6
|
+
onComplete?: (code: string) => void;
|
|
7
|
+
numeric?: boolean;
|
|
8
|
+
name?: string;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
label?: string;
|
|
11
|
+
id?: string;
|
|
12
|
+
className?: string;
|
|
13
|
+
'aria-label'?: string;
|
|
14
|
+
'aria-labelledby'?: string;
|
|
15
|
+
'aria-describedby'?: string;
|
|
16
|
+
'aria-invalid'?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/** One box per character of a one-time code; typing advances, Backspace goes back, a paste fills them all. */
|
|
19
|
+
export declare function OtpInput(props: OtpInputProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useRef, useState } from "react";
|
|
4
|
+
import { useUid } from "../../internal/useUid.js";
|
|
5
|
+
import { cx } from "../../lib/cx.js";
|
|
6
|
+
/** One character box: typing advances, Backspace goes back, the arrows move, a paste fills them all. */
|
|
7
|
+
function OtpBox({ index: i, length, value, pattern, firstId, props, boxRef, set, focus }) {
|
|
8
|
+
const first = i === 0;
|
|
9
|
+
return (_jsx("input", { ref: boxRef, id: first ? firstId : undefined, className: "vk-input vk-otp-box", inputMode: props.numeric === false ? "text" : "numeric", autoComplete: first ? "one-time-code" : "off", maxLength: 1, value: value[i] || "", disabled: props.disabled, "aria-label": (props.label || "Digit") + " " + (i + 1) + " of " + length, "aria-invalid": props["aria-invalid"], "aria-describedby": first ? props["aria-describedby"] : undefined, onFocus: (e) => e.target.select(), onChange: (e) => {
|
|
10
|
+
const ch = e.target.value.slice(-1);
|
|
11
|
+
if (ch && !pattern.test(ch))
|
|
12
|
+
return;
|
|
13
|
+
const arr = value.split("");
|
|
14
|
+
while (arr.length < i)
|
|
15
|
+
arr.push("");
|
|
16
|
+
arr[i] = ch;
|
|
17
|
+
set(arr.join("").replace(/\s+$/, ""));
|
|
18
|
+
if (ch)
|
|
19
|
+
focus(i + 1);
|
|
20
|
+
}, onKeyDown: (e) => {
|
|
21
|
+
if (e.key === "Backspace" && !value[i]) {
|
|
22
|
+
e.preventDefault();
|
|
23
|
+
const arr = value.split("");
|
|
24
|
+
arr[i - 1] = "";
|
|
25
|
+
set(arr.join(""));
|
|
26
|
+
focus(i - 1);
|
|
27
|
+
}
|
|
28
|
+
else if (e.key === "ArrowLeft") {
|
|
29
|
+
e.preventDefault();
|
|
30
|
+
focus(i - 1);
|
|
31
|
+
}
|
|
32
|
+
else if (e.key === "ArrowRight") {
|
|
33
|
+
e.preventDefault();
|
|
34
|
+
focus(i + 1);
|
|
35
|
+
}
|
|
36
|
+
}, onPaste: (e) => {
|
|
37
|
+
const text = (e.clipboardData.getData("text") || "").split("").filter((c) => pattern.test(c)).join("");
|
|
38
|
+
if (!text)
|
|
39
|
+
return;
|
|
40
|
+
e.preventDefault();
|
|
41
|
+
set(text);
|
|
42
|
+
focus(Math.min(text.length, length - 1));
|
|
43
|
+
} }));
|
|
44
|
+
}
|
|
45
|
+
/** One box per character of a one-time code; typing advances, Backspace goes back, a paste fills them all. */
|
|
46
|
+
export function OtpInput(props) {
|
|
47
|
+
const length = props.length || 6;
|
|
48
|
+
const [uncontrolled, setUncontrolled] = useState(() => (props.defaultValue || "").slice(0, length));
|
|
49
|
+
const value = props.value !== undefined ? props.value : uncontrolled;
|
|
50
|
+
const refs = useRef([]);
|
|
51
|
+
const uid = useUid("vk-otp");
|
|
52
|
+
const pattern = props.numeric === false ? /[^\s]/ : /\d/;
|
|
53
|
+
const set = (next) => {
|
|
54
|
+
const v = next.slice(0, length);
|
|
55
|
+
if (props.value === undefined)
|
|
56
|
+
setUncontrolled(v);
|
|
57
|
+
props.onChange?.(v);
|
|
58
|
+
if (v.length === length)
|
|
59
|
+
props.onComplete?.(v);
|
|
60
|
+
};
|
|
61
|
+
const focus = (i) => {
|
|
62
|
+
const el = refs.current[Math.max(0, Math.min(length - 1, i))];
|
|
63
|
+
if (el) {
|
|
64
|
+
el.focus();
|
|
65
|
+
el.select();
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
const boxes = [];
|
|
69
|
+
for (let i = 0; i < length; i++) {
|
|
70
|
+
boxes.push(_jsx(OtpBox, { index: i, length: length, value: value, pattern: pattern, firstId: props.id || uid, props: props, boxRef: (el) => {
|
|
71
|
+
refs.current[i] = el;
|
|
72
|
+
}, set: set, focus: focus }, i));
|
|
73
|
+
}
|
|
74
|
+
return (_jsxs("div", { role: "group", className: cx("vk-otp", props.className), "aria-labelledby": props["aria-labelledby"], "aria-label": props["aria-labelledby"] ? undefined : props["aria-label"] || "One-time code", children: [boxes, props.name ? _jsx("input", { type: "hidden", name: props.name, value: value }) : null] }));
|
|
75
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import { type BadgeProps } from "../Badge/Badge.js";
|
|
3
|
+
import { type BreadcrumbsProps } from "../Breadcrumbs/Breadcrumbs.js";
|
|
4
|
+
export interface PageHeaderProps {
|
|
5
|
+
title: ReactNode;
|
|
6
|
+
description?: ReactNode;
|
|
7
|
+
eyebrow?: ReactNode;
|
|
8
|
+
breadcrumbs?: BreadcrumbsProps["items"];
|
|
9
|
+
actions?: ReactNode;
|
|
10
|
+
badge?: ReactNode;
|
|
11
|
+
badgeTone?: BadgeProps["tone"];
|
|
12
|
+
divider?: boolean;
|
|
13
|
+
headingAs?: "h1" | "h2";
|
|
14
|
+
children?: ReactNode;
|
|
15
|
+
className?: string;
|
|
16
|
+
}
|
|
17
|
+
/** The top of a page inside an app: breadcrumbs, the page title, a description and the page's main actions. */
|
|
18
|
+
export declare function PageHeader({ title, description, eyebrow, breadcrumbs, actions, badge, badgeTone, divider, headingAs, children, className }: PageHeaderProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Badge } from "../Badge/Badge.js";
|
|
3
|
+
import { Breadcrumbs } from "../Breadcrumbs/Breadcrumbs.js";
|
|
4
|
+
import { cx } from "../../lib/cx.js";
|
|
5
|
+
import { para } from "../../lib/text.js";
|
|
6
|
+
/** The top of a page inside an app: breadcrumbs, the page title, a description and the page's main actions. */
|
|
7
|
+
export function PageHeader({ title, description, eyebrow, breadcrumbs, actions, badge, badgeTone, divider, headingAs, children, className }) {
|
|
8
|
+
const Heading = headingAs || "h1";
|
|
9
|
+
const Description = para(description);
|
|
10
|
+
return (_jsxs("header", { className: cx("vk-page-header", divider ? "vk-page-header-divider" : null, className), children: [breadcrumbs ? _jsx(Breadcrumbs, { items: breadcrumbs }) : null, _jsxs("div", { className: "vk-page-header-row", children: [_jsxs("div", { className: "vk-page-header-text", children: [eyebrow ? _jsx("p", { className: "vk-page-header-eyebrow", children: eyebrow }) : null, _jsxs(Heading, { className: "vk-page-header-title", children: [title, badge ? _jsx(Badge, { tone: badgeTone, children: badge }) : null] }), description ? _jsx(Description, { className: "vk-page-header-description", children: description }) : null] }), actions ? _jsx("div", { className: "vk-page-header-actions", children: actions }) : null] }), children] }));
|
|
11
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
export interface PaginationProps {
|
|
3
|
+
pageCount: number;
|
|
4
|
+
page?: number;
|
|
5
|
+
defaultPage?: number;
|
|
6
|
+
onChange?: (page: number) => void;
|
|
7
|
+
siblings?: number;
|
|
8
|
+
summary?: ReactNode;
|
|
9
|
+
previousLabel?: string;
|
|
10
|
+
nextLabel?: string;
|
|
11
|
+
label?: string;
|
|
12
|
+
className?: string;
|
|
13
|
+
}
|
|
14
|
+
/** Moves through a long list one page at a time, with an optional summary of what's shown. */
|
|
15
|
+
export declare function Pagination({ pageCount, page: pageProp, defaultPage, onChange, siblings, summary, previousLabel, nextLabel, label, className }: PaginationProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { Icon } from "../Icon/Icon.js";
|
|
5
|
+
import { cx } from "../../lib/cx.js";
|
|
6
|
+
import { pageList } from "../../lib/math.js";
|
|
7
|
+
/** Moves through a long list one page at a time, with an optional summary of what's shown. */
|
|
8
|
+
export function Pagination({ pageCount, page: pageProp, defaultPage, onChange, siblings, summary, previousLabel, nextLabel, label, className }) {
|
|
9
|
+
const count = Math.max(1, pageCount || 1);
|
|
10
|
+
const controlled = pageProp !== undefined;
|
|
11
|
+
const [internal, setInternal] = useState(defaultPage || 1);
|
|
12
|
+
const page = Math.min(count, Math.max(1, controlled ? pageProp : internal));
|
|
13
|
+
const go = (p) => {
|
|
14
|
+
if (p < 1 || p > count || p === page)
|
|
15
|
+
return;
|
|
16
|
+
if (!controlled)
|
|
17
|
+
setInternal(p);
|
|
18
|
+
onChange?.(p);
|
|
19
|
+
};
|
|
20
|
+
const pages = pageList(page, count, siblings ?? 1);
|
|
21
|
+
return (_jsxs("nav", { "aria-label": label || "Pagination", className: cx("vk-pagination", className), children: [summary ? _jsx("p", { className: "vk-pagination-summary", children: summary }) : null, _jsxs("ul", { className: "vk-pagination-list", children: [_jsx("li", { children: _jsxs("button", { type: "button", className: "vk-page vk-page-step", disabled: page === 1, onClick: () => go(page - 1), children: [_jsx(Icon, { name: "chevron-left" }), _jsx("span", { children: previousLabel || "Previous" })] }) }), pages.map((p) => typeof p === "string" ? (_jsx("li", { className: "vk-page-gap", "aria-hidden": "true", children: "…" }, p)) : (_jsx("li", { children: _jsx("button", { type: "button", className: "vk-page", "aria-current": p === page ? "page" : undefined, "aria-label": "Page " + p, onClick: () => go(p), children: p }) }, p))), _jsx("li", { children: _jsxs("button", { type: "button", className: "vk-page vk-page-step", disabled: page === count, onClick: () => go(page + 1), children: [_jsx("span", { children: nextLabel || "Next" }), _jsx(Icon, { name: "chevron-right" })] }) })] })] }));
|
|
22
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type InputProps } from "../Input/Input.js";
|
|
2
|
+
export interface PasswordInputProps extends Omit<InputProps, 'type' | 'suffix'> {
|
|
3
|
+
showLabel?: string;
|
|
4
|
+
hideLabel?: string;
|
|
5
|
+
}
|
|
6
|
+
/** Password field with a Show/Hide button, so people can check what they typed. The ref is the <input>. */
|
|
7
|
+
export declare const PasswordInput: import("react").ForwardRefExoticComponent<PasswordInputProps & import("react").RefAttributes<HTMLInputElement>>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { forwardRef, useState } from "react";
|
|
4
|
+
import { Input } from "../Input/Input.js";
|
|
5
|
+
import { omit } from "../../lib/omit.js";
|
|
6
|
+
/** Password field with a Show/Hide button, so people can check what they typed. The ref is the <input>. */
|
|
7
|
+
export const PasswordInput = forwardRef(function PasswordInput(props, ref) {
|
|
8
|
+
const [shown, setShown] = useState(false);
|
|
9
|
+
const rest = omit(props, ["showLabel", "hideLabel"]);
|
|
10
|
+
return (_jsx(Input, { autoComplete: "current-password", spellCheck: false, ...rest, ref: ref, type: shown ? "text" : "password", suffix: _jsx("button", { type: "button", className: "vk-affix-button", "aria-pressed": shown ? "true" : "false", disabled: props.disabled, onClick: () => setShown(!shown), children: shown ? props.hideLabel || "Hide" : props.showLabel || "Show" }) }));
|
|
11
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { IconName } from "../../types.js";
|
|
3
|
+
export interface PopoverProps {
|
|
4
|
+
label: string;
|
|
5
|
+
title?: string;
|
|
6
|
+
icon?: IconName;
|
|
7
|
+
variant?: 'outline' | 'ghost' | 'primary';
|
|
8
|
+
size?: 'sm';
|
|
9
|
+
align?: 'start' | 'end';
|
|
10
|
+
width?: string;
|
|
11
|
+
defaultOpen?: boolean;
|
|
12
|
+
children: ReactNode | ((api: {
|
|
13
|
+
close: () => void;
|
|
14
|
+
}) => ReactNode);
|
|
15
|
+
className?: string;
|
|
16
|
+
}
|
|
17
|
+
/** Non-modal panel attached to a button (Radix Popover). */
|
|
18
|
+
export declare function Popover({ label, title, icon, variant, size, align, width, defaultOpen, children, className }: PopoverProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useRef, useState } from "react";
|
|
4
|
+
import { Popover as Primitive } from "radix-ui";
|
|
5
|
+
import { Icon } from "../Icon/Icon.js";
|
|
6
|
+
import { focusables } from "../../internal/focusables.js";
|
|
7
|
+
import { cx } from "../../lib/cx.js";
|
|
8
|
+
/** Non-modal panel attached to a button (Radix Popover). */
|
|
9
|
+
export function Popover({ label, title, icon, variant, size, align, width, defaultOpen, children, className }) {
|
|
10
|
+
const [open, setOpen] = useState(Boolean(defaultOpen));
|
|
11
|
+
const popRef = useRef(null);
|
|
12
|
+
// Focus moves into the panel when it opens, not when it mounts already open.
|
|
13
|
+
const opened = useRef(false);
|
|
14
|
+
const onOpenChange = (next) => {
|
|
15
|
+
if (next)
|
|
16
|
+
opened.current = true;
|
|
17
|
+
setOpen(next);
|
|
18
|
+
};
|
|
19
|
+
return (_jsx("div", { className: cx("vk-menu-root", className), children: _jsxs(Primitive.Root, { open: open, onOpenChange: onOpenChange, children: [_jsxs(Primitive.Trigger, { className: cx("vk-btn", "vk-btn-" + (variant || "outline"), size === "sm" ? "vk-btn-sm" : null), 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: _jsxs(Primitive.Content, { ref: popRef, "aria-label": title || label, className: "vk-popover vk-popover-panel", side: "bottom", align: align === "end" ? "end" : "start", sideOffset: 4, collisionPadding: 8, style: width ? { width } : undefined, onOpenAutoFocus: (e) => {
|
|
20
|
+
e.preventDefault();
|
|
21
|
+
if (!opened.current || !popRef.current)
|
|
22
|
+
return;
|
|
23
|
+
const f = focusables(popRef.current);
|
|
24
|
+
(f[0] || popRef.current).focus();
|
|
25
|
+
}, children: [title ? _jsx("p", { className: "vk-popover-title", children: title }) : null, typeof children === "function" ? children({ close: () => setOpen(false) }) : children] }) })] }) }));
|
|
26
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
export interface ProgressProps {
|
|
3
|
+
value?: number;
|
|
4
|
+
max?: number;
|
|
5
|
+
label?: ReactNode;
|
|
6
|
+
showValue?: boolean;
|
|
7
|
+
valueText?: string;
|
|
8
|
+
tone?: "primary" | "success" | "warning" | "danger";
|
|
9
|
+
"aria-label"?: string;
|
|
10
|
+
className?: string;
|
|
11
|
+
}
|
|
12
|
+
/** A bar showing how far a task has got, or that it is still running (Radix Progress). */
|
|
13
|
+
export declare function Progress({ value, max: maxProp, label, showValue, valueText, tone, "aria-label": ariaLabel, className }: ProgressProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Progress as Primitive } from "radix-ui";
|
|
4
|
+
import { useUid } from "../../internal/useUid.js";
|
|
5
|
+
import { cx } from "../../lib/cx.js";
|
|
6
|
+
function measure(value, maxProp) {
|
|
7
|
+
const max = maxProp && maxProp > 0 ? maxProp : 100;
|
|
8
|
+
// Radix treats a value outside 0..max as indeterminate, so clamp it.
|
|
9
|
+
const now = value == null ? null : Math.max(0, Math.min(max, value));
|
|
10
|
+
const pct = now == null ? 0 : (now / max) * 100;
|
|
11
|
+
return { max, now, pct };
|
|
12
|
+
}
|
|
13
|
+
// The label and the value above the bar; the value is left out while indeterminate.
|
|
14
|
+
function ProgressRow({ label, labelId, value }) {
|
|
15
|
+
return (_jsxs("div", { className: "vk-progress-row", children: [label ? _jsx("span", { id: labelId, className: "vk-progress-label", children: label }) : _jsx("span", {}), value != null ? _jsx("span", { className: "vk-progress-value", children: value }) : null] }));
|
|
16
|
+
}
|
|
17
|
+
/** A bar showing how far a task has got, or that it is still running (Radix Progress). */
|
|
18
|
+
export function Progress({ value, max: maxProp, label, showValue, valueText, tone, "aria-label": ariaLabel, className }) {
|
|
19
|
+
const { max, now, pct } = measure(value, maxProp);
|
|
20
|
+
const indeterminate = now == null;
|
|
21
|
+
const labelId = useUid("vk-progress");
|
|
22
|
+
const shownValue = showValue && !indeterminate ? valueText || Math.round(pct) + "%" : null;
|
|
23
|
+
return (_jsxs("div", { className: cx("vk-progress", "vk-progress-" + (tone || "primary"), className), children: [label || showValue ? _jsx(ProgressRow, { label: label, labelId: labelId, value: shownValue }) : null, _jsx(Primitive.Root, { value: now, max: max, "aria-labelledby": label ? labelId : undefined, "aria-label": label ? undefined : ariaLabel || "Progress", "aria-valuetext": valueText, "aria-valuemin": indeterminate ? undefined : 0, "aria-valuemax": indeterminate ? undefined : max, className: "vk-progress-track", children: indeterminate ? null : _jsx(Primitive.Indicator, { className: "vk-progress-fill", style: { width: pct + "%" } }) })] }));
|
|
24
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { AsProp } from "../../types.js";
|
|
3
|
+
export interface ProseProps extends AsProp {
|
|
4
|
+
children?: ReactNode;
|
|
5
|
+
className?: string;
|
|
6
|
+
}
|
|
7
|
+
/** Styles long-form HTML (help articles, release notes, rendered Markdown) without a class on every element. */
|
|
8
|
+
export declare function Prose({ as, children, className }: ProseProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { cx } from "../../lib/cx.js";
|
|
3
|
+
/** Styles long-form HTML (help articles, release notes, rendered Markdown) without a class on every element. */
|
|
4
|
+
export function Prose({ as, children, className }) {
|
|
5
|
+
const Tag = as || "div";
|
|
6
|
+
return _jsx(Tag, { className: cx("vk-prose", className), children: children });
|
|
7
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Pull quote with optional attribution. */
|
|
2
|
+
export interface QuoteProps {
|
|
3
|
+
text: string;
|
|
4
|
+
emphasis?: string;
|
|
5
|
+
name?: string;
|
|
6
|
+
role?: string;
|
|
7
|
+
avatar?: string;
|
|
8
|
+
}
|
|
9
|
+
/** Pull quote with optional attribution. */
|
|
10
|
+
export declare function Quote({ text, emphasis, name, role, avatar }: QuoteProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Avatar } from "../Avatar/Avatar.js";
|
|
3
|
+
import { Icon } from "../Icon/Icon.js";
|
|
4
|
+
/** Pull quote with optional attribution. */
|
|
5
|
+
export function Quote({ text, emphasis, name, role, avatar }) {
|
|
6
|
+
return (_jsxs("blockquote", { className: "vk-quote", children: [_jsx("span", { className: "vk-quote-icon", "aria-hidden": "true", children: _jsx(Icon, { name: "quote" }) }), _jsxs("p", { className: "vk-quote-text", children: [_jsx("span", { children: text }), emphasis ? _jsx("strong", { children: emphasis }) : null] }), name ? (_jsx("footer", { className: "vk-quote-footer", children: _jsxs("cite", { className: "vk-quote-cite", children: [_jsxs("span", { className: "vk-quote-identity", children: [_jsx(Avatar, { src: avatar, name: name, decorative: true, size: 34 }), _jsx("span", { className: "vk-quote-name", children: name })] }), role ? _jsx("span", { className: "vk-quote-sep", "aria-hidden": "true", children: "|" }) : null, role ? _jsx("span", { className: "vk-quote-role", children: role }) : null] }) })) : null] }));
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { CheckboxProps } from "../Checkbox/Checkbox.js";
|
|
2
|
+
export type RadioProps = CheckboxProps;
|
|
3
|
+
/**
|
|
4
|
+
* Square radio (inner square dot) with label and optional description. A native radio, since Radix radios only
|
|
5
|
+
* work inside a group; `RadioGroup` draws the same box with Radix RadioGroup.
|
|
6
|
+
*/
|
|
7
|
+
export declare function Radio(props: RadioProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { nativeRadio } from "../../internal/choice.js";
|
|
3
|
+
/**
|
|
4
|
+
* Square radio (inner square dot) with label and optional description. A native radio, since Radix radios only
|
|
5
|
+
* work inside a group; `RadioGroup` draws the same box with Radix RadioGroup.
|
|
6
|
+
*/
|
|
7
|
+
export function Radio(props) {
|
|
8
|
+
return nativeRadio(props);
|
|
9
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type ChangeEventHandler, type ReactNode } from "react";
|
|
2
|
+
export interface RadioGroupProps {
|
|
3
|
+
label: ReactNode;
|
|
4
|
+
name: string;
|
|
5
|
+
options: (string | {
|
|
6
|
+
value: string;
|
|
7
|
+
label: ReactNode;
|
|
8
|
+
description?: ReactNode;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
})[];
|
|
11
|
+
value?: string;
|
|
12
|
+
defaultValue?: string;
|
|
13
|
+
/** Receives a change event whose target reads `value`, `name` and `checked` like a native radio. */
|
|
14
|
+
onChange?: ChangeEventHandler<HTMLInputElement>;
|
|
15
|
+
inline?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Fieldset of radios sharing one name (Radix RadioGroup): one Tab stop, arrow keys move and select.
|
|
19
|
+
* Inside a form each option submits through a hidden radio named `name`.
|
|
20
|
+
*/
|
|
21
|
+
export declare function RadioGroup(props: RadioGroupProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useRef, useState } from "react";
|
|
4
|
+
import { RadioGroup as Primitive } from "radix-ui";
|
|
5
|
+
import { ChoiceLabel, choiceChangeEvent, useArrowSelect } from "../../internal/choice.js";
|
|
6
|
+
import { useUid } from "../../internal/useUid.js";
|
|
7
|
+
import { cx } from "../../lib/cx.js";
|
|
8
|
+
/**
|
|
9
|
+
* Fieldset of radios sharing one name (Radix RadioGroup): one Tab stop, arrow keys move and select.
|
|
10
|
+
* Inside a form each option submits through a hidden radio named `name`.
|
|
11
|
+
*/
|
|
12
|
+
export function RadioGroup(props) {
|
|
13
|
+
const controlled = props.value !== undefined;
|
|
14
|
+
const [own, setOwn] = useState(props.defaultValue ?? null);
|
|
15
|
+
const value = controlled ? props.value : own;
|
|
16
|
+
const click = useRef(null);
|
|
17
|
+
const legendId = useUid("vk-radio-group");
|
|
18
|
+
const arrows = useArrowSelect();
|
|
19
|
+
// Radix is always controlled from here, so onValueChange runs inside the click that checked an option.
|
|
20
|
+
const onValueChange = (v) => {
|
|
21
|
+
const c = click.current;
|
|
22
|
+
click.current = null;
|
|
23
|
+
if (!c) {
|
|
24
|
+
// The form was reset; as natively, no change event.
|
|
25
|
+
if (!controlled)
|
|
26
|
+
setOwn(props.defaultValue ?? null);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (!controlled)
|
|
30
|
+
setOwn(v);
|
|
31
|
+
props.onChange?.(choiceChangeEvent(c.event, c.control, { type: "radio", checked: true, value: v, name: props.name }));
|
|
32
|
+
};
|
|
33
|
+
return (_jsx(Primitive.Root, { asChild: true, name: props.name, value: value, onValueChange: onValueChange, ...arrows.group, children: _jsxs("fieldset", { className: cx("vk-choice-group", props.inline && "vk-choice-group-inline"), "aria-labelledby": legendId, children: [_jsx("legend", { id: legendId, className: "vk-field-label", children: props.label }), _jsx("div", { className: "vk-choice-list", children: (props.options || []).map((o) => {
|
|
34
|
+
const opt = typeof o === "string" ? { value: o, label: o } : o;
|
|
35
|
+
return (_jsx(ChoiceLabel, { label: opt.label, description: opt.description, disabled: opt.disabled, children: _jsx(Primitive.Item, { className: "vk-choice-box vk-choice-box-radio", value: opt.value, disabled: opt.disabled, ...arrows.item, onClick: (e) => {
|
|
36
|
+
// Radix checks an option on its click (also the one it sends when an arrow key moves focus).
|
|
37
|
+
if (opt.value !== value)
|
|
38
|
+
click.current = { event: e, control: e.currentTarget };
|
|
39
|
+
}, children: _jsx(Primitive.Indicator, { forceMount: true, className: "vk-choice-dot" }) }) }, opt.value));
|
|
40
|
+
}) })] }) }));
|
|
41
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type ChangeEvent, type InputHTMLAttributes } from "react";
|
|
2
|
+
export interface SearchInputProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'value' | 'defaultValue' | 'onChange' | 'type'> {
|
|
3
|
+
value?: string;
|
|
4
|
+
defaultValue?: string;
|
|
5
|
+
onChange?: (value: string, event?: ChangeEvent<HTMLInputElement>) => void;
|
|
6
|
+
onClear?: () => void;
|
|
7
|
+
clearLabel?: string;
|
|
8
|
+
}
|
|
9
|
+
/** Search field with icon and clear button; no suggestions. The ref is the <input>. */
|
|
10
|
+
export declare const SearchInput: import("react").ForwardRefExoticComponent<SearchInputProps & import("react").RefAttributes<HTMLInputElement>>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { forwardRef, useCallback, useRef, useState } from "react";
|
|
4
|
+
import { Icon } from "../Icon/Icon.js";
|
|
5
|
+
import { cx } from "../../lib/cx.js";
|
|
6
|
+
import { omit } from "../../lib/omit.js";
|
|
7
|
+
/** Search field with icon and clear button; no suggestions. The ref is the <input>. */
|
|
8
|
+
export const SearchInput = forwardRef(function SearchInput(props, ref) {
|
|
9
|
+
const controlled = props.value !== undefined;
|
|
10
|
+
const [text, setText] = useState(props.defaultValue || "");
|
|
11
|
+
const value = controlled ? props.value : text;
|
|
12
|
+
const inputRef = useRef(null);
|
|
13
|
+
// The clear button refocuses the input; the forwarded ref gets it too.
|
|
14
|
+
const setRef = useCallback((el) => {
|
|
15
|
+
inputRef.current = el;
|
|
16
|
+
if (typeof ref === "function")
|
|
17
|
+
ref(el);
|
|
18
|
+
else if (ref)
|
|
19
|
+
ref.current = el;
|
|
20
|
+
}, [ref]);
|
|
21
|
+
const rest = omit(props, ["value", "defaultValue", "onChange", "onClear", "className", "clearLabel"]);
|
|
22
|
+
const set = (v, e) => {
|
|
23
|
+
if (!controlled)
|
|
24
|
+
setText(v);
|
|
25
|
+
props.onChange?.(v, e);
|
|
26
|
+
};
|
|
27
|
+
return (_jsxs("span", { className: cx("vk-search", props.className), children: [_jsx(Icon, { name: "search", size: 16, className: "vk-search-icon" }), _jsx("input", { ref: setRef, type: "search", className: "vk-input vk-search-input", autoComplete: "off", ...rest, value: value, onChange: (e) => set(e.target.value, e), onKeyDown: (e) => {
|
|
28
|
+
if (e.key === "Escape" && value) {
|
|
29
|
+
e.preventDefault();
|
|
30
|
+
set("");
|
|
31
|
+
props.onClear?.();
|
|
32
|
+
}
|
|
33
|
+
props.onKeyDown?.(e);
|
|
34
|
+
} }), value && !props.disabled ? (_jsx("button", { type: "button", className: "vk-field-clear", "aria-label": props.clearLabel || "Clear search", onClick: () => {
|
|
35
|
+
set("");
|
|
36
|
+
props.onClear?.();
|
|
37
|
+
inputRef.current?.focus();
|
|
38
|
+
}, children: _jsx(Icon, { name: "x", size: 16 }) })) : null] }));
|
|
39
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Section header: square glyph, uppercase label, optional lead. */
|
|
2
|
+
export interface SectionHeaderProps {
|
|
3
|
+
id: string;
|
|
4
|
+
heading: string;
|
|
5
|
+
lead?: string;
|
|
6
|
+
glyph?: string;
|
|
7
|
+
as?: "h1" | "h2" | "h3";
|
|
8
|
+
}
|
|
9
|
+
/** Section header: square glyph, uppercase label, optional lead. */
|
|
10
|
+
export declare function SectionHeader({ id, heading, lead, glyph, as }: SectionHeaderProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { SquareGlyph } from "../SquareGlyph/SquareGlyph.js";
|
|
3
|
+
import { para } from "../../lib/text.js";
|
|
4
|
+
/** Section header: square glyph, uppercase label, optional lead. */
|
|
5
|
+
export function SectionHeader({ id, heading, lead, glyph, as }) {
|
|
6
|
+
const Tag = as || "h2";
|
|
7
|
+
const Lead = para(lead);
|
|
8
|
+
return (_jsxs("header", { className: "vk-section-header", children: [_jsxs(Tag, { id: id, className: "vk-section-heading", children: [_jsx(SquareGlyph, { children: glyph == null ? "+" : glyph }), _jsx("span", { children: heading })] }), lead ? _jsx(Lead, { className: "vk-section-lead", children: lead }) : null] }));
|
|
9
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { IconName } from "../../types.js";
|
|
3
|
+
/** Exclusive options that apply immediately (radiogroup). */
|
|
4
|
+
export interface SegmentedControlProps {
|
|
5
|
+
options: (string | {
|
|
6
|
+
value: string;
|
|
7
|
+
label: ReactNode;
|
|
8
|
+
icon?: IconName;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
})[];
|
|
11
|
+
value?: string;
|
|
12
|
+
defaultValue?: string;
|
|
13
|
+
onChange?: (value: string) => void;
|
|
14
|
+
label?: string;
|
|
15
|
+
size?: "sm";
|
|
16
|
+
className?: string;
|
|
17
|
+
}
|
|
18
|
+
/** Exclusive options that apply immediately (Radix RadioGroup): one Tab stop, arrow keys move the selection and wrap. */
|
|
19
|
+
export declare function SegmentedControl({ options: optionsProp, value: valueProp, defaultValue, onChange, label, size, className }: SegmentedControlProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { RadioGroup as Primitive } from "radix-ui";
|
|
5
|
+
import { Icon } from "../Icon/Icon.js";
|
|
6
|
+
import { cx } from "../../lib/cx.js";
|
|
7
|
+
import { normalizeOptions } from "../../internal/options.js";
|
|
8
|
+
import { useArrowSelect } from "../../internal/choice.js";
|
|
9
|
+
/** Exclusive options that apply immediately (Radix RadioGroup): one Tab stop, arrow keys move the selection and wrap. */
|
|
10
|
+
export function SegmentedControl({ options: optionsProp, value: valueProp, defaultValue, onChange, label, size, className }) {
|
|
11
|
+
const options = normalizeOptions(optionsProp);
|
|
12
|
+
const controlled = valueProp !== undefined;
|
|
13
|
+
const [internal, setInternal] = useState(defaultValue !== undefined ? defaultValue : options.length ? options[0].value : null);
|
|
14
|
+
const value = controlled ? valueProp : internal;
|
|
15
|
+
const arrows = useArrowSelect();
|
|
16
|
+
return (_jsx(Primitive.Root, { "aria-label": label, className: cx("vk-segmented", size === "sm" && "vk-segmented-sm", className), value: value, ...arrows.group, onValueChange: (v) => {
|
|
17
|
+
if (!controlled)
|
|
18
|
+
setInternal(v);
|
|
19
|
+
onChange?.(v);
|
|
20
|
+
}, children: options.map((o) => (_jsxs(Primitive.Item, { value: o.value, disabled: o.disabled, className: "vk-segment", ...arrows.item, children: [o.icon ? _jsx(Icon, { name: o.icon, size: 16 }) : null, o.label] }, o.value))) }));
|
|
21
|
+
}
|