@xenosystem/elements-react 0.0.11 → 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.
@@ -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
+ }
@@ -0,0 +1,84 @@
1
+ import type { ReactElement, ReactNode } from 'react';
2
+ import { type ControlSizeToken } from '../controls/util.js';
3
+ export interface SelectOption {
4
+ readonly value: string;
5
+ readonly label: string;
6
+ readonly description?: string;
7
+ readonly disabled?: boolean;
8
+ readonly group?: string;
9
+ }
10
+ export interface SelectProps {
11
+ /** Ordered list of selectable options. */
12
+ readonly options: readonly SelectOption[];
13
+ /** Controlled selected option value. */
14
+ readonly value?: string;
15
+ /** Initial value when uncontrolled. */
16
+ readonly defaultValue?: string;
17
+ /** Called when the user selects an option. */
18
+ readonly onChange?: (value: string) => void;
19
+ /** Placeholder when no option is selected. */
20
+ readonly placeholder?: string;
21
+ /** Accessible label for the trigger button. */
22
+ readonly label?: string;
23
+ /** HTML id for `<FormField>` label association. */
24
+ readonly id?: string;
25
+ /** ARIA describedby id(s) from `<FormField>`. */
26
+ readonly 'aria-describedby'?: string;
27
+ /** Validation invalid marker. */
28
+ readonly 'aria-invalid'?: boolean;
29
+ /** Disables interaction. */
30
+ readonly disabled?: boolean;
31
+ /** Renders a zero-CLS skeleton bone matching the trigger footprint when true. */
32
+ readonly loading?: boolean;
33
+ /** Size token (`sm` | `md` | `lg`). Defaults to `'md'`. */
34
+ readonly size?: ControlSizeToken;
35
+ /** Extra CSS class on the root wrapper. */
36
+ readonly className?: string;
37
+ /** Portal the dropdown to `document.body`. Defaults to `true`. */
38
+ readonly portal?: boolean;
39
+ }
40
+ /**
41
+ * `<Select>` — accessible single-select dropdown with portaled collision-aware listbox,
42
+ * full WAI-ARIA 1.2 keyboard navigation (`ArrowDown`/`ArrowUp`/`Home`/`End`/`Enter`/`Space`/`Escape`),
43
+ * typeahead jump, and zero-CLS `loading` mode.
44
+ */
45
+ export declare function Select({ options, value: controlledValue, defaultValue, onChange, placeholder, label, id, 'aria-describedby': ariaDescribedBy, 'aria-invalid': ariaInvalid, disabled, loading, size, className, portal, }: SelectProps): ReactElement;
46
+ export interface ComboboxProps {
47
+ /** Selectable options. */
48
+ readonly options: readonly SelectOption[];
49
+ /** Selected value (single mode) or array of values (when `multiple` is true). */
50
+ readonly value?: string | readonly string[];
51
+ /** Uncontrolled initial value(s). */
52
+ readonly defaultValue?: string | readonly string[];
53
+ /** Called with the updated string (single) or `string[]` (multiple). */
54
+ readonly onChange?: (value: string | string[]) => void;
55
+ /** Enables multi-select chips with Backspace removal. Defaults to `false`. */
56
+ readonly multiple?: boolean;
57
+ /** Search input placeholder. */
58
+ readonly placeholder?: string;
59
+ /** Accessible label for the combobox input. */
60
+ readonly label?: string;
61
+ /** HTML id for `<FormField>` association. */
62
+ readonly id?: string;
63
+ /** ARIA describedby id(s). */
64
+ readonly 'aria-describedby'?: string;
65
+ /** Validation invalid marker. */
66
+ readonly 'aria-invalid'?: boolean;
67
+ /** Empty-filter message. */
68
+ readonly emptyMessage?: ReactNode;
69
+ /** Disables interaction. */
70
+ readonly disabled?: boolean;
71
+ /** Renders a zero-CLS skeleton bone when true. */
72
+ readonly loading?: boolean;
73
+ /** Size token (`sm` | `md` | `lg`). Defaults to `'md'`. */
74
+ readonly size?: ControlSizeToken;
75
+ /** Extra CSS class. */
76
+ readonly className?: string;
77
+ /** Portal the dropdown to `document.body`. Defaults to `true`. */
78
+ readonly portal?: boolean;
79
+ }
80
+ /**
81
+ * `<Combobox>` — WAI-ARIA 1.2 searchable single/multi-select combobox with live filtering,
82
+ * `aria-activedescendant`, portaled listbox, removable selection chips, and zero-CLS `loading`.
83
+ */
84
+ export declare function Combobox({ options, value: controlledValue, defaultValue, onChange, multiple, placeholder, label, id, 'aria-describedby': ariaDescribedBy, 'aria-invalid': ariaInvalid, emptyMessage, disabled, loading, size, className, portal, }: ComboboxProps): ReactElement;
@@ -0,0 +1,243 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { useId, useMemo, useRef, useState } from 'react';
3
+ import { cx, sizeAttr } from '../controls/util.js';
4
+ import { Popover } from '../overlays/Popover.js';
5
+ import { Skeleton } from '../status/Skeleton.js';
6
+ /**
7
+ * `<Select>` — accessible single-select dropdown with portaled collision-aware listbox,
8
+ * full WAI-ARIA 1.2 keyboard navigation (`ArrowDown`/`ArrowUp`/`Home`/`End`/`Enter`/`Space`/`Escape`),
9
+ * typeahead jump, and zero-CLS `loading` mode.
10
+ */
11
+ export function Select({ options, value: controlledValue, defaultValue, onChange, placeholder = 'Select an option…', label, id, 'aria-describedby': ariaDescribedBy, 'aria-invalid': ariaInvalid, disabled = false, loading = false, size = 'md', className, portal = true, }) {
12
+ const autoId = useId();
13
+ const triggerId = id ?? `xeno-select-${autoId}`;
14
+ const listboxId = `${triggerId}-listbox`;
15
+ const [uncontrolled, setUncontrolled] = useState(defaultValue ?? '');
16
+ const [open, setOpen] = useState(false);
17
+ const [activeIndex, setActiveIndex] = useState(0);
18
+ const triggerRef = useRef(null);
19
+ const current = controlledValue ?? uncontrolled;
20
+ const selected = useMemo(() => options.find((o) => o.value === current), [options, current]);
21
+ const enabledIndices = useMemo(() => options.map((o, i) => (o.disabled ? -1 : i)).filter((i) => i >= 0), [options]);
22
+ const openMenu = () => {
23
+ if (disabled || loading)
24
+ return;
25
+ const curIdx = options.findIndex((o) => o.value === current && !o.disabled);
26
+ setActiveIndex(curIdx >= 0 ? curIdx : (enabledIndices[0] ?? 0));
27
+ setOpen(true);
28
+ };
29
+ const commit = (opt) => {
30
+ if (opt.disabled)
31
+ return;
32
+ if (controlledValue === undefined)
33
+ setUncontrolled(opt.value);
34
+ onChange?.(opt.value);
35
+ setOpen(false);
36
+ triggerRef.current?.focus();
37
+ };
38
+ const move = (dir) => {
39
+ if (enabledIndices.length === 0)
40
+ return;
41
+ const pos = enabledIndices.indexOf(activeIndex);
42
+ const nextPos = pos < 0 ? 0 : (pos + dir + enabledIndices.length) % enabledIndices.length;
43
+ setActiveIndex(enabledIndices[nextPos]);
44
+ };
45
+ const onTriggerKeyDown = (e) => {
46
+ if (disabled || loading)
47
+ return;
48
+ if (e.key === 'ArrowDown' || e.key === 'ArrowUp' || e.key === 'Enter' || e.key === ' ') {
49
+ e.preventDefault();
50
+ if (!open) {
51
+ openMenu();
52
+ }
53
+ else if (e.key === 'ArrowDown') {
54
+ move(1);
55
+ }
56
+ else if (e.key === 'ArrowUp') {
57
+ move(-1);
58
+ }
59
+ else {
60
+ const opt = options[activeIndex];
61
+ if (opt)
62
+ commit(opt);
63
+ }
64
+ }
65
+ else if (e.key === 'Home' && open && enabledIndices.length > 0) {
66
+ e.preventDefault();
67
+ setActiveIndex(enabledIndices[0]);
68
+ }
69
+ else if (e.key === 'End' && open && enabledIndices.length > 0) {
70
+ e.preventDefault();
71
+ setActiveIndex(enabledIndices[enabledIndices.length - 1]);
72
+ }
73
+ else if (e.key === 'Escape' && open) {
74
+ e.preventDefault();
75
+ setOpen(false);
76
+ }
77
+ else if (e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey) {
78
+ const ch = e.key.toLowerCase();
79
+ const hit = options.findIndex((o) => !o.disabled && o.label.toLowerCase().startsWith(ch));
80
+ if (hit >= 0) {
81
+ setActiveIndex(hit);
82
+ if (!open)
83
+ commit(options[hit]);
84
+ }
85
+ }
86
+ };
87
+ const activeOptionId = open && options[activeIndex] ? `${listboxId}-opt-${activeIndex}` : undefined;
88
+ return (_jsx(Popover, { open: open, onOpenChange: setOpen, portal: portal, className: cx('xeno-select', className), trigger: _jsxs("button", { ref: triggerRef, id: triggerId, type: "button", role: "combobox", "aria-expanded": open, "aria-controls": listboxId, "aria-haspopup": "listbox", "aria-activedescendant": activeOptionId, "aria-label": label, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid || undefined, "aria-busy": loading || undefined, disabled: disabled || loading, className: "xeno-select-trigger", "data-open": open ? 'true' : undefined, "data-placeholder": !selected ? 'true' : undefined, ...sizeAttr(size), onClick: () => (open ? setOpen(false) : openMenu()), onKeyDown: onTriggerKeyDown, children: [_jsx("span", { className: "xeno-select-value", children: loading ? (_jsx(Skeleton, { width: "68%", height: 12 })) : (selected?.label ?? placeholder) }), _jsx("svg", { className: "xeno-select-caret", width: "12", height: "12", viewBox: "0 0 12 12", fill: "none", stroke: "currentColor", strokeWidth: "1.5", "aria-hidden": "true", children: _jsx("path", { d: "M3 4.5l3 3 3-3" }) })] }), panelProps: {
89
+ role: 'listbox',
90
+ id: listboxId,
91
+ 'aria-label': label ?? 'Options',
92
+ className: 'xeno-select-list',
93
+ }, children: options.length === 0 ? (_jsx("div", { className: "xeno-select-empty", children: "No options" })) : (options.map((opt, idx) => {
94
+ const isSelected = opt.value === current;
95
+ const isActive = idx === activeIndex;
96
+ return (_jsxs("div", { id: `${listboxId}-opt-${idx}`, role: "option", "aria-selected": isSelected, "aria-disabled": opt.disabled || undefined, className: "xeno-select-option", "data-selected": isSelected ? 'true' : undefined, "data-active": isActive ? 'true' : undefined, "data-disabled": opt.disabled ? 'true' : undefined, onMouseEnter: () => {
97
+ if (!opt.disabled)
98
+ setActiveIndex(idx);
99
+ }, onMouseDown: (e) => {
100
+ e.preventDefault();
101
+ commit(opt);
102
+ }, children: [_jsxs("span", { className: "xeno-select-opt-text", children: [_jsx("span", { className: "xeno-select-opt-label", children: opt.label }), opt.description ? (_jsx("span", { className: "xeno-select-opt-desc", children: opt.description })) : null] }), isSelected ? (_jsx("svg", { className: "xeno-select-check", width: "12", height: "12", viewBox: "0 0 12 12", fill: "none", stroke: "currentColor", strokeWidth: "1.75", "aria-hidden": "true", children: _jsx("path", { d: "M2.5 6.5l2.2 2.2 4.8-5.2" }) })) : null] }, opt.value));
103
+ })) }));
104
+ }
105
+ function toArray(v) {
106
+ if (v === undefined)
107
+ return [];
108
+ if (typeof v === 'string')
109
+ return v ? [v] : [];
110
+ return Array.from(v);
111
+ }
112
+ /**
113
+ * `<Combobox>` — WAI-ARIA 1.2 searchable single/multi-select combobox with live filtering,
114
+ * `aria-activedescendant`, portaled listbox, removable selection chips, and zero-CLS `loading`.
115
+ */
116
+ export function Combobox({ options, value: controlledValue, defaultValue, onChange, multiple = false, placeholder = 'Search or select…', label = 'Combobox', id, 'aria-describedby': ariaDescribedBy, 'aria-invalid': ariaInvalid, emptyMessage = 'No matching options', disabled = false, loading = false, size = 'md', className, portal = true, }) {
117
+ const autoId = useId();
118
+ const inputId = id ?? `xeno-combobox-${autoId}`;
119
+ const listboxId = `${inputId}-listbox`;
120
+ const [uncontrolled, setUncontrolled] = useState(() => toArray(defaultValue));
121
+ const selectedValues = controlledValue !== undefined ? toArray(controlledValue) : uncontrolled;
122
+ const singleSelected = !multiple
123
+ ? options.find((o) => o.value === selectedValues[0])
124
+ : undefined;
125
+ const [open, setOpen] = useState(false);
126
+ const [query, setQuery] = useState(() => (!multiple && singleSelected ? singleSelected.label : ''));
127
+ const [activeIndex, setActiveIndex] = useState(0);
128
+ const inputRef = useRef(null);
129
+ const filtered = useMemo(() => {
130
+ const q = query.trim().toLowerCase();
131
+ if (!q)
132
+ return options;
133
+ return options.filter((o) => o.label.toLowerCase().includes(q) ||
134
+ (o.description?.toLowerCase().includes(q) ?? false) ||
135
+ o.value.toLowerCase().includes(q));
136
+ }, [options, query]);
137
+ const emit = (next) => {
138
+ if (controlledValue === undefined)
139
+ setUncontrolled(next);
140
+ onChange?.(multiple ? next : (next[0] ?? ''));
141
+ };
142
+ const selectOption = (opt) => {
143
+ if (opt.disabled)
144
+ return;
145
+ if (multiple) {
146
+ const exists = selectedValues.includes(opt.value);
147
+ const next = exists
148
+ ? selectedValues.filter((v) => v !== opt.value)
149
+ : [...selectedValues, opt.value];
150
+ emit(next);
151
+ setQuery('');
152
+ inputRef.current?.focus();
153
+ }
154
+ else {
155
+ emit([opt.value]);
156
+ setQuery(opt.label);
157
+ setOpen(false);
158
+ }
159
+ };
160
+ const removeValue = (val) => {
161
+ emit(selectedValues.filter((v) => v !== val));
162
+ inputRef.current?.focus();
163
+ };
164
+ const enabledFilteredIndices = useMemo(() => filtered.map((o, i) => (o.disabled ? -1 : i)).filter((i) => i >= 0), [filtered]);
165
+ const move = (dir) => {
166
+ if (enabledFilteredIndices.length === 0)
167
+ return;
168
+ const pos = enabledFilteredIndices.indexOf(activeIndex);
169
+ const nextPos = pos < 0 ? 0 : (pos + dir + enabledFilteredIndices.length) % enabledFilteredIndices.length;
170
+ setActiveIndex(enabledFilteredIndices[nextPos]);
171
+ };
172
+ const onKeyDown = (e) => {
173
+ if (disabled || loading)
174
+ return;
175
+ if (e.key === 'ArrowDown') {
176
+ e.preventDefault();
177
+ if (!open) {
178
+ setOpen(true);
179
+ setActiveIndex(enabledFilteredIndices[0] ?? 0);
180
+ }
181
+ else {
182
+ move(1);
183
+ }
184
+ }
185
+ else if (e.key === 'ArrowUp') {
186
+ e.preventDefault();
187
+ if (!open) {
188
+ setOpen(true);
189
+ setActiveIndex(enabledFilteredIndices[enabledFilteredIndices.length - 1] ?? 0);
190
+ }
191
+ else {
192
+ move(-1);
193
+ }
194
+ }
195
+ else if (e.key === 'Enter' && open) {
196
+ e.preventDefault();
197
+ const opt = filtered[activeIndex];
198
+ if (opt)
199
+ selectOption(opt);
200
+ }
201
+ else if (e.key === 'Escape' && open) {
202
+ e.preventDefault();
203
+ setOpen(false);
204
+ }
205
+ else if (e.key === 'Backspace' && multiple && query === '' && selectedValues.length > 0) {
206
+ removeValue(selectedValues[selectedValues.length - 1]);
207
+ }
208
+ };
209
+ const activeOptId = open && filtered[activeIndex] ? `${listboxId}-opt-${activeIndex}` : undefined;
210
+ return (_jsx(Popover, { open: open, onOpenChange: setOpen, portal: portal, className: cx('xeno-combobox', className), trigger: _jsx("div", { className: "xeno-combobox-box", "data-open": open ? 'true' : undefined, "data-disabled": disabled ? 'true' : undefined, ...sizeAttr(size), onClick: () => {
211
+ if (!disabled && !loading) {
212
+ inputRef.current?.focus();
213
+ setOpen(true);
214
+ }
215
+ }, children: loading ? (_jsx(Skeleton, { width: "72%", height: 12 })) : (_jsxs(_Fragment, { children: [multiple && selectedValues.length > 0 ? (_jsx("div", { className: "xeno-combobox-chips", children: selectedValues.map((val) => {
216
+ const opt = options.find((o) => o.value === val);
217
+ return (_jsxs("span", { className: "xeno-combobox-chip", children: [_jsx("span", { children: opt?.label ?? val }), _jsx("button", { type: "button", className: "xeno-combobox-chip-x", "aria-label": `Remove ${opt?.label ?? val}`, disabled: disabled, onClick: (e) => {
218
+ e.stopPropagation();
219
+ removeValue(val);
220
+ }, children: "\u00D7" })] }, val));
221
+ }) })) : null, _jsx("input", { ref: inputRef, id: inputId, type: "text", role: "combobox", "aria-autocomplete": "list", "aria-expanded": open, "aria-controls": listboxId, "aria-activedescendant": activeOptId, "aria-label": label, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid || undefined, className: "xeno-combobox-input", value: query, placeholder: multiple && selectedValues.length > 0 ? '' : placeholder, disabled: disabled, onFocus: () => setOpen(true), onChange: (e) => {
222
+ setQuery(e.target.value);
223
+ setActiveIndex(0);
224
+ if (!open)
225
+ setOpen(true);
226
+ }, onKeyDown: onKeyDown })] })) }), panelProps: {
227
+ role: 'listbox',
228
+ id: listboxId,
229
+ 'aria-label': label,
230
+ 'aria-multiselectable': multiple || undefined,
231
+ className: 'xeno-select-list',
232
+ }, children: filtered.length === 0 ? (_jsx("div", { className: "xeno-select-empty", children: emptyMessage })) : (filtered.map((opt, idx) => {
233
+ const isSelected = selectedValues.includes(opt.value);
234
+ const isActive = idx === activeIndex;
235
+ return (_jsxs("div", { id: `${listboxId}-opt-${idx}`, role: "option", "aria-selected": isSelected, "aria-disabled": opt.disabled || undefined, className: "xeno-select-option", "data-selected": isSelected ? 'true' : undefined, "data-active": isActive ? 'true' : undefined, "data-disabled": opt.disabled ? 'true' : undefined, onMouseEnter: () => {
236
+ if (!opt.disabled)
237
+ setActiveIndex(idx);
238
+ }, onMouseDown: (e) => {
239
+ e.preventDefault();
240
+ selectOption(opt);
241
+ }, children: [_jsxs("span", { className: "xeno-select-opt-text", children: [_jsx("span", { className: "xeno-select-opt-label", children: opt.label }), opt.description ? (_jsx("span", { className: "xeno-select-opt-desc", children: opt.description })) : null] }), isSelected ? (_jsx("svg", { className: "xeno-select-check", width: "12", height: "12", viewBox: "0 0 12 12", fill: "none", stroke: "currentColor", strokeWidth: "1.75", "aria-hidden": "true", children: _jsx("path", { d: "M2.5 6.5l2.2 2.2 4.8-5.2" }) })) : null] }, opt.value));
242
+ })) }));
243
+ }
@@ -0,0 +1,38 @@
1
+ import type { HTMLAttributes, ReactElement } from 'react';
2
+ export interface SliderMark {
3
+ readonly value: number;
4
+ readonly label?: string;
5
+ }
6
+ export interface SliderProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onChange' | 'defaultValue'> {
7
+ /** Controlled numeric value. */
8
+ readonly value?: number;
9
+ /** Initial value when uncontrolled. */
10
+ readonly defaultValue?: number;
11
+ /** Minimum value. Defaults to `0`. */
12
+ readonly min?: number;
13
+ /** Maximum value. Defaults to `100`. */
14
+ readonly max?: number;
15
+ /** Step increment. Defaults to `1`. */
16
+ readonly step?: number;
17
+ /** Called whenever the value changes. */
18
+ readonly onChange?: (value: number) => void;
19
+ /** Accessible label (rendered visibly when `showLabel` is true). */
20
+ readonly label?: string;
21
+ /** Show the label above the track. Defaults to `false`. */
22
+ readonly showLabel?: boolean;
23
+ /** Show tabular formatted readout beside the label/track. Defaults to `false`. */
24
+ readonly showValue?: boolean;
25
+ /** Custom readout formatter (e.g. `(v) => `${v}%``). */
26
+ readonly formatValue?: (value: number) => string;
27
+ /** Optional discrete tick marks rendered along the track. */
28
+ readonly marks?: readonly SliderMark[];
29
+ /** Disables interaction. */
30
+ readonly disabled?: boolean;
31
+ /** Input id for external `<label>` / `<FormField>` association. */
32
+ readonly id?: string;
33
+ }
34
+ /**
35
+ * `<Slider>` — accessible Rung-1 continuous or stepped range control with tabular value readout,
36
+ * discrete tick marks, RTL logical direction support, and native keyboard step/Home/End/PageUp/PageDown.
37
+ */
38
+ export declare function Slider({ value: controlledValue, defaultValue, min, max, step, onChange, label, showLabel, showValue, formatValue, marks, disabled, id, className, ...rest }: SliderProps): ReactElement;
@@ -0,0 +1,31 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useId, useState } from 'react';
3
+ import { cx } from '../controls/util.js';
4
+ function clamp(v, min, max) {
5
+ return Math.min(max, Math.max(min, v));
6
+ }
7
+ /**
8
+ * `<Slider>` — accessible Rung-1 continuous or stepped range control with tabular value readout,
9
+ * discrete tick marks, RTL logical direction support, and native keyboard step/Home/End/PageUp/PageDown.
10
+ */
11
+ export function Slider({ value: controlledValue, defaultValue, min = 0, max = 100, step = 1, onChange, label, showLabel = false, showValue = false, formatValue = (v) => String(v), marks, disabled = false, id, className, ...rest }) {
12
+ const autoId = useId();
13
+ const inputId = id ?? `xeno-slider-${autoId}`;
14
+ const [uncontrolled, setUncontrolled] = useState(() => clamp(defaultValue ?? min, min, max));
15
+ const current = clamp(controlledValue ?? uncontrolled, min, max);
16
+ const pct = max > min ? ((current - min) / (max - min)) * 100 : 0;
17
+ const handleChange = (e) => {
18
+ const next = clamp(Number(e.target.value), min, max);
19
+ if (controlledValue === undefined)
20
+ setUncontrolled(next);
21
+ onChange?.(next);
22
+ };
23
+ return (_jsxs("div", { className: cx('xeno-slider', className), "data-disabled": disabled ? 'true' : undefined, ...rest, children: [(showLabel && label) || showValue ? (_jsxs("div", { className: "xeno-slider-head", children: [showLabel && label ? (_jsx("label", { className: "xeno-slider-label", htmlFor: inputId, children: label })) : _jsx("span", {}), showValue ? (_jsx("span", { className: "xeno-slider-value", children: formatValue(current) })) : null] })) : null, _jsxs("div", { className: "xeno-slider-track-wrap", children: [_jsx("div", { className: "xeno-slider-track", "aria-hidden": "true", children: _jsx("div", { className: "xeno-slider-fill", style: { width: `${pct}%` } }) }), _jsx("input", { id: inputId, type: "range", className: "xeno-slider-input", min: min, max: max, step: step, value: current, disabled: disabled, "aria-label": !showLabel ? label : undefined, "aria-valuetext": formatValue(current), onChange: handleChange })] }), marks && marks.length > 0 ? (_jsx("div", { className: "xeno-slider-marks", children: marks.map((mark) => {
24
+ const mPct = max > min ? ((clamp(mark.value, min, max) - min) / (max - min)) * 100 : 0;
25
+ return (_jsx("button", { type: "button", className: "xeno-slider-mark", "data-active": current === mark.value ? 'true' : undefined, style: { insetInlineStart: `${mPct}%` }, disabled: disabled, onClick: () => {
26
+ if (controlledValue === undefined)
27
+ setUncontrolled(mark.value);
28
+ onChange?.(mark.value);
29
+ }, children: mark.label ?? formatValue(mark.value) }, mark.value));
30
+ }) })) : null] }));
31
+ }
package/dist/index.d.ts CHANGED
@@ -49,6 +49,7 @@ export { Popover, type PopoverProps } from './overlays/Popover.js';
49
49
  export { Menu, type MenuProps } from './overlays/Menu.js';
