@finstack-com-public/design 0.10.3 → 0.11.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 +40 -0
- package/dist/css/combobox.css +58 -0
- package/dist/css/combobox.md +75 -0
- package/dist/css/input.md +6 -1
- package/dist/css/select.css +103 -0
- package/dist/css/select.md +69 -0
- package/dist/css/slider.css +169 -0
- package/dist/css/slider.md +87 -0
- package/dist/css/switch.css +137 -0
- package/dist/css/switch.md +28 -0
- package/dist/css-text/combobox.d.ts +2 -0
- package/dist/css-text/combobox.js +1 -0
- package/dist/css-text/kit.js +471 -0
- package/dist/css-text/select.d.ts +2 -0
- package/dist/css-text/select.js +1 -0
- package/dist/css-text/slider.d.ts +2 -0
- package/dist/css-text/slider.js +1 -0
- package/dist/css-text/switch.d.ts +2 -0
- package/dist/css-text/switch.js +1 -0
- package/dist/dom/combobox.d.ts +47 -0
- package/dist/dom/combobox.js +178 -0
- package/dist/dom/index.d.ts +3 -0
- package/dist/dom/index.js +3 -0
- package/dist/dom/listbox.d.ts +11 -0
- package/dist/dom/listbox.js +9 -3
- package/dist/dom/select.d.ts +39 -0
- package/dist/dom/select.js +221 -0
- package/dist/dom/slider.d.ts +51 -0
- package/dist/dom/slider.js +256 -0
- package/dist/kit.css +471 -0
- package/dist/react/actions.js +12 -6
- package/dist/react/inputs.d.ts +181 -0
- package/dist/react/inputs.js +291 -15
- package/dist/react/navigation.js +33 -15
- package/dist/tokens/contrast-pairs.js +4 -0
- package/package.json +1 -1
package/dist/react/inputs.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { type ButtonHTMLAttributes, type HTMLAttributes, type InputHTMLAttributes, type OutputHTMLAttributes, type ReactNode, type RefObject, type SelectHTMLAttributes, type TextareaHTMLAttributes } from 'react';
|
|
2
2
|
import { type CalendarOptions, type CalendarRange, type CalendarRangeChangeDetail, type CalendarRangeLabels } from '../dom/calendar.ts';
|
|
3
|
+
import type { Placement } from '../dom/position.ts';
|
|
4
|
+
import { type CompletionKind } from './editor.tsx';
|
|
3
5
|
type Tone = 'neutral' | 'caution' | 'warning' | 'danger';
|
|
4
6
|
/** What Field hands its control: spread it onto the input. */
|
|
5
7
|
export interface FieldControlProps {
|
|
@@ -41,12 +43,131 @@ export declare const PickerButton: import("react").ForwardRefExoticComponent<But
|
|
|
41
43
|
export declare const Textarea: import("react").ForwardRefExoticComponent<TextareaHTMLAttributes<HTMLTextAreaElement> & import("react").RefAttributes<HTMLTextAreaElement>>;
|
|
42
44
|
/** The native select in the wrapper that draws its chevron. `className` goes on the wrapper. */
|
|
43
45
|
export declare const Select: import("react").ForwardRefExoticComponent<SelectHTMLAttributes<HTMLSelectElement> & import("react").RefAttributes<HTMLSelectElement>>;
|
|
46
|
+
export interface ListboxSelectItem {
|
|
47
|
+
id: string;
|
|
48
|
+
/** The option's text, also shown on the trigger when it is the value and matched by typeahead. */
|
|
49
|
+
label: string;
|
|
50
|
+
/** Muted text at the right, cut with "…". */
|
|
51
|
+
detail?: ReactNode;
|
|
52
|
+
/** A Lucide name drawn before the label (decoration). */
|
|
53
|
+
icon?: string;
|
|
54
|
+
disabled?: boolean;
|
|
55
|
+
}
|
|
56
|
+
export interface ListboxSelectProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onChange' | 'defaultValue' | 'children' | 'placeholder'> {
|
|
57
|
+
/** The list's accessible name, and the trigger's unless `aria-labelledby` names a label. Required. */
|
|
58
|
+
label: string;
|
|
59
|
+
items: readonly ListboxSelectItem[];
|
|
60
|
+
/** Controlled: the chosen item's id, or null. A refused value is put back. */
|
|
61
|
+
value?: string | null;
|
|
62
|
+
/** Uncontrolled: the first value. */
|
|
63
|
+
defaultValue?: string | null;
|
|
64
|
+
/** An item was accepted and the value changed: its id. */
|
|
65
|
+
onChange?: (id: string) => void;
|
|
66
|
+
/** Shown on the trigger with no value, muted. */
|
|
67
|
+
placeholder?: ReactNode;
|
|
68
|
+
/** Controlled: whether the list is shown. */
|
|
69
|
+
open?: boolean;
|
|
70
|
+
defaultOpen?: boolean;
|
|
71
|
+
onOpenChange?: (open: boolean) => void;
|
|
72
|
+
/** Renders a hidden `<input name>` holding the value's id, for a form (T132 S4). */
|
|
73
|
+
name?: string;
|
|
74
|
+
/** `aria-disabled` on the trigger: it stays focusable and never opens. */
|
|
75
|
+
disabled?: boolean;
|
|
76
|
+
/** `aria-invalid` on the trigger. */
|
|
77
|
+
invalid?: boolean;
|
|
78
|
+
/** `aria-readonly` on the trigger: no edge, no chevron, never opens. */
|
|
79
|
+
readOnly?: boolean;
|
|
80
|
+
placement?: Placement;
|
|
81
|
+
/** How long typed letters keep adding to one search, in ms. Default 500. */
|
|
82
|
+
typeaheadTimeout?: number;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The custom select (F2 draft §2, T132) on createSelect: a select-only combobox whose options can
|
|
86
|
+
* carry an icon and a detail. `className` goes on the wrapper, the ref and other props on the
|
|
87
|
+
* trigger (as `Select`), so a Field's control props spread onto it. The native `Select` stays the
|
|
88
|
+
* default.
|
|
89
|
+
*/
|
|
90
|
+
export declare const ListboxSelect: import("react").ForwardRefExoticComponent<ListboxSelectProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
91
|
+
export type ComboboxItem = {
|
|
92
|
+
id: string;
|
|
93
|
+
/** The option's text, written into the input when it is accepted. */
|
|
94
|
+
label: string;
|
|
95
|
+
/** Muted text at the right, cut with "…". */
|
|
96
|
+
detail?: ReactNode;
|
|
97
|
+
disabled?: boolean;
|
|
98
|
+
} & ({
|
|
99
|
+
kind?: undefined;
|
|
100
|
+
kindLabel?: undefined;
|
|
101
|
+
}
|
|
102
|
+
/** `kindLabel` is the kind in words ("measure"), for screen readers: the icon is decoration. */
|
|
103
|
+
| {
|
|
104
|
+
kind: CompletionKind;
|
|
105
|
+
kindLabel: string;
|
|
106
|
+
});
|
|
107
|
+
/** Options under a heading (T133 C1): a `role="group"` named by its `__group-label`. */
|
|
108
|
+
export interface ComboboxGroup {
|
|
109
|
+
id: string;
|
|
110
|
+
label: string;
|
|
111
|
+
items: readonly ComboboxItem[];
|
|
112
|
+
}
|
|
113
|
+
export interface ComboboxProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'value' | 'defaultValue' | 'onChange' | 'children' | 'role' | 'type' | 'aria-autocomplete'> {
|
|
114
|
+
/**
|
|
115
|
+
* The list's accessible name. Required. It also names the input when nothing else does (no
|
|
116
|
+
* `id` for a `<label for>`, no `aria-label`, no `aria-labelledby`).
|
|
117
|
+
*/
|
|
118
|
+
label: string;
|
|
119
|
+
/** The options to show: the product passes the filtered set. Items, or groups of items. */
|
|
120
|
+
items: readonly (ComboboxItem | ComboboxGroup)[];
|
|
121
|
+
/** The line shown when no item matches ("No matches"). Required. */
|
|
122
|
+
emptyText: ReactNode;
|
|
123
|
+
/** Controlled: the input's text. */
|
|
124
|
+
value?: string;
|
|
125
|
+
/** Uncontrolled: the first text. */
|
|
126
|
+
defaultValue?: string;
|
|
127
|
+
/**
|
|
128
|
+
* The text changed: typed (`id` null), an item accepted (its id), cleared by Escape (`''`, null),
|
|
129
|
+
* or, with `strict`, a commit matching no item (null). A refused controlled value is put back.
|
|
130
|
+
*/
|
|
131
|
+
onChange?: (value: string, id: string | null) => void;
|
|
132
|
+
/** The user typed (or Escape cleared the input): filter `items` here. */
|
|
133
|
+
onInputChange?: (text: string) => void;
|
|
134
|
+
/** Controlled: whether the list is shown. */
|
|
135
|
+
open?: boolean;
|
|
136
|
+
defaultOpen?: boolean;
|
|
137
|
+
onOpenChange?: (open: boolean) => void;
|
|
138
|
+
/** Renders the toggle button, named by this. Read when it mounts. */
|
|
139
|
+
toggleLabel?: string;
|
|
140
|
+
/** `aria-autocomplete`: `'list'` (default) when `items` follow the text, `'none'` when not. */
|
|
141
|
+
autocomplete?: 'list' | 'none';
|
|
142
|
+
/** Only an item's label is accepted (see createCombobox); the product sets `aria-invalid`. */
|
|
143
|
+
strict?: boolean;
|
|
144
|
+
/** Escape on a closed list clears the input. */
|
|
145
|
+
clearOnEscape?: boolean;
|
|
146
|
+
placement?: Placement;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* The editable combobox (F2 draft §1, T133) on createCombobox: a text input with list
|
|
150
|
+
* autocomplete. Typing opens the list and calls `onInputChange`, where the product filters
|
|
151
|
+
* `items`. `className` goes on the wrapper, the ref and other props on the input, so a Field's
|
|
152
|
+
* control props spread onto it.
|
|
153
|
+
*/
|
|
154
|
+
export declare const Combobox: import("react").ForwardRefExoticComponent<ComboboxProps & import("react").RefAttributes<HTMLInputElement>>;
|
|
44
155
|
export interface CheckProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'type'> {
|
|
45
156
|
/** The visible label. Required. */
|
|
46
157
|
label: ReactNode;
|
|
47
158
|
}
|
|
48
159
|
export declare const Checkbox: import("react").ForwardRefExoticComponent<CheckProps & import("react").RefAttributes<HTMLInputElement>>;
|
|
49
160
|
export declare const Radio: import("react").ForwardRefExoticComponent<CheckProps & import("react").RefAttributes<HTMLInputElement>>;
|
|
161
|
+
export interface SwitchProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'type' | 'role'> {
|
|
162
|
+
/** The visible label. Required. */
|
|
163
|
+
label: ReactNode;
|
|
164
|
+
/** `'before'` puts the label first and the switch at the row's end (`--end`). */
|
|
165
|
+
labelPosition?: 'after' | 'before';
|
|
166
|
+
/** aria-busy on the row while the change is on its way: the knob keeps its place, without motion. */
|
|
167
|
+
busy?: boolean;
|
|
168
|
+
}
|
|
169
|
+
/** A switch that acts at once: a native checkbox with `role="switch"`. For a choice applied later, use Checkbox. */
|
|
170
|
+
export declare const Switch: import("react").ForwardRefExoticComponent<SwitchProps & import("react").RefAttributes<HTMLInputElement>>;
|
|
50
171
|
export interface ChipProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
51
172
|
pressed?: boolean;
|
|
52
173
|
}
|
|
@@ -116,3 +237,63 @@ export interface DateRangeCalendarProps extends Omit<HTMLAttributes<HTMLDivEleme
|
|
|
116
237
|
* root. A pending start lives in the helper: a parent re-rendering the same range keeps it.
|
|
117
238
|
*/
|
|
118
239
|
export declare const DateRangeCalendar: import("react").ForwardRefExoticComponent<DateRangeCalendarProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
240
|
+
export type { RangeSliderChangeDetail, SliderChangeDetail, SliderLabels } from '../dom/slider.ts';
|
|
241
|
+
/** The props both sliders take. */
|
|
242
|
+
interface SliderCommonProps {
|
|
243
|
+
min: number;
|
|
244
|
+
max: number;
|
|
245
|
+
/** Values snap to `step` from `min`. Default 1. */
|
|
246
|
+
step?: number;
|
|
247
|
+
/** PageUp/PageDown's step. Default ten steps. */
|
|
248
|
+
pageStep?: number;
|
|
249
|
+
/** The value in words, for `aria-valuetext` and the shown value ("40 %"). Required. */
|
|
250
|
+
valueText: (value: number) => string;
|
|
251
|
+
/** Renders the `__value` output after the track. */
|
|
252
|
+
showValue?: boolean;
|
|
253
|
+
/** Values to mark under the track (unlabelled, Q3). */
|
|
254
|
+
ticks?: readonly number[];
|
|
255
|
+
/** `aria-disabled` on the thumbs: reachable, not movable. */
|
|
256
|
+
disabled?: boolean;
|
|
257
|
+
/** Renders a hidden `<input name>` per thumb holding its value, for a form (S4). */
|
|
258
|
+
name?: string;
|
|
259
|
+
}
|
|
260
|
+
export interface SliderProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onChange' | 'onInput' | 'defaultValue' | 'children'>, SliderCommonProps {
|
|
261
|
+
/** The thumb's accessible name, unless `aria-labelledby` names a visible label. Required. */
|
|
262
|
+
label: string;
|
|
263
|
+
/** Controlled: the value. A refused value is put back when the move ends. */
|
|
264
|
+
value?: number;
|
|
265
|
+
/** Uncontrolled: the first value. Default `min`. */
|
|
266
|
+
defaultValue?: number;
|
|
267
|
+
/** While it moves (each key press, each pointer move that changes it). */
|
|
268
|
+
onInput?: (value: number) => void;
|
|
269
|
+
/** When a move ends (each key press, or the pointer's release) with a new value. */
|
|
270
|
+
onChange?: (value: number) => void;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* The slider (F2 draft §4, T134) on createSlider. `className` goes on the `.fs-slider` root, the ref
|
|
274
|
+
* and other props on the thumb (as `ListboxSelect`'s trigger), so a Field's control props spread
|
|
275
|
+
* onto it. The thumb is named by `label`; a Field's `<label for>` can't name a `div`.
|
|
276
|
+
*/
|
|
277
|
+
export declare const Slider: import("react").ForwardRefExoticComponent<SliderProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
278
|
+
export interface RangeSliderProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onChange' | 'onInput' | 'defaultValue' | 'children'>, SliderCommonProps {
|
|
279
|
+
/** The group's accessible name, unless `aria-labelledby` names a visible label. Required. */
|
|
280
|
+
label: string;
|
|
281
|
+
/** The lower thumb's name ("From"). Required. */
|
|
282
|
+
startLabel: string;
|
|
283
|
+
/** The upper thumb's name ("To"). Required. */
|
|
284
|
+
endLabel: string;
|
|
285
|
+
/** Controlled: both ends, lower first. A refused range is put back when the move ends. */
|
|
286
|
+
value?: readonly [number, number];
|
|
287
|
+
/** Uncontrolled: the first range. Default `[min, max]`. */
|
|
288
|
+
defaultValue?: readonly [number, number];
|
|
289
|
+
/** While a thumb moves. */
|
|
290
|
+
onInput?: (value: [number, number]) => void;
|
|
291
|
+
/** When a move ends with a new range. */
|
|
292
|
+
onChange?: (value: [number, number]) => void;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* The range slider (F2 draft §4, T134): two dependent thumbs that never cross, on createSlider with a
|
|
296
|
+
* `[low, high]` value. A separate wrapper, as `DateRangeCalendar`, since the value and names differ.
|
|
297
|
+
* `className`, the ref and other props go on the `.fs-slider` root, a `role="group"` named by `label`.
|
|
298
|
+
*/
|
|
299
|
+
export declare const RangeSlider: import("react").ForwardRefExoticComponent<RangeSliderProps & import("react").RefAttributes<HTMLDivElement>>;
|
package/dist/react/inputs.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
// React wrappers for spec 02 B: inputs.
|
|
3
|
-
import { forwardRef, useId, useRef, } from 'react';
|
|
3
|
+
import { forwardRef, useId, useRef, useState, } from 'react';
|
|
4
4
|
import { createCalendar, } from "../dom/calendar.js";
|
|
5
|
+
import { createCombobox } from "../dom/combobox.js";
|
|
6
|
+
import { createSelect } from "../dom/select.js";
|
|
7
|
+
import { createSlider, rangeValueText, } from "../dom/slider.js";
|
|
8
|
+
import { completionKindIcons } from "./editor.js";
|
|
5
9
|
import { Icon } from "./icon.js";
|
|
6
10
|
import { cx, useFsEvent, useIsoLayoutEffect, useLatest, useMergedRef } from "./util.js";
|
|
7
11
|
const MESSAGE_ICON = { warning: 'triangle-alert', danger: 'circle-alert' };
|
|
@@ -39,12 +43,176 @@ export const Textarea = forwardRef(function Textarea({ className, ...rest }, ref
|
|
|
39
43
|
export const Select = forwardRef(function Select({ className, ...rest }, ref) {
|
|
40
44
|
return (_jsx("span", { className: cx('fs-select', className), children: _jsx("select", { ref: ref, className: "fs-select__control", ...rest }) }));
|
|
41
45
|
});
|
|
46
|
+
/**
|
|
47
|
+
* The custom select (F2 draft §2, T132) on createSelect: a select-only combobox whose options can
|
|
48
|
+
* carry an icon and a detail. `className` goes on the wrapper, the ref and other props on the
|
|
49
|
+
* trigger (as `Select`), so a Field's control props spread onto it. The native `Select` stays the
|
|
50
|
+
* default.
|
|
51
|
+
*/
|
|
52
|
+
export const ListboxSelect = forwardRef(function ListboxSelect({ label, items, value, defaultValue, onChange, placeholder, open, defaultOpen, onOpenChange, name, disabled, invalid, readOnly, placement, typeaheadTimeout, className, 'aria-labelledby': labelledBy, ...rest }, ref) {
|
|
53
|
+
const base = useId();
|
|
54
|
+
const root = useRef(null);
|
|
55
|
+
const trigger = useRef(null);
|
|
56
|
+
const list = useRef(null);
|
|
57
|
+
const ctl = useRef(null);
|
|
58
|
+
const [own, setOwn] = useState(defaultValue ?? null);
|
|
59
|
+
const current = value !== undefined ? value : own;
|
|
60
|
+
const latestValue = useLatest(value);
|
|
61
|
+
const prefix = `${base}-o-`;
|
|
62
|
+
const domId = (id) => (id === null ? null : `${prefix}${id}`);
|
|
63
|
+
const chosen = items.find((i) => i.id === current);
|
|
64
|
+
const initial = useLatest({ open: open ?? defaultOpen, value: current, placement, typeaheadTimeout });
|
|
65
|
+
// The helper keeps only the value and the keys: React renders the trigger's text, the mark and
|
|
66
|
+
// the hidden input (writeValue: false).
|
|
67
|
+
useIsoLayoutEffect(() => {
|
|
68
|
+
const { open: shown, value: first, ...rest } = initial.current;
|
|
69
|
+
const set = Object.fromEntries(Object.entries(rest).filter(([, v]) => v !== undefined));
|
|
70
|
+
ctl.current = createSelect(root.current, {
|
|
71
|
+
trigger: trigger.current,
|
|
72
|
+
list: list.current,
|
|
73
|
+
value: domId(first),
|
|
74
|
+
writeValue: false,
|
|
75
|
+
...set,
|
|
76
|
+
});
|
|
77
|
+
if (shown)
|
|
78
|
+
ctl.current.open();
|
|
79
|
+
return () => {
|
|
80
|
+
ctl.current?.destroy();
|
|
81
|
+
ctl.current = null;
|
|
82
|
+
};
|
|
83
|
+
}, []);
|
|
84
|
+
useIsoLayoutEffect(() => {
|
|
85
|
+
const set = Object.fromEntries(Object.entries({ placement, typeaheadTimeout }).filter(([, v]) => v !== undefined));
|
|
86
|
+
ctl.current?.update(set);
|
|
87
|
+
}, [placement, typeaheadTimeout]);
|
|
88
|
+
// New options, or a new value: the helper re-reads them.
|
|
89
|
+
useIsoLayoutEffect(() => {
|
|
90
|
+
ctl.current?.update({ value: domId(current) });
|
|
91
|
+
}, [items, current]);
|
|
92
|
+
// As Slider's: a re-render after each fs-change, in the parent's batch, puts back a controlled value
|
|
93
|
+
// the parent didn't take. Not a microtask, which could run before the parent's render (I25).
|
|
94
|
+
const [settled, settle] = useState(0);
|
|
95
|
+
useIsoLayoutEffect(() => {
|
|
96
|
+
if (settled && ctl.current && ctl.current.value !== domId(current))
|
|
97
|
+
ctl.current.setValue(domId(current));
|
|
98
|
+
}, [settled]);
|
|
99
|
+
useIsoLayoutEffect(() => {
|
|
100
|
+
if (open === undefined || !ctl.current)
|
|
101
|
+
return;
|
|
102
|
+
if (open && !ctl.current.isOpen)
|
|
103
|
+
ctl.current.open();
|
|
104
|
+
if (!open && ctl.current.isOpen)
|
|
105
|
+
ctl.current.close();
|
|
106
|
+
}, [open]);
|
|
107
|
+
useFsEvent(root, 'fs-change', ({ value: picked }) => {
|
|
108
|
+
const id = picked.slice(prefix.length);
|
|
109
|
+
if (latestValue.current === undefined)
|
|
110
|
+
setOwn(id);
|
|
111
|
+
else
|
|
112
|
+
settle((n) => n + 1);
|
|
113
|
+
onChange?.(id);
|
|
114
|
+
});
|
|
115
|
+
useFsEvent(list, 'fs-open', () => onOpenChange?.(true));
|
|
116
|
+
useFsEvent(list, 'fs-close', () => onOpenChange?.(false));
|
|
117
|
+
const nameId = `${base}-name`;
|
|
118
|
+
const valueId = `${base}-value`;
|
|
119
|
+
return (_jsxs("div", { ref: root, className: cx('fs-select', 'fs-select--listbox', className), children: [labelledBy === undefined && (_jsx("span", { id: nameId, hidden: true, children: label })), _jsx("div", { ref: useMergedRef(trigger, ref), className: "fs-select__control fs-select__trigger", role: "combobox", tabIndex: 0, "aria-labelledby": `${labelledBy ?? nameId} ${valueId}`, "aria-disabled": disabled || undefined, "aria-invalid": invalid || undefined, "aria-readonly": readOnly || undefined, ...rest, children: chosen ? (_jsx("span", { className: "fs-select__value", id: valueId, children: chosen.label })) : (_jsx("span", { className: "fs-select__placeholder", id: valueId, children: placeholder })) }), _jsx("div", { ref: list, id: `${base}-list`, className: "fs-menu fs-menu--listbox", role: "listbox", "aria-label": label, hidden: true, children: items.map((item) => (_jsxs("div", { id: `${prefix}${item.id}`, className: cx('fs-menu__item', item.id === current && 'fs-is-value'), role: "option", "aria-disabled": item.disabled || undefined, children: [item.icon && _jsx(Icon, { name: item.icon }), _jsx("span", { className: "fs-menu__label", children: item.label }), item.detail !== undefined && _jsx("span", { className: "fs-menu__detail", children: item.detail })] }, item.id))) }), name !== undefined && _jsx("input", { type: "hidden", name: name, value: current ?? '', disabled: disabled || undefined })] }));
|
|
120
|
+
});
|
|
121
|
+
const isGroup = (entry) => 'items' in entry;
|
|
122
|
+
/**
|
|
123
|
+
* The editable combobox (F2 draft §1, T133) on createCombobox: a text input with list
|
|
124
|
+
* autocomplete. Typing opens the list and calls `onInputChange`, where the product filters
|
|
125
|
+
* `items`. `className` goes on the wrapper, the ref and other props on the input, so a Field's
|
|
126
|
+
* control props spread onto it.
|
|
127
|
+
*/
|
|
128
|
+
export const Combobox = forwardRef(function Combobox({ label, items, emptyText, value, defaultValue, onChange, onInputChange, open, defaultOpen, onOpenChange, toggleLabel, autocomplete, strict, clearOnEscape, placement, className, ...rest }, ref) {
|
|
129
|
+
const base = useId();
|
|
130
|
+
const root = useRef(null);
|
|
131
|
+
const input = useRef(null);
|
|
132
|
+
const list = useRef(null);
|
|
133
|
+
const toggle = useRef(null);
|
|
134
|
+
const ctl = useRef(null);
|
|
135
|
+
const [own, setOwn] = useState(defaultValue ?? '');
|
|
136
|
+
const text = value !== undefined ? value : own;
|
|
137
|
+
const latestValue = useLatest(value);
|
|
138
|
+
const prefix = `${base}-o-`;
|
|
139
|
+
const settings = { autocomplete, strict, clearOnEscape, placement };
|
|
140
|
+
const defined = (o) => Object.fromEntries(Object.entries(o).filter(([, v]) => v !== undefined));
|
|
141
|
+
const initial = useLatest({ open: open ?? defaultOpen, settings });
|
|
142
|
+
useIsoLayoutEffect(() => {
|
|
143
|
+
ctl.current = createCombobox(root.current, {
|
|
144
|
+
input: input.current,
|
|
145
|
+
list: list.current,
|
|
146
|
+
toggle: toggle.current,
|
|
147
|
+
...defined(initial.current.settings),
|
|
148
|
+
});
|
|
149
|
+
if (initial.current.open)
|
|
150
|
+
ctl.current.open();
|
|
151
|
+
return () => {
|
|
152
|
+
ctl.current?.destroy();
|
|
153
|
+
ctl.current = null;
|
|
154
|
+
};
|
|
155
|
+
}, []);
|
|
156
|
+
useIsoLayoutEffect(() => {
|
|
157
|
+
ctl.current?.update(defined(settings));
|
|
158
|
+
}, [autocomplete, strict, clearOnEscape, placement]);
|
|
159
|
+
// The filtered options changed: the helper re-reads them.
|
|
160
|
+
useIsoLayoutEffect(() => {
|
|
161
|
+
ctl.current?.update();
|
|
162
|
+
}, [items]);
|
|
163
|
+
useIsoLayoutEffect(() => {
|
|
164
|
+
if (open === undefined || !ctl.current)
|
|
165
|
+
return;
|
|
166
|
+
if (open && !ctl.current.isOpen)
|
|
167
|
+
ctl.current.open();
|
|
168
|
+
if (!open && ctl.current.isOpen)
|
|
169
|
+
ctl.current.close();
|
|
170
|
+
}, [open]);
|
|
171
|
+
// As Slider's: a re-render after each report, in the parent's batch, puts back a controlled text the
|
|
172
|
+
// parent didn't take. Not a microtask, which could run before the parent's render (I25).
|
|
173
|
+
const [settled, settle] = useState(0);
|
|
174
|
+
useIsoLayoutEffect(() => {
|
|
175
|
+
if (settled && value !== undefined && input.current && input.current.value !== value)
|
|
176
|
+
input.current.value = value;
|
|
177
|
+
}, [settled]);
|
|
178
|
+
/** Tells the parent; a controlled text it didn't take is put back. */
|
|
179
|
+
function report(next, id) {
|
|
180
|
+
if (latestValue.current === undefined)
|
|
181
|
+
setOwn(next);
|
|
182
|
+
else
|
|
183
|
+
settle((n) => n + 1);
|
|
184
|
+
onChange?.(next, id);
|
|
185
|
+
}
|
|
186
|
+
useFsEvent(root, 'fs-change', ({ value: next, option }) => {
|
|
187
|
+
report(next, option ? option.id.slice(prefix.length) : null);
|
|
188
|
+
if (!option && next === '')
|
|
189
|
+
onInputChange?.('');
|
|
190
|
+
});
|
|
191
|
+
useFsEvent(list, 'fs-open', () => onOpenChange?.(true));
|
|
192
|
+
useFsEvent(list, 'fs-close', () => onOpenChange?.(false));
|
|
193
|
+
const option = (item) => (_jsxs("div", { id: `${prefix}${item.id}`, className: "fs-menu__item", role: "option", "aria-disabled": item.disabled || undefined, children: [item.kind && _jsx(Icon, { name: completionKindIcons[item.kind], className: "fs-menu__kind" }), _jsx("span", { className: "fs-menu__label", children: item.label }), item.kind && _jsx("span", { className: "fs-visually-hidden", children: `, ${item.kindLabel}` }), item.detail !== undefined && _jsx("span", { className: "fs-menu__detail", children: item.detail })] }, item.id));
|
|
194
|
+
const count = items.reduce((n, e) => n + (isGroup(e) ? e.items.length : 1), 0);
|
|
195
|
+
const named = rest.id !== undefined || rest['aria-label'] !== undefined || rest['aria-labelledby'] !== undefined;
|
|
196
|
+
return (_jsxs("div", { ref: root, className: cx('fs-combobox', className), children: [_jsx("input", { ref: useMergedRef(input, ref), className: "fs-input", type: "text", role: "combobox", autoComplete: "off", "aria-autocomplete": autocomplete ?? 'list', "aria-label": named ? undefined : label, ...rest, value: text, onChange: (e) => {
|
|
197
|
+
const next = e.currentTarget.value;
|
|
198
|
+
report(next, null);
|
|
199
|
+
onInputChange?.(next);
|
|
200
|
+
if (ctl.current && !ctl.current.isOpen)
|
|
201
|
+
ctl.current.open();
|
|
202
|
+
} }), toggleLabel !== undefined && (_jsx("button", { ref: toggle, type: "button", className: "fs-icon-button fs-icon-button--row fs-combobox__toggle", tabIndex: -1, "aria-label": toggleLabel })), _jsx("div", { ref: list, id: `${base}-list`, className: "fs-menu fs-menu--listbox", role: "listbox", "aria-label": label, hidden: true, children: count === 0 ? (_jsx("div", { className: "fs-menu__empty", role: "option", "aria-disabled": "true", children: emptyText })) : (items.map((entry) => isGroup(entry)
|
|
203
|
+
? entry.items.length > 0 && (_jsxs("div", { role: "group", "aria-labelledby": `${prefix}g-${entry.id}`, children: [_jsx("div", { className: "fs-menu__group-label", id: `${prefix}g-${entry.id}`, role: "presentation", children: entry.label }), entry.items.map(option)] }, entry.id))
|
|
204
|
+
: option(entry))) })] }));
|
|
205
|
+
});
|
|
42
206
|
export const Checkbox = forwardRef(function Checkbox({ label, className, ...rest }, ref) {
|
|
43
207
|
return (_jsxs("label", { className: cx('fs-checkbox', className), children: [_jsx("input", { ref: ref, type: "checkbox", className: "fs-checkbox__input", ...rest }), _jsx("span", { className: "fs-checkbox__label", children: label })] }));
|
|
44
208
|
});
|
|
45
209
|
export const Radio = forwardRef(function Radio({ label, className, ...rest }, ref) {
|
|
46
210
|
return (_jsxs("label", { className: cx('fs-radio', className), children: [_jsx("input", { ref: ref, type: "radio", className: "fs-radio__input", ...rest }), _jsx("span", { className: "fs-radio__label", children: label })] }));
|
|
47
211
|
});
|
|
212
|
+
/** A switch that acts at once: a native checkbox with `role="switch"`. For a choice applied later, use Checkbox. */
|
|
213
|
+
export const Switch = forwardRef(function Switch({ label, labelPosition = 'after', busy, className, ...rest }, ref) {
|
|
214
|
+
return (_jsxs("label", { className: cx('fs-switch', labelPosition === 'before' && 'fs-switch--end', className), "aria-busy": busy || undefined, children: [_jsx("input", { ref: ref, type: "checkbox", role: "switch", className: "fs-switch__input", ...rest }), _jsx("span", { className: "fs-switch__label", children: label })] }));
|
|
215
|
+
});
|
|
48
216
|
/** A choice chip: a button; aria-pressed marks it chosen. */
|
|
49
217
|
export const Chip = forwardRef(function Chip({ pressed = false, className, type = 'button', ...rest }, ref) {
|
|
50
218
|
return (_jsx("button", { ref: ref, type: type, className: cx('fs-chip', 'fs-chip--choice', className), "aria-pressed": pressed, ...rest }));
|
|
@@ -138,18 +306,17 @@ export const Calendar = forwardRef(function Calendar({ value, defaultValue, onCh
|
|
|
138
306
|
labels,
|
|
139
307
|
};
|
|
140
308
|
const ctl = useCalendarHelper(own, { ...common, announcer, autoFocus }, (root, options) => createCalendar(root, { ...options, value: value === undefined ? defaultValue : value }));
|
|
309
|
+
// As Slider's: a re-render after each fs-change, in the parent's batch, puts back a controlled value
|
|
310
|
+
// the parent didn't take. Not a microtask, which could run before the parent's render (I25).
|
|
311
|
+
const [settled, settle] = useState(0);
|
|
141
312
|
useIsoLayoutEffect(() => {
|
|
142
313
|
if (value !== undefined && ctl.current && ctl.current.value !== value)
|
|
143
314
|
ctl.current.setValue(value);
|
|
144
|
-
}, [value]);
|
|
315
|
+
}, [value, settled]);
|
|
145
316
|
useFsEvent(own, 'fs-change', ({ value: picked }) => {
|
|
317
|
+
if (latestValue.current !== undefined)
|
|
318
|
+
settle((n) => n + 1);
|
|
146
319
|
onChange?.(picked);
|
|
147
|
-
// A controlled value the parent didn't take is put back.
|
|
148
|
-
queueMicrotask(() => {
|
|
149
|
-
const held = latestValue.current;
|
|
150
|
-
if (held !== undefined && ctl.current && ctl.current.value !== held)
|
|
151
|
-
ctl.current.setValue(held);
|
|
152
|
-
});
|
|
153
320
|
});
|
|
154
321
|
return _jsx("div", { ref: useMergedRef(own, ref), className: cx('fs-calendar', className), ...rest });
|
|
155
322
|
});
|
|
@@ -178,18 +345,127 @@ export const DateRangeCalendar = forwardRef(function DateRangeCalendar({ value,
|
|
|
178
345
|
// Only a new range in the prop resets the helper: an equal one keeps a pending start.
|
|
179
346
|
const start = value === undefined ? undefined : (value?.start ?? null);
|
|
180
347
|
const end = value === undefined ? undefined : (value?.end ?? null);
|
|
348
|
+
// As Calendar's: a re-render after each fs-change puts back a controlled range the parent didn't take.
|
|
349
|
+
const [settled, settle] = useState(0);
|
|
181
350
|
useIsoLayoutEffect(() => {
|
|
182
351
|
if (value !== undefined && ctl.current && !sameRange(ctl.current.value, value))
|
|
183
352
|
ctl.current.setValue(value);
|
|
184
|
-
}, [start, end]);
|
|
353
|
+
}, [start, end, settled]);
|
|
185
354
|
useFsEvent(own, 'fs-change', (picked) => {
|
|
355
|
+
if (latestValue.current !== undefined)
|
|
356
|
+
settle((n) => n + 1);
|
|
186
357
|
onChange?.({ start: picked.start, end: picked.end });
|
|
187
|
-
// A controlled range the parent didn't take is put back.
|
|
188
|
-
queueMicrotask(() => {
|
|
189
|
-
const held = latestValue.current;
|
|
190
|
-
if (held !== undefined && ctl.current && !sameRange(ctl.current.value, held))
|
|
191
|
-
ctl.current.setValue(held);
|
|
192
|
-
});
|
|
193
358
|
});
|
|
194
359
|
return _jsx("div", { ref: useMergedRef(own, ref), className: cx('fs-calendar', className), ...rest });
|
|
195
360
|
});
|
|
361
|
+
const sliderPercent = (v, min, max) => (max === min ? 0 : ((v - min) / (max - min)) * 100);
|
|
362
|
+
/** The parts both wrappers render: the track, its fill, ticks and thumbs, the output and the hidden inputs. */
|
|
363
|
+
function SliderParts({ values, common: { min, max, valueText, showValue, ticks, disabled, name }, thumb, }) {
|
|
364
|
+
const range = values.length === 2;
|
|
365
|
+
const bounds = (i) => (!range ? [min, max] : i === 0 ? [min, values[1]] : [values[0], max]);
|
|
366
|
+
return (_jsxs(_Fragment, { children: [_jsxs("div", { className: "fs-slider__track", children: [_jsx("div", { className: "fs-slider__fill" }), ticks && ticks.length > 0 && (_jsx("div", { className: "fs-slider__ticks", "aria-hidden": "true", children: ticks.map((t) => (_jsx("span", { style: { '--fs-slider-at': `${sliderPercent(t, min, max)}%` } }, t))) })), values.map((v, i) => thumb(i, {
|
|
367
|
+
className: 'fs-slider__thumb',
|
|
368
|
+
role: 'slider',
|
|
369
|
+
tabIndex: 0,
|
|
370
|
+
'aria-valuemin': bounds(i)[0],
|
|
371
|
+
'aria-valuemax': bounds(i)[1],
|
|
372
|
+
'aria-valuenow': v,
|
|
373
|
+
'aria-valuetext': valueText(v),
|
|
374
|
+
'aria-disabled': disabled || undefined,
|
|
375
|
+
style: { '--fs-slider-at': `${sliderPercent(v, min, max)}%` },
|
|
376
|
+
}))] }), showValue && (_jsx("output", { className: "fs-slider__value", children: range ? rangeValueText(valueText(values[0]), valueText(values[1])) : valueText(values[0]) })), name !== undefined &&
|
|
377
|
+
values.map((v, i) => _jsx("input", { type: "hidden", name: name, value: v, disabled: disabled || undefined }, i))] }));
|
|
378
|
+
}
|
|
379
|
+
const fillStyle = (values, min, max) => ({
|
|
380
|
+
'--fs-slider-low': `${values.length === 2 ? sliderPercent(values[0], min, max) : 0}%`,
|
|
381
|
+
'--fs-slider-high': `${sliderPercent(values[values.length - 1], min, max)}%`,
|
|
382
|
+
});
|
|
383
|
+
/** Runs createSlider on mount and destroy on unmount; new bounds, steps or words call `update`. */
|
|
384
|
+
function useSliderHelper(root, { min, max, step, pageStep, valueText }, create) {
|
|
385
|
+
const ctl = useRef(null);
|
|
386
|
+
const text = useLatest(valueText);
|
|
387
|
+
const set = (o) => Object.fromEntries(Object.entries(o).filter(([, v]) => v !== undefined));
|
|
388
|
+
useIsoLayoutEffect(() => {
|
|
389
|
+
ctl.current = create(root.current, {
|
|
390
|
+
min,
|
|
391
|
+
max,
|
|
392
|
+
...set({ step, pageStep }),
|
|
393
|
+
valueText: (v) => text.current(v),
|
|
394
|
+
});
|
|
395
|
+
return () => {
|
|
396
|
+
ctl.current?.destroy();
|
|
397
|
+
ctl.current = null;
|
|
398
|
+
};
|
|
399
|
+
}, []);
|
|
400
|
+
useIsoLayoutEffect(() => {
|
|
401
|
+
// A new valueText re-renders the words; the helper calls the latest one.
|
|
402
|
+
ctl.current?.update({ min, max, step, pageStep });
|
|
403
|
+
}, [min, max, step, pageStep, valueText]);
|
|
404
|
+
return ctl;
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* The slider (F2 draft §4, T134) on createSlider. `className` goes on the `.fs-slider` root, the ref
|
|
408
|
+
* and other props on the thumb (as `ListboxSelect`'s trigger), so a Field's control props spread
|
|
409
|
+
* onto it. The thumb is named by `label`; a Field's `<label for>` can't name a `div`.
|
|
410
|
+
*/
|
|
411
|
+
export const Slider = forwardRef(function Slider({ label, min, max, step, pageStep, value, defaultValue, onInput, onChange, valueText, showValue, ticks, disabled, name, className, style, 'aria-labelledby': labelledBy, ...rest }, ref) {
|
|
412
|
+
const root = useRef(null);
|
|
413
|
+
const [own, setOwn] = useState(defaultValue ?? min);
|
|
414
|
+
const current = value !== undefined ? value : own;
|
|
415
|
+
const latestValue = useLatest(value);
|
|
416
|
+
const common = { min, max, step, pageStep, valueText, showValue, ticks, disabled, name };
|
|
417
|
+
const first = useLatest(current);
|
|
418
|
+
const ctl = useSliderHelper(root, common, (el, options) => createSlider(el, { ...options, value: first.current }));
|
|
419
|
+
// `settled` re-renders after each fs-change, in the same batch as the parent's update, so the effect
|
|
420
|
+
// puts back a controlled value the parent didn't take. Not a microtask: fs-change isn't a discrete
|
|
421
|
+
// event to React, so the parent's render may come after it, and the put-back would undo a move (T134).
|
|
422
|
+
const [settled, settle] = useState(0);
|
|
423
|
+
useIsoLayoutEffect(() => {
|
|
424
|
+
if (ctl.current && ctl.current.value !== current)
|
|
425
|
+
ctl.current.setValue(current);
|
|
426
|
+
}, [current, settled]);
|
|
427
|
+
useFsEvent(root, 'fs-input', ({ value: moved }) => onInput?.(moved));
|
|
428
|
+
useFsEvent(root, 'fs-change', ({ value: moved }) => {
|
|
429
|
+
if (latestValue.current === undefined)
|
|
430
|
+
setOwn(moved);
|
|
431
|
+
else
|
|
432
|
+
settle((n) => n + 1);
|
|
433
|
+
onChange?.(moved);
|
|
434
|
+
});
|
|
435
|
+
return (_jsx("div", { ref: root, className: cx('fs-slider', className), style: fillStyle([current], min, max), children: _jsx(SliderParts, { values: [current], common: common, thumb: (i, base) => (_jsx("div", { ref: ref, ...base, "aria-label": labelledBy === undefined ? label : undefined, "aria-labelledby": labelledBy, ...rest, style: { ...base.style, ...style } }, i)) }) }));
|
|
436
|
+
});
|
|
437
|
+
const samePair = (a, b) => a[0] === b[0] && a[1] === b[1];
|
|
438
|
+
/**
|
|
439
|
+
* The range slider (F2 draft §4, T134): two dependent thumbs that never cross, on createSlider with a
|
|
440
|
+
* `[low, high]` value. A separate wrapper, as `DateRangeCalendar`, since the value and names differ.
|
|
441
|
+
* `className`, the ref and other props go on the `.fs-slider` root, a `role="group"` named by `label`.
|
|
442
|
+
*/
|
|
443
|
+
export const RangeSlider = forwardRef(function RangeSlider({ label, startLabel, endLabel, min, max, step, pageStep, value, defaultValue, onInput, onChange, valueText, showValue, ticks, disabled, name, className, style, ...rest }, ref) {
|
|
444
|
+
const root = useRef(null);
|
|
445
|
+
const [own, setOwn] = useState(defaultValue ?? [min, max]);
|
|
446
|
+
const current = value !== undefined ? value : own;
|
|
447
|
+
const latestValue = useLatest(value);
|
|
448
|
+
const labels = useLatest({ start: startLabel, end: endLabel });
|
|
449
|
+
const common = { min, max, step, pageStep, valueText, showValue, ticks, disabled, name };
|
|
450
|
+
const first = useLatest(current);
|
|
451
|
+
const ctl = useSliderHelper(root, common, (el, options) => createSlider(el, { ...options, value: first.current, labels: labels.current }));
|
|
452
|
+
useIsoLayoutEffect(() => {
|
|
453
|
+
ctl.current?.update({ labels: { start: startLabel, end: endLabel } });
|
|
454
|
+
}, [startLabel, endLabel]);
|
|
455
|
+
const [low, high] = current;
|
|
456
|
+
// As Slider's: a re-render after each fs-change puts back a controlled range the parent didn't take.
|
|
457
|
+
const [settled, settle] = useState(0);
|
|
458
|
+
useIsoLayoutEffect(() => {
|
|
459
|
+
if (ctl.current && !samePair(ctl.current.value, current))
|
|
460
|
+
ctl.current.setValue(current);
|
|
461
|
+
}, [low, high, settled]);
|
|
462
|
+
useFsEvent(root, 'fs-input', ({ value: moved }) => onInput?.(moved));
|
|
463
|
+
useFsEvent(root, 'fs-change', ({ value: moved }) => {
|
|
464
|
+
if (latestValue.current === undefined)
|
|
465
|
+
setOwn(moved);
|
|
466
|
+
else
|
|
467
|
+
settle((n) => n + 1);
|
|
468
|
+
onChange?.(moved);
|
|
469
|
+
});
|
|
470
|
+
return (_jsx("div", { ref: useMergedRef(root, ref), className: cx('fs-slider', 'fs-slider--range', className), role: "group", "aria-label": rest['aria-labelledby'] === undefined ? label : undefined, style: { ...fillStyle(current, min, max), ...style }, ...rest, children: _jsx(SliderParts, { values: current, common: common, thumb: (i, base) => _jsx("div", { ...base, "aria-label": i === 0 ? startLabel : endLabel }, i) }) }));
|
|
471
|
+
});
|
package/dist/react/navigation.js
CHANGED
|
@@ -18,17 +18,17 @@ export const Tabs = forwardRef(function Tabs({ label, items, value, defaultValue
|
|
|
18
18
|
const [current, setCurrent] = useControllable(value, defaultValue ?? items[0]?.id ?? '');
|
|
19
19
|
const latest = useLatest({ current, items });
|
|
20
20
|
const hasActions = actions !== undefined;
|
|
21
|
+
// As Slider's: a re-render after each fs-select, in the parent's batch, puts back a controlled value
|
|
22
|
+
// the parent didn't take. Not a microtask, which could run before the parent's render (I25).
|
|
23
|
+
const [settled, settle] = useState(0);
|
|
21
24
|
const onSelect = useLatest((index) => {
|
|
22
25
|
const id = latest.current.items[index]?.id;
|
|
23
26
|
if (id === undefined)
|
|
24
27
|
return;
|
|
25
28
|
setCurrent(id);
|
|
29
|
+
if (value !== undefined)
|
|
30
|
+
settle((n) => n + 1);
|
|
26
31
|
onValueChange?.(id);
|
|
27
|
-
queueMicrotask(() => {
|
|
28
|
-
const i = latest.current.items.findIndex((t) => t.id === latest.current.current);
|
|
29
|
-
if (i >= 0)
|
|
30
|
-
tabs.current?.select(i);
|
|
31
|
-
});
|
|
32
32
|
});
|
|
33
33
|
// Adding or dropping `actions` moves the list into or out of the row, a new element: the
|
|
34
34
|
// helper and the listener follow it.
|
|
@@ -43,6 +43,13 @@ export const Tabs = forwardRef(function Tabs({ label, items, value, defaultValue
|
|
|
43
43
|
};
|
|
44
44
|
}, [activation, hasActions]);
|
|
45
45
|
useIsoLayoutEffect(() => tabs.current?.update());
|
|
46
|
+
useIsoLayoutEffect(() => {
|
|
47
|
+
if (!settled)
|
|
48
|
+
return;
|
|
49
|
+
const i = items.findIndex((t) => t.id === current);
|
|
50
|
+
if (i >= 0 && tabs.current && tabs.current.selected !== i)
|
|
51
|
+
tabs.current.select(i);
|
|
52
|
+
}, [settled]);
|
|
46
53
|
const tabList = (_jsx("div", { ref: list, className: "fs-tabs__list", role: "tablist", "aria-label": label, children: items.map((t) => (_jsxs("button", { type: "button", className: "fs-tabs__tab", role: "tab", id: `${base}-t-${t.id}`, "aria-controls": t.panel !== undefined ? `${base}-p-${t.id}` : controls, "aria-selected": t.id === current, disabled: t.disabled, children: [t.icon && _jsx(Icon, { name: t.icon, type: t.iconType }), t.label, t.count !== undefined && _jsx("span", { className: "fs-count", children: t.count })] }, t.id))) }));
|
|
47
54
|
return (_jsxs("div", { ref: ref, className: cx('fs-tabs', variant !== 'default' && `fs-tabs--${variant}`, className), ...rest, children: [!hasActions ? (tabList) : (_jsxs("div", { className: "fs-tabs__row", children: [tabList, _jsx("div", { className: "fs-tabs__actions", children: actions })] })), items
|
|
48
55
|
.filter((t) => t.panel !== undefined)
|
|
@@ -59,17 +66,23 @@ export const TabBar = forwardRef(function TabBar({ label, items, value, defaultV
|
|
|
59
66
|
return () => tabs.current?.destroy();
|
|
60
67
|
}, []);
|
|
61
68
|
useIsoLayoutEffect(() => tabs.current?.update());
|
|
69
|
+
// As Tabs': a re-render after each fs-select puts back a controlled value the parent didn't take (I25).
|
|
70
|
+
const [settled, settle] = useState(0);
|
|
71
|
+
useIsoLayoutEffect(() => {
|
|
72
|
+
if (!settled)
|
|
73
|
+
return;
|
|
74
|
+
const i = items.findIndex((t) => t.id === current);
|
|
75
|
+
if (i >= 0 && tabs.current && tabs.current.selected !== i)
|
|
76
|
+
tabs.current.select(i);
|
|
77
|
+
}, [settled]);
|
|
62
78
|
useFsEvent(own, 'fs-select', ({ index }) => {
|
|
63
79
|
const id = latest.current.items[index]?.id;
|
|
64
80
|
if (id === undefined)
|
|
65
81
|
return;
|
|
66
82
|
setCurrent(id);
|
|
83
|
+
if (value !== undefined)
|
|
84
|
+
settle((n) => n + 1);
|
|
67
85
|
onValueChange?.(id);
|
|
68
|
-
queueMicrotask(() => {
|
|
69
|
-
const i = latest.current.items.findIndex((t) => t.id === latest.current.current);
|
|
70
|
-
if (i >= 0)
|
|
71
|
-
tabs.current?.select(i);
|
|
72
|
-
});
|
|
73
86
|
});
|
|
74
87
|
useFsEvent(own, 'fs-close', ({ index }) => {
|
|
75
88
|
const item = latest.current.items[index];
|
|
@@ -104,15 +117,20 @@ export const Tree = forwardRef(function Tree({ label, items, selected, defaultSe
|
|
|
104
117
|
return () => tree.current?.destroy();
|
|
105
118
|
}, []);
|
|
106
119
|
useIsoLayoutEffect(() => tree.current?.update());
|
|
107
|
-
// Puts the DOM back to the state when a controlled parent didn't take the change
|
|
108
|
-
|
|
120
|
+
// Puts the DOM back to the state when a controlled parent didn't take the change: as Slider's, after
|
|
121
|
+
// a re-render in the parent's batch, not in a microtask that could run before the parent's render (I25).
|
|
122
|
+
const [settled, settle] = useState(0);
|
|
123
|
+
useIsoLayoutEffect(() => {
|
|
124
|
+
if (!settled)
|
|
125
|
+
return;
|
|
109
126
|
for (const el of own.current?.querySelectorAll('[role="treeitem"]') ?? []) {
|
|
110
127
|
const id = fromDom(el);
|
|
111
|
-
el.setAttribute('aria-selected', String(id ===
|
|
128
|
+
el.setAttribute('aria-selected', String(id === sel));
|
|
112
129
|
if (el.hasAttribute('aria-expanded'))
|
|
113
|
-
el.setAttribute('aria-expanded', String(
|
|
130
|
+
el.setAttribute('aria-expanded', String(open.includes(id)));
|
|
114
131
|
}
|
|
115
|
-
});
|
|
132
|
+
}, [settled]);
|
|
133
|
+
const resync = () => settle((n) => n + 1);
|
|
116
134
|
useFsEvent(own, 'fs-toggle', ({ item, expanded: isOpen }) => {
|
|
117
135
|
const id = fromDom(item);
|
|
118
136
|
const next = isOpen ? [...latest.current.open, id] : latest.current.open.filter((x) => x !== id);
|