@xenosystem/elements-react 0.0.10 → 0.0.12
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/dist/containers/Avatar.d.ts +8 -1
- package/dist/containers/Avatar.js +3 -3
- package/dist/containers/BulkActionBar.d.ts +20 -0
- package/dist/containers/BulkActionBar.js +8 -0
- package/dist/containers/DataTable.d.ts +50 -6
- package/dist/containers/DataTable.js +185 -11
- package/dist/containers/Table.d.ts +2 -2
- package/dist/containers/Table.js +4 -3
- package/dist/content/Kbd.d.ts +16 -0
- package/dist/content/Kbd.js +8 -0
- package/dist/forms/FormField.d.ts +32 -0
- package/dist/forms/FormField.js +26 -0
- package/dist/forms/NumberInput.d.ts +27 -0
- package/dist/forms/NumberInput.js +69 -0
- package/dist/forms/Select.d.ts +84 -0
- package/dist/forms/Select.js +243 -0
- package/dist/forms/Slider.d.ts +38 -0
- package/dist/forms/Slider.js +31 -0
- package/dist/index.d.ts +20 -1
- package/dist/index.js +20 -1
- package/dist/nav/Breadcrumb.d.ts +22 -0
- package/dist/nav/Breadcrumb.js +10 -0
- package/dist/nav/Pagination.d.ts +22 -0
- package/dist/nav/Pagination.js +35 -0
- package/dist/overlays/CommandPalette.d.ts +43 -0
- package/dist/overlays/CommandPalette.js +96 -0
- package/dist/overlays/Drawer.d.ts +30 -0
- package/dist/overlays/Drawer.js +41 -0
- package/dist/overlays/Popover.d.ts +27 -12
- package/dist/overlays/Popover.js +104 -7
- package/dist/overlays/ShortcutsSheet.d.ts +21 -0
- package/dist/overlays/ShortcutsSheet.js +7 -0
- package/dist/overlays/Tooltip.d.ts +21 -10
- package/dist/overlays/Tooltip.js +93 -9
- package/dist/shortcuts.d.ts +45 -0
- package/dist/shortcuts.js +164 -0
- package/dist/status/Banner.d.ts +23 -0
- package/dist/status/Banner.js +8 -0
- package/dist/status/EmptyState.d.ts +20 -0
- package/dist/status/EmptyState.js +9 -0
- package/dist/status/Skeleton.d.ts +36 -0
- package/dist/status/Skeleton.js +31 -0
- package/dist/status/Toast.d.ts +28 -0
- package/dist/status/Toast.js +11 -0
- package/dist/uiTree.d.ts +53 -0
- package/dist/uiTree.js +197 -0
- package/dist/useDialog.d.ts +3 -1
- package/dist/useDialog.js +37 -1
- package/dist/useMenu.js +31 -1
- package/dist/useToastQueue.d.ts +29 -0
- package/dist/useToastQueue.js +73 -0
- package/package.json +9 -3
- package/src/chrome-separated.css +133 -72
- package/src/chrome-unified.css +48 -16
- package/src/containers/Badges.css +52 -28
- package/src/containers/avatar.css +7 -2
- package/src/containers/bulk-action-bar.css +45 -0
- package/src/containers/card.css +14 -13
- package/src/containers/chip.css +1 -1
- package/src/containers/panel.css +16 -53
- package/src/containers/table.css +107 -1
- package/src/content/kbd.css +33 -0
- package/src/content/model-picker.css +2 -1
- package/src/controls.css +25 -11
- package/src/fonts.css +8 -2
- package/src/forced-colors.css +41 -0
- package/src/forms/form-field.css +78 -0
- package/src/forms/number-input.css +86 -0
- package/src/forms/select.css +210 -0
- package/src/forms/slider.css +145 -0
- package/src/layout-platform.css +495 -0
- package/src/mcp-app-platform.css +1019 -0
- package/src/nav/breadcrumb.css +84 -0
- package/src/nav/pagination.css +61 -0
- package/src/overlays/command-palette.css +157 -0
- package/src/overlays/drawer.css +79 -0
- package/src/overlays/menu.css +25 -16
- package/src/overlays/modal.css +9 -27
- package/src/overlays/onboarding.css +1305 -0
- package/src/overlays/segmented-control.css +6 -3
- package/src/overlays/shortcuts-sheet.css +55 -0
- package/src/overlays/tooltip.css +22 -4
- package/src/size.css +40 -0
- package/src/status/banner.css +83 -0
- package/src/status/empty-state.css +56 -0
- package/src/status/skeleton.css +70 -0
- package/src/status/toast.css +95 -0
- package/src/xeno-elements.css +71 -44
- package/src/xeno-theme.css +75 -31
|
@@ -18,8 +18,15 @@ export interface AvatarProps extends Omit<HTMLAttributes<HTMLSpanElement>, 'chil
|
|
|
18
18
|
readonly icon?: ElementDeclaration;
|
|
19
19
|
/** Accessible label / image alt. Falls back to `name`, then a generic label. */
|
|
20
20
|
readonly alt?: string;
|
|
21
|
+
/**
|
|
22
|
+
* How many letters the initials fallback draws: 2 (default) or 1. An {@link AvatarStack} draws 1,
|
|
23
|
+
* because overlapping tiles hide the left of every tile but the first, and a two-letter monogram
|
|
24
|
+
* then reads as half a letter ("MK" showed as "|U"). The owner's design references draw one letter
|
|
25
|
+
* in every stack. The accessible label is the full name either way.
|
|
26
|
+
*/
|
|
27
|
+
readonly initials?: 1 | 2;
|
|
21
28
|
}
|
|
22
|
-
export declare function Avatar({ size, src, name, icon, alt, className, style, ...rest }: AvatarProps): ReactElement;
|
|
29
|
+
export declare function Avatar({ size, src, name, icon, alt, initials, className, style, ...rest }: AvatarProps): ReactElement;
|
|
23
30
|
/** One entry in an {@link AvatarStack} — the same content priority as {@link Avatar}. */
|
|
24
31
|
export interface AvatarStackItem {
|
|
25
32
|
readonly src?: string;
|
|
@@ -14,16 +14,16 @@ const initialsOf = (name) => {
|
|
|
14
14
|
const last = parts[parts.length - 1] ?? '';
|
|
15
15
|
return (first.charAt(0) + last.charAt(0)).toUpperCase();
|
|
16
16
|
};
|
|
17
|
-
export function Avatar({ size = 24, src, name, icon, alt, className, style, ...rest }) {
|
|
17
|
+
export function Avatar({ size = 24, src, name, icon, alt, initials = 2, className, style, ...rest }) {
|
|
18
18
|
const variant = src !== undefined ? 'image' : icon !== undefined ? 'icon' : name !== undefined ? 'initials' : 'empty';
|
|
19
19
|
const label = alt ?? name ?? 'Avatar';
|
|
20
20
|
const rootStyle = { ['--xeno-avatar-size']: `${size}px`, ...style };
|
|
21
|
-
const content = src !== undefined ? (_jsx("img", { className: "xeno-avatar-img", src: src, alt: "", draggable: false })) : icon !== undefined ? (_jsx(XenoElement, { decl: icon, size: Math.round(size * 0.58) })) : name !== undefined ? (_jsx("span", { className: "xeno-avatar-initials", "aria-hidden": "true", children: initialsOf(name) })) : null;
|
|
21
|
+
const content = src !== undefined ? (_jsx("img", { className: "xeno-avatar-img", src: src, alt: "", draggable: false })) : icon !== undefined ? (_jsx(XenoElement, { decl: icon, size: Math.round(size * 0.58) })) : name !== undefined ? (_jsx("span", { className: "xeno-avatar-initials", "aria-hidden": "true", children: initials === 1 ? initialsOf(name).charAt(0) : initialsOf(name) })) : null;
|
|
22
22
|
return (_jsx("span", { className: cx('xeno-avatar', className), "data-variant": variant, role: "img", "aria-label": label, style: rootStyle, ...rest, children: content }));
|
|
23
23
|
}
|
|
24
24
|
export function AvatarStack({ items, max = 4, size = 24, className, style, ...rest }) {
|
|
25
25
|
const visible = items.slice(0, max);
|
|
26
26
|
const overflow = items.length - visible.length;
|
|
27
27
|
const rootStyle = { ['--xeno-avatar-size']: `${size}px`, ...style };
|
|
28
|
-
return (_jsxs("div", { className: cx('xeno-avatar-stack', className), role: "group", style: rootStyle, ...rest, children: [visible.map((item, i) => (_jsx(Avatar, { size: size, style: { zIndex: visible.length - i }, ...(item.src !== undefined ? { src: item.src } : {}), ...(item.name !== undefined ? { name: item.name } : {}), ...(item.icon !== undefined ? { icon: item.icon } : {}) }, i))), overflow > 0 ? (_jsx("span", { className: "xeno-avatar xeno-avatar-more", "data-variant": "more", role: "img", "aria-label": `${overflow} more`, style: { ['--xeno-avatar-size']: `${size}px`, zIndex: 0 }, children: _jsxs("span", { className: "xeno-avatar-initials", "aria-hidden": "true", children: ["+", overflow] }) })) : null] }));
|
|
28
|
+
return (_jsxs("div", { className: cx('xeno-avatar-stack', className), role: "group", style: rootStyle, ...rest, children: [visible.map((item, i) => (_jsx(Avatar, { size: size, initials: 1, style: { zIndex: visible.length - i }, ...(item.src !== undefined ? { src: item.src } : {}), ...(item.name !== undefined ? { name: item.name } : {}), ...(item.icon !== undefined ? { icon: item.icon } : {}) }, i))), overflow > 0 ? (_jsx("span", { className: "xeno-avatar xeno-avatar-more", "data-variant": "more", role: "img", "aria-label": `${overflow} more`, style: { ['--xeno-avatar-size']: `${size}px`, zIndex: 0 }, children: _jsxs("span", { className: "xeno-avatar-initials", "aria-hidden": "true", children: ["+", overflow] }) })) : null] }));
|
|
29
29
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { HTMLAttributes, ReactElement, ReactNode } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* `<BulkActionBar>` — contextual selection strip shown above tables/lists when one or more rows
|
|
4
|
+
* are selected (Corpus Tenets bulk bar in `--xeno-info-soft`, Desktop Files bulk bar).
|
|
5
|
+
*/
|
|
6
|
+
export interface BulkActionBarProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {
|
|
7
|
+
/** Number of selected items. Renders nothing when `<= 0` unless `alwaysShow` is true. */
|
|
8
|
+
readonly count: number;
|
|
9
|
+
/** Singular/plural noun, or custom summary node. Default `'selected'`. */
|
|
10
|
+
readonly label?: ReactNode;
|
|
11
|
+
/** Primary/secondary action buttons for the selection. */
|
|
12
|
+
readonly children?: ReactNode;
|
|
13
|
+
/** Called when the clear button is pressed. */
|
|
14
|
+
readonly onClear?: () => void;
|
|
15
|
+
/** Clear button label. Default `'Clear selection'`. */
|
|
16
|
+
readonly clearLabel?: string;
|
|
17
|
+
/** Keep mounted even when `count === 0`. */
|
|
18
|
+
readonly alwaysShow?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export declare function BulkActionBar({ count, label, children, onClear, clearLabel, alwaysShow, className, ...rest }: BulkActionBarProps): ReactElement | null;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Button } from '../controls/Button.js';
|
|
3
|
+
import { cx } from '../controls/util.js';
|
|
4
|
+
export function BulkActionBar({ count, label = 'selected', children, onClear, clearLabel = 'Clear selection', alwaysShow = false, className, ...rest }) {
|
|
5
|
+
if (count <= 0 && !alwaysShow)
|
|
6
|
+
return null;
|
|
7
|
+
return (_jsxs("div", { className: cx('xeno-bulk-bar', className), role: "region", "aria-label": "Bulk selection actions", "aria-live": "polite", ...rest, children: [_jsxs("span", { className: "xeno-bulk-bar-count", children: [_jsx("span", { className: "xeno-bulk-bar-num", children: count }), " ", label] }), _jsx("div", { className: "xeno-bulk-bar-actions", children: children }), onClear ? (_jsx(Button, { size: "xs", variant: "ghost", className: "xeno-bulk-bar-clear", onClick: onClear, children: clearLabel })) : null] }));
|
|
8
|
+
}
|
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
import type { ReactElement, ReactNode, TableHTMLAttributes } from 'react';
|
|
2
2
|
import { type ColumnAlign } from './Table.js';
|
|
3
3
|
/**
|
|
4
|
-
* `<DataTable>` —
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* `<DataTable>` — production data table over {@link Table} primitives.
|
|
5
|
+
*
|
|
6
|
+
* Supports:
|
|
7
|
+
* - **Column sorting** (`col.sortable`, controlled `sort`/`onSortChange` or uncontrolled, `aria-sort`).
|
|
8
|
+
* - **Multi-row selection** (`selectable`, `selectedKeys`, `onSelectionChange`, header select-all / mixed).
|
|
9
|
+
* - **Sticky headers** (`stickyHeader`).
|
|
10
|
+
* - **Single delegated keyboard handler** on `<TBody>` (`ArrowDown`/`ArrowUp`/`Home`/`End`/`Enter`/`Space`),
|
|
11
|
+
* avoiding per-row listener closures at scale (GitHub Engineering 2026).
|
|
12
|
+
* - **Selective virtualization** (`virtualizeAbove`, default 2,500 rows): preserves native browser
|
|
13
|
+
* `Ctrl+F` on everyday tables while capping DOM nodes on 10,000+ row tables.
|
|
9
14
|
*/
|
|
15
|
+
export type DataTableSortDirection = 'asc' | 'desc';
|
|
16
|
+
export interface DataTableSort {
|
|
17
|
+
readonly key: string;
|
|
18
|
+
readonly direction: DataTableSortDirection;
|
|
19
|
+
}
|
|
10
20
|
export interface DataTableColumn<T> {
|
|
11
21
|
/** Stable column id; also the property read from the row when `render` is absent. */
|
|
12
22
|
readonly key: string;
|
|
@@ -16,6 +26,16 @@ export interface DataTableColumn<T> {
|
|
|
16
26
|
readonly render?: (row: T, rowIndex: number) => ReactNode;
|
|
17
27
|
/** Cell text alignment for both the header and the column's body cells. */
|
|
18
28
|
readonly align?: ColumnAlign;
|
|
29
|
+
/** Enable interactive sorting on this column. */
|
|
30
|
+
readonly sortable?: boolean;
|
|
31
|
+
/** Custom comparable value extractor for sorting (defaults to `row[key]`). */
|
|
32
|
+
readonly sortValue?: (row: T) => string | number;
|
|
33
|
+
/** Optional explicit width (e.g. `84px`, `120px`). */
|
|
34
|
+
readonly width?: string;
|
|
35
|
+
/** Minimum pixel width when `resizable` is enabled. Default `64`. */
|
|
36
|
+
readonly minWidth?: number;
|
|
37
|
+
/** Disable resizing for this individual column when table `resizable` is true. */
|
|
38
|
+
readonly resizable?: boolean;
|
|
19
39
|
}
|
|
20
40
|
export interface DataTableProps<T> extends Omit<TableHTMLAttributes<HTMLTableElement>, 'children'> {
|
|
21
41
|
readonly columns: readonly DataTableColumn<T>[];
|
|
@@ -24,5 +44,29 @@ export interface DataTableProps<T> extends Omit<TableHTMLAttributes<HTMLTableEle
|
|
|
24
44
|
readonly getRowKey?: (row: T, index: number) => string | number;
|
|
25
45
|
/** Shown (column-spanning, muted) when `rows` is empty. */
|
|
26
46
|
readonly empty?: ReactNode;
|
|
47
|
+
/** Controlled sort state. Omit for internal uncontrolled sorting when columns are `sortable`. */
|
|
48
|
+
readonly sort?: DataTableSort | null;
|
|
49
|
+
/** Called when a sortable header is clicked. */
|
|
50
|
+
readonly onSortChange?: (next: DataTableSort | null) => void;
|
|
51
|
+
/** Show a leading selection checkbox column (with select-all header). */
|
|
52
|
+
readonly selectable?: boolean;
|
|
53
|
+
/** Controlled selected row keys. */
|
|
54
|
+
readonly selectedKeys?: ReadonlySet<string | number>;
|
|
55
|
+
/** Called when selection changes. */
|
|
56
|
+
readonly onSelectionChange?: (next: Set<string | number>) => void;
|
|
57
|
+
/** Called when a row is activated via click or Enter. */
|
|
58
|
+
readonly onRowActivate?: (row: T, key: string | number) => void;
|
|
59
|
+
/** Keep header row pinned during vertical scroll. */
|
|
60
|
+
readonly stickyHeader?: boolean;
|
|
61
|
+
/** Allow interactive column width resizing via header drag handles or keyboard arrows. */
|
|
62
|
+
readonly resizable?: boolean;
|
|
63
|
+
/** Called when a column is resized to a new pixel width. */
|
|
64
|
+
readonly onColumnResize?: (columnKey: string, widthPx: number) => void;
|
|
65
|
+
/** Enable windowed row virtualization when `rows.length >= virtualizeAbove`. Default `2500`. */
|
|
66
|
+
readonly virtualizeAbove?: number;
|
|
67
|
+
/** Scroll viewport height in px when virtualizing. Default `420`. */
|
|
68
|
+
readonly viewportHeight?: number;
|
|
69
|
+
/** Estimated row height in px for virtualization geometry. Default `36`. */
|
|
70
|
+
readonly rowHeight?: number;
|
|
27
71
|
}
|
|
28
|
-
export declare function DataTable<T>({ columns, rows, getRowKey, empty, ...rest }: DataTableProps<T>): ReactElement;
|
|
72
|
+
export declare function DataTable<T>({ columns, rows, getRowKey, empty, sort: controlledSort, onSortChange, selectable, selectedKeys: controlledSelected, onSelectionChange, onRowActivate, stickyHeader, resizable, onColumnResize, virtualizeAbove, viewportHeight, rowHeight, className, ...rest }: DataTableProps<T>): ReactElement;
|
|
@@ -1,13 +1,187 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useMemo, useRef, useState } from 'react';
|
|
3
|
+
import ChevronUp from '@xenosystem/elements/elements/chevron-up';
|
|
4
|
+
import ChevronDown from '@xenosystem/elements/elements/chevron-down';
|
|
5
|
+
import ChevronsUpDown from '@xenosystem/elements/elements/chevrons-up-down';
|
|
6
|
+
import { XenoElement } from '../XenoElement.js';
|
|
7
|
+
import { Checkbox } from '../forms/Checkbox.js';
|
|
2
8
|
import { Table, THead, TBody, Tr, Th, Td } from './Table.js';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
const OVERSCAN = 8;
|
|
10
|
+
function compareValues(a, b) {
|
|
11
|
+
if (a === b)
|
|
12
|
+
return 0;
|
|
13
|
+
if (a == null)
|
|
14
|
+
return 1;
|
|
15
|
+
if (b == null)
|
|
16
|
+
return -1;
|
|
17
|
+
if (typeof a === 'number' && typeof b === 'number')
|
|
18
|
+
return a - b;
|
|
19
|
+
return String(a).localeCompare(String(b), undefined, { numeric: true, sensitivity: 'base' });
|
|
20
|
+
}
|
|
21
|
+
export function DataTable({ columns, rows, getRowKey, empty, sort: controlledSort, onSortChange, selectable = false, selectedKeys: controlledSelected, onSelectionChange, onRowActivate, stickyHeader = false, resizable = false, onColumnResize, virtualizeAbove = 2500, viewportHeight = 420, rowHeight = 36, className, ...rest }) {
|
|
22
|
+
const [internalSort, setInternalSort] = useState(null);
|
|
23
|
+
const [internalSelected, setInternalSelected] = useState(() => new Set());
|
|
24
|
+
const [colWidths, setColWidths] = useState({});
|
|
25
|
+
const [scrollTop, setScrollTop] = useState(0);
|
|
26
|
+
const tbodyRef = useRef(null);
|
|
27
|
+
const commitColumnWidth = useCallback((colKey, nextPx, minWidth = 64) => {
|
|
28
|
+
const clamped = Math.max(minWidth, Math.round(nextPx));
|
|
29
|
+
setColWidths((prev) => ({ ...prev, [colKey]: clamped }));
|
|
30
|
+
onColumnResize?.(colKey, clamped);
|
|
31
|
+
}, [onColumnResize]);
|
|
32
|
+
const startColumnResize = useCallback((e, col) => {
|
|
33
|
+
e.preventDefault();
|
|
34
|
+
e.stopPropagation();
|
|
35
|
+
const th = e.currentTarget.closest('th');
|
|
36
|
+
const startX = e.clientX;
|
|
37
|
+
const startWidth = colWidths[col.key] ?? th?.getBoundingClientRect().width ?? 120;
|
|
38
|
+
const minW = col.minWidth ?? 64;
|
|
39
|
+
const onMove = (ev) => {
|
|
40
|
+
commitColumnWidth(col.key, startWidth + (ev.clientX - startX), minW);
|
|
41
|
+
};
|
|
42
|
+
const onUp = () => {
|
|
43
|
+
window.removeEventListener('pointermove', onMove);
|
|
44
|
+
window.removeEventListener('pointerup', onUp);
|
|
45
|
+
};
|
|
46
|
+
window.addEventListener('pointermove', onMove);
|
|
47
|
+
window.addEventListener('pointerup', onUp);
|
|
48
|
+
}, [colWidths, commitColumnWidth]);
|
|
49
|
+
const activeSort = controlledSort !== undefined ? controlledSort : internalSort;
|
|
50
|
+
const selected = controlledSelected !== undefined ? controlledSelected : internalSelected;
|
|
51
|
+
const updateSort = useCallback((colKey) => {
|
|
52
|
+
const next = !activeSort || activeSort.key !== colKey
|
|
53
|
+
? { key: colKey, direction: 'asc' }
|
|
54
|
+
: activeSort.direction === 'asc'
|
|
55
|
+
? { key: colKey, direction: 'desc' }
|
|
56
|
+
: null;
|
|
57
|
+
if (controlledSort === undefined)
|
|
58
|
+
setInternalSort(next);
|
|
59
|
+
onSortChange?.(next);
|
|
60
|
+
}, [activeSort, controlledSort, onSortChange]);
|
|
61
|
+
const updateSelection = useCallback((next) => {
|
|
62
|
+
if (controlledSelected === undefined)
|
|
63
|
+
setInternalSelected(next);
|
|
64
|
+
onSelectionChange?.(next);
|
|
65
|
+
}, [controlledSelected, onSelectionChange]);
|
|
66
|
+
const sortedEntries = useMemo(() => {
|
|
67
|
+
const entries = rows.map((row, index) => ({
|
|
68
|
+
row,
|
|
69
|
+
index,
|
|
70
|
+
key: getRowKey ? getRowKey(row, index) : index,
|
|
71
|
+
}));
|
|
72
|
+
if (!activeSort)
|
|
73
|
+
return entries;
|
|
74
|
+
const col = columns.find((c) => c.key === activeSort.key);
|
|
75
|
+
if (!col)
|
|
76
|
+
return entries;
|
|
77
|
+
const dir = activeSort.direction === 'asc' ? 1 : -1;
|
|
78
|
+
return [...entries].sort((a, b) => {
|
|
79
|
+
const av = col.sortValue ? col.sortValue(a.row) : a.row[col.key];
|
|
80
|
+
const bv = col.sortValue ? col.sortValue(b.row) : b.row[col.key];
|
|
81
|
+
return compareValues(av, bv) * dir;
|
|
82
|
+
});
|
|
83
|
+
}, [rows, getRowKey, activeSort, columns]);
|
|
84
|
+
const allSelected = sortedEntries.length > 0 && sortedEntries.every((e) => selected.has(e.key));
|
|
85
|
+
const someSelected = !allSelected && sortedEntries.some((e) => selected.has(e.key));
|
|
86
|
+
const toggleAll = useCallback(() => {
|
|
87
|
+
if (allSelected) {
|
|
88
|
+
updateSelection(new Set());
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
updateSelection(new Set(sortedEntries.map((e) => e.key)));
|
|
92
|
+
}
|
|
93
|
+
}, [allSelected, sortedEntries, updateSelection]);
|
|
94
|
+
const toggleKey = useCallback((key) => {
|
|
95
|
+
const next = new Set(selected);
|
|
96
|
+
if (next.has(key))
|
|
97
|
+
next.delete(key);
|
|
98
|
+
else
|
|
99
|
+
next.add(key);
|
|
100
|
+
updateSelection(next);
|
|
101
|
+
}, [selected, updateSelection]);
|
|
102
|
+
const isVirtualized = sortedEntries.length >= virtualizeAbove;
|
|
103
|
+
const startIndex = isVirtualized ? Math.max(0, Math.floor(scrollTop / rowHeight) - OVERSCAN) : 0;
|
|
104
|
+
const visibleCount = isVirtualized ? Math.ceil(viewportHeight / rowHeight) + OVERSCAN * 2 : sortedEntries.length;
|
|
105
|
+
const endIndex = isVirtualized ? Math.min(sortedEntries.length, startIndex + visibleCount) : sortedEntries.length;
|
|
106
|
+
const slice = isVirtualized ? sortedEntries.slice(startIndex, endIndex) : sortedEntries;
|
|
107
|
+
const topPad = isVirtualized ? startIndex * rowHeight : 0;
|
|
108
|
+
const bottomPad = isVirtualized ? Math.max(0, (sortedEntries.length - endIndex) * rowHeight) : 0;
|
|
109
|
+
const totalColSpan = columns.length + (selectable ? 1 : 0);
|
|
110
|
+
// Single delegated keyboard handler on <TBody> — zero per-row listener closures.
|
|
111
|
+
const onBodyKeyDown = useCallback((e) => {
|
|
112
|
+
const tr = e.target.closest('tr[data-row-idx]');
|
|
113
|
+
if (!tr || !tbodyRef.current)
|
|
114
|
+
return;
|
|
115
|
+
const rowEls = Array.from(tbodyRef.current.querySelectorAll('tr[data-row-idx]'));
|
|
116
|
+
const pos = rowEls.indexOf(tr);
|
|
117
|
+
if (pos < 0)
|
|
118
|
+
return;
|
|
119
|
+
if (e.key === 'ArrowDown') {
|
|
120
|
+
e.preventDefault();
|
|
121
|
+
rowEls[Math.min(rowEls.length - 1, pos + 1)]?.focus();
|
|
122
|
+
}
|
|
123
|
+
else if (e.key === 'ArrowUp') {
|
|
124
|
+
e.preventDefault();
|
|
125
|
+
rowEls[Math.max(0, pos - 1)]?.focus();
|
|
126
|
+
}
|
|
127
|
+
else if (e.key === 'Home') {
|
|
128
|
+
e.preventDefault();
|
|
129
|
+
rowEls[0]?.focus();
|
|
130
|
+
}
|
|
131
|
+
else if (e.key === 'End') {
|
|
132
|
+
e.preventDefault();
|
|
133
|
+
rowEls[rowEls.length - 1]?.focus();
|
|
134
|
+
}
|
|
135
|
+
else if (e.key === 'Enter' || (e.key === ' ' && selectable && e.target === tr)) {
|
|
136
|
+
e.preventDefault();
|
|
137
|
+
const idx = Number(tr.dataset.rowIdx);
|
|
138
|
+
const entry = sortedEntries[idx];
|
|
139
|
+
if (!entry)
|
|
140
|
+
return;
|
|
141
|
+
if (e.key === ' ' && selectable)
|
|
142
|
+
toggleKey(entry.key);
|
|
143
|
+
else
|
|
144
|
+
onRowActivate?.(entry.row, entry.key);
|
|
145
|
+
}
|
|
146
|
+
}, [sortedEntries, selectable, toggleKey, onRowActivate]);
|
|
147
|
+
const tableEl = (_jsxs(Table, { className: className, "data-sticky-header": stickyHeader || isVirtualized ? 'true' : undefined, "data-virtualized": isVirtualized ? 'true' : undefined, ...rest, children: [_jsx(THead, { children: _jsxs(Tr, { children: [selectable ? (_jsx(Th, { className: "xeno-th-select", style: { width: '36px' }, children: _jsx(Checkbox, { checked: allSelected ? true : someSelected ? 'mixed' : false, onCheckedChange: toggleAll, "aria-label": "Select all rows" }) })) : null, columns.map((col) => {
|
|
148
|
+
const isSorted = activeSort?.key === col.key;
|
|
149
|
+
const ariaSort = col.sortable
|
|
150
|
+
? isSorted
|
|
151
|
+
? activeSort.direction === 'asc'
|
|
152
|
+
? 'ascending'
|
|
153
|
+
: 'descending'
|
|
154
|
+
: 'none'
|
|
155
|
+
: undefined;
|
|
156
|
+
const resolvedWidth = colWidths[col.key] !== undefined ? `${colWidths[col.key]}px` : col.width;
|
|
157
|
+
const canResize = resizable && col.resizable !== false;
|
|
158
|
+
return (_jsxs(Th, { "aria-sort": ariaSort, className: canResize ? 'xeno-th-resizable' : undefined, style: resolvedWidth ? { width: resolvedWidth } : undefined, ...(col.align !== undefined ? { align: col.align } : {}), children: [col.sortable ? (_jsxs("button", { type: "button", className: "xeno-th-sort", onClick: () => updateSort(col.key), children: [_jsx("span", { children: col.header }), _jsx("span", { className: "xeno-th-sort-mark", "aria-hidden": "true", children: _jsx(XenoElement, { decl: isSorted
|
|
159
|
+
? activeSort.direction === 'asc'
|
|
160
|
+
? ChevronUp
|
|
161
|
+
: ChevronDown
|
|
162
|
+
: ChevronsUpDown, size: 12 }) })] })) : (col.header), canResize ? (_jsx("span", { role: "separator", "aria-orientation": "vertical", "aria-label": `Resize ${String(col.key)} column`, tabIndex: 0, className: "xeno-th-resizer", onPointerDown: (e) => startColumnResize(e, col), onKeyDown: (e) => {
|
|
163
|
+
const cur = colWidths[col.key] ?? (parseInt(col.width ?? '120', 10) || 120);
|
|
164
|
+
if (e.key === 'ArrowRight') {
|
|
165
|
+
e.preventDefault();
|
|
166
|
+
commitColumnWidth(col.key, cur + 16, col.minWidth ?? 64);
|
|
167
|
+
}
|
|
168
|
+
else if (e.key === 'ArrowLeft') {
|
|
169
|
+
e.preventDefault();
|
|
170
|
+
commitColumnWidth(col.key, cur - 16, col.minWidth ?? 64);
|
|
171
|
+
}
|
|
172
|
+
} })) : null] }, col.key));
|
|
173
|
+
})] }) }), _jsx(TBody, { ref: tbodyRef, onKeyDown: onBodyKeyDown, children: sortedEntries.length === 0 && empty !== undefined ? (_jsx(Tr, { children: _jsx(Td, { className: "xeno-table-empty", colSpan: totalColSpan, children: empty }) })) : (_jsxs(_Fragment, { children: [topPad > 0 ? (_jsx("tr", { "aria-hidden": "true", className: "xeno-tr-spacer", children: _jsx("td", { colSpan: totalColSpan, style: { height: topPad, padding: 0, border: 0 } }) })) : null, slice.map((entry, localIdx) => {
|
|
174
|
+
const absIdx = startIndex + localIdx;
|
|
175
|
+
const isSelected = selected.has(entry.key);
|
|
176
|
+
return (_jsxs(Tr, { selected: isSelected, "data-row-idx": absIdx, tabIndex: selectable || onRowActivate ? 0 : undefined, style: isVirtualized ? { height: rowHeight } : undefined, onClick: onRowActivate ? () => onRowActivate(entry.row, entry.key) : undefined, children: [selectable ? (_jsx(Td, { className: "xeno-td-select", onClick: (e) => e.stopPropagation(), children: _jsx(Checkbox, { checked: isSelected, onCheckedChange: () => toggleKey(entry.key), "aria-label": `Select row ${String(entry.key)}` }) })) : null, columns.map((col) => {
|
|
177
|
+
const content = col.render
|
|
178
|
+
? col.render(entry.row, entry.index)
|
|
179
|
+
: entry.row[col.key];
|
|
180
|
+
return (_jsx(Td, { ...(col.align !== undefined ? { align: col.align } : {}), children: content }, col.key));
|
|
181
|
+
})] }, entry.key));
|
|
182
|
+
}), bottomPad > 0 ? (_jsx("tr", { "aria-hidden": "true", className: "xeno-tr-spacer", children: _jsx("td", { colSpan: totalColSpan, style: { height: bottomPad, padding: 0, border: 0 } }) })) : null] })) })] }));
|
|
183
|
+
if (!isVirtualized) {
|
|
184
|
+
return _jsx("div", { className: "xeno-table-scroll", children: tableEl });
|
|
185
|
+
}
|
|
186
|
+
return (_jsx("div", { className: "xeno-table-viewport", style: { maxHeight: viewportHeight, overflow: 'auto' }, onScroll: (e) => setScrollTop(e.currentTarget.scrollTop), children: tableEl }));
|
|
13
187
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type HTMLAttributes, type ReactElement, type ReactNode, type TableHTMLAttributes, type TdHTMLAttributes, type ThHTMLAttributes } from 'react';
|
|
2
2
|
/**
|
|
3
3
|
* Dense table PRIMITIVES — the thin, purely-presentational wrappers over the native table elements
|
|
4
4
|
* (`table`/`thead`/`tbody`/`tr`/`th`/`td`). They carry only the `xeno-*` classes so the locked table
|
|
@@ -20,7 +20,7 @@ export declare function THead({ className, children, ...rest }: THeadProps): Rea
|
|
|
20
20
|
export interface TBodyProps extends HTMLAttributes<HTMLTableSectionElement> {
|
|
21
21
|
readonly children?: ReactNode;
|
|
22
22
|
}
|
|
23
|
-
export declare
|
|
23
|
+
export declare const TBody: import("react").ForwardRefExoticComponent<TBodyProps & import("react").RefAttributes<HTMLTableSectionElement>>;
|
|
24
24
|
export interface TrProps extends HTMLAttributes<HTMLTableRowElement> {
|
|
25
25
|
/** Presentational selection state — rides the `selection` axis. Omit for a plain row. */
|
|
26
26
|
readonly selected?: boolean;
|
package/dist/containers/Table.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, } from 'react';
|
|
2
3
|
import { cx } from '../controls/util.js';
|
|
3
4
|
export function Table({ className, children, ...rest }) {
|
|
4
5
|
return (_jsx("table", { className: cx('xeno-table', className), ...rest, children: children }));
|
|
@@ -6,9 +7,9 @@ export function Table({ className, children, ...rest }) {
|
|
|
6
7
|
export function THead({ className, children, ...rest }) {
|
|
7
8
|
return (_jsx("thead", { className: cx('xeno-thead', className), ...rest, children: children }));
|
|
8
9
|
}
|
|
9
|
-
export function TBody({ className, children, ...rest }) {
|
|
10
|
-
return (_jsx("tbody", { className: cx('xeno-tbody', className), ...rest, children: children }));
|
|
11
|
-
}
|
|
10
|
+
export const TBody = forwardRef(function TBody({ className, children, ...rest }, ref) {
|
|
11
|
+
return (_jsx("tbody", { ref: ref, className: cx('xeno-tbody', className), ...rest, children: children }));
|
|
12
|
+
});
|
|
12
13
|
export function Tr({ selected, className, children, ...rest }) {
|
|
13
14
|
return (_jsx("tr", { className: cx('xeno-tr', className), "data-selection": selected === undefined ? undefined : selected ? 'on' : 'off', "aria-selected": selected, ...rest, children: children }));
|
|
14
15
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { HTMLAttributes, ReactElement, ReactNode } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* `<Kbd>` — a keyboard shortcut hint (`⌘K`, `Esc`, `⇧⌘P`), measured from all five references
|
|
4
|
+
* (header palette trigger, command palette rows, shortcuts sheet, composer send hint).
|
|
5
|
+
*
|
|
6
|
+
* Pass `keys` for a multi-key chord (`['⌘', 'K']`), or `children` for a single cap.
|
|
7
|
+
*/
|
|
8
|
+
export interface KbdProps extends Omit<HTMLAttributes<HTMLElement>, 'children'> {
|
|
9
|
+
/** Ordered key caps in a chord, rendered as individual `<kbd>` elements inside a `<span class="xeno-kbd-group">`. */
|
|
10
|
+
readonly keys?: readonly string[];
|
|
11
|
+
/** Single key label when `keys` is not provided. */
|
|
12
|
+
readonly children?: ReactNode;
|
|
13
|
+
/** Visual size: `sm` (18px, inline/header) or `md` (20px, shortcuts sheet). Default `sm`. */
|
|
14
|
+
readonly size?: 'sm' | 'md';
|
|
15
|
+
}
|
|
16
|
+
export declare function Kbd({ keys, children, size, className, ...rest }: KbdProps): ReactElement;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { cx } from '../controls/util.js';
|
|
3
|
+
export function Kbd({ keys, children, size = 'sm', className, ...rest }) {
|
|
4
|
+
if (keys && keys.length > 0) {
|
|
5
|
+
return (_jsx("span", { className: cx('xeno-kbd-group', className), "data-size": size, ...rest, children: keys.map((key, index) => (_jsx("kbd", { className: "xeno-kbd", "data-size": size, children: key }, `${key}-${index}`))) }));
|
|
6
|
+
}
|
|
7
|
+
return (_jsx("kbd", { className: cx('xeno-kbd', className), "data-size": size, ...rest, children: children }));
|
|
8
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { HTMLAttributes, ReactElement, ReactNode } from 'react';
|
|
2
|
+
export interface FormFieldControlProps {
|
|
3
|
+
readonly id: string;
|
|
4
|
+
readonly 'aria-describedby'?: string;
|
|
5
|
+
readonly 'aria-invalid'?: true;
|
|
6
|
+
readonly 'aria-required'?: true;
|
|
7
|
+
}
|
|
8
|
+
export interface FormFieldProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {
|
|
9
|
+
/** Visible field label. */
|
|
10
|
+
readonly label: ReactNode;
|
|
11
|
+
/** Explicit id matching the nested control (auto-generated when omitted). */
|
|
12
|
+
readonly htmlFor?: string;
|
|
13
|
+
/** Shows a required indicator and passes `aria-required="true"` to render-prop children. */
|
|
14
|
+
readonly required?: boolean;
|
|
15
|
+
/** Helper caption rendered beneath the control when no error is active. */
|
|
16
|
+
readonly hint?: ReactNode;
|
|
17
|
+
/** Validation error message rendered with `role="alert"` and linked via `aria-describedby`. */
|
|
18
|
+
readonly error?: ReactNode;
|
|
19
|
+
/** Optional trailing metadata beside the label (e.g. character count or shortcut). */
|
|
20
|
+
readonly labelAction?: ReactNode;
|
|
21
|
+
/** Visually dims the field label when disabled. */
|
|
22
|
+
readonly disabled?: boolean;
|
|
23
|
+
/** Horizontal label + control layout when true. */
|
|
24
|
+
readonly inline?: boolean;
|
|
25
|
+
/** Control node, or render callback receiving standardized `{ id, aria-describedby, aria-invalid, aria-required }`. */
|
|
26
|
+
readonly children: ReactNode | ((controlProps: FormFieldControlProps) => ReactNode);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* `<FormField>` — standardized accessible label, hint, required, and validation error contract
|
|
30
|
+
* shared across `TextInput`, `Textarea`, `Select`, `Combobox`, `NumberInput`, and `Slider`.
|
|
31
|
+
*/
|
|
32
|
+
export declare function FormField({ label, htmlFor, required, hint, error, labelAction, disabled, inline, className, children, ...rest }: FormFieldProps): ReactElement;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useId } from 'react';
|
|
3
|
+
import { cx } from '../controls/util.js';
|
|
4
|
+
/**
|
|
5
|
+
* `<FormField>` — standardized accessible label, hint, required, and validation error contract
|
|
6
|
+
* shared across `TextInput`, `Textarea`, `Select`, `Combobox`, `NumberInput`, and `Slider`.
|
|
7
|
+
*/
|
|
8
|
+
export function FormField({ label, htmlFor, required = false, hint, error, labelAction, disabled = false, inline = false, className, children, ...rest }) {
|
|
9
|
+
const autoId = useId();
|
|
10
|
+
const fieldId = htmlFor ?? `xeno-field-${autoId}`;
|
|
11
|
+
const hintId = `${fieldId}-hint`;
|
|
12
|
+
const errorId = `${fieldId}-error`;
|
|
13
|
+
const describedBy = [
|
|
14
|
+
error ? errorId : undefined,
|
|
15
|
+
hint ? hintId : undefined,
|
|
16
|
+
]
|
|
17
|
+
.filter(Boolean)
|
|
18
|
+
.join(' ') || undefined;
|
|
19
|
+
const controlProps = {
|
|
20
|
+
id: fieldId,
|
|
21
|
+
...(describedBy ? { 'aria-describedby': describedBy } : {}),
|
|
22
|
+
...(error ? { 'aria-invalid': true } : {}),
|
|
23
|
+
...(required ? { 'aria-required': true } : {}),
|
|
24
|
+
};
|
|
25
|
+
return (_jsxs("div", { className: cx('xeno-form-field', className), "data-invalid": error ? 'true' : undefined, "data-disabled": disabled ? 'true' : undefined, "data-inline": inline ? 'true' : undefined, ...rest, children: [_jsxs("div", { className: "xeno-form-field-head", children: [_jsxs("label", { className: "xeno-form-field-label", htmlFor: fieldId, children: [_jsx("span", { children: label }), required ? (_jsx("span", { className: "xeno-form-field-req", "aria-hidden": "true", children: "*" })) : null] }), labelAction != null ? _jsx("span", { className: "xeno-form-field-action", children: labelAction }) : null] }), _jsx("div", { className: "xeno-form-field-control", children: typeof children === 'function' ? children(controlProps) : children }), error ? (_jsx("div", { id: errorId, className: "xeno-form-field-error", role: "alert", children: error })) : null, hint ? (_jsx("div", { id: hintId, className: "xeno-form-field-hint", children: hint })) : null] }));
|
|
26
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { InputHTMLAttributes, ReactElement } from 'react';
|
|
2
|
+
import { type ControlSizeToken } from '../controls/util.js';
|
|
3
|
+
export interface NumberInputProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'value' | 'defaultValue' | 'onChange' | 'size' | 'type'> {
|
|
4
|
+
/** Controlled numeric value. */
|
|
5
|
+
readonly value?: number;
|
|
6
|
+
/** Uncontrolled initial numeric value. */
|
|
7
|
+
readonly defaultValue?: number;
|
|
8
|
+
/** Called whenever the committed numeric value changes. */
|
|
9
|
+
readonly onChange?: (value: number) => void;
|
|
10
|
+
/** Minimum allowed value. */
|
|
11
|
+
readonly min?: number;
|
|
12
|
+
/** Maximum allowed value. */
|
|
13
|
+
readonly max?: number;
|
|
14
|
+
/** Step increment per click or arrow key. Defaults to `1`. */
|
|
15
|
+
readonly step?: number;
|
|
16
|
+
/** Optional unit suffix (e.g. `'px'`, `'ms'`, `'%'`). */
|
|
17
|
+
readonly unit?: string;
|
|
18
|
+
/** Visual size token. Defaults to `'md'`. */
|
|
19
|
+
readonly size?: ControlSizeToken;
|
|
20
|
+
/** Hide increment/decrement stepper buttons when true. */
|
|
21
|
+
readonly hideSteppers?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* `<NumberInput>` — tabular-nums numeric field with keyboard `ArrowUp`/`ArrowDown` (`Shift`×10),
|
|
25
|
+
* accessible increment/decrement steppers, clamping on blur, and optional unit readout.
|
|
26
|
+
*/
|
|
27
|
+
export declare function NumberInput({ value: controlledValue, defaultValue, onChange, min, max, step, unit, size, hideSteppers, disabled, className, onBlur, ...rest }: NumberInputProps): ReactElement;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
import { cx, sizeAttr } from '../controls/util.js';
|
|
4
|
+
function clampNum(n, min, max) {
|
|
5
|
+
let out = n;
|
|
6
|
+
if (min !== undefined)
|
|
7
|
+
out = Math.max(min, out);
|
|
8
|
+
if (max !== undefined)
|
|
9
|
+
out = Math.min(max, out);
|
|
10
|
+
return out;
|
|
11
|
+
}
|
|
12
|
+
function roundStep(n, step) {
|
|
13
|
+
const decimals = (step.toString().split('.')[1] ?? '').length;
|
|
14
|
+
return Number(n.toFixed(decimals));
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* `<NumberInput>` — tabular-nums numeric field with keyboard `ArrowUp`/`ArrowDown` (`Shift`×10),
|
|
18
|
+
* accessible increment/decrement steppers, clamping on blur, and optional unit readout.
|
|
19
|
+
*/
|
|
20
|
+
export function NumberInput({ value: controlledValue, defaultValue = 0, onChange, min, max, step = 1, unit, size = 'md', hideSteppers = false, disabled = false, className, onBlur, ...rest }) {
|
|
21
|
+
const [uncontrolled, setUncontrolled] = useState(() => clampNum(defaultValue, min, max));
|
|
22
|
+
const current = controlledValue ?? uncontrolled;
|
|
23
|
+
const [draft, setDraft] = useState(String(current));
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
setDraft(String(current));
|
|
26
|
+
}, [current]);
|
|
27
|
+
const commit = (nextRaw) => {
|
|
28
|
+
const next = roundStep(clampNum(nextRaw, min, max), step);
|
|
29
|
+
if (controlledValue === undefined)
|
|
30
|
+
setUncontrolled(next);
|
|
31
|
+
setDraft(String(next));
|
|
32
|
+
onChange?.(next);
|
|
33
|
+
};
|
|
34
|
+
const nudge = (delta) => {
|
|
35
|
+
if (disabled)
|
|
36
|
+
return;
|
|
37
|
+
commit(current + delta);
|
|
38
|
+
};
|
|
39
|
+
const onKeyDown = (e) => {
|
|
40
|
+
if (e.key === 'ArrowUp') {
|
|
41
|
+
e.preventDefault();
|
|
42
|
+
nudge(step * (e.shiftKey ? 10 : 1));
|
|
43
|
+
}
|
|
44
|
+
else if (e.key === 'ArrowDown') {
|
|
45
|
+
e.preventDefault();
|
|
46
|
+
nudge(-step * (e.shiftKey ? 10 : 1));
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
return (_jsxs("div", { className: cx('xeno-num-input', className), "data-availability": disabled ? 'disabled' : 'enabled', ...sizeAttr(size), children: [!hideSteppers ? (_jsx("button", { type: "button", className: "xeno-num-step", "aria-label": "Decrease value", disabled: disabled || (min !== undefined && current <= min), onClick: () => nudge(-step), tabIndex: -1, children: "\u2212" })) : null, _jsx("input", { ...rest, type: "text", inputMode: "decimal", role: "spinbutton", "aria-valuenow": current, "aria-valuemin": min, "aria-valuemax": max, className: "xeno-num-field", value: draft, disabled: disabled, onKeyDown: onKeyDown, onChange: (e) => {
|
|
50
|
+
const raw = e.target.value;
|
|
51
|
+
setDraft(raw);
|
|
52
|
+
const parsed = Number(raw);
|
|
53
|
+
if (raw.trim() !== '' && Number.isFinite(parsed)) {
|
|
54
|
+
const clamped = clampNum(parsed, min, max);
|
|
55
|
+
if (controlledValue === undefined)
|
|
56
|
+
setUncontrolled(clamped);
|
|
57
|
+
onChange?.(clamped);
|
|
58
|
+
}
|
|
59
|
+
}, onBlur: (e) => {
|
|
60
|
+
const parsed = Number(draft);
|
|
61
|
+
if (draft.trim() === '' || !Number.isFinite(parsed)) {
|
|
62
|
+
setDraft(String(current));
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
commit(parsed);
|
|
66
|
+
}
|
|
67
|
+
onBlur?.(e);
|
|
68
|
+
} }), unit ? (_jsx("span", { className: "xeno-num-unit", "aria-hidden": "true", children: unit })) : null, !hideSteppers ? (_jsx("button", { type: "button", className: "xeno-num-step", "aria-label": "Increase value", disabled: disabled || (max !== undefined && current >= max), onClick: () => nudge(step), tabIndex: -1, children: "+" })) : null] }));
|
|
69
|
+
}
|