@vokality/design-system 2.0.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 +28 -0
- package/README.md +49 -3
- 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 +2 -2
- package/dist/components/FileUpload/FileUpload.js +17 -9
- package/dist/components/Grid/Grid.d.ts +5 -5
- package/dist/components/Grid/Grid.js +1 -1
- package/dist/components/Heading/Heading.js +2 -1
- package/dist/components/Icon/Icon.js +4 -2
- package/dist/components/Inline/Inline.d.ts +7 -7
- 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 +5 -5
- 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 +1 -1
- 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 +179 -8
- 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/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/vokality.css +179 -8
- package/dist/vokality.iife.js +35986 -9685
- package/docs/brand.md +6 -3
- package/docs/components/AppShell/README.md +1 -1
- package/docs/components/BarChart/README.md +1 -0
- 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/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/Toaster/README.md +3 -1
- package/docs/components/Tooltip/README.md +5 -3
- package/package.json +49 -5
|
@@ -1,27 +1,28 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { useLocale } from "../../localization.js";
|
|
4
|
+
import { isValidElement, useState } from "react";
|
|
4
5
|
import { Checkbox } from "../Checkbox/Checkbox.js";
|
|
5
6
|
import { Icon } from "../Icon/Icon.js";
|
|
6
7
|
import { Pagination } from "../Pagination/Pagination.js";
|
|
7
8
|
import { Skeleton } from "../Skeleton/Skeleton.js";
|
|
8
9
|
import { cx } from "../../lib/cx.js";
|
|
9
10
|
/** Reads a row's field by name: columns and `rowKey` address rows by string keys. */
|
|
10
|
-
const field = (row, key) => row
|
|
11
|
+
const field = (row, key) => typeof row === "object" && row !== null ? Reflect.get(row, key) : undefined;
|
|
11
12
|
/** A row's key: rowKey(row), else row[rowKey || "id"], else its index. Keys are strings or numbers by contract. */
|
|
12
13
|
function keyOfRow(rowKey, r, i) {
|
|
13
14
|
if (typeof rowKey === "function")
|
|
14
15
|
return rowKey(r);
|
|
15
16
|
const k = field(r, rowKey || "id");
|
|
16
|
-
return k
|
|
17
|
+
return typeof k === "string" || typeof k === "number" ? k : i;
|
|
17
18
|
}
|
|
18
19
|
/** `rows` in `sort` order, by the column's sortValue or else the field itself. */
|
|
19
|
-
function sortRows(rows, columns, sort) {
|
|
20
|
+
function sortRows(rows, columns, sort, locale) {
|
|
20
21
|
const col = columns.find((c) => c.key === sort.key);
|
|
21
22
|
const get = col?.sortValue || ((r) => field(r, sort.key));
|
|
22
23
|
return rows.slice().sort((a, b) => {
|
|
23
24
|
const x = get(a), y = get(b);
|
|
24
|
-
const cmp = typeof x === "number" && typeof y === "number" ? x - y : String(x).localeCompare(String(y),
|
|
25
|
+
const cmp = typeof x === "number" && typeof y === "number" ? x - y : String(x).localeCompare(String(y), locale, { numeric: true });
|
|
25
26
|
return sort.direction === "asc" ? cmp : -cmp;
|
|
26
27
|
});
|
|
27
28
|
}
|
|
@@ -58,32 +59,45 @@ const alignsEnd = (c) => c.numeric || c.align === "end";
|
|
|
58
59
|
function TableHeaderCell({ column: c, sort, onSort }) {
|
|
59
60
|
// The active sort direction for this column, if it is the sorted one.
|
|
60
61
|
const dir = sort && sort.key === c.key ? sort.direction : null;
|
|
61
|
-
return (_jsx("th", { scope: "col", style: c.width ? { width: c.width } : undefined, className: cx(alignsEnd(c) && "vk-td-end"), "aria-sort": c.sortable ? (dir ? ARIA_SORT[dir] : "none") : undefined, children: c.sortable ? (_jsxs("button", { type: "button", className: cx("vk-th-sort", dir && "vk-th-sort-active"), onClick: () => onSort(c.key), children: [c.header, _jsx(Icon, { name: dir ? SORT_ICON[dir] : "chevrons-up-down", size: 14, className: "vk-th-sort-icon" })] })) : (c.header) }));
|
|
62
|
+
return (_jsx("th", { scope: "col", style: c.width ? { width: c.width } : undefined, className: cx(alignsEnd(c) && "vk-td-end"), "aria-sort": c.sortable ? (dir ? ARIA_SORT[dir] : "none") : undefined, children: c.sortable ? (_jsxs("button", { type: "button", className: cx("vk-th-sort", dir && "vk-th-sort-active"), onClick: () => { onSort(c.key); }, children: [c.header, _jsx(Icon, { name: dir ? SORT_ICON[dir] : "chevrons-up-down", size: 14, className: "vk-th-sort-icon" })] })) : (c.header) }));
|
|
62
63
|
}
|
|
63
64
|
/** The header row: the details column, the select-all checkbox and the column headers. */
|
|
64
65
|
function TableHead({ columns, sort, onSort, expandable, expandColumnLabel, selectable, selectAllLabel, allKeys, selCount, onSelectAll }) {
|
|
65
|
-
|
|
66
|
+
const { messages } = useLocale();
|
|
67
|
+
return (_jsxs("tr", { children: [expandable ? (_jsx("th", { className: "vk-td-select", scope: "col", children: _jsx("span", { className: "vk-sr-only", children: expandColumnLabel || messages.details }) })) : null, selectable ? (_jsx("th", { className: "vk-td-select", scope: "col", children: _jsx(Checkbox, { label: selectAllLabel || messages.selectAllRows, hideLabel: true, checked: selCount > 0 && selCount < allKeys.length ? "indeterminate" : allKeys.length > 0 && selCount === allKeys.length, onCheckedChange: onSelectAll }) })) : null, columns.map((c) => _jsx(TableHeaderCell, { column: c, sort: sort, onSort: onSort }, c.key))] }));
|
|
68
|
+
}
|
|
69
|
+
/** Unknown row fields must be renderable; richer values need the column's typed render callback. */
|
|
70
|
+
function cellContent(value) {
|
|
71
|
+
if (value == null || typeof value === "string" || typeof value === "number" || typeof value === "boolean")
|
|
72
|
+
return value;
|
|
73
|
+
if (isValidElement(value))
|
|
74
|
+
return value;
|
|
75
|
+
if (Array.isArray(value))
|
|
76
|
+
return value.map(cellContent);
|
|
77
|
+
throw new TypeError("Table cells must contain renderable values; provide a column render callback for objects.");
|
|
66
78
|
}
|
|
67
79
|
/** A row's data cells: the first is the row header unless `rowHeader` is false. */
|
|
68
80
|
function TableCells({ row: r, columns, rowHeader }) {
|
|
69
81
|
return columns.map((c, ci) => {
|
|
70
|
-
const content = c.render ? c.render(r) : field(r, c.key);
|
|
82
|
+
const content = c.render ? c.render(r) : cellContent(field(r, c.key));
|
|
71
83
|
const cls = cx(c.numeric && "vk-td-num", alignsEnd(c) && "vk-td-end", (c.nowrap || c.numeric) && "vk-td-nowrap");
|
|
72
84
|
return ci === 0 && rowHeader !== false ? (_jsx("th", { scope: "row", className: cx("vk-td-rowheader", cls), children: content }, c.key)) : (_jsx("td", { className: cls, children: content }, c.key));
|
|
73
85
|
});
|
|
74
86
|
}
|
|
75
87
|
/** The cell with the button that shows or hides a row's details. */
|
|
76
88
|
function RowToggleCell({ rowKey: k, name, isOpen, onToggle }) {
|
|
77
|
-
|
|
89
|
+
const { messages } = useLocale();
|
|
90
|
+
return (_jsx("td", { className: "vk-td-select", children: _jsx("button", { type: "button", className: "vk-icon-btn vk-icon-btn-ghost vk-row-toggle", "aria-expanded": isOpen ? "true" : "false", "aria-controls": "vk-row-" + String(k), "aria-label": isOpen ? messages.hideDetails(name) : messages.showDetails(name), onClick: onToggle, children: _jsx(Icon, { name: "chevron-right", size: 14, className: cx("vk-tree-caret", isOpen && "vk-tree-caret-open") }) }) }));
|
|
78
91
|
}
|
|
79
92
|
/** One record: its details toggle and checkbox, its cells, and its details row when open. */
|
|
80
93
|
function TableRow({ row: r, index: i, rowKey: k, columns, colCount, selectable, isSel, isOpen, rowLabel, rowHeader, renderExpanded, onToggleSelect, onToggleOpen }) {
|
|
94
|
+
const { messages } = useLocale();
|
|
81
95
|
const label = rowLabel ? rowLabel(r) : null;
|
|
82
|
-
return (_jsxs(_Fragment, { children: [_jsxs("tr", { "aria-selected": selectable ?
|
|
96
|
+
return (_jsxs(_Fragment, { children: [_jsxs("tr", { "aria-selected": selectable ? isSel : undefined, className: cx(isSel && "vk-tr-selected", isOpen && "vk-tr-open"), children: [renderExpanded ? _jsx(RowToggleCell, { rowKey: k, name: label != null ? label.replace(/^Select /, "") : messages.row(i + 1), isOpen: isOpen, onToggle: onToggleOpen }) : null, selectable ? (_jsx("td", { className: "vk-td-select", children: _jsx(Checkbox, { label: label != null ? label : messages.selectRow(i + 1), hideLabel: true, checked: isSel, onCheckedChange: onToggleSelect }) })) : null, _jsx(TableCells, { row: r, columns: columns, rowHeader: rowHeader })] }), renderExpanded && isOpen ? (_jsx("tr", { id: "vk-row-" + String(k), className: "vk-tr-expanded", children: _jsx("td", { colSpan: colCount, children: renderExpanded(r) }) })) : null] }));
|
|
83
97
|
}
|
|
84
98
|
/** Placeholder rows while the data loads. */
|
|
85
99
|
function TableLoadingRows({ rows, colCount }) {
|
|
86
|
-
return Array.from({ length: rows }, (_, li) => (_jsx("tr", { className: "vk-tr-loading", children: Array.from({ length: colCount }, (_, ci) => (_jsx("td", { children: _jsx(Skeleton, { width: ci === 0 ? "70%" : "50%", height: "0.8rem" }) }, ci))) }, "_load" + li)));
|
|
100
|
+
return Array.from({ length: rows }, (_, li) => (_jsx("tr", { className: "vk-tr-loading", children: Array.from({ length: colCount }, (_, ci) => (_jsx("td", { children: _jsx(Skeleton, { width: ci === 0 ? "70%" : "50%", height: "0.8rem" }) }, ci))) }, "_load" + String(li))));
|
|
87
101
|
}
|
|
88
102
|
/** The scroll container around the table: a focusable, labelled region when it has a max height. */
|
|
89
103
|
function TableWrap({ maxHeight, caption, density, loading, className, children }) {
|
|
@@ -91,9 +105,10 @@ function TableWrap({ maxHeight, caption, density, loading, className, children }
|
|
|
91
105
|
}
|
|
92
106
|
/** The rows on view: sorted unless `manualSort`, then cut to the current page when `pageSize` is set. */
|
|
93
107
|
function useTableView(props, columns) {
|
|
108
|
+
const { locale } = useLocale();
|
|
94
109
|
const { sort, setSort } = useTableSort(props);
|
|
95
|
-
const rows = props.rows
|
|
96
|
-
const sorted = sort && !props.manualSort ? sortRows(rows, columns, sort) : rows;
|
|
110
|
+
const rows = props.rows;
|
|
111
|
+
const sorted = sort && !props.manualSort ? sortRows(rows, columns, sort, locale) : rows;
|
|
97
112
|
const pageSize = props.pageSize;
|
|
98
113
|
const [pageState, setPage] = useState(1);
|
|
99
114
|
const pageCount = pageSize ? Math.max(1, Math.ceil(sorted.length / pageSize)) : 1;
|
|
@@ -103,11 +118,12 @@ function useTableView(props, columns) {
|
|
|
103
118
|
}
|
|
104
119
|
/** The pager below a paginated table, with its "1–10 of 42" summary; nothing when everything fits on one page. */
|
|
105
120
|
function TablePager({ page, pageCount, onChange, pageSize, total, summaryFormat }) {
|
|
121
|
+
const { messages } = useLocale();
|
|
106
122
|
if (total <= pageSize)
|
|
107
123
|
return null;
|
|
108
124
|
const from = (page - 1) * pageSize + 1;
|
|
109
125
|
const to = Math.min(total, page * pageSize);
|
|
110
|
-
return _jsx(Pagination, { page: page, pageCount: pageCount, onChange: onChange, summary: summaryFormat ? summaryFormat(from, to, total) : from
|
|
126
|
+
return _jsx(Pagination, { page: page, pageCount: pageCount, onChange: onChange, summary: summaryFormat ? summaryFormat(from, to, total) : messages.pageSummary(from, to, total) });
|
|
111
127
|
}
|
|
112
128
|
/** The record rows, each with its selection and details state. */
|
|
113
129
|
function TableBodyRows({ view, allKeys, selected, setSelected, expanded, setExpanded, ...rowProps }) {
|
|
@@ -115,15 +131,18 @@ function TableBodyRows({ view, allKeys, selected, setSelected, expanded, setExpa
|
|
|
115
131
|
const expandedSet = new Set(expanded);
|
|
116
132
|
return view.map((r, i) => {
|
|
117
133
|
const k = allKeys[i];
|
|
134
|
+
if (k === undefined)
|
|
135
|
+
return null;
|
|
118
136
|
const isSel = selectedSet.has(k);
|
|
119
137
|
const isOpen = expandedSet.has(k);
|
|
120
|
-
return (_jsx(TableRow, { ...rowProps, row: r, index: i, rowKey: k, isSel: isSel, isOpen: isOpen, onToggleSelect: () => setSelected(isSel ? selected.filter((x) => x !== k) : selected.concat([k])), onToggleOpen: () => setExpanded(isOpen ? expanded.filter((x) => x !== k) : expanded.concat([k])) }, k));
|
|
138
|
+
return (_jsx(TableRow, { ...rowProps, row: r, index: i, rowKey: k, isSel: isSel, isOpen: isOpen, onToggleSelect: () => { setSelected(isSel ? selected.filter((x) => x !== k) : selected.concat([k])); }, onToggleOpen: () => { setExpanded(isOpen ? expanded.filter((x) => x !== k) : expanded.concat([k])); } }, k));
|
|
121
139
|
});
|
|
122
140
|
}
|
|
123
141
|
/** A data table for comparing records: sortable columns, row selection, numeric alignment and an empty state. */
|
|
124
142
|
export function Table(props) {
|
|
143
|
+
const { messages } = useLocale();
|
|
125
144
|
const { caption, selectable, loading, renderExpanded, pageSize, className } = props;
|
|
126
|
-
const columns = props.columns
|
|
145
|
+
const columns = props.columns;
|
|
127
146
|
const { sort, setSort, view, page, pageCount, setPage, total } = useTableView(props, columns);
|
|
128
147
|
const { selected, setSelected } = useTableSelection(props);
|
|
129
148
|
const [expanded, setExpanded] = useState(props.defaultExpanded || []);
|
|
@@ -131,13 +150,13 @@ export function Table(props) {
|
|
|
131
150
|
const allKeys = view.map((r, i) => keyOfRow(props.rowKey, r, i));
|
|
132
151
|
const selectedSet = new Set(selected);
|
|
133
152
|
const selCount = allKeys.filter((k) => selectedSet.has(k)).length;
|
|
134
|
-
let body = _jsx("tr", { children: _jsx("td", { className: "vk-td-empty", colSpan: colCount, children: props.emptyText ||
|
|
153
|
+
let body = _jsx("tr", { children: _jsx("td", { className: "vk-td-empty", colSpan: colCount, children: props.emptyText || messages.nothingToShow }) });
|
|
135
154
|
if (loading)
|
|
136
155
|
body = _jsx(TableLoadingRows, { rows: props.loadingRows || 5, colCount: colCount });
|
|
137
156
|
else if (view.length) {
|
|
138
157
|
body = (_jsx(TableBodyRows, { view: view, allKeys: allKeys, selected: selected, setSelected: setSelected, expanded: expanded, setExpanded: setExpanded, columns: columns, colCount: colCount, selectable: selectable, rowLabel: props.rowLabel, rowHeader: props.rowHeader, renderExpanded: renderExpanded }));
|
|
139
158
|
}
|
|
140
|
-
const table = (_jsx(TableWrap, { maxHeight: props.maxHeight, caption: caption, density: props.density, loading: loading, className: pageSize ? undefined : className, children: _jsxs("table", { className: "vk-table", children: [caption ? _jsx("caption", { className: props.captionHidden ? "vk-sr-only" : "vk-table-caption", children: caption }) : null, _jsx("thead", { children: _jsx(TableHead, { columns: columns, sort: sort, onSort: setSort, expandable: Boolean(renderExpanded), expandColumnLabel: props.expandColumnLabel, selectable: selectable, selectAllLabel: props.selectAllLabel, allKeys: allKeys, selCount: selCount, onSelectAll: () => setSelected(selCount === allKeys.length ? [] : allKeys) }) }), _jsx("tbody", { children: body })] }) }));
|
|
159
|
+
const table = (_jsx(TableWrap, { maxHeight: props.maxHeight, caption: caption, density: props.density, loading: loading, className: pageSize ? undefined : className, children: _jsxs("table", { className: "vk-table", children: [caption ? _jsx("caption", { className: props.captionHidden ? "vk-sr-only" : "vk-table-caption", children: caption }) : null, _jsx("thead", { children: _jsx(TableHead, { columns: columns, sort: sort, onSort: setSort, expandable: Boolean(renderExpanded), expandColumnLabel: props.expandColumnLabel, selectable: selectable, selectAllLabel: props.selectAllLabel, allKeys: allKeys, selCount: selCount, onSelectAll: () => { setSelected(selCount === allKeys.length ? [] : allKeys); } }) }), _jsx("tbody", { children: body })] }) }));
|
|
141
160
|
if (!pageSize)
|
|
142
161
|
return table;
|
|
143
162
|
return (_jsxs("div", { className: cx("vk-table-paged", className), children: [table, _jsx(TablePager, { page: page, pageCount: pageCount, onChange: setPage, pageSize: pageSize, total: total, summaryFormat: props.summaryFormat })] }));
|
|
@@ -1,29 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { useRef, useState } from "react";
|
|
4
3
|
import { Tabs as Primitive } from "radix-ui";
|
|
5
4
|
import { cx } from "../../lib/cx.js";
|
|
6
5
|
/** Tabs with automatic activation (Radix Tabs): arrow keys move focus and selection, wrapping; Home and End jump. */
|
|
7
6
|
export function Tabs({ tabs: tabsProp, value: valueProp, defaultValue, onChange, label, keepMounted, className }) {
|
|
8
|
-
const tabs = tabsProp
|
|
9
|
-
|
|
10
|
-
const [internal, setInternal] = useState(defaultValue !== undefined ? defaultValue : tabs.length ? tabs[0].id : undefined);
|
|
11
|
-
const value = controlled ? valueProp : internal;
|
|
12
|
-
// A mouse press reports the same tab twice in one event (focus, then press); pass it on once.
|
|
13
|
-
const reported = useRef(null);
|
|
14
|
-
const select = (id) => {
|
|
15
|
-
if (reported.current === id)
|
|
16
|
-
return;
|
|
17
|
-
reported.current = id;
|
|
18
|
-
queueMicrotask(() => { reported.current = null; });
|
|
19
|
-
if (!controlled)
|
|
20
|
-
setInternal(id);
|
|
21
|
-
onChange?.(id);
|
|
22
|
-
};
|
|
23
|
-
return (_jsxs(Primitive.Root, { className: cx("vk-tabs", className), value: value ?? "", onValueChange: select, activationMode: "automatic", children: [_jsx(Primitive.List, { "aria-label": label, className: "vk-tablist", loop: true, children: tabs.map((t) => (_jsxs(Primitive.Trigger, { value: t.id, disabled: t.disabled, className: "vk-tab", "data-tab": t.id, children: [t.label, t.count != null ? _jsx("span", { className: "vk-tab-count", children: t.count }) : null] }, t.id))) }), tabs.map((t) => {
|
|
24
|
-
const selected = t.id === value;
|
|
25
|
-
// Every panel stays in the DOM (hidden when not selected) so each tab's aria-controls resolves;
|
|
26
|
-
// only the selected panel renders its content unless keepMounted.
|
|
27
|
-
return (_jsx(Primitive.Content, { value: t.id, forceMount: true, hidden: !selected, className: "vk-tabpanel", children: selected || keepMounted ? t.content : null }, t.id));
|
|
28
|
-
})] }));
|
|
7
|
+
const tabs = tabsProp;
|
|
8
|
+
return (_jsxs(Primitive.Root, { className: cx("vk-tabs", className), value: valueProp, defaultValue: defaultValue, onValueChange: onChange, activationMode: "automatic", children: [_jsx(Primitive.List, { "aria-label": label, className: "vk-tablist", loop: true, children: tabs.map((t) => (_jsxs(Primitive.Trigger, { value: t.id, disabled: t.disabled, className: "vk-tab", "data-tab": t.id, children: [t.label, t.count != null ? _jsx("span", { className: "vk-tab-count", children: t.count }) : null] }, t.id))) }), tabs.map((t) => (_jsx(Primitive.Content, { value: t.id, forceMount: keepMounted ? true : undefined, className: "vk-tabpanel", children: t.content }, t.id)))] }));
|
|
29
9
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
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 { Icon } from "../Icon/Icon.js";
|
|
4
5
|
import { cx } from "../../lib/cx.js";
|
|
5
6
|
/** Chip for a chosen value or filter, optionally removable. */
|
|
6
7
|
export function Tag({ children, onRemove, removeLabel, className, removeTabIndex }) {
|
|
7
|
-
|
|
8
|
+
const { messages } = useLocale();
|
|
9
|
+
return (_jsxs("span", { className: cx("vk-tag", className), children: [_jsx("span", { className: "vk-tag-label", children: children }), onRemove ? (_jsx("button", { type: "button", className: "vk-tag-remove", tabIndex: removeTabIndex, "aria-label": removeLabel || messages.remove(typeof children === "string" ? children : ""), onMouseDown: (e) => { e.preventDefault(); }, onClick: onRemove, children: _jsx(Icon, { name: "x", size: 12 }) })) : null] }));
|
|
8
10
|
}
|
|
@@ -18,4 +18,4 @@ export type TextProps<T extends ElementTag = "p"> = PolymorphicProps<T, TextOwnP
|
|
|
18
18
|
/** Running text in one of the system's text styles and tones. */
|
|
19
19
|
export declare function Text<T extends ElementTag = "p">({ as, size, tone, numeric, overflowWrap, truncate, weight, children, className, ...rest }: TextProps<T>): import("react").ReactElement<{
|
|
20
20
|
className: string;
|
|
21
|
-
} & Omit<TextProps<T>, "
|
|
21
|
+
} & Omit<TextProps<T>, "numeric" | "size" | "tone" | "truncate" | "overflowWrap" | "className" | "children" | "weight" | "as">, string | import("react").JSXElementConstructor<any>>;
|
|
@@ -4,5 +4,5 @@ import { cx } from "../../lib/cx.js";
|
|
|
4
4
|
/** Grid of link tiles between sibling pages; the current one is marked active. */
|
|
5
5
|
export function TileGrid({ heading, headingId: id, label, items }) {
|
|
6
6
|
const headingId = id || "tiles-heading";
|
|
7
|
-
return (_jsxs("nav", { "aria-labelledby": heading ? headingId : undefined, "aria-label": heading ? undefined : label, children: [heading ? _jsx("h2", { id: headingId, className: "vk-tile-heading", children: heading }) : null, _jsx("ul", { className: "vk-tile-grid", children:
|
|
7
|
+
return (_jsxs("nav", { "aria-labelledby": heading ? headingId : undefined, "aria-label": heading ? undefined : label, children: [heading ? _jsx("h2", { id: headingId, className: "vk-tile-heading", children: heading }) : null, _jsx("ul", { className: "vk-tile-grid", children: items.map((item) => (_jsx("li", { children: _jsx(Anchor, { href: item.href, className: cx("vk-tile", item.active && "vk-tile-active"), "aria-current": item.active ? "page" : undefined, children: _jsx("span", { className: "vk-tile-label", children: item.label }) }) }, item.label))) })] }));
|
|
8
8
|
}
|
|
@@ -1,12 +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 { forwardRef, useCallback, useEffect, useRef, useState } from "react";
|
|
4
5
|
import { Popover as Primitive } from "radix-ui";
|
|
5
6
|
import { Icon } from "../Icon/Icon.js";
|
|
6
7
|
import { useUid } from "../../internal/useUid.js";
|
|
7
8
|
import { cx } from "../../lib/cx.js";
|
|
8
9
|
import { formatTime, pad2, parseTime } from "../../lib/dates.js";
|
|
9
|
-
import { resolveLocale } from "../../lib/format.js";
|
|
10
10
|
import { omit } from "../../lib/omit.js";
|
|
11
11
|
/** Every step from `from` to `to`. An unparseable min or max (null) matches no time. */
|
|
12
12
|
function timeOptions(stepMin, from, to, locale) {
|
|
@@ -33,16 +33,14 @@ function useTimeValue(props, locale, from, to) {
|
|
|
33
33
|
const controlled = valueProp !== undefined;
|
|
34
34
|
const [uncontrolled, setUncontrolled] = useState(props.defaultValue || null);
|
|
35
35
|
const value = controlled ? valueProp : uncontrolled;
|
|
36
|
-
const [
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}, [value, locale]);
|
|
36
|
+
const [draft, setDraft] = useState(null);
|
|
37
|
+
const current = draft && draft.value === value && draft.locale === locale ? draft : null;
|
|
38
|
+
const text = current ? current.text : formatTime(value, locale);
|
|
39
|
+
const invalid = Boolean(current?.invalid);
|
|
41
40
|
const commit = (v) => {
|
|
42
41
|
if (!controlled)
|
|
43
42
|
setUncontrolled(v);
|
|
44
|
-
|
|
45
|
-
setInvalid(false);
|
|
43
|
+
setDraft(null);
|
|
46
44
|
props.onChange?.(v);
|
|
47
45
|
};
|
|
48
46
|
const commitText = () => {
|
|
@@ -54,12 +52,9 @@ function useTimeValue(props, locale, from, to) {
|
|
|
54
52
|
if (v && allowed(v, props, from, to))
|
|
55
53
|
commit(v);
|
|
56
54
|
else
|
|
57
|
-
|
|
58
|
-
};
|
|
59
|
-
const type = (next) => {
|
|
60
|
-
setText(next);
|
|
61
|
-
setInvalid(false);
|
|
55
|
+
setDraft({ text, invalid: true, value, locale });
|
|
62
56
|
};
|
|
57
|
+
const type = (next) => { setDraft({ text: next, invalid: false, value, locale }); };
|
|
63
58
|
return { value, text, invalid, type, commit, commitText };
|
|
64
59
|
}
|
|
65
60
|
/** The field's aria-invalid, and aria-describedby pointing at the error while the typed time is invalid. */
|
|
@@ -70,17 +65,21 @@ function invalidAria(invalid, props, errId) {
|
|
|
70
65
|
};
|
|
71
66
|
}
|
|
72
67
|
function InvalidTime({ id, message, locale }) {
|
|
73
|
-
|
|
68
|
+
const { messages } = useLocale(locale);
|
|
69
|
+
return _jsx("span", { id: id, className: "vk-field-error vk-inline-error", children: message || messages.invalidTime(formatTime("14:30", locale)) });
|
|
74
70
|
}
|
|
75
71
|
/** The portalled list of times. */
|
|
76
|
-
function TimeList({ listId, label, times, value, open, active, setActive, onPick, rootRef,
|
|
72
|
+
function TimeList({ listId, label, times, value, open, active, setActive, onPick, rootRef, escapedRef }) {
|
|
77
73
|
// The list mounts a render after `open` turns true (it is portalled): keep it in state so scrolling waits for it.
|
|
78
|
-
const
|
|
74
|
+
const listRef = useRef(null);
|
|
75
|
+
const [shown, setShown] = useState(false);
|
|
76
|
+
const setList = useCallback((node) => { listRef.current = node; setShown(node !== null); }, []);
|
|
79
77
|
// Keep the active option in view, scrolling only the list.
|
|
80
78
|
useEffect(() => {
|
|
81
|
-
|
|
79
|
+
const list = listRef.current;
|
|
80
|
+
if (!open || !shown || !list || active < 0)
|
|
82
81
|
return;
|
|
83
|
-
const el = list.querySelector(`[data-index="${active}"]`);
|
|
82
|
+
const el = list.querySelector(`[data-index="${String(active)}"]`);
|
|
84
83
|
if (!el)
|
|
85
84
|
return;
|
|
86
85
|
const top = el.offsetTop, bottom = top + el.offsetHeight;
|
|
@@ -88,21 +87,21 @@ function TimeList({ listId, label, times, value, open, active, setActive, onPick
|
|
|
88
87
|
list.scrollTop = top;
|
|
89
88
|
else if (bottom > list.scrollTop + list.clientHeight)
|
|
90
89
|
list.scrollTop = bottom - list.clientHeight;
|
|
91
|
-
}, [open,
|
|
90
|
+
}, [open, shown, active]);
|
|
92
91
|
return (_jsx(Primitive.Portal, { children: _jsx(Primitive.Content, { asChild: true, side: "bottom", align: "start", sideOffset: 4, collisionPadding: 8,
|
|
93
92
|
// Focus stays in the input while the list is open, and wherever people moved it after.
|
|
94
|
-
onOpenAutoFocus: (e) => e.preventDefault(), onCloseAutoFocus: (e) => e.preventDefault(), onEscapeKeyDown: () => {
|
|
95
|
-
|
|
93
|
+
onOpenAutoFocus: (e) => { e.preventDefault(); }, onCloseAutoFocus: (e) => { e.preventDefault(); }, onEscapeKeyDown: () => {
|
|
94
|
+
escapedRef.current = true;
|
|
96
95
|
}, onInteractOutside: (e) => {
|
|
97
96
|
// Pressing the field keeps the list open.
|
|
98
|
-
if (rootRef.current && rootRef.current.contains(e.target))
|
|
97
|
+
if (e.target instanceof Node && rootRef.current && rootRef.current.contains(e.target))
|
|
99
98
|
e.preventDefault();
|
|
100
99
|
}, children: _jsx("ul", { ref: setList, id: listId, role: "listbox", "aria-label": label, className: "vk-select-menu vk-time-menu",
|
|
101
100
|
// Keep focus (and the typed text) in the input when pressing the list.
|
|
102
|
-
onMouseDown: (e) => e.preventDefault(), children: times.map((t, i) => (_jsxs("li", { id: listId + "-" + i, "data-index": i, role: "option", "aria-selected": t.value === value ? "true" : "false", className: cx("vk-select-option", i === active && "vk-select-option-active"), onMouseMove: () => {
|
|
101
|
+
onMouseDown: (e) => { e.preventDefault(); }, children: times.map((t, i) => (_jsxs("li", { id: listId + "-" + String(i), "data-index": i, role: "option", "aria-selected": t.value === value ? "true" : "false", className: cx("vk-select-option", i === active && "vk-select-option-active"), onMouseMove: () => {
|
|
103
102
|
if (i !== active)
|
|
104
103
|
setActive(i);
|
|
105
|
-
}, onClick: () => onPick(t.value), children: [_jsx("span", { className: "vk-time-option", children: t.label }), t.value === value ? _jsx(Icon, { name: "check", size: 16, className: "vk-select-check" }) : null] }, t.value))) }) }) }));
|
|
104
|
+
}, onClick: () => { onPick(t.value); }, children: [_jsx("span", { className: "vk-time-option", children: t.label }), t.value === value ? _jsx(Icon, { name: "check", size: 16, className: "vk-select-check" }) : null] }, t.value))) }) }) }));
|
|
106
105
|
}
|
|
107
106
|
/**
|
|
108
107
|
* A time field: type a time or pick one from a list in steps. The list is a
|
|
@@ -110,7 +109,7 @@ function TimeList({ listId, label, times, value, open, active, setActive, onPick
|
|
|
110
109
|
* (aria-activedescendant). The ref goes to the input.
|
|
111
110
|
*/
|
|
112
111
|
export const TimePicker = forwardRef(function TimePicker(props, ref) {
|
|
113
|
-
const locale =
|
|
112
|
+
const { locale, messages } = useLocale(props.locale);
|
|
114
113
|
const from = parseTime(props.min || "00:00"), to = parseTime(props.max || "23:59");
|
|
115
114
|
const times = timeOptions(props.step || 30, from, to, locale);
|
|
116
115
|
const { value, text, invalid, type, commit, commitText } = useTimeValue(props, locale, from, to);
|
|
@@ -125,7 +124,7 @@ export const TimePicker = forwardRef(function TimePicker(props, ref) {
|
|
|
125
124
|
const listId = uid + "-list";
|
|
126
125
|
const rootRef = useRef(null);
|
|
127
126
|
// Set when Radix closes the list on Escape, which happens before the input sees the key.
|
|
128
|
-
const
|
|
127
|
+
const escapedRef = useRef(false);
|
|
129
128
|
const setInputRef = useCallback((el) => {
|
|
130
129
|
if (typeof ref === "function")
|
|
131
130
|
ref(el);
|
|
@@ -139,7 +138,7 @@ export const TimePicker = forwardRef(function TimePicker(props, ref) {
|
|
|
139
138
|
return i < 0 ? times.length - 1 : i;
|
|
140
139
|
};
|
|
141
140
|
const openList = () => {
|
|
142
|
-
|
|
141
|
+
escapedRef.current = false;
|
|
143
142
|
setOpen(true);
|
|
144
143
|
setActive(nearest());
|
|
145
144
|
};
|
|
@@ -164,23 +163,26 @@ export const TimePicker = forwardRef(function TimePicker(props, ref) {
|
|
|
164
163
|
}
|
|
165
164
|
else if (e.key === "Enter") {
|
|
166
165
|
e.preventDefault();
|
|
167
|
-
if (open && active >= 0)
|
|
168
|
-
|
|
166
|
+
if (open && active >= 0) {
|
|
167
|
+
const option = times[active];
|
|
168
|
+
if (option)
|
|
169
|
+
pick(option.value);
|
|
170
|
+
}
|
|
169
171
|
else
|
|
170
172
|
commitText();
|
|
171
173
|
}
|
|
172
174
|
else if (e.key === "Escape") {
|
|
173
|
-
if (open ||
|
|
175
|
+
if (open || escapedRef.current) {
|
|
174
176
|
// Closes the list only, not an enclosing dialog.
|
|
175
177
|
e.preventDefault();
|
|
176
178
|
e.stopPropagation();
|
|
177
179
|
setOpen(false);
|
|
178
180
|
}
|
|
179
|
-
|
|
181
|
+
escapedRef.current = false;
|
|
180
182
|
}
|
|
181
183
|
};
|
|
182
184
|
const a11y = omit(props, ["value", "defaultValue", "onChange", "step", "min", "max", "locale", "id", "name", "placeholder", "defaultOpen", "className", "disabled", "invalidMessage"]);
|
|
183
|
-
return (_jsx(Primitive.Root, { open: open, onOpenChange: setOpen, children: _jsxs("div", { ref: rootRef, className: cx("vk-select", "vk-timepicker", props.className), "data-state": open ? "open" : "closed", children: [_jsx(Primitive.Anchor, { asChild: true, children: _jsxs("div", { className: "vk-combobox-field", children: [_jsx("input", { ref: setInputRef, id: props.id || uid, type: "text", role: "combobox", autoComplete: "off", className: "vk-input vk-combobox-input", placeholder: props.placeholder || formatTime("09:30", locale), disabled: props.disabled, value: text, "aria-autocomplete": "none", "aria-expanded": open ? "true" : "false", "aria-controls": listId, "aria-activedescendant": open && active >= 0 ? listId + "-" + active : undefined, onChange: (e) => type(e.target.value), onClick: () => {
|
|
185
|
+
return (_jsx(Primitive.Root, { open: open, onOpenChange: setOpen, children: _jsxs("div", { ref: rootRef, className: cx("vk-select", "vk-timepicker", props.className), "data-state": open ? "open" : "closed", children: [_jsx(Primitive.Anchor, { asChild: true, children: _jsxs("div", { className: "vk-combobox-field", children: [_jsx("input", { ref: setInputRef, id: props.id || uid, type: "text", role: "combobox", autoComplete: "off", className: "vk-input vk-combobox-input", placeholder: props.placeholder || formatTime("09:30", locale), disabled: props.disabled, value: text, "aria-autocomplete": "none", "aria-expanded": open ? "true" : "false", "aria-controls": listId, "aria-activedescendant": open && active >= 0 ? listId + "-" + String(active) : undefined, onChange: (e) => { type(e.target.value); }, onClick: () => {
|
|
184
186
|
if (!open)
|
|
185
187
|
openList();
|
|
186
188
|
}, onKeyDown: onKeyDown, onBlur: (e) => {
|
|
@@ -188,5 +190,5 @@ export const TimePicker = forwardRef(function TimePicker(props, ref) {
|
|
|
188
190
|
setOpen(false);
|
|
189
191
|
commitText();
|
|
190
192
|
}
|
|
191
|
-
}, ...a11y, ...invalidAria(invalid, props, uid + "-err") }), _jsx(Icon, { name: "clock", size: 16, className: "vk-select-icon" })] }) }), _jsx(TimeList, { listId: listId, label: props["aria-label"] ||
|
|
193
|
+
}, ...a11y, ...invalidAria(invalid, props, uid + "-err") }), _jsx(Icon, { name: "clock", size: 16, className: "vk-select-icon" })] }) }), _jsx(TimeList, { listId: listId, label: props["aria-label"] || messages.times, times: times, value: value, open: open, active: active, setActive: setActive, onPick: pick, rootRef: rootRef, escapedRef: escapedRef }), invalid ? _jsx(InvalidTime, { id: uid + "-err", message: props.invalidMessage, locale: locale }) : null, props.name ? _jsx("input", { type: "hidden", name: props.name, value: value || "" }) : null] }) }));
|
|
192
194
|
});
|
|
@@ -1,10 +1,11 @@
|
|
|
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 { Icon } from "../Icon/Icon.js";
|
|
3
|
-
import {
|
|
5
|
+
import { statusWord } from "../../internal/status.js";
|
|
4
6
|
import { cx } from "../../lib/cx.js";
|
|
5
|
-
/** A status without a word of its own ("primary") is announced as itself. */
|
|
6
|
-
const STATUS_TEXT = STATUS_WORD;
|
|
7
7
|
/** A vertical sequence of events: an invoice's history, an audit log, a delivery's progress. */
|
|
8
8
|
export function Timeline({ items, label, className }) {
|
|
9
|
-
|
|
9
|
+
const { messages } = useLocale();
|
|
10
|
+
return (_jsx("ol", { className: cx("vk-timeline", className), "aria-label": label, children: items.map((it, i) => (_jsxs("li", { className: cx("vk-timeline-item", it.status && "vk-timeline-" + it.status), children: [_jsx("span", { className: "vk-timeline-marker", "aria-hidden": "true", children: it.icon ? _jsx(Icon, { name: it.icon, size: 14 }) : null }), _jsxs("div", { className: "vk-timeline-body", children: [_jsxs("p", { className: "vk-timeline-title", children: [it.title, it.status ? _jsx("span", { className: "vk-sr-only", children: " (" + statusWord(it.status, messages) + ")" }) : null] }), it.description ? _jsx("div", { className: "vk-timeline-description", children: it.description }) : null, it.time ? _jsx("time", { className: "vk-timeline-time", dateTime: it.dateTime, children: it.time }) : null] })] }, (it.dateTime || (typeof it.title === "string" ? it.title : "")) + "#" + String(i)))) }));
|
|
10
11
|
}
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useLocale } from "../../localization.js";
|
|
4
|
+
import { useSyncExternalStore } from "react";
|
|
4
5
|
import { Portal, Toast as Primitive } from "radix-ui";
|
|
5
6
|
import { Button } from "../Button/Button.js";
|
|
6
7
|
import { Icon } from "../Icon/Icon.js";
|
|
7
8
|
import { IconButton } from "../IconButton/IconButton.js";
|
|
8
|
-
import { STATUS_ICON,
|
|
9
|
+
import { STATUS_ICON, statusWord } from "../../internal/status.js";
|
|
9
10
|
import { cx } from "../../lib/cx.js";
|
|
10
11
|
/** Module-level, so toast() works from anywhere; each mounted Toaster subscribes. */
|
|
11
12
|
export const toastStore = { items: [], listeners: [], seq: 0 };
|
|
12
13
|
export function emitToasts() {
|
|
13
|
-
toastStore.listeners.forEach((l) => l(toastStore.items.slice()));
|
|
14
|
+
toastStore.listeners.forEach((l) => { l(toastStore.items.slice()); });
|
|
14
15
|
}
|
|
15
16
|
function showToast(opts) {
|
|
16
17
|
const o = typeof opts === "string" ? { title: opts } : opts;
|
|
17
18
|
const key = ++toastStore.seq;
|
|
18
|
-
const id = o.id || "t" + key;
|
|
19
|
+
const id = o.id || "t" + String(key);
|
|
19
20
|
const item = { status: "info", duration: o.status === "danger" ? 0 : 5000, ...o, id, key };
|
|
20
21
|
// A toast with the same id replaces the old one and moves to the end (and is announced again).
|
|
21
22
|
toastStore.items = toastStore.items.filter((t) => t.id !== id).concat([item]);
|
|
@@ -36,28 +37,31 @@ export const toast = Object.assign(showToast, {
|
|
|
36
37
|
});
|
|
37
38
|
/** One toast (Radix Toast.Root). Radix runs its timer, pausing it while the pointer or focus is in the stack. */
|
|
38
39
|
export function ToastItem({ toast: t }) {
|
|
40
|
+
const { messages } = useLocale();
|
|
39
41
|
const action = t.action;
|
|
40
42
|
return (_jsxs(Primitive.Root, { className: cx("vk-toast", "vk-toast-" + t.status),
|
|
41
43
|
// Danger interrupts (assertive), the rest wait their turn (polite).
|
|
42
44
|
type: t.status === "danger" ? "foreground" : "background",
|
|
43
|
-
//
|
|
45
|
+
// The public data adapter maps persistence to Radix's native Infinity duration.
|
|
44
46
|
duration: t.duration > 0 ? t.duration : Infinity, open: true, onOpenChange: (open) => { if (!open)
|
|
45
47
|
toast.dismiss(t.id); }, "aria-atomic": "true",
|
|
46
48
|
// Follow the pointer while swiping; Radix sets the variable and clears it on cancel.
|
|
47
|
-
style: { translate: "var(--radix-toast-swipe-move-x, 0) 0" }, children: [_jsx(Icon, { name: STATUS_ICON[t.status], size: 18, className: "vk-alert-icon" }), _jsxs("div", { className: "vk-alert-body", children: [_jsx("span", { className: "vk-sr-only", children:
|
|
49
|
+
style: { translate: "var(--radix-toast-swipe-move-x, 0) 0" }, children: [_jsx(Icon, { name: STATUS_ICON[t.status], size: 18, className: "vk-alert-icon" }), _jsxs("div", { className: "vk-alert-body", children: [_jsx("span", { className: "vk-sr-only", children: statusWord(t.status, messages) + ": " }), _jsx(Primitive.Title, { asChild: true, children: _jsx("p", { className: "vk-alert-title", children: t.title }) }), t.description ? _jsxs(_Fragment, { children: [" ", _jsx(Primitive.Description, { className: "vk-alert-text", children: t.description })] }) : null, action
|
|
48
50
|
? (_jsxs(_Fragment, { children: [" ", _jsx("div", { className: "vk-alert-action", children: _jsx(Primitive.Action, { altText: action.label, asChild: true, children: _jsx(Button, { variant: "outline", size: "sm", onClick: () => action.onClick?.(), children: action.label }) }) })] }))
|
|
49
|
-
: null] }), _jsx(Primitive.Close, { asChild: true, children: _jsx(IconButton, { icon: "x", size: 16, label:
|
|
51
|
+
: null] }), _jsx(Primitive.Close, { asChild: true, children: _jsx(IconButton, { icon: "x", size: 16, label: messages.dismissNotification, className: "vk-alert-close" }) })] }));
|
|
52
|
+
}
|
|
53
|
+
const emptyServerToasts = [];
|
|
54
|
+
const readToasts = () => toastStore.items;
|
|
55
|
+
const readServerToasts = () => emptyServerToasts;
|
|
56
|
+
function subscribeToasts(onChange) {
|
|
57
|
+
const listener = () => { onChange(); };
|
|
58
|
+
toastStore.listeners.push(listener);
|
|
59
|
+
return () => { toastStore.listeners = toastStore.listeners.filter((item) => item !== listener); };
|
|
50
60
|
}
|
|
51
61
|
/** Toast stack; render once per app. Radix Toast: F8 focuses the stack, a swipe right dismisses a toast. */
|
|
52
62
|
export function Toaster({ max, position, label }) {
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
const l = (items) => setToasts(items);
|
|
56
|
-
toastStore.listeners.push(l);
|
|
57
|
-
// Pick up anything shown between the first render and subscribing.
|
|
58
|
-
setToasts(toastStore.items.slice());
|
|
59
|
-
return () => { toastStore.listeners = toastStore.listeners.filter((x) => x !== l); };
|
|
60
|
-
}, []);
|
|
63
|
+
const { messages } = useLocale();
|
|
64
|
+
const toasts = useSyncExternalStore(subscribeToasts, readToasts, readServerToasts);
|
|
61
65
|
const items = toasts.slice(-(max || 3));
|
|
62
|
-
return (_jsxs(Primitive.Provider, { swipeDirection: "right", children: [items.map((t) => _jsx(ToastItem, { toast: t }, t.key)), _jsx(Portal.Root, { asChild: true, children: _jsx("div", { className: cx("vk-toaster", position === "top" ? "vk-toaster-top" : null), children: _jsx(Primitive.Viewport, { className: "vk-toast-list", label: label ||
|
|
66
|
+
return (_jsxs(Primitive.Provider, { swipeDirection: "right", label: messages.notificationAnnouncement, children: [items.map((t) => _jsx(ToastItem, { toast: t }, t.key)), _jsx(Portal.Root, { asChild: true, children: _jsx("div", { className: cx("vk-toaster", position === "top" ? "vk-toaster-top" : null), children: _jsx(Primitive.Viewport, { className: "vk-toast-list", label: label || messages.notifications }) }) })] }));
|
|
63
67
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import type { ReactElement, ReactNode } from "react";
|
|
2
|
+
import { Tooltip as Primitive } from "radix-ui";
|
|
3
|
+
export interface TooltipProps extends Pick<Primitive.TooltipProps, 'open' | 'defaultOpen' | 'onOpenChange'> {
|
|
3
4
|
content: ReactNode;
|
|
4
5
|
children: ReactElement;
|
|
5
6
|
placement?: 'top' | 'bottom';
|
|
6
7
|
align?: 'center' | 'start';
|
|
7
|
-
delay?: number;
|
|
8
|
-
touchDuration?: number;
|
|
8
|
+
delay?: number;
|
|
9
9
|
}
|
|
10
|
-
/** Text label
|
|
11
|
-
export declare function Tooltip({ content, children, placement, align, delay,
|
|
10
|
+
/** Text label with Radix Tooltip's native hover, focus and dismissal behavior. */
|
|
11
|
+
export declare function Tooltip({ content, children, placement, align, delay, open, defaultOpen, onOpenChange }: TooltipProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,21 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { useEffect, useRef, useState } from "react";
|
|
4
3
|
import { Tooltip as Primitive } from "radix-ui";
|
|
5
|
-
/** Text label
|
|
6
|
-
export function Tooltip({ content, children, placement, align, delay,
|
|
7
|
-
|
|
8
|
-
const touchTimer = useRef();
|
|
9
|
-
useEffect(() => () => clearTimeout(touchTimer.current), []);
|
|
10
|
-
const onPointerUp = (e) => {
|
|
11
|
-
if (e.pointerType !== "touch")
|
|
12
|
-
return;
|
|
13
|
-
clearTimeout(touchTimer.current);
|
|
14
|
-
// After the click that follows the tap, which closes a Radix tooltip.
|
|
15
|
-
touchTimer.current = setTimeout(() => {
|
|
16
|
-
setOpen(true);
|
|
17
|
-
touchTimer.current = setTimeout(() => setOpen(false), touchDuration || 1500);
|
|
18
|
-
}, 0);
|
|
19
|
-
};
|
|
20
|
-
return (_jsx(Primitive.Provider, { delayDuration: delay ?? 400, children: _jsxs(Primitive.Root, { open: open, onOpenChange: setOpen, children: [_jsx(Primitive.Trigger, { asChild: true, onPointerUp: onPointerUp, children: children }), _jsx(Primitive.Portal, { children: _jsx(Primitive.Content, { className: "vk-tooltip", side: placement || "top", align: align === "start" ? "start" : "center", sideOffset: 6, collisionPadding: 8, children: content }) })] }) }));
|
|
4
|
+
/** Text label with Radix Tooltip's native hover, focus and dismissal behavior. */
|
|
5
|
+
export function Tooltip({ content, children, placement, align, delay, open, defaultOpen, onOpenChange }) {
|
|
6
|
+
return (_jsx(Primitive.Provider, { delayDuration: delay ?? 400, children: _jsxs(Primitive.Root, { open: open, defaultOpen: defaultOpen, onOpenChange: onOpenChange, children: [_jsx(Primitive.Trigger, { asChild: true, children: children }), _jsx(Primitive.Portal, { children: _jsx(Primitive.Content, { className: "vk-tooltip", side: placement || "top", align: align === "start" ? "start" : "center", sideOffset: 6, collisionPadding: 8, children: content }) })] }) }));
|
|
21
7
|
}
|