50
50
  export { MenuItem, type MenuItemProps, type MenuItemVariant } from './overlays/MenuItem.js';
51
51
  export { Modal, Sheet, type ModalProps, type SheetProps, type ModalVariant } from './overlays/Modal.js';
52
+ export { Drawer, type DrawerProps, type DrawerSide } from './overlays/Drawer.js';
52
53
  export { Tabs, type TabsProps, type TabItem } from './overlays/Tabs.js';
53
54
  export { SegmentedControl, type SegmentedControlProps, type SegmentedOption } from './overlays/SegmentedControl.js';
54
55
  export { PillFilter, type PillFilterProps, type PillOption } from './overlays/PillFilter.js';
@@ -61,6 +62,10 @@ export { CommandPalette, type CommandPaletteProps, type CommandPaletteItem, } fr
61
62
  export { ShortcutsSheet, type ShortcutsSheetProps, type ShortcutSection, type ShortcutEntry, } from './overlays/ShortcutsSheet.js';
62
63
  export { Checkbox, type CheckboxProps, type CheckboxState } from './forms/Checkbox.js';
63
64
  export { RadioGroup, type RadioGroupProps, RadioRow, type RadioRowProps, type RadioOption } from './forms/RadioGroup.js';
65
+ export { FormField, type FormFieldProps, type FormFieldControlProps } from './forms/FormField.js';
66
+ export { Select, Combobox, type SelectProps, type ComboboxProps, type SelectOption } from './forms/Select.js';
67
+ export { Slider, type SliderProps, type SliderMark } from './forms/Slider.js';
68
+ export { NumberInput, type NumberInputProps } from './forms/NumberInput.js';
64
69
  export { CodeBlock, type CodeBlockProps, type CodeBlockOutput, type CodeBlockOutputStatus, } from './content/CodeBlock.js';
