@vokality/design-system 1.3.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +54 -0
- package/README.md +51 -5
- package/dist/browser.d.ts +13 -0
- package/dist/browser.js +7 -0
- package/dist/charts/chart.d.ts +6 -5
- package/dist/charts/chart.js +44 -25
- package/dist/chat.d.ts +54 -0
- package/dist/chat.js +1 -0
- package/dist/components/Accordion/Accordion.js +1 -1
- package/dist/components/Alert/Alert.js +5 -2
- package/dist/components/AppShell/AppShell.js +10 -14
- package/dist/components/Avatar/Avatar.js +2 -2
- package/dist/components/AvatarGroup/AvatarGroup.js +2 -2
- package/dist/components/BarChart/BarChart.js +17 -15
- package/dist/components/Breadcrumbs/Breadcrumbs.js +6 -3
- package/dist/components/Calendar/Calendar.js +6 -5
- package/dist/components/Card/Card.js +2 -3
- package/dist/components/ChatInbox/ChatInbox.d.ts +11 -0
- package/dist/components/ChatInbox/ChatInbox.js +49 -0
- package/dist/components/ChatPanel/ChatPanel.d.ts +3 -0
- package/dist/components/ChatPanel/ChatPanel.js +13 -0
- package/dist/components/ChatPanel/composer.d.ts +5 -0
- package/dist/components/ChatPanel/composer.js +32 -0
- package/dist/components/ChatPanel/transcript.d.ts +13 -0
- package/dist/components/ChatPanel/transcript.js +39 -0
- package/dist/components/ChatWidget/ChatWidget.d.ts +12 -0
- package/dist/components/ChatWidget/ChatWidget.js +42 -0
- package/dist/components/Checkbox/Checkbox.d.ts +5 -10
- package/dist/components/Checkbox/Checkbox.js +5 -19
- package/dist/components/CodeBlock/CodeBlock.js +19 -5
- package/dist/components/Combobox/Combobox.js +22 -15
- package/dist/components/Combobox/ListPanel.js +20 -9
- package/dist/components/CommandPalette/CommandPalette.js +33 -14
- package/dist/components/ContextMenu/ContextMenu.d.ts +2 -2
- package/dist/components/ContextMenu/ContextMenu.js +5 -50
- package/dist/components/DatePicker/DatePicker.js +35 -29
- package/dist/components/DescriptionList/DescriptionList.js +1 -1
- package/dist/components/Dialog/Dialog.d.ts +24 -7
- package/dist/components/Dialog/Dialog.js +30 -41
- package/dist/components/Drawer/Drawer.d.ts +4 -2
- package/dist/components/EmptyState/EmptyState.js +2 -2
- package/dist/components/ErrorSummary/ErrorSummary.js +5 -3
- package/dist/components/FaqList/FaqList.js +1 -1
- package/dist/components/Field/Field.js +4 -4
- package/dist/components/Fieldset/Fieldset.js +3 -3
- package/dist/components/FileUpload/FileUpload.js +17 -9
- package/dist/components/Grid/Grid.d.ts +867 -5
- package/dist/components/Grid/Grid.js +3 -4
- package/dist/components/Heading/Heading.js +2 -1
- package/dist/components/Icon/Icon.js +4 -2
- package/dist/components/Inline/Inline.d.ts +867 -5
- package/dist/components/Inline/Inline.js +2 -3
- package/dist/components/LineChart/LineChart.js +17 -15
- package/dist/components/LinkProvider/LinkProvider.d.ts +1 -1
- package/dist/components/LinkProvider/LinkProvider.js +6 -2
- package/dist/components/List/List.js +1 -1
- package/dist/components/MediaCard/MediaCard.js +2 -2
- package/dist/components/Menu/Menu.js +6 -43
- package/dist/components/Menu/entries.d.ts +1 -30
- package/dist/components/Menu/entries.js +16 -100
- package/dist/components/MultiSelect/MultiSelect.js +43 -34
- package/dist/components/NumberInput/NumberInput.js +17 -18
- package/dist/components/OtpInput/OtpInput.d.ts +1 -1
- package/dist/components/OtpInput/OtpInput.js +10 -67
- package/dist/components/PageHeader/PageHeader.js +2 -2
- package/dist/components/Pagination/Pagination.js +3 -1
- package/dist/components/PasswordInput/PasswordInput.d.ts +1 -1
- package/dist/components/PasswordInput/PasswordInput.js +9 -4
- package/dist/components/Popover/Popover.d.ts +6 -7
- package/dist/components/Popover/Popover.js +2 -19
- package/dist/components/Progress/Progress.d.ts +1 -1
- package/dist/components/Progress/Progress.js +7 -11
- package/dist/components/Radio/Radio.d.ts +4 -2
- package/dist/components/RadioGroup/RadioGroup.d.ts +5 -12
- package/dist/components/RadioGroup/RadioGroup.js +6 -33
- package/dist/components/RichTextEditor/RichTextEditor.d.ts +63 -0
- package/dist/components/RichTextEditor/RichTextEditor.js +175 -0
- package/dist/components/RichTextEditor/toolbar.d.ts +15 -0
- package/dist/components/RichTextEditor/toolbar.js +142 -0
- package/dist/components/RichTextEditor/uploads.d.ts +41 -0
- package/dist/components/RichTextEditor/uploads.js +124 -0
- package/dist/components/SearchInput/SearchInput.js +4 -2
- package/dist/components/SectionHeader/SectionHeader.js +1 -3
- package/dist/components/SegmentedControl/SegmentedControl.js +2 -12
- package/dist/components/Select/Select.d.ts +15 -16
- package/dist/components/Select/Select.js +11 -252
- package/dist/components/Slider/Slider.js +11 -21
- package/dist/components/Sparkline/Sparkline.js +8 -3
- package/dist/components/Spinner/Spinner.js +5 -2
- package/dist/components/Stack/Stack.d.ts +867 -5
- package/dist/components/Stack/Stack.js +2 -3
- package/dist/components/Stat/Stat.js +6 -3
- package/dist/components/Steps/Steps.js +6 -3
- package/dist/components/Switch/Switch.d.ts +7 -7
- package/dist/components/Switch/Switch.js +4 -10
- package/dist/components/Table/Table.js +38 -19
- package/dist/components/Tabs/Tabs.js +2 -22
- package/dist/components/Tag/Tag.js +3 -1
- package/dist/components/Text/Text.d.ts +9 -5
- package/dist/components/Text/Text.js +3 -4
- package/dist/components/TileGrid/TileGrid.js +1 -1
- package/dist/components/TimePicker/TimePicker.js +35 -33
- package/dist/components/Timeline/Timeline.js +5 -4
- package/dist/components/Toaster/Toaster.js +21 -17
- package/dist/components/Tooltip/Tooltip.d.ts +6 -6
- package/dist/components/Tooltip/Tooltip.js +3 -17
- package/dist/components/TreeView/TreeView.js +15 -12
- package/dist/components.css +281 -60
- package/dist/hooks/useTheme.js +6 -6
- package/dist/icons/message-circle.svg +1 -0
- package/dist/internal/CharCount.js +3 -1
- package/dist/internal/choice.d.ts +10 -48
- package/dist/internal/choice.js +8 -96
- package/dist/internal/describedBy.d.ts +3 -0
- package/dist/internal/describedBy.js +4 -0
- package/dist/internal/options.d.ts +10 -5
- package/dist/internal/options.js +25 -11
- package/dist/internal/status.d.ts +3 -2
- package/dist/internal/status.js +10 -2
- package/dist/internal/useScrollActive.js +2 -2
- package/dist/internal/useToday.d.ts +3 -0
- package/dist/internal/useToday.js +42 -0
- package/dist/lib/dates.js +25 -15
- package/dist/lib/format.js +11 -8
- package/dist/lib/icons.d.ts +5 -0
- package/dist/lib/icons.js +2 -0
- package/dist/lib/math.js +17 -5
- package/dist/lib/rich-text.d.ts +13 -0
- package/dist/lib/rich-text.js +62 -0
- package/dist/lib/space.d.ts +1 -2
- package/dist/lib/space.js +4 -1
- package/dist/lib/text.js +1 -1
- package/dist/lib/theme.js +1 -1
- package/dist/localization.d.ts +166 -0
- package/dist/localization.js +142 -0
- package/dist/tokens.css +2 -0
- package/dist/tokens.dtcg.json +10 -0
- package/dist/tokens.json +10 -0
- package/dist/types.d.ts +6 -1
- package/dist/vokality.css +283 -60
- package/dist/vokality.iife.js +35981 -9698
- package/docs/brand.md +8 -5
- package/docs/components/AppShell/README.md +1 -1
- package/docs/components/Badge/README.md +1 -1
- package/docs/components/BarChart/README.md +1 -0
- package/docs/components/Button/README.md +4 -2
- package/docs/components/ChatInbox/README.md +41 -0
- package/docs/components/ChatWidget/README.md +47 -0
- package/docs/components/Checkbox/README.md +7 -3
- package/docs/components/ContextMenu/README.md +7 -3
- package/docs/components/Dialog/README.md +9 -4
- package/docs/components/Drawer/README.md +1 -1
- package/docs/components/Field/README.md +1 -1
- package/docs/components/Fieldset/README.md +2 -2
- package/docs/components/Inline/README.md +1 -1
- package/docs/components/LineChart/README.md +1 -0
- package/docs/components/LocaleProvider/README.md +48 -0
- package/docs/components/Menu/README.md +13 -8
- package/docs/components/OtpInput/README.md +9 -5
- package/docs/components/PasswordInput/README.md +11 -2
- package/docs/components/Popover/README.md +6 -3
- package/docs/components/Progress/README.md +3 -1
- package/docs/components/RadioGroup/README.md +5 -2
- package/docs/components/RichTextEditor/README.md +84 -0
- package/docs/components/SegmentedControl/README.md +2 -0
- package/docs/components/Select/README.md +13 -17
- package/docs/components/Skeleton/README.md +1 -1
- package/docs/components/Slider/README.md +4 -2
- package/docs/components/Steps/README.md +1 -1
- package/docs/components/Switch/README.md +5 -2
- package/docs/components/Tabs/README.md +4 -2
- package/docs/components/Text/README.md +1 -1
- package/docs/components/Toaster/README.md +3 -1
- package/docs/components/Tooltip/README.md +5 -3
- package/package.json +49 -5
|
@@ -1,45 +1,47 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useLocale } from "../../localization.js";
|
|
3
4
|
import { ChartFrame, cellLabel, cellNumber, chartKeys, chartTooltip, seriesColor, useChart } from "../../charts/chart.js";
|
|
4
5
|
import { niceTicks } from "../../lib/math.js";
|
|
5
6
|
/** Vertical bars for comparing amounts across categories: grouped, or stacked to show a total and its parts. */
|
|
6
7
|
export function BarChart(props) {
|
|
7
|
-
const
|
|
8
|
+
const { messages } = useLocale(props.locale);
|
|
9
|
+
const { setPlotElement, width, active, setActive, fmt, series, xKey } = useChart(props);
|
|
8
10
|
const { stacked } = props;
|
|
9
|
-
const data = props.data
|
|
11
|
+
const data = props.data;
|
|
10
12
|
const height = props.height || 240;
|
|
11
13
|
const pad = { top: 12, right: 8, bottom: 28, left: 48 };
|
|
12
14
|
let max = 0;
|
|
13
15
|
for (const d of data) {
|
|
14
16
|
if (stacked)
|
|
15
|
-
max = Math.max(max,
|
|
17
|
+
max = Math.max(max, series.reduce((sum, s) => sum + cellNumber(d, s.key), 0));
|
|
16
18
|
else
|
|
17
|
-
for (const s of
|
|
19
|
+
for (const s of series)
|
|
18
20
|
max = Math.max(max, cellNumber(d, s.key));
|
|
19
21
|
}
|
|
20
|
-
const ticks = niceTicks(max, 4), top = ticks
|
|
21
|
-
const plotW = Math.max(10,
|
|
22
|
+
const ticks = niceTicks(max, 4), top = ticks.at(-1) ?? 1;
|
|
23
|
+
const plotW = Math.max(10, width - pad.left - pad.right), plotH = height - pad.top - pad.bottom;
|
|
22
24
|
const band = plotW / Math.max(1, data.length), groupW = band * 0.64;
|
|
23
25
|
const y = (v) => pad.top + plotH - (v / top) * plotH;
|
|
24
|
-
const fmtTick = props.tickFormat ||
|
|
26
|
+
const fmtTick = props.tickFormat || fmt;
|
|
25
27
|
const bars = data.flatMap((d, i) => {
|
|
26
28
|
const x0 = pad.left + band * i + (band - groupW) / 2;
|
|
27
29
|
if (stacked) {
|
|
28
30
|
let acc = 0;
|
|
29
|
-
return
|
|
31
|
+
return series.map((s, si) => {
|
|
30
32
|
const v = cellNumber(d, s.key), y1 = y(acc + v), y0 = y(acc);
|
|
31
33
|
acc += v;
|
|
32
34
|
// 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 <
|
|
35
|
+
return _jsx("rect", { x: x0, y: y1, width: groupW, height: Math.max(0, y0 - y1 - (si < series.length - 1 && v ? 2 : 0)), fill: seriesColor(si), className: "vk-chart-bar" }, `${String(i)}-${String(si)}`);
|
|
34
36
|
});
|
|
35
37
|
}
|
|
36
|
-
const w = (groupW - 2 * (
|
|
37
|
-
return
|
|
38
|
+
const w = (groupW - 2 * (series.length - 1)) / series.length;
|
|
39
|
+
return series.map((s, si) => {
|
|
38
40
|
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
|
|
41
|
+
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" }, `${String(i)}-${String(si)}`);
|
|
40
42
|
});
|
|
41
43
|
});
|
|
42
|
-
const activeX =
|
|
43
|
-
const view = { ...props, data, series
|
|
44
|
-
return (_jsx(ChartFrame, { ...view, children: _jsxs("div", { ref:
|
|
44
|
+
const activeX = active == null ? 0 : pad.left + band * active + band / 2;
|
|
45
|
+
const view = { ...props, data, series, format: fmt, xKey };
|
|
46
|
+
return (_jsx(ChartFrame, { ...view, children: _jsxs("div", { ref: setPlotElement, className: "vk-chart-plot", tabIndex: 0, role: "img", "aria-label": messages.chartInstructions(props.title || messages.barChart), onKeyDown: chartKeys({ active, setActive }, data.length), onMouseLeave: () => { setActive(null); }, onBlur: () => { setActive(null); }, children: [_jsxs("svg", { width: width, height: height, viewBox: `0 0 ${String(width)} ${String(height)}`, "aria-hidden": "true", className: "vk-chart-svg", children: [ticks.map((t) => (_jsxs("g", { children: [_jsx("line", { x1: pad.left, x2: 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))), active != null ? _jsx("rect", { x: pad.left + band * 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, xKey) }, `x${String(i)}`)), data.map((_, i) => _jsx("rect", { x: pad.left + band * i, y: pad.top, width: band, height: plotH, fill: "transparent", onMouseEnter: () => { setActive(i); } }, `hit${String(i)}`))] }), chartTooltip(view, active, activeX, width)] }) }));
|
|
45
47
|
}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
+
"use client";
|
|
1
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useLocale } from "../../localization.js";
|
|
2
4
|
import { Anchor } from "../LinkProvider/LinkProvider.js";
|
|
3
5
|
import { cx } from "../../lib/cx.js";
|
|
4
6
|
/** The path from a section to the current page, for pages nested more than one level deep. */
|
|
5
7
|
export function Breadcrumbs({ items: itemsProp, label, className }) {
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
+
const { messages } = useLocale();
|
|
9
|
+
const items = itemsProp;
|
|
10
|
+
return (_jsx("nav", { "aria-label": label || messages.breadcrumb, className: cx("vk-breadcrumbs", className), children: _jsx("ol", { children: items.map((it, i) => {
|
|
8
11
|
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));
|
|
12
|
+
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 || "") + "#" + String(i)));
|
|
10
13
|
}) }) }));
|
|
11
14
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useLocale } from "../../localization.js";
|
|
3
4
|
import { useEffect, useRef, useState } from "react";
|
|
4
5
|
import { IconButton } from "../IconButton/IconButton.js";
|
|
5
6
|
import { useUid } from "../../internal/useUid.js";
|
|
7
|
+
import { useToday } from "../../internal/useToday.js";
|
|
6
8
|
import { cx } from "../../lib/cx.js";
|
|
7
9
|
import { addDays, addMonths, clampDate, parseISO, sameDay, toISO } from "../../lib/dates.js";
|
|
8
|
-
import { resolveLocale } from "../../lib/format.js";
|
|
9
10
|
import { dateFormat } from "../../lib/intl.js";
|
|
10
11
|
/** Days from the start of the week to d. */
|
|
11
12
|
const weekday = (d, weekStart) => (d.getDay() - weekStart + 7) % 7;
|
|
@@ -66,15 +67,15 @@ function dayLook({ date: d, focus, today, range, selStart, selEnd, rangeEnd }) {
|
|
|
66
67
|
function DayCell(props) {
|
|
67
68
|
const { date: d, onPick, onHover } = props;
|
|
68
69
|
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
|
+
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
|
}
|
|
71
72
|
/** Month grid for a date or a range (WAI-ARIA grid). */
|
|
72
73
|
export function Calendar(props) {
|
|
74
|
+
const { locale, messages } = useLocale(props.locale);
|
|
73
75
|
const range = props.mode === "range";
|
|
74
|
-
const locale = resolveLocale(props.locale);
|
|
75
76
|
const weekStart = props.weekStartsOn == null ? 0 : props.weekStartsOn;
|
|
76
77
|
const min = parseISO(props.min), max = parseISO(props.max);
|
|
77
|
-
const today =
|
|
78
|
+
const today = useToday(props.today);
|
|
78
79
|
const { selStart, selEnd, select } = useSelection(props, range);
|
|
79
80
|
const [focus, setFocus] = useState(() => clampDate(selStart || parseISO(props.defaultMonth) || today, min, max));
|
|
80
81
|
const [hover, setHover] = useState(null);
|
|
@@ -140,5 +141,5 @@ export function Calendar(props) {
|
|
|
140
141
|
}
|
|
141
142
|
rows.push(_jsx("tr", { children: cells }, r));
|
|
142
143
|
}
|
|
143
|
-
return (_jsxs("div", { className: cx("vk-calendar", props.className), children: [_jsxs("div", { className: "vk-calendar-header", children: [_jsx(IconButton, { icon: "chevron-left", label:
|
|
144
|
+
return (_jsxs("div", { className: cx("vk-calendar", props.className), children: [_jsxs("div", { className: "vk-calendar-header", children: [_jsx(IconButton, { icon: "chevron-left", label: messages.previousMonth, 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: messages.nextMonth, 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
145
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { createElement } from "react";
|
|
2
3
|
import { cx } from "../../lib/cx.js";
|
|
3
4
|
import { pad, para } from "../../lib/text.js";
|
|
4
5
|
/** Outlined panel for a feature, plan, step or summary. */
|
|
5
6
|
export function Card({ title, children, eyebrow, step, points, footnote, as, titleAs, className }) {
|
|
6
7
|
const Tag = as || "div";
|
|
7
8
|
const TitleTag = titleAs || "h3";
|
|
8
|
-
|
|
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] }));
|
|
9
|
+
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 ? createElement(para(children), { className: "vk-card-body" }, children) : null, points && points.length ? (_jsx("ul", { className: "vk-card-points", children: points.map((p) => _jsx("li", { children: p }, p)) })) : null, footnote ? createElement(para(footnote), { className: "vk-card-footnote" }, footnote) : null] }));
|
|
11
10
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { ChatPanelProps, ChatThread } from "../../chat.js";
|
|
3
|
+
export interface ChatInboxProps extends ChatPanelProps {
|
|
4
|
+
title?: string;
|
|
5
|
+
threads: readonly ChatThread[];
|
|
6
|
+
selectedThreadId: string | null;
|
|
7
|
+
onSelectThread: (threadId: string | null) => void;
|
|
8
|
+
emptySelection?: ReactNode;
|
|
9
|
+
}
|
|
10
|
+
/** Controlled thread selection; CSS handles the narrow-screen list/detail presentation. */
|
|
11
|
+
export declare function ChatInbox({ title, threads, selectedThreadId, onSelectThread, emptySelection, className, ...panel }: ChatInboxProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { useRef } from "react";
|
|
4
|
+
import { useLocale } from "../../localization.js";
|
|
5
|
+
import { useIsoLayoutEffect } from "../../internal/useIsoLayoutEffect.js";
|
|
6
|
+
import { useUid } from "../../internal/useUid.js";
|
|
7
|
+
import { cx } from "../../lib/cx.js";
|
|
8
|
+
import { formatNumber } from "../../lib/format.js";
|
|
9
|
+
import { Avatar } from "../Avatar/Avatar.js";
|
|
10
|
+
import { IconButton } from "../IconButton/IconButton.js";
|
|
11
|
+
import { ChatPanel } from "../ChatPanel/ChatPanel.js";
|
|
12
|
+
function ThreadList({ threads, selectedId, activeRef, onSelect }) {
|
|
13
|
+
const { locale, messages } = useLocale();
|
|
14
|
+
if (!threads.length)
|
|
15
|
+
return _jsx("div", { className: "vk-chat-empty", children: messages.chat.noThreads });
|
|
16
|
+
return _jsx("ul", { className: "vk-chat-threads", children: threads.map((thread) => _jsx("li", { children: _jsxs("button", { ref: thread.id === selectedId ? activeRef : undefined, type: "button", className: "vk-chat-thread", "aria-current": thread.id === selectedId ? "true" : undefined, disabled: thread.disabled, onClick: () => { onSelect(thread.id); }, children: [_jsx("span", { className: "vk-chat-thread-avatar", children: thread.avatar || _jsx(Avatar, { name: thread.title, decorative: true }) }), _jsxs("span", { className: "vk-chat-thread-text", children: [_jsx("span", { className: "vk-chat-thread-title", children: thread.title }), thread.preview ? _jsx("span", { className: "vk-chat-thread-preview", children: thread.preview }) : null, _jsxs("span", { className: "vk-chat-thread-meta", children: [thread.timestamp, thread.unreadCount && thread.unreadCount > 0 ? _jsx("span", { className: "vk-chat-thread-count", "aria-label": messages.chat.unread(thread.unreadCount), children: formatNumber(thread.unreadCount, { locale }) }) : null] })] })] }) }, thread.id)) });
|
|
17
|
+
}
|
|
18
|
+
/** Controlled thread selection; CSS handles the narrow-screen list/detail presentation. */
|
|
19
|
+
export function ChatInbox({ title, threads, selectedThreadId, onSelectThread, emptySelection, className, ...panel }) {
|
|
20
|
+
const { messages } = useLocale();
|
|
21
|
+
const listTitleId = useUid("vk-chat-threads");
|
|
22
|
+
const selected = threads.find((thread) => thread.id === selectedThreadId);
|
|
23
|
+
const headingRef = useRef(null);
|
|
24
|
+
const activeRef = useRef(null);
|
|
25
|
+
const navigation = useRef(null);
|
|
26
|
+
useIsoLayoutEffect(() => {
|
|
27
|
+
const request = navigation.current;
|
|
28
|
+
if (!request)
|
|
29
|
+
return;
|
|
30
|
+
if ("threadId" in request && request.threadId === selectedThreadId) {
|
|
31
|
+
headingRef.current?.focus();
|
|
32
|
+
navigation.current = null;
|
|
33
|
+
}
|
|
34
|
+
else if ("returnTo" in request && selectedThreadId === null) {
|
|
35
|
+
request.returnTo?.focus();
|
|
36
|
+
navigation.current = null;
|
|
37
|
+
}
|
|
38
|
+
}, [selectedThreadId]);
|
|
39
|
+
const select = (id) => {
|
|
40
|
+
navigation.current = { threadId: id };
|
|
41
|
+
onSelectThread(id);
|
|
42
|
+
};
|
|
43
|
+
const back = () => {
|
|
44
|
+
navigation.current = { returnTo: activeRef.current };
|
|
45
|
+
onSelectThread(null);
|
|
46
|
+
};
|
|
47
|
+
const empty = emptySelection === undefined ? messages.chat.chooseThread : emptySelection;
|
|
48
|
+
return (_jsxs("div", { className: cx("vk-chat-inbox", selected && "vk-chat-inbox-selected", className), children: [_jsxs("section", { className: "vk-chat-inbox-list", "aria-labelledby": listTitleId, children: [_jsx("header", { className: "vk-chat-header", children: _jsx("h2", { id: listTitleId, className: "vk-chat-title", children: title || messages.chat.conversations }) }), _jsx(ThreadList, { threads: threads, selectedId: selectedThreadId, activeRef: activeRef, onSelect: select })] }), _jsx("section", { className: "vk-chat-inbox-detail", "aria-label": selected?.title || messages.chat.messages, children: selected ? _jsxs(_Fragment, { children: [_jsxs("header", { className: "vk-chat-header", children: [_jsx(IconButton, { icon: "chevron-left", label: messages.chat.back, className: "vk-chat-back", onClick: back }), _jsx("h2", { ref: headingRef, tabIndex: -1, className: "vk-chat-title", children: selected.title })] }), _jsx(ChatPanel, { ...panel }, selected.id)] }) : _jsx("div", { className: "vk-chat-empty vk-chat-no-selection", children: empty }) })] }));
|
|
49
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useLocale } from "../../localization.js";
|
|
4
|
+
import { cx } from "../../lib/cx.js";
|
|
5
|
+
import { Button } from "../Button/Button.js";
|
|
6
|
+
import { Icon } from "../Icon/Icon.js";
|
|
7
|
+
import { ChatComposer } from "./composer.js";
|
|
8
|
+
import { ChatTranscript } from "./transcript.js";
|
|
9
|
+
/** Shared transcript, feedback and Markdown composer; no transport or persistence. */
|
|
10
|
+
export function ChatPanel(props) {
|
|
11
|
+
const { messages } = useLocale();
|
|
12
|
+
return (_jsxs("div", { className: cx("vk-chat-panel", props.className), children: [_jsx(ChatTranscript, { messages: props.messages, emptyState: props.emptyState, pending: props.pending, error: props.error, label: props["aria-label"], onRetryMessage: props.onRetryMessage }), props.error ? _jsxs("div", { className: "vk-chat-feedback", role: "alert", children: [_jsx(Icon, { name: "circle-alert", size: 16 }), _jsx("div", { children: props.error }), props.onRetry ? _jsx(Button, { type: "button", size: "sm", variant: "ghost", onClick: props.onRetry, children: messages.chat.tryAgain }) : null] }) : null, _jsx(ChatComposer, { options: props.composer })] }));
|
|
13
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ChatComposerOptions } from "../../chat.js";
|
|
2
|
+
/** Draft state belongs to this form, or to the application when value is supplied. */
|
|
3
|
+
export declare function ChatComposer({ options }: {
|
|
4
|
+
options: ChatComposerOptions;
|
|
5
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { useLocale } from "../../localization.js";
|
|
5
|
+
import { Field } from "../Field/Field.js";
|
|
6
|
+
import { Button } from "../Button/Button.js";
|
|
7
|
+
import { RichTextEditor } from "../RichTextEditor/RichTextEditor.js";
|
|
8
|
+
/** Draft state belongs to this form, or to the application when value is supplied. */
|
|
9
|
+
export function ChatComposer({ options }) {
|
|
10
|
+
const { messages } = useLocale();
|
|
11
|
+
const [uncontrolled, setUncontrolled] = useState(options.defaultValue || "");
|
|
12
|
+
const controlled = options.value !== undefined;
|
|
13
|
+
const [uploadPending, setUploadPending] = useState(false);
|
|
14
|
+
const draft = options.value ?? uncontrolled;
|
|
15
|
+
const locked = Boolean(options.disabled || options.sending);
|
|
16
|
+
const change = (value) => {
|
|
17
|
+
if (!controlled)
|
|
18
|
+
setUncontrolled(value);
|
|
19
|
+
options.onChange?.(value);
|
|
20
|
+
};
|
|
21
|
+
const submit = (event) => {
|
|
22
|
+
if (event.target !== event.currentTarget)
|
|
23
|
+
return;
|
|
24
|
+
event.preventDefault();
|
|
25
|
+
if (locked || uploadPending || !draft.trim())
|
|
26
|
+
return;
|
|
27
|
+
options.onSend(draft);
|
|
28
|
+
if (!controlled)
|
|
29
|
+
change("");
|
|
30
|
+
};
|
|
31
|
+
return (_jsxs("form", { className: "vk-chat-composer", onSubmit: submit, children: [_jsx(Field, { label: options.label || messages.chat.message, children: _jsx(RichTextEditor, { toolbar: "minimal", value: draft, onChange: change, name: options.name, disabled: locked, placeholder: options.placeholder || messages.chat.placeholder, onUploadAttachment: options.onUploadAttachment, accept: options.accept, maxFileSize: options.maxFileSize, emojiOptions: options.emojiOptions, onUploadError: options.onUploadError, onUploadPendingChange: setUploadPending }) }), _jsx("div", { className: "vk-chat-composer-actions", children: _jsx(Button, { type: "submit", size: "sm", loading: options.sending, loadingLabel: messages.chat.sending, disabled: locked || uploadPending || !draft.trim(), children: options.sendLabel || messages.chat.send }) })] }));
|
|
32
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { ChatMessage } from "../../chat.js";
|
|
3
|
+
interface TranscriptProps {
|
|
4
|
+
messages: readonly ChatMessage[];
|
|
5
|
+
emptyState?: ReactNode;
|
|
6
|
+
pending?: ReactNode;
|
|
7
|
+
error?: ReactNode;
|
|
8
|
+
label?: string;
|
|
9
|
+
onRetryMessage?: (id: string) => void;
|
|
10
|
+
}
|
|
11
|
+
/** A native scrollable log. Follow new messages only while the reader is near its end. */
|
|
12
|
+
export declare function ChatTranscript(props: TranscriptProps): import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useRef } from "react";
|
|
4
|
+
import { AnimatePresence, LazyMotion, domAnimation, useReducedMotion } from "motion/react";
|
|
5
|
+
import * as m from "motion/react-m";
|
|
6
|
+
import { useLocale } from "../../localization.js";
|
|
7
|
+
import { useIsoLayoutEffect } from "../../internal/useIsoLayoutEffect.js";
|
|
8
|
+
import { Avatar } from "../Avatar/Avatar.js";
|
|
9
|
+
import { Button } from "../Button/Button.js";
|
|
10
|
+
import { Icon } from "../Icon/Icon.js";
|
|
11
|
+
import { cx } from "../../lib/cx.js";
|
|
12
|
+
function MessageDelivery({ message, onRetry }) {
|
|
13
|
+
const { messages } = useLocale();
|
|
14
|
+
if (!message.delivery)
|
|
15
|
+
return null;
|
|
16
|
+
if (message.delivery.state === "pending")
|
|
17
|
+
return _jsxs("span", { className: "vk-chat-delivery", children: [_jsx(Icon, { name: "clock", size: 14 }), messages.chat.sending] });
|
|
18
|
+
return (_jsxs("div", { className: "vk-chat-delivery vk-chat-delivery-failed", children: [_jsx(Icon, { name: "circle-alert", size: 14 }), _jsx("span", { children: message.delivery.error || messages.chat.failed }), onRetry ? _jsx(Button, { type: "button", size: "sm", variant: "ghost", "aria-label": messages.chat.retryMessage(message.author.name), onClick: () => { onRetry(message.id); }, children: messages.chat.retry }) : null] }));
|
|
19
|
+
}
|
|
20
|
+
function MessageItem({ message, onRetry, reducedMotion }) {
|
|
21
|
+
return (_jsxs(m.li, { className: cx("vk-chat-message", "vk-chat-message-" + message.direction), initial: { opacity: 0, y: reducedMotion ? 0 : 4 }, animate: { opacity: 1, y: 0 }, transition: { duration: reducedMotion ? 0 : 0.16, ease: "easeOut" }, children: [_jsx("span", { className: "vk-chat-message-avatar", children: message.author.avatar || _jsx(Avatar, { name: message.author.name, size: 28, decorative: true }) }), _jsxs("div", { className: "vk-chat-message-body", children: [_jsxs("div", { className: "vk-chat-message-meta", children: [_jsx("span", { className: "vk-chat-message-author", children: message.author.name }), message.timestamp ? _jsx("span", { className: "vk-chat-message-time", children: message.timestamp }) : null] }), _jsx("div", { className: "vk-prose vk-chat-message-content", children: message.content }), _jsx(MessageDelivery, { message: message, onRetry: onRetry })] })] }));
|
|
22
|
+
}
|
|
23
|
+
/** A native scrollable log. Follow new messages only while the reader is near its end. */
|
|
24
|
+
export function ChatTranscript(props) {
|
|
25
|
+
const { messages } = useLocale();
|
|
26
|
+
const reducedMotion = useReducedMotion() === true;
|
|
27
|
+
const scrollRef = useRef(null);
|
|
28
|
+
const follow = useRef(true);
|
|
29
|
+
useIsoLayoutEffect(() => {
|
|
30
|
+
const node = scrollRef.current;
|
|
31
|
+
if (node && follow.current)
|
|
32
|
+
node.scrollTop = node.scrollHeight;
|
|
33
|
+
}, [props.messages, props.pending]);
|
|
34
|
+
const empty = props.emptyState === undefined ? messages.chat.empty : props.emptyState;
|
|
35
|
+
return (_jsxs("div", { ref: scrollRef, role: "log", "aria-label": props.label || messages.chat.messages, "aria-live": "polite", "aria-relevant": "additions text", "aria-atomic": "false", tabIndex: 0, className: "vk-chat-transcript", onScroll: (event) => {
|
|
36
|
+
const node = event.currentTarget;
|
|
37
|
+
follow.current = node.scrollHeight - node.scrollTop - node.clientHeight <= 32;
|
|
38
|
+
}, children: [_jsx(LazyMotion, { features: domAnimation, children: _jsx("ol", { className: "vk-chat-messages", children: _jsx(AnimatePresence, { initial: false, children: props.messages.map((message) => _jsx(MessageItem, { message: message, onRetry: props.onRetryMessage, reducedMotion: reducedMotion }, message.id)) }) }) }), !props.messages.length && !props.pending && !props.error ? _jsx("div", { className: "vk-chat-empty", children: empty }) : null, props.pending ? _jsx("div", { className: "vk-chat-pending", role: "status", children: props.pending }) : null] }));
|
|
39
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { Popover as Primitive } from "radix-ui";
|
|
3
|
+
import type { ChatPanelProps } from "../../chat.js";
|
|
4
|
+
export interface ChatWidgetProps extends ChatPanelProps, Pick<Primitive.PopoverProps, "open" | "defaultOpen" | "onOpenChange" | "modal"> {
|
|
5
|
+
title: string;
|
|
6
|
+
description?: ReactNode;
|
|
7
|
+
align?: "start" | "end";
|
|
8
|
+
triggerLabel?: string;
|
|
9
|
+
unreadCount?: number;
|
|
10
|
+
}
|
|
11
|
+
/** A floating chat launcher with native Radix Popover focus, state and dismissal. */
|
|
12
|
+
export declare function ChatWidget({ title, description, align, triggerLabel, unreadCount, open, defaultOpen, onOpenChange, modal, className, ...panel }: ChatWidgetProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { Popover as Primitive } from "radix-ui";
|
|
5
|
+
import { AnimatePresence, LazyMotion, domAnimation, useReducedMotion } from "motion/react";
|
|
6
|
+
import * as m from "motion/react-m";
|
|
7
|
+
import { useLocale } from "../../localization.js";
|
|
8
|
+
import { useUid } from "../../internal/useUid.js";
|
|
9
|
+
import { formatNumber } from "../../lib/format.js";
|
|
10
|
+
import { cx } from "../../lib/cx.js";
|
|
11
|
+
import { ChatPanel } from "../ChatPanel/ChatPanel.js";
|
|
12
|
+
import { IconButton } from "../IconButton/IconButton.js";
|
|
13
|
+
const MotionIconButton = m.create(IconButton);
|
|
14
|
+
/** Hoist only Radix's public state contract so Motion can retain native content during exit. */
|
|
15
|
+
function useChatOpen({ open, defaultOpen, onOpenChange }) {
|
|
16
|
+
const [localOpen, setLocalOpen] = useState(defaultOpen ?? false);
|
|
17
|
+
return {
|
|
18
|
+
open: open ?? localOpen,
|
|
19
|
+
change: (next) => {
|
|
20
|
+
if (open === undefined)
|
|
21
|
+
setLocalOpen(next);
|
|
22
|
+
onOpenChange?.(next);
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/** Motion retains the native content during exit; Radix still owns its focus scope and position. */
|
|
27
|
+
function WidgetContent({ title, description, align, titleId, panel }) {
|
|
28
|
+
const { messages } = useLocale();
|
|
29
|
+
const reducedMotion = useReducedMotion() === true;
|
|
30
|
+
const descriptionId = titleId + "-description";
|
|
31
|
+
return _jsx(Primitive.Portal, { forceMount: true, children: _jsx(Primitive.Content, { forceMount: true, asChild: true, side: "top", align: align, sideOffset: 12, collisionPadding: 12, "aria-labelledby": titleId, "aria-describedby": description ? descriptionId : undefined, className: "vk-chat-widget-panel", children: _jsxs(m.div, { initial: { opacity: 0, y: reducedMotion ? 0 : 8, scale: reducedMotion ? 1 : 0.99 }, animate: { opacity: 1, y: 0, scale: 1, transition: { duration: reducedMotion ? 0 : 0.2, ease: [0.2, 0.8, 0.2, 1] } }, exit: { opacity: 0, y: reducedMotion ? 0 : 8, scale: reducedMotion ? 1 : 0.99, transition: { duration: reducedMotion ? 0 : 0.12 } }, children: [_jsxs("header", { className: "vk-chat-header", children: [_jsxs("div", { className: "vk-chat-heading", children: [_jsx("h2", { id: titleId, className: "vk-chat-title", children: title }), description ? _jsx("div", { id: descriptionId, className: "vk-chat-description", children: description }) : null] }), _jsx(Primitive.Close, { asChild: true, children: _jsx(IconButton, { icon: "x", label: messages.chat.close }) })] }), _jsx(ChatPanel, { ...panel })] }) }) });
|
|
32
|
+
}
|
|
33
|
+
/** A floating chat launcher with native Radix Popover focus, state and dismissal. */
|
|
34
|
+
export function ChatWidget({ title, description, align = "end", triggerLabel, unreadCount, open, defaultOpen, onOpenChange, modal, className, ...panel }) {
|
|
35
|
+
const { locale, messages } = useLocale();
|
|
36
|
+
const disclosure = useChatOpen({ open, defaultOpen, onOpenChange });
|
|
37
|
+
const reducedMotion = useReducedMotion() === true;
|
|
38
|
+
const titleId = useUid("vk-chat-title");
|
|
39
|
+
const unread = unreadCount && unreadCount > 0 ? messages.chat.unread(unreadCount) : "";
|
|
40
|
+
const label = (triggerLabel || messages.chat.open) + (unread ? ", " + unread : "");
|
|
41
|
+
return (_jsx(LazyMotion, { features: domAnimation, children: _jsxs(Primitive.Root, { open: disclosure.open, onOpenChange: disclosure.change, modal: modal, children: [_jsxs("div", { className: cx("vk-chat-widget-launcher", "vk-chat-widget-" + align, className), children: [_jsx(Primitive.Trigger, { asChild: true, children: _jsx(MotionIconButton, { icon: "message-circle", size: 24, label: label, variant: "outline", className: "vk-chat-widget-trigger", whileHover: reducedMotion ? undefined : { scale: 1.03 }, whileTap: reducedMotion ? undefined : { scale: 0.97 }, transition: { duration: reducedMotion ? 0 : 0.12 } }) }), unreadCount && unreadCount > 0 ? _jsx("span", { className: "vk-chat-unread", "aria-hidden": "true", children: formatNumber(unreadCount, { locale }) }) : null] }), _jsx(AnimatePresence, { initial: false, children: disclosure.open ? _jsx(WidgetContent, { title: title, description: description, align: align, titleId: titleId, panel: panel }) : null })] }) }));
|
|
42
|
+
}
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
indeterminate?: boolean;
|
|
6
|
-
hideLabel?: boolean;
|
|
1
|
+
import { type ComponentPropsWithoutRef } from "react";
|
|
2
|
+
import { Checkbox as Primitive } from "radix-ui";
|
|
3
|
+
import { type ChoiceTextProps } from "../../internal/choice.js";
|
|
4
|
+
export interface CheckboxProps extends Omit<ComponentPropsWithoutRef<typeof Primitive.Root>, "asChild" | "children" | "onChange">, ChoiceTextProps {
|
|
7
5
|
}
|
|
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
|
-
*/
|
|
6
|
+
/** Styled Radix Checkbox; checked state, callbacks, keyboard and form behavior belong to Radix. */
|
|
12
7
|
export declare const Checkbox: import("react").ForwardRefExoticComponent<CheckboxProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
@@ -1,24 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { forwardRef
|
|
3
|
+
import { forwardRef } from "react";
|
|
4
4
|
import { Checkbox as Primitive } from "radix-ui";
|
|
5
|
-
import { checkMark, ChoiceLabel, hiddenLabel
|
|
5
|
+
import { checkMark, ChoiceLabel, hiddenLabel } from "../../internal/choice.js";
|
|
6
6
|
import { omit } from "../../lib/omit.js";
|
|
7
|
-
/**
|
|
8
|
-
|
|
9
|
-
|
|
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) }) }) }));
|
|
7
|
+
/** Styled Radix Checkbox; checked state, callbacks, keyboard and form behavior belong to Radix. */
|
|
8
|
+
export const Checkbox = forwardRef(function Checkbox({ label, description, hideLabel, className, ...props }, ref) {
|
|
9
|
+
return (_jsx(ChoiceLabel, { label: label, description: description, hideLabel: hideLabel, disabled: props.disabled, className: className, children: _jsx(Primitive.Root, { ...omit(props, ["data-state"]), ref: ref, "aria-label": props["aria-label"] || hiddenLabel({ label, hideLabel }), className: "vk-choice-box", children: _jsx(Primitive.Indicator, { forceMount: true, asChild: true, children: checkMark() }) }) }));
|
|
24
10
|
});
|
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import {
|
|
3
|
+
import { useLocale } from "../../localization.js";
|
|
4
|
+
import { useEffect, useRef, useState } from "react";
|
|
4
5
|
import { Icon } from "../Icon/Icon.js";
|
|
5
6
|
import { cx } from "../../lib/cx.js";
|
|
6
7
|
// Copies the code, or, without clipboard access, selects it so it can be copied by hand.
|
|
7
8
|
function useCopy(code, preRef) {
|
|
8
9
|
const [copied, setCopied] = useState(false);
|
|
10
|
+
const timer = useRef();
|
|
11
|
+
const mounted = useRef(false);
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
mounted.current = true;
|
|
14
|
+
return () => { mounted.current = false; clearTimeout(timer.current); };
|
|
15
|
+
}, []);
|
|
9
16
|
const selectAll = () => {
|
|
17
|
+
if (!mounted.current)
|
|
18
|
+
return;
|
|
10
19
|
const pre = preRef.current;
|
|
11
20
|
const sel = window.getSelection();
|
|
12
21
|
if (!pre || !sel)
|
|
@@ -18,8 +27,11 @@ function useCopy(code, preRef) {
|
|
|
18
27
|
};
|
|
19
28
|
const copy = () => {
|
|
20
29
|
const done = () => {
|
|
30
|
+
if (!mounted.current)
|
|
31
|
+
return;
|
|
32
|
+
clearTimeout(timer.current);
|
|
21
33
|
setCopied(true);
|
|
22
|
-
setTimeout(() => setCopied(false), 1600);
|
|
34
|
+
timer.current = setTimeout(() => { setCopied(false); }, 1600);
|
|
23
35
|
};
|
|
24
36
|
try {
|
|
25
37
|
navigator.clipboard.writeText(code).then(done, selectAll);
|
|
@@ -31,13 +43,15 @@ function useCopy(code, preRef) {
|
|
|
31
43
|
return { copied, copy };
|
|
32
44
|
}
|
|
33
45
|
function CodeBlockHead({ title, showCopy, copied, onCopy }) {
|
|
34
|
-
|
|
46
|
+
const { messages } = useLocale();
|
|
47
|
+
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 ? messages.copied : messages.copy })] })) : null] }));
|
|
35
48
|
}
|
|
36
49
|
/** A block of code or terminal output with a title, an optional line-number gutter and a copy button. */
|
|
37
50
|
export function CodeBlock({ code, title, language, lineNumbers, copy: showCopy, className }) {
|
|
51
|
+
const { messages } = useLocale();
|
|
38
52
|
const preRef = useRef(null);
|
|
39
53
|
const { copied, copy } = useCopy(code, preRef);
|
|
40
|
-
const lines =
|
|
54
|
+
const lines = code.replace(/\n$/, "").split("\n");
|
|
41
55
|
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
|
|
56
|
+
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 ? messages.languageCode(language) : messages.code), children: _jsx("code", { children: lineNumbers ? lines.map((l, i) => _jsx("span", { className: "vk-code-line", children: l + "\n" }, i)) : lines.join("\n") }) })] }));
|
|
43
57
|
}
|