@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,45 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { ChartFrame, cellLabel, cellNumber, chartKeys, chartTooltip, seriesColor, useChart } from "../../charts/chart.js";
|
|
4
|
+
import { niceTicks } from "../../lib/math.js";
|
|
5
|
+
/** Vertical bars for comparing amounts across categories: grouped, or stacked to show a total and its parts. */
|
|
6
|
+
export function BarChart(props) {
|
|
7
|
+
const c = useChart(props);
|
|
8
|
+
const { stacked } = props;
|
|
9
|
+
const data = props.data || [];
|
|
10
|
+
const height = props.height || 240;
|
|
11
|
+
const pad = { top: 12, right: 8, bottom: 28, left: 48 };
|
|
12
|
+
let max = 0;
|
|
13
|
+
for (const d of data) {
|
|
14
|
+
if (stacked)
|
|
15
|
+
max = Math.max(max, c.series.reduce((sum, s) => sum + cellNumber(d, s.key), 0));
|
|
16
|
+
else
|
|
17
|
+
for (const s of c.series)
|
|
18
|
+
max = Math.max(max, cellNumber(d, s.key));
|
|
19
|
+
}
|
|
20
|
+
const ticks = niceTicks(max, 4), top = ticks[ticks.length - 1];
|
|
21
|
+
const plotW = Math.max(10, c.width - pad.left - pad.right), plotH = height - pad.top - pad.bottom;
|
|
22
|
+
const band = plotW / Math.max(1, data.length), groupW = band * 0.64;
|
|
23
|
+
const y = (v) => pad.top + plotH - (v / top) * plotH;
|
|
24
|
+
const fmtTick = props.tickFormat || c.fmt;
|
|
25
|
+
const bars = data.flatMap((d, i) => {
|
|
26
|
+
const x0 = pad.left + band * i + (band - groupW) / 2;
|
|
27
|
+
if (stacked) {
|
|
28
|
+
let acc = 0;
|
|
29
|
+
return c.series.map((s, si) => {
|
|
30
|
+
const v = cellNumber(d, s.key), y1 = y(acc + v), y0 = y(acc);
|
|
31
|
+
acc += v;
|
|
32
|
+
// A 2px gap between stacked segments, except above the top one.
|
|
33
|
+
return _jsx("rect", { x: x0, y: y1, width: groupW, height: Math.max(0, y0 - y1 - (si < c.series.length - 1 && v ? 2 : 0)), fill: seriesColor(si), className: "vk-chart-bar" }, i + "-" + si);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
const w = (groupW - 2 * (c.series.length - 1)) / c.series.length;
|
|
37
|
+
return c.series.map((s, si) => {
|
|
38
|
+
const v = cellNumber(d, s.key);
|
|
39
|
+
return _jsx("rect", { x: x0 + si * (w + 2), y: y(v), width: Math.max(1, w), height: Math.max(0, y(0) - y(v)), fill: seriesColor(si), className: "vk-chart-bar" }, i + "-" + si);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
const activeX = c.active == null ? 0 : pad.left + band * c.active + band / 2;
|
|
43
|
+
const view = { ...props, data, series: c.series, format: c.fmt, xKey: c.xKey };
|
|
44
|
+
return (_jsx(ChartFrame, { ...view, children: _jsxs("div", { ref: c.ref, className: "vk-chart-plot", tabIndex: 0, role: "img", "aria-label": (props.title || "Bar chart") + ". Use the arrow keys to read each value.", onKeyDown: chartKeys(c, data.length), onMouseLeave: () => c.setActive(null), onBlur: () => c.setActive(null), children: [_jsxs("svg", { width: c.width, height: height, viewBox: "0 0 " + c.width + " " + height, "aria-hidden": "true", className: "vk-chart-svg", children: [ticks.map((t) => (_jsxs("g", { children: [_jsx("line", { x1: pad.left, x2: c.width - pad.right, y1: y(t), y2: y(t), className: t === 0 ? "vk-chart-baseline" : "vk-chart-grid" }), _jsx("text", { x: pad.left - 8, y: y(t), dy: "0.32em", textAnchor: "end", className: "vk-chart-tick", children: fmtTick(t) })] }, t))), c.active != null ? _jsx("rect", { x: pad.left + band * c.active, y: pad.top, width: band, height: plotH, className: "vk-chart-hoverband" }) : null, bars, data.map((d, i) => _jsx("text", { x: pad.left + band * i + band / 2, y: height - 8, textAnchor: "middle", className: "vk-chart-tick", children: cellLabel(d, c.xKey) }, "x" + i)), data.map((_, i) => _jsx("rect", { x: pad.left + band * i, y: pad.top, width: band, height: plotH, fill: "transparent", onMouseEnter: () => c.setActive(i) }, "hit" + i))] }), chartTooltip(view, c.active, activeX, c.width)] }) }));
|
|
45
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
export interface BreadcrumbsProps {
|
|
3
|
+
items: {
|
|
4
|
+
label: ReactNode;
|
|
5
|
+
href?: string;
|
|
6
|
+
}[];
|
|
7
|
+
label?: string;
|
|
8
|
+
className?: string;
|
|
9
|
+
}
|
|
10
|
+
/** The path from a section to the current page, for pages nested more than one level deep. */
|
|
11
|
+
export declare function Breadcrumbs({ items: itemsProp, label, className }: BreadcrumbsProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Anchor } from "../LinkProvider/LinkProvider.js";
|
|
3
|
+
import { cx } from "../../lib/cx.js";
|
|
4
|
+
/** The path from a section to the current page, for pages nested more than one level deep. */
|
|
5
|
+
export function Breadcrumbs({ items: itemsProp, label, className }) {
|
|
6
|
+
const items = itemsProp || [];
|
|
7
|
+
return (_jsx("nav", { "aria-label": label || "Breadcrumb", className: cx("vk-breadcrumbs", className), children: _jsx("ol", { children: items.map((it, i) => {
|
|
8
|
+
const last = i === items.length - 1;
|
|
9
|
+
return (_jsxs("li", { children: [last || !it.href ? (_jsx("span", { "aria-current": last ? "page" : undefined, className: "vk-crumb-current", children: it.label })) : (_jsx(Anchor, { href: it.href, className: "vk-crumb", children: it.label })), last ? null : _jsx("span", { className: "vk-crumb-sep", "aria-hidden": "true", children: "/" })] }, (it.href || "") + "#" + i));
|
|
10
|
+
}) }) }));
|
|
11
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type AnchorHTMLAttributes, type ButtonHTMLAttributes, type ReactNode } from "react";
|
|
2
|
+
export interface ButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement> & AnchorHTMLAttributes<HTMLAnchorElement>, 'children'> {
|
|
3
|
+
variant?: 'primary' | 'outline' | 'ghost' | 'danger';
|
|
4
|
+
size?: 'sm';
|
|
5
|
+
href?: string;
|
|
6
|
+
/** Disables the button, sets aria-busy and shows a spinner. */
|
|
7
|
+
loading?: boolean;
|
|
8
|
+
/** Label shown while loading ("Saving…"). */
|
|
9
|
+
loadingLabel?: ReactNode;
|
|
10
|
+
/** Full width. */
|
|
11
|
+
block?: boolean;
|
|
12
|
+
/** Adds the arrow-up-right glyph cell for links that leave the product. */
|
|
13
|
+
arrow?: boolean;
|
|
14
|
+
children: ReactNode;
|
|
15
|
+
}
|
|
16
|
+
/** Text button: primary, outline or ghost; an <a> when href is set. */
|
|
17
|
+
export declare const Button: import("react").ForwardRefExoticComponent<ButtonProps & import("react").RefAttributes<HTMLButtonElement & HTMLAnchorElement>>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from "react";
|
|
3
|
+
import { Icon } from "../Icon/Icon.js";
|
|
4
|
+
import { Anchor } from "../LinkProvider/LinkProvider.js";
|
|
5
|
+
import { cx } from "../../lib/cx.js";
|
|
6
|
+
import { omit } from "../../lib/omit.js";
|
|
7
|
+
/** Text button: primary, outline or ghost; an <a> when href is set. */
|
|
8
|
+
export const Button = forwardRef(function Button(props, ref) {
|
|
9
|
+
const variant = props.variant || "primary";
|
|
10
|
+
const rest = omit(props, ["variant", "size", "href", "arrow", "children", "className", "loading", "loadingLabel", "block"]);
|
|
11
|
+
const className = cx("vk-btn", "vk-btn-" + variant, props.size === "sm" && "vk-btn-sm", props.block && "vk-btn-block", props.loading && "vk-btn-loading", props.className);
|
|
12
|
+
const kids = [
|
|
13
|
+
_jsxs("span", { className: "vk-btn-label", children: [props.loading ? _jsx("span", { className: "vk-spinner vk-btn-spinner", "aria-hidden": "true" }) : null, props.loading && props.loadingLabel ? props.loadingLabel : props.children] }, "l"),
|
|
14
|
+
];
|
|
15
|
+
if (props.arrow) {
|
|
16
|
+
kids.push(_jsx("span", { className: "vk-btn-glyph", "aria-hidden": "true", children: _jsx(Icon, { name: "arrow-up-right" }) }, "g"));
|
|
17
|
+
}
|
|
18
|
+
if (props.href) {
|
|
19
|
+
return (_jsx(Anchor, { ref: ref, href: props.href, className: className, ...rest, children: kids }));
|
|
20
|
+
}
|
|
21
|
+
const busy = props.loading ? { disabled: true, "aria-busy": "true" } : null;
|
|
22
|
+
return (_jsx("button", { ref: ref, type: "button", className: className, ...rest, ...busy, children: kids }));
|
|
23
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { DateRange, ISODate } from "../../types.js";
|
|
2
|
+
/** Month grid for a date or a range (WAI-ARIA grid). */
|
|
3
|
+
export interface CalendarProps {
|
|
4
|
+
mode?: 'single' | 'range';
|
|
5
|
+
value?: ISODate | DateRange | null;
|
|
6
|
+
defaultValue?: ISODate | DateRange | null;
|
|
7
|
+
onChange?: (next: ISODate | DateRange) => void;
|
|
8
|
+
min?: ISODate;
|
|
9
|
+
max?: ISODate;
|
|
10
|
+
isDateDisabled?: (date: ISODate) => boolean;
|
|
11
|
+
/** 0 = Sunday (default), 1 = Monday. */
|
|
12
|
+
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
13
|
+
locale?: string;
|
|
14
|
+
defaultMonth?: ISODate;
|
|
15
|
+
autoFocus?: boolean;
|
|
16
|
+
/** The date marked as today. Default: the current date (pass it to render the same markup on server and client). */
|
|
17
|
+
today?: ISODate;
|
|
18
|
+
className?: string;
|
|
19
|
+
}
|
|
20
|
+
/** Month grid for a date or a range (WAI-ARIA grid). */
|
|
21
|
+
export declare function Calendar(props: CalendarProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useRef, useState } from "react";
|
|
4
|
+
import { IconButton } from "../IconButton/IconButton.js";
|
|
5
|
+
import { useUid } from "../../internal/useUid.js";
|
|
6
|
+
import { cx } from "../../lib/cx.js";
|
|
7
|
+
import { addDays, addMonths, clampDate, parseISO, sameDay, toISO } from "../../lib/dates.js";
|
|
8
|
+
import { resolveLocale } from "../../lib/format.js";
|
|
9
|
+
import { dateFormat } from "../../lib/intl.js";
|
|
10
|
+
/** Days from the start of the week to d. */
|
|
11
|
+
const weekday = (d, weekStart) => (d.getDay() - weekStart + 7) % 7;
|
|
12
|
+
/** The date a grid navigation key moves focus to, or null for any other key. */
|
|
13
|
+
function keyTarget(key, shift, focus, weekStart) {
|
|
14
|
+
switch (key) {
|
|
15
|
+
case "ArrowLeft": return addDays(focus, -1);
|
|
16
|
+
case "ArrowRight": return addDays(focus, 1);
|
|
17
|
+
case "ArrowUp": return addDays(focus, -7);
|
|
18
|
+
case "ArrowDown": return addDays(focus, 7);
|
|
19
|
+
case "Home": return addDays(focus, -weekday(focus, weekStart));
|
|
20
|
+
case "End": return addDays(focus, 6 - weekday(focus, weekStart));
|
|
21
|
+
case "PageUp": return addMonths(focus, shift ? -12 : -1);
|
|
22
|
+
case "PageDown": return addMonths(focus, shift ? 12 : 1);
|
|
23
|
+
default: return null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/** The value after choosing d: a date, or the range it starts, ends or restarts. */
|
|
27
|
+
function nextValue(d, range, selStart, selEnd) {
|
|
28
|
+
if (!range)
|
|
29
|
+
return toISO(d);
|
|
30
|
+
if (!selStart || selEnd)
|
|
31
|
+
return { start: toISO(d), end: null };
|
|
32
|
+
if (d < selStart)
|
|
33
|
+
return { start: toISO(d), end: toISO(selStart) };
|
|
34
|
+
return { start: toISO(selStart), end: toISO(d) };
|
|
35
|
+
}
|
|
36
|
+
/** The chosen date or range (controlled or not), as local dates, and a setter that reports changes. */
|
|
37
|
+
function useSelection(props, range) {
|
|
38
|
+
const valueProp = props.value;
|
|
39
|
+
const controlled = valueProp !== undefined;
|
|
40
|
+
const [uncontrolled, setUncontrolled] = useState(props.defaultValue !== undefined ? props.defaultValue : range ? { start: null, end: null } : null);
|
|
41
|
+
const value = controlled ? valueProp : uncontrolled;
|
|
42
|
+
const rangeValue = value && typeof value === "object" ? value : null;
|
|
43
|
+
const selStart = range ? parseISO(rangeValue?.start) : parseISO(typeof value === "string" ? value : null);
|
|
44
|
+
const selEnd = range ? parseISO(rangeValue?.end) : null;
|
|
45
|
+
const select = (next) => {
|
|
46
|
+
if (!controlled)
|
|
47
|
+
setUncontrolled(next);
|
|
48
|
+
props.onChange?.(next);
|
|
49
|
+
};
|
|
50
|
+
return { selStart, selEnd, select };
|
|
51
|
+
}
|
|
52
|
+
/** How a day shows: its selection state and the classes of its cell and button. */
|
|
53
|
+
function dayLook({ date: d, focus, today, range, selStart, selEnd, rangeEnd }) {
|
|
54
|
+
const outside = d.getMonth() !== focus.getMonth();
|
|
55
|
+
const isStart = sameDay(d, selStart), isEnd = sameDay(d, selEnd);
|
|
56
|
+
const inRange = range && selStart !== null && rangeEnd !== null && d > selStart && d < rangeEnd;
|
|
57
|
+
const isSel = isStart || isEnd;
|
|
58
|
+
const isToday = sameDay(d, today);
|
|
59
|
+
return {
|
|
60
|
+
selected: isSel || inRange,
|
|
61
|
+
isToday,
|
|
62
|
+
cellClass: cx(inRange && "vk-day-in-range", range && isStart && rangeEnd !== null && "vk-day-range-start", range && isEnd && "vk-day-range-end"),
|
|
63
|
+
dayClass: cx("vk-day", outside && "vk-day-outside", isSel && "vk-day-selected", isToday && "vk-day-today"),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function DayCell(props) {
|
|
67
|
+
const { date: d, onPick, onHover } = props;
|
|
68
|
+
const look = dayLook(props);
|
|
69
|
+
return (_jsx("td", { role: "gridcell", "aria-selected": look.selected ? "true" : "false", className: look.cellClass, children: _jsx("button", { type: "button", "data-date": toISO(d), tabIndex: sameDay(d, props.focus) ? 0 : -1, className: look.dayClass, "aria-label": props.label, "aria-current": look.isToday ? "date" : undefined, "aria-disabled": props.disabled ? "true" : undefined, onClick: () => onPick(d), onMouseEnter: onHover ? () => onHover(d) : undefined, children: d.getDate() }) }));
|
|
70
|
+
}
|
|
71
|
+
/** Month grid for a date or a range (WAI-ARIA grid). */
|
|
72
|
+
export function Calendar(props) {
|
|
73
|
+
const range = props.mode === "range";
|
|
74
|
+
const locale = resolveLocale(props.locale);
|
|
75
|
+
const weekStart = props.weekStartsOn == null ? 0 : props.weekStartsOn;
|
|
76
|
+
const min = parseISO(props.min), max = parseISO(props.max);
|
|
77
|
+
const today = parseISO(props.today) || parseISO(toISO(new Date()));
|
|
78
|
+
const { selStart, selEnd, select } = useSelection(props, range);
|
|
79
|
+
const [focus, setFocus] = useState(() => clampDate(selStart || parseISO(props.defaultMonth) || today, min, max));
|
|
80
|
+
const [hover, setHover] = useState(null);
|
|
81
|
+
const gridRef = useRef(null);
|
|
82
|
+
const wantFocus = useRef(Boolean(props.autoFocus));
|
|
83
|
+
const titleId = useUid("vk-cal-title");
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
if (!wantFocus.current || !gridRef.current)
|
|
86
|
+
return;
|
|
87
|
+
const el = gridRef.current.querySelector('[data-date="' + toISO(focus) + '"]');
|
|
88
|
+
if (el)
|
|
89
|
+
el.focus();
|
|
90
|
+
wantFocus.current = false;
|
|
91
|
+
});
|
|
92
|
+
const blocked = (d) => (min !== null && d < min) || (max !== null && d > max) || Boolean(props.isDateDisabled?.(toISO(d)));
|
|
93
|
+
const moveTo = (d, keepFocus) => {
|
|
94
|
+
setFocus(clampDate(d, min, max));
|
|
95
|
+
if (keepFocus !== false)
|
|
96
|
+
wantFocus.current = true;
|
|
97
|
+
};
|
|
98
|
+
const choose = (d) => {
|
|
99
|
+
if (blocked(d))
|
|
100
|
+
return;
|
|
101
|
+
setFocus(d);
|
|
102
|
+
select(nextValue(d, range, selStart, selEnd));
|
|
103
|
+
};
|
|
104
|
+
const onKeyDown = (e) => {
|
|
105
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
106
|
+
e.preventDefault();
|
|
107
|
+
choose(focus);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const d = keyTarget(e.key, e.shiftKey, focus, weekStart);
|
|
111
|
+
if (d) {
|
|
112
|
+
e.preventDefault();
|
|
113
|
+
moveTo(d);
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
const monthStart = new Date(focus.getFullYear(), focus.getMonth(), 1);
|
|
117
|
+
const gridStart = addDays(monthStart, -weekday(monthStart, weekStart));
|
|
118
|
+
const title = dateFormat(locale, { month: "long", year: "numeric" }).format(monthStart);
|
|
119
|
+
const wdShort = dateFormat(locale, { weekday: "short" });
|
|
120
|
+
const wdLong = dateFormat(locale, { weekday: "long" });
|
|
121
|
+
const dayLabel = dateFormat(locale, { weekday: "long", month: "long", day: "numeric", year: "numeric" });
|
|
122
|
+
const prevMonthEnd = new Date(focus.getFullYear(), focus.getMonth(), 0);
|
|
123
|
+
const nextMonthStart = new Date(focus.getFullYear(), focus.getMonth() + 1, 1);
|
|
124
|
+
const rangeEnd = selEnd || (range && selStart && hover && hover > selStart ? hover : null);
|
|
125
|
+
const pick = (d) => {
|
|
126
|
+
setFocus(d);
|
|
127
|
+
choose(d);
|
|
128
|
+
};
|
|
129
|
+
const head = [];
|
|
130
|
+
for (let c = 0; c < 7; c++) {
|
|
131
|
+
const wd = addDays(gridStart, c);
|
|
132
|
+
head.push(_jsx("th", { scope: "col", abbr: wdLong.format(wd), children: wdShort.format(wd).slice(0, 2) }, c));
|
|
133
|
+
}
|
|
134
|
+
const rows = [];
|
|
135
|
+
for (let r = 0; r < 6; r++) {
|
|
136
|
+
const cells = [];
|
|
137
|
+
for (let c = 0; c < 7; c++) {
|
|
138
|
+
const d = addDays(gridStart, r * 7 + c);
|
|
139
|
+
cells.push(_jsx(DayCell, { date: d, focus: focus, today: today, range: range, selStart: selStart, selEnd: selEnd, rangeEnd: rangeEnd, disabled: blocked(d), label: dayLabel.format(d), onPick: pick, onHover: range ? setHover : undefined }, toISO(d)));
|
|
140
|
+
}
|
|
141
|
+
rows.push(_jsx("tr", { children: cells }, r));
|
|
142
|
+
}
|
|
143
|
+
return (_jsxs("div", { className: cx("vk-calendar", props.className), children: [_jsxs("div", { className: "vk-calendar-header", children: [_jsx(IconButton, { icon: "chevron-left", label: "Previous month", disabled: min !== null && prevMonthEnd < min, onClick: () => moveTo(addMonths(focus, -1), false) }), _jsx("h2", { id: titleId, className: "vk-calendar-title", "aria-live": "polite", children: title }), _jsx(IconButton, { icon: "chevron-right", label: "Next month", disabled: max !== null && nextMonthStart > max, onClick: () => moveTo(addMonths(focus, 1), false) })] }), _jsxs("table", { ref: gridRef, role: "grid", className: "vk-calendar-grid", "aria-labelledby": titleId, onKeyDown: onKeyDown, onMouseLeave: () => setHover(null), children: [_jsx("thead", { children: _jsx("tr", { children: head }) }), _jsx("tbody", { children: rows })] })] }));
|
|
144
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
/** Outlined panel for a feature, plan, step or summary. */
|
|
3
|
+
export interface CardProps {
|
|
4
|
+
title: ReactNode;
|
|
5
|
+
children?: ReactNode;
|
|
6
|
+
eyebrow?: ReactNode;
|
|
7
|
+
/** Shown zero-padded ("01") in Space Grotesk. */
|
|
8
|
+
step?: number;
|
|
9
|
+
points?: string[];
|
|
10
|
+
footnote?: ReactNode;
|
|
11
|
+
as?: "div" | "li" | "article";
|
|
12
|
+
titleAs?: "h2" | "h3" | "h4";
|
|
13
|
+
className?: string;
|
|
14
|
+
}
|
|
15
|
+
/** Outlined panel for a feature, plan, step or summary. */
|
|
16
|
+
export declare function Card({ title, children, eyebrow, step, points, footnote, as, titleAs, className }: CardProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { cx } from "../../lib/cx.js";
|
|
3
|
+
import { pad, para } from "../../lib/text.js";
|
|
4
|
+
/** Outlined panel for a feature, plan, step or summary. */
|
|
5
|
+
export function Card({ title, children, eyebrow, step, points, footnote, as, titleAs, className }) {
|
|
6
|
+
const Tag = as || "div";
|
|
7
|
+
const TitleTag = titleAs || "h3";
|
|
8
|
+
const Body = para(children);
|
|
9
|
+
const Footnote = para(footnote);
|
|
10
|
+
return (_jsxs(Tag, { className: cx("vk-card", className), children: [step != null && _jsx("span", { className: "vk-step-number", "aria-hidden": "true", children: pad(step) }), eyebrow ? _jsx("p", { className: "vk-card-eyebrow", children: eyebrow }) : null, title ? _jsx(TitleTag, { className: "vk-card-title", children: title }) : null, children ? _jsx(Body, { className: "vk-card-body", children: children }) : null, points && points.length ? (_jsx("ul", { className: "vk-card-points", children: points.map((p) => _jsx("li", { children: p }, p)) })) : null, footnote ? _jsx(Footnote, { className: "vk-card-footnote", children: footnote }) : null] }));
|
|
11
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type InputHTMLAttributes, type ReactNode } from "react";
|
|
2
|
+
export interface CheckboxProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'type'> {
|
|
3
|
+
label: ReactNode;
|
|
4
|
+
description?: ReactNode;
|
|
5
|
+
indeterminate?: boolean;
|
|
6
|
+
hideLabel?: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Square checkbox with label and optional description (Radix Checkbox). `onChange` receives a change event whose
|
|
10
|
+
* target reads `checked`, `value` and `name` like a native checkbox. The ref is the checkbox control.
|
|
11
|
+
*/
|
|
12
|
+
export declare const Checkbox: import("react").ForwardRefExoticComponent<CheckboxProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { forwardRef, useState } from "react";
|
|
4
|
+
import { Checkbox as Primitive } from "radix-ui";
|
|
5
|
+
import { checkMark, ChoiceLabel, hiddenLabel, useChoiceToggle } from "../../internal/choice.js";
|
|
6
|
+
import { omit } from "../../lib/omit.js";
|
|
7
|
+
/**
|
|
8
|
+
* Square checkbox with label and optional description (Radix Checkbox). `onChange` receives a change event whose
|
|
9
|
+
* target reads `checked`, `value` and `name` like a native checkbox. The ref is the checkbox control.
|
|
10
|
+
*/
|
|
11
|
+
export const Checkbox = forwardRef(function Checkbox(props, ref) {
|
|
12
|
+
const toggle = useChoiceToggle(props);
|
|
13
|
+
// As natively, a click clears the indeterminate look until `indeterminate` changes.
|
|
14
|
+
const [cleared, setCleared] = useState(false);
|
|
15
|
+
const [wasIndeterminate, setWasIndeterminate] = useState(props.indeterminate);
|
|
16
|
+
if (wasIndeterminate !== props.indeterminate) {
|
|
17
|
+
setWasIndeterminate(props.indeterminate);
|
|
18
|
+
setCleared(false);
|
|
19
|
+
}
|
|
20
|
+
const mixed = Boolean(props.indeterminate) && !cleared;
|
|
21
|
+
// Radix owns data-state on the control, so a trigger's data-state (Tooltip, Popover) is not passed on.
|
|
22
|
+
const rest = omit(props, ["label", "description", "className", "indeterminate", "hideLabel", "checked", "defaultChecked", "onChange", "onClick", "value", "data-state"]);
|
|
23
|
+
return (_jsx(ChoiceLabel, { label: props.label, description: props.description, hideLabel: props.hideLabel, disabled: props.disabled, className: props.className, children: _jsx(Primitive.Root, { "aria-label": hiddenLabel(props), ...rest, ref: ref, className: "vk-choice-box", value: props.value == null ? undefined : String(props.value), checked: mixed ? "indeterminate" : toggle.checked, onClick: toggle.onClick, onCheckedChange: () => setCleared(toggle.change()), children: _jsx(Primitive.Indicator, { forceMount: true, asChild: true, children: checkMark(mixed) }) }) }));
|
|
24
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
export interface CodeProps {
|
|
3
|
+
children?: ReactNode;
|
|
4
|
+
className?: string;
|
|
5
|
+
}
|
|
6
|
+
/** Inline code: a value, a key or a command inside a sentence. */
|
|
7
|
+
export declare function Code({ children, className }: CodeProps): 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
|
+
/** Inline code: a value, a key or a command inside a sentence. */
|
|
4
|
+
export function Code({ children, className }) {
|
|
5
|
+
return _jsx("code", { className: cx("vk-code", className), children: children });
|
|
6
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface CodeBlockProps {
|
|
2
|
+
code: string;
|
|
3
|
+
title?: string;
|
|
4
|
+
language?: string;
|
|
5
|
+
lineNumbers?: boolean;
|
|
6
|
+
copy?: boolean;
|
|
7
|
+
className?: string;
|
|
8
|
+
}
|
|
9
|
+
/** A block of code or terminal output with a title, an optional line-number gutter and a copy button. */
|
|
10
|
+
export declare function CodeBlock({ code, title, language, lineNumbers, copy: showCopy, className }: CodeBlockProps): 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 { useRef, useState } from "react";
|
|
4
|
+
import { Icon } from "../Icon/Icon.js";
|
|
5
|
+
import { cx } from "../../lib/cx.js";
|
|
6
|
+
// Copies the code, or, without clipboard access, selects it so it can be copied by hand.
|
|
7
|
+
function useCopy(code, preRef) {
|
|
8
|
+
const [copied, setCopied] = useState(false);
|
|
9
|
+
const selectAll = () => {
|
|
10
|
+
const pre = preRef.current;
|
|
11
|
+
const sel = window.getSelection();
|
|
12
|
+
if (!pre || !sel)
|
|
13
|
+
return;
|
|
14
|
+
const range = document.createRange();
|
|
15
|
+
range.selectNodeContents(pre);
|
|
16
|
+
sel.removeAllRanges();
|
|
17
|
+
sel.addRange(range);
|
|
18
|
+
};
|
|
19
|
+
const copy = () => {
|
|
20
|
+
const done = () => {
|
|
21
|
+
setCopied(true);
|
|
22
|
+
setTimeout(() => setCopied(false), 1600);
|
|
23
|
+
};
|
|
24
|
+
try {
|
|
25
|
+
navigator.clipboard.writeText(code).then(done, selectAll);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
selectAll();
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
return { copied, copy };
|
|
32
|
+
}
|
|
33
|
+
function CodeBlockHead({ title, showCopy, copied, onCopy }) {
|
|
34
|
+
return (_jsxs("figcaption", { className: "vk-codeblock-head", children: [_jsx("span", { className: "vk-codeblock-title", children: title }), showCopy ? (_jsxs("button", { type: "button", className: "vk-codeblock-copy", onClick: onCopy, children: [_jsx(Icon, { name: copied ? "check" : "copy", size: 14 }), _jsx("span", { "aria-live": "polite", children: copied ? "Copied" : "Copy" })] })) : null] }));
|
|
35
|
+
}
|
|
36
|
+
/** A block of code or terminal output with a title, an optional line-number gutter and a copy button. */
|
|
37
|
+
export function CodeBlock({ code, title, language, lineNumbers, copy: showCopy, className }) {
|
|
38
|
+
const preRef = useRef(null);
|
|
39
|
+
const { copied, copy } = useCopy(code, preRef);
|
|
40
|
+
const lines = String(code || "").replace(/\n$/, "").split("\n");
|
|
41
|
+
const canCopy = showCopy !== false;
|
|
42
|
+
return (_jsxs("figure", { className: cx("vk-codeblock", className), children: [title || language || canCopy ? (_jsx(CodeBlockHead, { title: title || language, showCopy: canCopy, copied: copied, onCopy: copy })) : null, _jsx("pre", { ref: preRef, className: cx("vk-codeblock-pre", lineNumbers && "vk-codeblock-numbered"), tabIndex: 0, "aria-label": title || (language ? language + " code" : "Code"), children: _jsx("code", { children: lineNumbers ? lines.map((l, i) => _jsx("span", { className: "vk-code-line", children: l + "\n" }, i)) : lines.join("\n") }) })] }));
|
|
43
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { SelectOption } from "../../types.js";
|
|
2
|
+
export interface ComboboxProps {
|
|
3
|
+
options: (string | SelectOption)[];
|
|
4
|
+
value?: string | null;
|
|
5
|
+
defaultValue?: string;
|
|
6
|
+
onChange?: (value: string | null, option: SelectOption | null) => void;
|
|
7
|
+
placeholder?: string;
|
|
8
|
+
icon?: 'search';
|
|
9
|
+
name?: string;
|
|
10
|
+
emptyText?: string;
|
|
11
|
+
clearLabel?: string;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
required?: boolean;
|
|
14
|
+
defaultOpen?: boolean;
|
|
15
|
+
id?: string;
|
|
16
|
+
className?: string;
|
|
17
|
+
'aria-label'?: string;
|
|
18
|
+
'aria-labelledby'?: string;
|
|
19
|
+
'aria-describedby'?: string;
|
|
20
|
+
'aria-invalid'?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/** Searchable single select (WAI-ARIA combobox, list autocomplete). The list is a Radix Popover anchored to the field. */
|
|
23
|
+
export declare function Combobox(props: ComboboxProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useRef, useState } from "react";
|
|
4
|
+
import { Popover } from "radix-ui";
|
|
5
|
+
import { Icon } from "../Icon/Icon.js";
|
|
6
|
+
import { highlight, matches, nextEnabled, normalizeOptions } from "../../internal/options.js";
|
|
7
|
+
import { useIsoLayoutEffect } from "../../internal/useIsoLayoutEffect.js";
|
|
8
|
+
import { useUid } from "../../internal/useUid.js";
|
|
9
|
+
import { cx } from "../../lib/cx.js";
|
|
10
|
+
import { omit } from "../../lib/omit.js";
|
|
11
|
+
import { ListPanel } from "./ListPanel.js";
|
|
12
|
+
/** The option with this value; the last one wins. */
|
|
13
|
+
function optionWithValue(options, value) {
|
|
14
|
+
let selected = null;
|
|
15
|
+
for (const o of options)
|
|
16
|
+
if (o.value === value)
|
|
17
|
+
selected = o;
|
|
18
|
+
return selected;
|
|
19
|
+
}
|
|
20
|
+
/** The end of the field: a clear button while there is text, else the chevron. */
|
|
21
|
+
function FieldEnd({ clearable, clearLabel, onClear }) {
|
|
22
|
+
if (!clearable)
|
|
23
|
+
return _jsx(Icon, { name: "chevron-down", className: "vk-select-icon" });
|
|
24
|
+
return (_jsx("button", { type: "button", tabIndex: -1, className: "vk-field-clear", "aria-label": clearLabel || "Clear", onMouseDown: (e) => e.preventDefault(), onClick: onClear, children: _jsx(Icon, { name: "x", size: 16 }) }));
|
|
25
|
+
}
|
|
26
|
+
/** The popup, which ListPanel makes the Radix content (so a plain element, not a component): a <ul> listbox, or a <div> status when nothing matches. */
|
|
27
|
+
function optionList({ listId, options, value, active, setActive, query, onPick, emptyText, ...labels }) {
|
|
28
|
+
if (!options.length) {
|
|
29
|
+
return (_jsx("div", { id: listId, className: "vk-select-menu vk-select-empty", role: "status", children: emptyText || "No matches for “" + query + "”" }));
|
|
30
|
+
}
|
|
31
|
+
return (_jsx("ul", { id: listId, role: "listbox", className: "vk-select-menu", "aria-labelledby": labels["aria-labelledby"], "aria-label": labels["aria-label"], children: options.map((o, i) => {
|
|
32
|
+
const isSel = o.value === value;
|
|
33
|
+
return (_jsxs("li", { id: listId + "-" + i, "data-index": i, role: "option", "aria-selected": isSel ? "true" : "false", "aria-disabled": o.disabled ? "true" : undefined, className: cx("vk-select-option", i === active && "vk-select-option-active"), onMouseDown: (e) => e.preventDefault(), onMouseMove: () => {
|
|
34
|
+
if (!o.disabled && i !== active)
|
|
35
|
+
setActive(i);
|
|
36
|
+
}, onClick: () => onPick(o), children: [_jsxs("span", { className: "vk-select-option-text", children: [_jsx("span", { children: highlight(o.label, query) }), o.description ? _jsx("span", { className: "vk-select-option-description", children: o.description }) : null] }), isSel ? _jsx(Icon, { name: "check", size: 16, className: "vk-select-check" }) : null] }, o.value));
|
|
37
|
+
}) }));
|
|
38
|
+
}
|
|
39
|
+
/** Searchable single select (WAI-ARIA combobox, list autocomplete). The list is a Radix Popover anchored to the field. */
|
|
40
|
+
export function Combobox(props) {
|
|
41
|
+
const options = normalizeOptions(props.options);
|
|
42
|
+
const base = useUid("vk-combo");
|
|
43
|
+
const inputId = props.id || base + "-input";
|
|
44
|
+
const listId = base + "-list";
|
|
45
|
+
const controlled = props.value !== undefined;
|
|
46
|
+
const [uncontrolledValue, setUncontrolledValue] = useState(props.defaultValue !== undefined ? props.defaultValue : null);
|
|
47
|
+
const value = controlled ? props.value : uncontrolledValue;
|
|
48
|
+
const selected = optionWithValue(options, value);
|
|
49
|
+
const selectedLabel = selected ? String(selected.label) : "";
|
|
50
|
+
const [text, setText] = useState(selectedLabel);
|
|
51
|
+
const [query, setQuery] = useState("");
|
|
52
|
+
const [open, setOpen] = useState(Boolean(props.defaultOpen));
|
|
53
|
+
const [active, setActive] = useState(-1);
|
|
54
|
+
const rootRef = useRef(null);
|
|
55
|
+
const inputRef = useRef(null);
|
|
56
|
+
const filtered = options.filter((o) => matches(o, query));
|
|
57
|
+
// A new controlled value shows its label. Only the value changing resets the text: options changing
|
|
58
|
+
// (say, loaded for what is being typed) leave it alone, so the label is read from a ref.
|
|
59
|
+
const labelRef = useRef(selectedLabel);
|
|
60
|
+
useIsoLayoutEffect(() => {
|
|
61
|
+
labelRef.current = selectedLabel;
|
|
62
|
+
});
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
if (!controlled)
|
|
65
|
+
return;
|
|
66
|
+
setText(labelRef.current);
|
|
67
|
+
}, [controlled, value]);
|
|
68
|
+
const restore = () => {
|
|
69
|
+
setText(selectedLabel);
|
|
70
|
+
setQuery("");
|
|
71
|
+
};
|
|
72
|
+
const close = () => {
|
|
73
|
+
setOpen(false);
|
|
74
|
+
setActive(-1);
|
|
75
|
+
};
|
|
76
|
+
const setValue = (o) => {
|
|
77
|
+
if (!controlled)
|
|
78
|
+
setUncontrolledValue(o ? o.value : null);
|
|
79
|
+
props.onChange?.(o ? o.value : null, o);
|
|
80
|
+
};
|
|
81
|
+
const commit = (o) => {
|
|
82
|
+
if (!o || o.disabled)
|
|
83
|
+
return;
|
|
84
|
+
setValue(o);
|
|
85
|
+
setText(String(o.label));
|
|
86
|
+
setQuery("");
|
|
87
|
+
close();
|
|
88
|
+
};
|
|
89
|
+
const openAt = (i) => {
|
|
90
|
+
if (props.disabled)
|
|
91
|
+
return;
|
|
92
|
+
setOpen(true);
|
|
93
|
+
setActive(i);
|
|
94
|
+
};
|
|
95
|
+
const selectedIn = (list) => {
|
|
96
|
+
for (let i = 0; i < list.length; i++)
|
|
97
|
+
if (list[i].value === value && !list[i].disabled)
|
|
98
|
+
return i;
|
|
99
|
+
return nextEnabled(list, 0, 1);
|
|
100
|
+
};
|
|
101
|
+
const onKeyDown = (e) => {
|
|
102
|
+
const key = e.key;
|
|
103
|
+
if (key === "ArrowDown") {
|
|
104
|
+
e.preventDefault();
|
|
105
|
+
if (!open)
|
|
106
|
+
return openAt(e.altKey ? -1 : selectedIn(filtered));
|
|
107
|
+
const n = nextEnabled(filtered, active + 1, 1);
|
|
108
|
+
if (n >= 0)
|
|
109
|
+
setActive(n);
|
|
110
|
+
}
|
|
111
|
+
else if (key === "ArrowUp") {
|
|
112
|
+
e.preventDefault();
|
|
113
|
+
if (!open)
|
|
114
|
+
return openAt(nextEnabled(filtered, filtered.length - 1, -1));
|
|
115
|
+
const p = nextEnabled(filtered, active - 1, -1);
|
|
116
|
+
if (p >= 0)
|
|
117
|
+
setActive(p);
|
|
118
|
+
}
|
|
119
|
+
else if (key === "Enter") {
|
|
120
|
+
if (open && active >= 0) {
|
|
121
|
+
e.preventDefault();
|
|
122
|
+
commit(filtered[active]);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
else if (key === "Escape") {
|
|
126
|
+
if (open) {
|
|
127
|
+
e.preventDefault();
|
|
128
|
+
close();
|
|
129
|
+
restore();
|
|
130
|
+
}
|
|
131
|
+
else if (text) {
|
|
132
|
+
e.preventDefault();
|
|
133
|
+
setText("");
|
|
134
|
+
setQuery("");
|
|
135
|
+
setValue(null);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
else if (key === "Tab") {
|
|
139
|
+
if (open) {
|
|
140
|
+
close();
|
|
141
|
+
restore();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
const a11y = omit(props, ["options", "placeholder", "className", "value", "defaultValue", "onChange", "disabled", "name", "id", "defaultOpen", "emptyText", "icon", "required", "clearLabel"]);
|
|
146
|
+
const input = (_jsx("input", { ref: inputRef, id: inputId, type: "text", role: "combobox", autoComplete: "off", spellCheck: false, className: cx("vk-input", "vk-combobox-input", props.icon === "search" && "vk-has-lead"), placeholder: props.placeholder, disabled: props.disabled, required: props.required, "aria-autocomplete": "list", "aria-expanded": open ? "true" : "false", "aria-controls": listId, "aria-activedescendant": open && active >= 0 ? listId + "-" + active : undefined, value: text, onChange: (e) => {
|
|
147
|
+
const v = e.target.value;
|
|
148
|
+
setText(v);
|
|
149
|
+
setQuery(v);
|
|
150
|
+
const list = options.filter((o) => matches(o, v));
|
|
151
|
+
openAt(v ? nextEnabled(list, 0, 1) : -1);
|
|
152
|
+
}, onFocus: (e) => {
|
|
153
|
+
if (text)
|
|
154
|
+
e.target.select();
|
|
155
|
+
}, onClick: () => {
|
|
156
|
+
if (!open)
|
|
157
|
+
openAt(selectedIn(filtered));
|
|
158
|
+
}, onKeyDown: onKeyDown, onBlur: (e) => {
|
|
159
|
+
if (rootRef.current && !rootRef.current.contains(e.relatedTarget)) {
|
|
160
|
+
close();
|
|
161
|
+
restore();
|
|
162
|
+
}
|
|
163
|
+
}, ...a11y }));
|
|
164
|
+
return (_jsx(Popover.Root, { open: open, onOpenChange: (next) => {
|
|
165
|
+
// A press outside, or Escape from outside the field.
|
|
166
|
+
if (!next) {
|
|
167
|
+
close();
|
|
168
|
+
restore();
|
|
169
|
+
}
|
|
170
|
+
}, children: _jsxs("div", { ref: rootRef, className: cx("vk-select", "vk-combobox", open && "vk-select-open", props.className), children: [_jsx(Popover.Anchor, { asChild: true, children: _jsxs("div", { className: "vk-combobox-field", children: [props.icon === "search" ? _jsx(Icon, { name: "search", size: 16, className: "vk-search-icon" }) : null, input, _jsx(FieldEnd, { clearable: Boolean(text) && !props.disabled, clearLabel: props.clearLabel, onClear: () => {
|
|
171
|
+
setText("");
|
|
172
|
+
setQuery("");
|
|
173
|
+
setValue(null);
|
|
174
|
+
openAt(-1);
|
|
175
|
+
inputRef.current?.focus();
|
|
176
|
+
} })] }) }), _jsx(ListPanel, { rootRef: rootRef, active: active, children: optionList({
|
|
177
|
+
listId,
|
|
178
|
+
options: filtered,
|
|
179
|
+
value,
|
|
180
|
+
active,
|
|
181
|
+
setActive,
|
|
182
|
+
query,
|
|
183
|
+
onPick: commit,
|
|
184
|
+
emptyText: props.emptyText,
|
|
185
|
+
"aria-label": props["aria-label"],
|
|
186
|
+
"aria-labelledby": props["aria-labelledby"],
|
|
187
|
+
}) }), props.name ? _jsx("input", { type: "hidden", name: props.name, value: value ?? "" }) : null] }) }));
|
|
188
|
+
}
|