65
70
  export { SourceCard, type SourceCardProps } from './content/SourceCard.js';
66
71
  export { SourcesDisclosure, type SourcesDisclosureProps, type SourceRef } from './content/SourcesDisclosure.js';
@@ -72,6 +77,7 @@ export { Collapsible, type CollapsibleProps } from './content/Collapsible.js';
72
77
  export { Caret, type CaretProps } from './content/Caret.js';
73
78
  export { Sidebar, type SidebarProps, type SidebarItem, type SidebarSection } from './nav/Sidebar.js';
74
79
  export { Breadcrumb, type BreadcrumbProps, type BreadcrumbItem } from './nav/Breadcrumb.js';
80
+ export { Pagination, type PaginationProps } from './nav/Pagination.js';
75
81
  export { ResizablePanel, type ResizablePanelProps, type ResizablePanelSide } from './layout/ResizablePanel.js';
76
82
  export { ThinkingCube, type ThinkingCubeProps, type ThinkingCubeState } from './status/ThinkingCube.js';
77
83
  export { Spinner, type SpinnerProps } from './status/Spinner.js';
@@ -80,6 +86,8 @@ export { StepTimeline, type StepTimelineProps, type Step, type StepStatus } from
80
86
  export { StatusIndicator, type StatusIndicatorProps, type StatusIndicatorTone } from './status/StatusIndicator.js';
