@vokality/design-system 0.0.0-stage → 1.2.3
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 +97 -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,26 @@
|
|
|
1
|
+
import type { SelectOption } from "../../types.js";
|
|
2
|
+
export interface SelectProps {
|
|
3
|
+
options: (string | SelectOption)[];
|
|
4
|
+
placeholder?: string;
|
|
5
|
+
value?: string | null;
|
|
6
|
+
defaultValue?: string;
|
|
7
|
+
onChange?: (value: string, option: SelectOption) => void;
|
|
8
|
+
/** Adds a hidden input so the value posts with a form. */
|
|
9
|
+
name?: string;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
required?: boolean;
|
|
12
|
+
/** Start open (documentation and tests). */
|
|
13
|
+
defaultOpen?: boolean;
|
|
14
|
+
id?: string;
|
|
15
|
+
className?: string;
|
|
16
|
+
'aria-label'?: string;
|
|
17
|
+
'aria-labelledby'?: string;
|
|
18
|
+
'aria-describedby'?: string;
|
|
19
|
+
'aria-invalid'?: boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Custom select (Radix Select, popper position; WAI-ARIA select-only combobox); no native <select>.
|
|
23
|
+
* The ref is the trigger button. Radix forbids "" as an item value, so items carry their index
|
|
24
|
+
* and "" means nothing is chosen: any option value, "" included, works.
|
|
25
|
+
*/
|
|
26
|
+
export declare const Select: import("react").ForwardRefExoticComponent<SelectProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { forwardRef, useCallback, useEffect, useRef, useState } from "react";
|
|
4
|
+
import { flushSync } from "react-dom";
|
|
5
|
+
import { Select as Primitive } from "radix-ui";
|
|
6
|
+
import { Icon } from "../Icon/Icon.js";
|
|
7
|
+
import { focusables } from "../../internal/focusables.js";
|
|
8
|
+
import { normalizeOptions } from "../../internal/options.js";
|
|
9
|
+
import { useIsoLayoutEffect } from "../../internal/useIsoLayoutEffect.js";
|
|
10
|
+
import { useUid } from "../../internal/useUid.js";
|
|
11
|
+
import { omit } from "../../lib/omit.js";
|
|
12
|
+
import { cx } from "../../lib/cx.js";
|
|
13
|
+
/** Keys the closed trigger or the opening list holds for the list until it has focus. */
|
|
14
|
+
const HELD = ["ArrowDown", "ArrowUp", "Home", "End", "PageUp", "PageDown", "Enter"];
|
|
15
|
+
const typed = (e) => e.key.length === 1 && !e.altKey && !e.ctrlKey && !e.metaKey;
|
|
16
|
+
/** Focus the next (dir 1) or previous (-1) tabbable element after `from`, wrapping inside a modal dialog like its focus trap. */
|
|
17
|
+
function focusNext(from, dir) {
|
|
18
|
+
const body = from.ownerDocument.body;
|
|
19
|
+
const scope = from.closest('[aria-modal="true"]') || body;
|
|
20
|
+
const list = focusables(scope).filter((n) => n.tabIndex >= 0);
|
|
21
|
+
const at = list.indexOf(from);
|
|
22
|
+
let next = at >= 0 ? list[at + dir] : undefined;
|
|
23
|
+
if (!next && at >= 0 && scope !== body)
|
|
24
|
+
next = list[dir > 0 ? 0 : list.length - 1];
|
|
25
|
+
(next || from).focus();
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Custom select (Radix Select, popper position; WAI-ARIA select-only combobox); no native <select>.
|
|
29
|
+
* The ref is the trigger button. Radix forbids "" as an item value, so items carry their index
|
|
30
|
+
* and "" means nothing is chosen: any option value, "" included, works.
|
|
31
|
+
*/
|
|
32
|
+
export const Select = forwardRef(function Select(props, ref) {
|
|
33
|
+
const options = normalizeOptions(props.options);
|
|
34
|
+
const baseId = useUid("vk-select");
|
|
35
|
+
const controlled = props.value !== undefined;
|
|
36
|
+
const [uncontrolledValue, setValue] = useState(() => props.defaultValue !== undefined ? props.defaultValue : props.placeholder ? null : options.length ? options[0].value : null);
|
|
37
|
+
const value = controlled ? props.value : uncontrolledValue;
|
|
38
|
+
const [open, setOpen] = useState(Boolean(props.defaultOpen));
|
|
39
|
+
const triggerRef = useRef(null);
|
|
40
|
+
const contentRef = useRef(null);
|
|
41
|
+
const held = useRef([]);
|
|
42
|
+
const tabbing = useRef(0);
|
|
43
|
+
const search = useRef({ text: "", timer: 0 });
|
|
44
|
+
let selectedIndex = -1;
|
|
45
|
+
for (let k = 0; k < options.length; k++)
|
|
46
|
+
if (options[k].value === value)
|
|
47
|
+
selectedIndex = k;
|
|
48
|
+
const selected = selectedIndex >= 0 ? options[selectedIndex] : null;
|
|
49
|
+
const choose = (i) => {
|
|
50
|
+
const o = options[i];
|
|
51
|
+
if (!o || o.disabled || i === selectedIndex)
|
|
52
|
+
return;
|
|
53
|
+
if (!controlled)
|
|
54
|
+
setValue(o.value);
|
|
55
|
+
props.onChange?.(o.value, o);
|
|
56
|
+
};
|
|
57
|
+
const onValueChange = (v) => {
|
|
58
|
+
// "" only comes from a form reset back to "nothing chosen".
|
|
59
|
+
if (v === "") {
|
|
60
|
+
if (!controlled)
|
|
61
|
+
setValue(null);
|
|
62
|
+
}
|
|
63
|
+
else
|
|
64
|
+
choose(Number(v));
|
|
65
|
+
};
|
|
66
|
+
// Radix hands focus back to the trigger only after the list has unmounted (a frame or two
|
|
67
|
+
// later), so keys typed right after choosing or Escape would land on <body>. Close
|
|
68
|
+
// synchronously and move focus at once: to the trigger, or on from it after Tab.
|
|
69
|
+
const onOpenChange = (next) => {
|
|
70
|
+
if (next) {
|
|
71
|
+
setOpen(true);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
held.current = [];
|
|
75
|
+
search.current.text = "";
|
|
76
|
+
const hadFocus = Boolean(contentRef.current?.contains(document.activeElement));
|
|
77
|
+
const dir = tabbing.current;
|
|
78
|
+
tabbing.current = 0;
|
|
79
|
+
flushSync(() => setOpen(false));
|
|
80
|
+
const trigger = triggerRef.current;
|
|
81
|
+
if (!trigger || (!hadFocus && !dir))
|
|
82
|
+
return;
|
|
83
|
+
if (dir)
|
|
84
|
+
focusNext(trigger, dir);
|
|
85
|
+
else
|
|
86
|
+
trigger.focus({ preventScroll: true });
|
|
87
|
+
};
|
|
88
|
+
const items = () => Array.from(contentRef.current?.querySelectorAll("[role=option]:not([data-disabled])") || []);
|
|
89
|
+
const highlighted = () => {
|
|
90
|
+
const el = document.activeElement;
|
|
91
|
+
return el && el.getAttribute("role") === "option" && contentRef.current?.contains(el) ? Number(el.dataset.index) : -1;
|
|
92
|
+
};
|
|
93
|
+
const focusItem = (el) => {
|
|
94
|
+
if (!el)
|
|
95
|
+
return;
|
|
96
|
+
el.focus({ preventScroll: true });
|
|
97
|
+
el.scrollIntoView({ block: "nearest" });
|
|
98
|
+
};
|
|
99
|
+
const setTriggerRef = useCallback((el) => {
|
|
100
|
+
triggerRef.current = el;
|
|
101
|
+
if (typeof ref === "function")
|
|
102
|
+
ref(el);
|
|
103
|
+
else if (ref)
|
|
104
|
+
ref.current = el;
|
|
105
|
+
}, [ref]);
|
|
106
|
+
// Radix opens on Enter, Space, ↓ and ↑. Home/End (PageUp/PageDown), ↑ with nothing chosen, and
|
|
107
|
+
// typing a letter that matches open the list too, at that spot; keys pressed while the list is
|
|
108
|
+
// still opening are handed to it once it has focus.
|
|
109
|
+
const onTriggerKeyDown = (e) => {
|
|
110
|
+
const key = e.key;
|
|
111
|
+
if (open) {
|
|
112
|
+
if (typed(e) || HELD.includes(key)) {
|
|
113
|
+
e.preventDefault();
|
|
114
|
+
held.current.push(key);
|
|
115
|
+
}
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (props.disabled)
|
|
119
|
+
return;
|
|
120
|
+
let start = null;
|
|
121
|
+
if (key === "Home" || key === "PageUp")
|
|
122
|
+
start = "Home";
|
|
123
|
+
else if (key === "End" || key === "PageDown")
|
|
124
|
+
start = "End";
|
|
125
|
+
else if (key === "ArrowUp" && selectedIndex < 0)
|
|
126
|
+
start = "End";
|
|
127
|
+
else if (typed(e) && key !== " ") {
|
|
128
|
+
// Radix would change the value without opening; open at the match instead.
|
|
129
|
+
e.preventDefault();
|
|
130
|
+
const ch = key.toLowerCase();
|
|
131
|
+
if (options.some((o) => !o.disabled && String(o.label).toLowerCase().indexOf(ch) === 0))
|
|
132
|
+
start = key;
|
|
133
|
+
}
|
|
134
|
+
if (start) {
|
|
135
|
+
e.preventDefault();
|
|
136
|
+
held.current = [start];
|
|
137
|
+
setOpen(true);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
// Radix focuses the chosen (or first) option once the list is placed: replay the held keys there.
|
|
141
|
+
const onContentFocus = () => {
|
|
142
|
+
if (!held.current.length)
|
|
143
|
+
return;
|
|
144
|
+
const keys = held.current;
|
|
145
|
+
held.current = [];
|
|
146
|
+
const press = (list) => {
|
|
147
|
+
for (const key of list) {
|
|
148
|
+
const content = contentRef.current;
|
|
149
|
+
if (!content)
|
|
150
|
+
return;
|
|
151
|
+
const at = content.contains(document.activeElement) ? document.activeElement : content;
|
|
152
|
+
at.dispatchEvent(new window.KeyboardEvent("keydown", { key, bubbles: true, cancelable: true }));
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
// Moves happen at once, so the list never shows the interim option. A choosing key closes
|
|
156
|
+
// the list, which can't happen inside Radix's focus effect: it waits for the next task.
|
|
157
|
+
let cut = keys.findIndex((k) => k === "Enter" || k === " ");
|
|
158
|
+
if (cut < 0)
|
|
159
|
+
cut = keys.length;
|
|
160
|
+
press(keys.slice(0, cut));
|
|
161
|
+
if (cut < keys.length)
|
|
162
|
+
setTimeout(() => press(keys.slice(cut)));
|
|
163
|
+
};
|
|
164
|
+
// Type-to-jump, as Radix does it (1s buffer, a repeated letter cycles), but moving focus at once:
|
|
165
|
+
// Radix moves it in a timeout, so a quick Enter after a key would choose the old option.
|
|
166
|
+
const typeahead = (ch) => {
|
|
167
|
+
const s = search.current;
|
|
168
|
+
window.clearTimeout(s.timer);
|
|
169
|
+
s.text += ch.toLowerCase();
|
|
170
|
+
s.timer = window.setTimeout(() => (s.text = ""), 1000);
|
|
171
|
+
const repeated = s.text.length > 1 && Array.from(s.text).every((c) => c === s.text[0]);
|
|
172
|
+
const q = repeated ? s.text[0] : s.text;
|
|
173
|
+
const list = items();
|
|
174
|
+
const cur = list.indexOf(document.activeElement);
|
|
175
|
+
for (let n = 0; n < list.length; n++) {
|
|
176
|
+
const el = list[(Math.max(cur, 0) + n) % list.length];
|
|
177
|
+
if (q.length === 1 && el === list[cur])
|
|
178
|
+
continue;
|
|
179
|
+
if (String(options[Number(el.dataset.index)].label).toLowerCase().indexOf(q) === 0)
|
|
180
|
+
return focusItem(el);
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
const onContentKeyDown = (e) => {
|
|
184
|
+
const key = e.key;
|
|
185
|
+
const list = items();
|
|
186
|
+
const cur = list.indexOf(document.activeElement);
|
|
187
|
+
if (key === "Escape") {
|
|
188
|
+
// Radix closes the list; don't let a surrounding dialog close too.
|
|
189
|
+
e.stopPropagation();
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
if (key === "Enter") {
|
|
193
|
+
// The option has been chosen and focus is back on the trigger button: stop Enter from also clicking it open.
|
|
194
|
+
e.preventDefault();
|
|
195
|
+
}
|
|
196
|
+
else if (key === "Tab") {
|
|
197
|
+
// Choose the active option, close, and move focus on from the trigger.
|
|
198
|
+
e.preventDefault();
|
|
199
|
+
e.stopPropagation();
|
|
200
|
+
choose(highlighted());
|
|
201
|
+
tabbing.current = e.shiftKey ? -1 : 1;
|
|
202
|
+
onOpenChange(false);
|
|
203
|
+
}
|
|
204
|
+
else if (key === "ArrowUp" && e.altKey) {
|
|
205
|
+
e.preventDefault();
|
|
206
|
+
choose(highlighted());
|
|
207
|
+
onOpenChange(false);
|
|
208
|
+
}
|
|
209
|
+
else if (key === "ArrowDown" && e.altKey) {
|
|
210
|
+
e.preventDefault();
|
|
211
|
+
}
|
|
212
|
+
else if (key === "ArrowDown" || key === "ArrowUp" || key === "Home" || key === "End" || key === "PageUp" || key === "PageDown") {
|
|
213
|
+
// Moved here (not left to Radix's timeout) so the next key acts on the new option.
|
|
214
|
+
e.preventDefault();
|
|
215
|
+
const last = list.length - 1;
|
|
216
|
+
if (key === "ArrowDown")
|
|
217
|
+
focusItem(list[cur < 0 ? 0 : cur + 1]);
|
|
218
|
+
else if (key === "ArrowUp")
|
|
219
|
+
focusItem(list[cur < 0 ? last : cur - 1]);
|
|
220
|
+
else
|
|
221
|
+
focusItem(list[key === "Home" || key === "PageUp" ? 0 : last]);
|
|
222
|
+
}
|
|
223
|
+
else if (typed(e)) {
|
|
224
|
+
// Space while typing ahead is part of the search (see the option's onKeyDown).
|
|
225
|
+
if (key === " " && !search.current.text)
|
|
226
|
+
return;
|
|
227
|
+
e.preventDefault();
|
|
228
|
+
typeahead(key);
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
// A press outside the list and its trigger closes it. Radix does this too, but on slow machines
|
|
232
|
+
// (seen on CI) its dismiss can miss the press, leaving the list open over a page that ignores
|
|
233
|
+
// the pointer. Close on our own as well; a second close is a no-op.
|
|
234
|
+
const closeRef = useRef(onOpenChange);
|
|
235
|
+
useIsoLayoutEffect(() => {
|
|
236
|
+
closeRef.current = onOpenChange;
|
|
237
|
+
});
|
|
238
|
+
useEffect(() => {
|
|
239
|
+
if (!open)
|
|
240
|
+
return undefined;
|
|
241
|
+
const onDown = (e) => {
|
|
242
|
+
const target = e.target instanceof Node ? e.target : null;
|
|
243
|
+
if (!target || contentRef.current?.contains(target) || triggerRef.current?.contains(target))
|
|
244
|
+
return;
|
|
245
|
+
closeRef.current(false);
|
|
246
|
+
};
|
|
247
|
+
document.addEventListener("pointerdown", onDown, true);
|
|
248
|
+
return () => document.removeEventListener("pointerdown", onDown, true);
|
|
249
|
+
}, [open]);
|
|
250
|
+
// Radix chooses on Space; while a search is being typed, Space belongs to it instead.
|
|
251
|
+
const onOptionKeyDown = (e) => {
|
|
252
|
+
if (e.key === " " && search.current.text)
|
|
253
|
+
e.preventDefault();
|
|
254
|
+
};
|
|
255
|
+
// Focus has already been placed (see onOpenChange); don't let Radix pull it back to the trigger.
|
|
256
|
+
const onCloseAutoFocus = (e) => {
|
|
257
|
+
if (document.activeElement && document.activeElement !== document.body)
|
|
258
|
+
e.preventDefault();
|
|
259
|
+
};
|
|
260
|
+
const a11y = omit(props, ["options", "placeholder", "className", "value", "defaultValue", "onChange", "disabled", "name", "id", "defaultOpen", "required"]);
|
|
261
|
+
return (_jsxs("div", { className: cx("vk-select", props.className), children: [_jsxs(Primitive.Root, { value: selectedIndex >= 0 ? String(selectedIndex) : "", onValueChange: onValueChange, open: open, onOpenChange: onOpenChange, disabled: props.disabled, children: [_jsxs(Primitive.Trigger, { ref: setTriggerRef, id: props.id, className: "vk-input vk-select-trigger", "aria-haspopup": "listbox", "aria-required": props.required ? true : undefined, onKeyDown: onTriggerKeyDown, ...a11y, children: [_jsx("span", { className: selected ? "vk-select-value" : "vk-select-value vk-select-placeholder", children: selected ? selected.label : props.placeholder || "Select one" }), _jsx(Icon, { name: "chevron-down", className: "vk-select-icon" })] }), _jsx(Primitive.Portal, { children: _jsx(Primitive.Content, { ref: contentRef, position: "popper", side: "bottom", align: "start", sideOffset: 4, collisionPadding: 8, className: "vk-select-menu vk-select-content", "aria-label": props["aria-label"], "aria-labelledby": props["aria-labelledby"], onKeyDown: onContentKeyDown, onFocus: onContentFocus, onCloseAutoFocus: onCloseAutoFocus, children: _jsx(Primitive.Viewport, { className: "vk-select-viewport", children: options.map((o, i) => (_jsxs(Primitive.Item, { value: String(i), textValue: String(o.label), disabled: o.disabled, "data-index": i, "aria-describedby": o.description ? baseId + "-" + i + "-desc" : undefined, onKeyDown: onOptionKeyDown, className: "vk-select-option", children: [_jsxs("span", { className: "vk-select-option-text", children: [_jsx(Primitive.ItemText, { children: o.label }), o.description ? _jsx("span", { id: baseId + "-" + i + "-desc", className: "vk-select-option-description", children: o.description }) : null] }), i === selectedIndex ? _jsx(Icon, { name: "check", size: 16, className: "vk-select-check" }) : null] }, i + ":" + o.value))) }) }) })] }), props.name ? _jsx("input", { type: "hidden", name: props.name, value: value ?? "" }) : null] }));
|
|
262
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface SkeletonProps {
|
|
2
|
+
width?: string;
|
|
3
|
+
height?: string;
|
|
4
|
+
lines?: number;
|
|
5
|
+
className?: string;
|
|
6
|
+
}
|
|
7
|
+
/** Placeholder blocks shown where content is loading, in its final shape. */
|
|
8
|
+
export declare function Skeleton({ width, height, lines, className }: SkeletonProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { cx } from "../../lib/cx.js";
|
|
3
|
+
/** Placeholder blocks shown where content is loading, in its final shape. */
|
|
4
|
+
export function Skeleton({ width, height, lines, className }) {
|
|
5
|
+
if (lines) {
|
|
6
|
+
const out = [];
|
|
7
|
+
for (let i = 0; i < lines; i++) {
|
|
8
|
+
out.push(_jsx("span", { className: "vk-skeleton", style: { width: i === lines - 1 ? "62%" : "100%", height: "0.875rem" } }, i));
|
|
9
|
+
}
|
|
10
|
+
return _jsx("span", { className: cx("vk-skeleton-lines", className), "aria-hidden": "true", children: out });
|
|
11
|
+
}
|
|
12
|
+
return _jsx("span", { className: cx("vk-skeleton", className), "aria-hidden": "true", style: { width: width || "100%", height: height || "1rem" } });
|
|
13
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface SliderProps {
|
|
2
|
+
value?: number;
|
|
3
|
+
defaultValue?: number;
|
|
4
|
+
onChange?: (value: number) => void;
|
|
5
|
+
min?: number;
|
|
6
|
+
max?: number;
|
|
7
|
+
step?: number;
|
|
8
|
+
format?: (value: number) => string;
|
|
9
|
+
valueText?: (value: number) => string;
|
|
10
|
+
showValue?: boolean;
|
|
11
|
+
showLimits?: boolean;
|
|
12
|
+
name?: string;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
id?: string;
|
|
15
|
+
className?: string;
|
|
16
|
+
'aria-label'?: string;
|
|
17
|
+
'aria-labelledby'?: string;
|
|
18
|
+
'aria-describedby'?: string;
|
|
19
|
+
}
|
|
20
|
+
/** Picks a number from a range by dragging or with the keyboard (Radix Slider; WAI-ARIA slider). */
|
|
21
|
+
export declare function Slider(props: SliderProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { Slider as Primitive } from "radix-ui";
|
|
5
|
+
import { useUid } from "../../internal/useUid.js";
|
|
6
|
+
import { cx } from "../../lib/cx.js";
|
|
7
|
+
/** Picks a number from a range by dragging or with the keyboard (Radix Slider; WAI-ARIA slider). */
|
|
8
|
+
export function Slider(props) {
|
|
9
|
+
const min = props.min == null ? 0 : props.min, max = props.max == null ? 100 : props.max, step = props.step || 1;
|
|
10
|
+
const controlled = props.value !== undefined;
|
|
11
|
+
const [uncontrolled, setUncontrolled] = useState(props.defaultValue != null ? props.defaultValue : min);
|
|
12
|
+
const value = controlled ? props.value : uncontrolled;
|
|
13
|
+
const uid = useUid("vk-slider");
|
|
14
|
+
const id = props.id || uid;
|
|
15
|
+
const set = (n) => {
|
|
16
|
+
if (!controlled)
|
|
17
|
+
setUncontrolled(n);
|
|
18
|
+
props.onChange?.(n);
|
|
19
|
+
};
|
|
20
|
+
// PageUp / PageDown move a tenth of the range (Radix moves ten steps); the rest of the keys are Radix's.
|
|
21
|
+
const onKeyDown = (e) => {
|
|
22
|
+
if (props.disabled || (e.key !== "PageUp" && e.key !== "PageDown"))
|
|
23
|
+
return;
|
|
24
|
+
e.preventDefault();
|
|
25
|
+
const big = Math.max(step, (max - min) / 10);
|
|
26
|
+
const snapped = Math.round((value + (e.key === "PageUp" ? big : -big) - min) / step) * step + min;
|
|
27
|
+
const next = Math.max(min, Math.min(max, +snapped.toFixed(6)));
|
|
28
|
+
if (next !== value)
|
|
29
|
+
set(next);
|
|
30
|
+
};
|
|
31
|
+
const text = announce(props, value);
|
|
32
|
+
return (_jsxs("div", { className: cx("vk-slider", props.className), children: [props.showValue ? _jsx("output", { className: "vk-slider-value", htmlFor: id, children: text }) : null, _jsxs(Primitive.Root, { className: "vk-slider-track", min: min, max: max, step: step, name: props.name, disabled: props.disabled, value: [value], onValueChange: (v) => set(v[0]), onKeyDown: onKeyDown, children: [_jsx(Primitive.Range, { className: "vk-slider-fill" }), _jsx(Primitive.Thumb, { id: id, className: "vk-slider-thumb", "aria-valuenow": value, "aria-valuetext": text, "aria-disabled": props.disabled ? "true" : undefined, "aria-label": props["aria-label"], "aria-labelledby": props["aria-labelledby"], "aria-describedby": props["aria-describedby"] })] }), props.showLimits ? _jsx(SliderLimits, { min: min, max: max, format: props.format }) : null] }));
|
|
33
|
+
}
|
|
34
|
+
// The value as shown and announced: valueText, else format, else the number.
|
|
35
|
+
function announce({ valueText, format }, value) {
|
|
36
|
+
if (valueText)
|
|
37
|
+
return valueText(value);
|
|
38
|
+
return format ? format(value) : String(value);
|
|
39
|
+
}
|
|
40
|
+
// The ends of the range under the track; visual only, the thumb announces its range.
|
|
41
|
+
function SliderLimits({ min, max, format }) {
|
|
42
|
+
return (_jsxs("div", { className: "vk-slider-limits", "aria-hidden": "true", children: [_jsx("span", { children: format ? format(min) : min }), _jsx("span", { children: format ? format(max) : max })] }));
|
|
43
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Status } from "../../types.js";
|
|
2
|
+
export interface SparklineProps {
|
|
3
|
+
values: number[];
|
|
4
|
+
width?: number;
|
|
5
|
+
height?: number;
|
|
6
|
+
tone?: Status | 'primary';
|
|
7
|
+
label?: string;
|
|
8
|
+
className?: string;
|
|
9
|
+
}
|
|
10
|
+
/** A word-sized trend line beside a number, in a table cell or a Stat. */
|
|
11
|
+
export declare function Sparkline(props: SparklineProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { cx } from "../../lib/cx.js";
|
|
3
|
+
/** A word-sized trend line beside a number, in a table cell or a Stat. */
|
|
4
|
+
export function Sparkline(props) {
|
|
5
|
+
const { width, height, tone, label, className } = props;
|
|
6
|
+
const values = props.values || [];
|
|
7
|
+
const w = width || 96, hgt = height || 28, p = 3;
|
|
8
|
+
const min = Math.min(...values), max = Math.max(...values);
|
|
9
|
+
const span = max - min || 1;
|
|
10
|
+
const pt = (v, i) => [p + ((w - 2 * p) * i) / Math.max(1, values.length - 1), hgt - p - ((v - min) / span) * (hgt - 2 * p)];
|
|
11
|
+
const pts = values.map((v, i) => pt(v, i).join(",")).join(" ");
|
|
12
|
+
const end = values.length ? pt(values[values.length - 1], values.length - 1) : [0, 0];
|
|
13
|
+
const color = tone ? "var(--" + tone + ")" : "var(--chart-1)";
|
|
14
|
+
return (_jsxs("svg", { className: cx("vk-sparkline", className), width: w, height: hgt, viewBox: "0 0 " + w + " " + hgt, role: "img", "aria-label": label || "Trend: " + values.join(", "), children: [_jsx("polyline", { points: pts, fill: "none", stroke: color, strokeWidth: 1.5, strokeLinejoin: "round", strokeLinecap: "round" }), values.length ? _jsx("circle", { cx: end[0], cy: end[1], r: 2.5, fill: color }) : null] }));
|
|
15
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface SpinnerProps {
|
|
2
|
+
size?: number;
|
|
3
|
+
label?: string;
|
|
4
|
+
showLabel?: boolean;
|
|
5
|
+
className?: string;
|
|
6
|
+
}
|
|
7
|
+
/** A small loading indicator for waits under a few seconds. */
|
|
8
|
+
export declare function Spinner({ size: sizeProp, label, showLabel, className }: SpinnerProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { cx } from "../../lib/cx.js";
|
|
3
|
+
/** A small loading indicator for waits under a few seconds. */
|
|
4
|
+
export function Spinner({ size: sizeProp, label, showLabel, className }) {
|
|
5
|
+
const size = sizeProp || 16;
|
|
6
|
+
const text = label || "Loading";
|
|
7
|
+
return (_jsxs("span", { role: "status", className: cx("vk-spinner-wrap", className), children: [_jsx("span", { className: "vk-spinner", style: { width: size + "px", height: size + "px" }, "aria-hidden": "true" }), showLabel ? _jsx("span", { className: "vk-spinner-label", children: text }) : _jsx("span", { className: "vk-sr-only", children: text })] }));
|
|
8
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
export interface SquareGlyphProps {
|
|
3
|
+
children?: ReactNode;
|
|
4
|
+
className?: string;
|
|
5
|
+
}
|
|
6
|
+
/** 34px square outline holding one character. Decorative. */
|
|
7
|
+
export declare function SquareGlyph({ children, className }: SquareGlyphProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { cx } from "../../lib/cx.js";
|
|
3
|
+
/** 34px square outline holding one character. Decorative. */
|
|
4
|
+
export function SquareGlyph({ children, className }) {
|
|
5
|
+
return (_jsx("span", { className: cx("vk-glyph", className), "aria-hidden": "true", children: _jsx("span", { className: "vk-glyph-char", children: children == null ? "+" : children }) }));
|
|
6
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { CSSProperties, ReactNode } from "react";
|
|
2
|
+
import type { AsProp, SpaceStep } from "../../types.js";
|
|
3
|
+
export interface StackProps extends AsProp {
|
|
4
|
+
gap?: SpaceStep | string;
|
|
5
|
+
align?: CSSProperties['alignItems'];
|
|
6
|
+
children?: ReactNode;
|
|
7
|
+
className?: string;
|
|
8
|
+
style?: CSSProperties;
|
|
9
|
+
}
|
|
10
|
+
/** Lays children out vertically with one gap from the spacing scale. */
|
|
11
|
+
export declare function Stack({ as, gap, align, children, className, style }: StackProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { cx } from "../../lib/cx.js";
|
|
3
|
+
import { space } from "../../lib/space.js";
|
|
4
|
+
/** Lays children out vertically with one gap from the spacing scale. */
|
|
5
|
+
export function Stack({ as, gap, align, children, className, style }) {
|
|
6
|
+
const Tag = as || "div";
|
|
7
|
+
return _jsx(Tag, { className: cx("vk-layout-stack", className), style: { gap: space(gap, "md"), alignItems: align, ...style }, children: children });
|
|
8
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
export interface StatProps {
|
|
3
|
+
label: ReactNode;
|
|
4
|
+
value: ReactNode;
|
|
5
|
+
unit?: string;
|
|
6
|
+
delta?: ReactNode;
|
|
7
|
+
deltaContext?: string;
|
|
8
|
+
trend?: "up" | "down";
|
|
9
|
+
upIsGood?: boolean;
|
|
10
|
+
className?: string;
|
|
11
|
+
}
|
|
12
|
+
/** One key number with its label and the change since the last period. */
|
|
13
|
+
export declare function Stat({ label, value, unit, delta, deltaContext, trend, upIsGood, className }: StatProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Icon } from "../Icon/Icon.js";
|
|
3
|
+
import { cx } from "../../lib/cx.js";
|
|
4
|
+
const DIRECTIONS = {
|
|
5
|
+
up: { icon: "arrow-up", spoken: "Up " },
|
|
6
|
+
down: { icon: "arrow-down", spoken: "Down " },
|
|
7
|
+
};
|
|
8
|
+
// Up is good unless upIsGood is false; without a trend the change is neutral.
|
|
9
|
+
function deltaTone(trend, upIsGood) {
|
|
10
|
+
if (trend !== "up" && trend !== "down")
|
|
11
|
+
return "neutral";
|
|
12
|
+
const good = (trend === "up") !== (upIsGood === false);
|
|
13
|
+
return good ? "success" : "danger";
|
|
14
|
+
}
|
|
15
|
+
function StatDelta({ delta, deltaContext, trend, upIsGood }) {
|
|
16
|
+
const dir = trend === "up" || trend === "down" ? DIRECTIONS[trend] : null;
|
|
17
|
+
return (_jsxs("p", { className: "vk-stat-delta vk-stat-" + deltaTone(trend, upIsGood), children: [dir ? _jsx(Icon, { name: dir.icon, size: 14 }) : null, _jsx("span", { className: "vk-sr-only", children: dir ? dir.spoken : "" }), _jsx("span", { children: delta }), deltaContext ? _jsx("span", { className: "vk-stat-context", children: " " + deltaContext }) : null] }));
|
|
18
|
+
}
|
|
19
|
+
/** One key number with its label and the change since the last period. */
|
|
20
|
+
export function Stat({ label, value, unit, delta, deltaContext, trend, upIsGood, className }) {
|
|
21
|
+
return (_jsxs("div", { className: cx("vk-stat", className), children: [_jsx("p", { className: "vk-stat-label", children: label }), _jsxs("p", { className: "vk-stat-value", children: [value, unit ? _jsx("span", { className: "vk-stat-unit", children: unit }) : null] }), delta ? _jsx(StatDelta, { delta: delta, deltaContext: deltaContext, trend: trend, upIsGood: upIsGood }) : null] }));
|
|
22
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
export interface StepsProps {
|
|
3
|
+
steps: {
|
|
4
|
+
label: ReactNode;
|
|
5
|
+
description?: ReactNode;
|
|
6
|
+
}[];
|
|
7
|
+
current?: number;
|
|
8
|
+
orientation?: "horizontal" | "vertical";
|
|
9
|
+
label?: string;
|
|
10
|
+
className?: string;
|
|
11
|
+
}
|
|
12
|
+
/** Shows where someone is in a fixed sequence: onboarding, a checkout, a multi-page form. */
|
|
13
|
+
export declare function Steps({ steps: stepsProp, current: currentProp, orientation, label, className }: StepsProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Icon } from "../Icon/Icon.js";
|
|
3
|
+
import { cx } from "../../lib/cx.js";
|
|
4
|
+
import { pad } from "../../lib/text.js";
|
|
5
|
+
/** Shows where someone is in a fixed sequence: onboarding, a checkout, a multi-page form. */
|
|
6
|
+
export function Steps({ steps: stepsProp, current: currentProp, orientation, label, className }) {
|
|
7
|
+
const steps = stepsProp || [];
|
|
8
|
+
const current = currentProp || 0;
|
|
9
|
+
return (_jsx("ol", { className: cx("vk-steps", orientation === "vertical" && "vk-steps-vertical", className), "aria-label": label || "Progress", children: steps.map((s, i) => {
|
|
10
|
+
const state = i < current ? "complete" : i === current ? "current" : "upcoming";
|
|
11
|
+
return (_jsxs("li", { className: "vk-step vk-step-" + state, "aria-current": state === "current" ? "step" : undefined, children: [_jsx("span", { className: "vk-step-marker", "aria-hidden": "true", children: state === "complete" ? _jsx(Icon, { name: "check", size: 14 }) : pad(i + 1) }), _jsxs("span", { className: "vk-step-text", children: [_jsx("span", { className: "vk-step-label", children: s.label }), _jsx("span", { className: "vk-sr-only", children: state === "complete" ? " (completed)" : state === "current" ? " (current step)" : "" }), s.description ? _jsx("span", { className: "vk-step-description", children: s.description }) : null] })] }, (typeof s.label === "string" ? s.label : "") + "#" + i));
|
|
12
|
+
}) }));
|
|
13
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { CheckboxProps } from "../Checkbox/Checkbox.js";
|
|
2
|
+
export type SwitchProps = CheckboxProps;
|
|
3
|
+
/**
|
|
4
|
+
* Square on/off toggle for settings that apply immediately (Radix Switch: a button with role=switch). `onChange`
|
|
5
|
+
* receives a change event whose target reads `checked`, `value` and `name` like a native checkbox. The ref is the switch.
|
|
6
|
+
*/
|
|
7
|
+
export declare const Switch: import("react").ForwardRefExoticComponent<CheckboxProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { forwardRef } from "react";
|
|
4
|
+
import { Switch as Primitive } from "radix-ui";
|
|
5
|
+
import { ChoiceLabel, hiddenLabel, useChoiceToggle } from "../../internal/choice.js";
|
|
6
|
+
import { omit } from "../../lib/omit.js";
|
|
7
|
+
/**
|
|
8
|
+
* Square on/off toggle for settings that apply immediately (Radix Switch: a button with role=switch). `onChange`
|
|
9
|
+
* receives a change event whose target reads `checked`, `value` and `name` like a native checkbox. The ref is the switch.
|
|
10
|
+
*/
|
|
11
|
+
export const Switch = forwardRef(function Switch(props, ref) {
|
|
12
|
+
const toggle = useChoiceToggle(props);
|
|
13
|
+
// Radix owns data-state on the control, so a trigger's data-state (Tooltip, Popover) is not passed on.
|
|
14
|
+
const rest = omit(props, ["label", "description", "className", "indeterminate", "hideLabel", "checked", "defaultChecked", "onChange", "onClick", "value", "data-state"]);
|
|
15
|
+
return (_jsx(ChoiceLabel, { kind: "vk-switch", label: props.label, description: props.description, hideLabel: props.hideLabel, disabled: props.disabled, className: props.className, children: _jsx(Primitive.Root, { "aria-label": hiddenLabel(props), ...rest, ref: ref, className: "vk-switch-track", value: props.value == null ? undefined : String(props.value), checked: toggle.checked, onClick: toggle.onClick, onCheckedChange: toggle.change, children: _jsx(Primitive.Thumb, { className: "vk-switch-thumb" }) }) }));
|
|
16
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
export interface TableColumn<Row> {
|
|
3
|
+
key: string;
|
|
4
|
+
header: ReactNode;
|
|
5
|
+
sortable?: boolean;
|
|
6
|
+
numeric?: boolean;
|
|
7
|
+
nowrap?: boolean;
|
|
8
|
+
align?: "start" | "end";
|
|
9
|
+
width?: string;
|
|
10
|
+
render?: (row: Row) => ReactNode;
|
|
11
|
+
sortValue?: (row: Row) => string | number;
|
|
12
|
+
}
|
|
13
|
+
export interface TableSort {
|
|
14
|
+
key: string;
|
|
15
|
+
direction: "asc" | "desc";
|
|
16
|
+
}
|
|
17
|
+
export interface TableProps<Row = Record<string, unknown>> {
|
|
18
|
+
columns: TableColumn<Row>[];
|
|
19
|
+
rows: Row[];
|
|
20
|
+
rowKey?: string | ((row: Row) => string | number);
|
|
21
|
+
caption?: string;
|
|
22
|
+
captionHidden?: boolean;
|
|
23
|
+
density?: "default" | "compact";
|
|
24
|
+
maxHeight?: string;
|
|
25
|
+
emptyText?: ReactNode;
|
|
26
|
+
sort?: TableSort | null;
|
|
27
|
+
defaultSort?: TableSort | null;
|
|
28
|
+
onSortChange?: (sort: TableSort | null) => void;
|
|
29
|
+
manualSort?: boolean;
|
|
30
|
+
selectable?: boolean;
|
|
31
|
+
selected?: (string | number)[];
|
|
32
|
+
defaultSelected?: (string | number)[];
|
|
33
|
+
onSelectionChange?: (keys: (string | number)[]) => void;
|
|
34
|
+
rowLabel?: (row: Row) => string;
|
|
35
|
+
selectAllLabel?: string;
|
|
36
|
+
rowHeader?: boolean;
|
|
37
|
+
loading?: boolean;
|
|
38
|
+
loadingRows?: number;
|
|
39
|
+
renderExpanded?: (row: Row) => ReactNode;
|
|
40
|
+
defaultExpanded?: (string | number)[];
|
|
41
|
+
expandColumnLabel?: string;
|
|
42
|
+
/** Client-side pagination with a summary below. */
|
|
43
|
+
pageSize?: number;
|
|
44
|
+
summaryFormat?: (from: number, to: number, total: number) => ReactNode;
|
|
45
|
+
className?: string;
|
|
46
|
+
}
|
|
47
|
+
/** A data table for comparing records: sortable columns, row selection, numeric alignment and an empty state. */
|
|
48
|
+
export declare function Table<Row = Record<string, unknown>>(props: TableProps<Row>): import("react/jsx-runtime").JSX.Element;
|