81
87
  export { Banner, type BannerProps, type BannerTone } from './status/Banner.js';
82
88
  export { Toast, ToastStack, type ToastProps, type ToastStackProps, type ToastTone } from './status/Toast.js';
89
+ export { Skeleton, SkeletonContainer, type SkeletonProps, type SkeletonContainerProps } from './status/Skeleton.js';
90
+ export { EmptyState, type EmptyStateProps } from './status/EmptyState.js';
83
91
  export { computeTooltipPosition, type TooltipPosition } from './overlays/Tooltip.js';
84
92
  export { useShortcutRegistry, formatShortcutKeys, detectShortcutCollisions, toShortcutSections, toCommandItems, type ShortcutBinding, type ShortcutCollision, type UseShortcutRegistryResult, } from './shortcuts.js';
85
93
  export { useToastQueue, type QueuedToast, type PushToastInput, type UseToastQueueResult, } from './useToastQueue.js';
package/dist/index.js CHANGED
@@ -51,6 +51,7 @@ export { Popover } from './overlays/Popover.js';
51
51
  export { Menu } from './overlays/Menu.js';
52
52
  export { MenuItem } from './overlays/MenuItem.js';
53
53
  export { Modal, Sheet } from './overlays/Modal.js';
54
+ export { Drawer } from './overlays/Drawer.js';
54
55
  export { Tabs } from './overlays/Tabs.js';
55
56
  export { SegmentedControl } from './overlays/SegmentedControl.js';
56
57
  export { PillFilter } from './overlays/PillFilter.js';
@@ -63,6 +64,10 @@ export { ShortcutsSheet, } from './overlays/ShortcutsSheet.js';
63
64
  // ── Forms ───────────────────────────────────────────────────────────────────────────────────────
64
65
  export { Checkbox } from './forms/Checkbox.js';
65
66
  export { RadioGroup, RadioRow } from './forms/RadioGroup.js';
67
+ export { FormField } from './forms/FormField.js';
68
+ export { Select, Combobox } from './forms/Select.js';
69
+ export { Slider } from './forms/Slider.js';
70
+ export { NumberInput } from './forms/NumberInput.js';
66
71
  // ── Content ─────────────────────────────────────────────────────────────────────────────────────
67
72
  export { CodeBlock, } from './content/CodeBlock.js';
68
73
  export { SourceCard } from './content/SourceCard.js';
@@ -76,6 +81,7 @@ export { Caret } from './content/Caret.js';
76
81
  // ── Nav ─────────────────────────────────────────────────────────────────────────────────────────
77
82
  export { Sidebar } from './nav/Sidebar.js';
78
83
  export { Breadcrumb } from './nav/Breadcrumb.js';
84
+ export { Pagination } from './nav/Pagination.js';
79
85
  // ── Layout ──────────────────────────────────────────────────────────────────────────────────────
80
86
  export { ResizablePanel } from './layout/ResizablePanel.js';
81
87
  // ── Status ──────────────────────────────────────────────────────────────────────────────────────
@@ -86,6 +92,8 @@ export { StepTimeline } from './status/StepTimeline.js';
86
92
  export { StatusIndicator } from './status/StatusIndicator.js';
87
93
  export { Banner } from './status/Banner.js';
88
94
  export { Toast, ToastStack } from './status/Toast.js';
95
+ export { Skeleton, SkeletonContainer } from './status/Skeleton.js';
96
+ export { EmptyState } from './status/EmptyState.js';
89
97
  export { computeTooltipPosition } from './overlays/Tooltip.js';
90
98
  export { useShortcutRegistry, formatShortcutKeys, detectShortcutCollisions, toShortcutSections, toCommandItems, } from './shortcuts.js';
91
99
  export { useToastQueue, } from './useToastQueue.js';