@mistriwork/ui 1.0.0-rc.46 → 1.0.0-rc.48
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/Carousel.d.ts +2 -1
- package/dist/Carousel.js +9 -8
- package/dist/Choices.d.ts +5 -4
- package/dist/Choices.js +18 -16
- package/dist/DateField.d.ts +8 -3
- package/dist/DateField.js +17 -14
- package/dist/Drawer.d.ts +2 -1
- package/dist/Drawer.js +4 -3
- package/dist/DropMenu.d.ts +2 -1
- package/dist/DropMenu.js +3 -2
- package/dist/Dropdown.d.ts +8 -3
- package/dist/Dropdown.js +10 -6
- package/dist/FileField.d.ts +3 -2
- package/dist/FileField.js +4 -2
- package/dist/Pagination.d.ts +2 -1
- package/dist/Pagination.js +3 -2
- package/dist/Popover.d.ts +2 -1
- package/dist/Popover.js +3 -2
- package/dist/Resizable.d.ts +2 -1
- package/dist/Resizable.js +10 -9
- package/dist/Select.d.ts +3 -3
- package/dist/Select.js +2 -2
- package/dist/SensitiveField.d.ts +2 -1
- package/dist/SensitiveField.js +6 -5
- package/dist/Slider.d.ts +2 -1
- package/dist/Slider.js +3 -2
- package/dist/Switch.d.ts +2 -2
- package/dist/Switch.js +4 -3
- package/dist/Tabs.d.ts +5 -2
- package/dist/Tabs.js +3 -2
- package/dist/TextField.d.ts +3 -2
- package/dist/TextField.js +6 -5
- package/dist/Tooltip.d.ts +2 -1
- package/dist/Tooltip.js +3 -3
- package/dist/Typeahead.d.ts +5 -2
- package/dist/Typeahead.js +31 -10
- package/dist/UiKit.d.ts +8 -2
- package/dist/changeDetails.d.ts +28 -0
- package/dist/changeDetails.js +54 -0
- package/dist/conformance.d.ts +1 -1
- package/dist/conformance.js +83 -5
- package/dist/conformancePatterns.d.ts +27 -0
- package/dist/conformancePatterns.js +421 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.js +2 -0
- package/dist/internal/uiKitContext.d.ts +4 -1
- package/dist/internal/uiKitContext.js +49 -3
- package/package.json +1 -1
package/dist/Popover.d.ts
CHANGED
|
@@ -13,12 +13,13 @@
|
|
|
13
13
|
* and a dialog's focus trap keeps it as its own.
|
|
14
14
|
*/
|
|
15
15
|
import { type ReactNode } from 'react';
|
|
16
|
+
import { type ChangeDetails } from './changeDetails.js';
|
|
16
17
|
export interface PopoverProps {
|
|
17
18
|
trigger: ReactNode;
|
|
18
19
|
children: ReactNode;
|
|
19
20
|
open?: boolean;
|
|
20
21
|
defaultOpen?: boolean;
|
|
21
|
-
onOpenChange?: (open: boolean) => void;
|
|
22
|
+
onOpenChange?: (open: boolean, details: ChangeDetails<'trigger-hover' | 'trigger-focus' | 'trigger-press' | 'outside-press' | 'escape-key' | 'close-press' | 'focus-out' | 'imperative-action' | 'implicit'>) => void;
|
|
22
23
|
className?: string;
|
|
23
24
|
/** The popup's accessible name, where it needs one. */
|
|
24
25
|
ariaLabel?: string;
|
package/dist/Popover.js
CHANGED
|
@@ -18,6 +18,7 @@ import { Popover as BasePopover } from '@base-ui/react/popover';
|
|
|
18
18
|
import { layoutViewport, zoomAnchor } from './internal/anchor.js';
|
|
19
19
|
import { ComponentStyleScope } from './internal/ComponentStyleScope.js';
|
|
20
20
|
import { popupContainer, useDialogContainer } from './internal/popups.js';
|
|
21
|
+
import { fromBaseUi } from './changeDetails.js';
|
|
21
22
|
import { slotted } from './internal/uiKitContext.js';
|
|
22
23
|
function DefaultPopover({ trigger, children, open, defaultOpen, onOpenChange, className, ariaLabel }) {
|
|
23
24
|
/* The trigger is rendered as the trigger, not inside one: a button
|
|
@@ -29,7 +30,7 @@ function DefaultPopover({ trigger, children, open, defaultOpen, onOpenChange, cl
|
|
|
29
30
|
const container = useDialogContainer(anchor);
|
|
30
31
|
/* The layer is drawn outside the page that opened it; the page's scope goes with it (Modal.tsx). */
|
|
31
32
|
const componentScope = useContext(ComponentStyleScope);
|
|
32
|
-
return (_jsxs(BasePopover.Root, { open: open, defaultOpen: defaultOpen, onOpenChange: onOpenChange, children: [_jsx(BasePopover.Trigger, { className: "ui-popover-trigger", render: triggerElement, ref: anchor }), _jsx(BasePopover.Portal, { container: container ?? popupContainer(), children: _jsx(BasePopover.Positioner, { anchor: () => (anchor.current ? zoomAnchor(anchor.current) : null), positionMethod: "fixed", sideOffset: 8, collisionBoundary: layoutViewport(), collisionPadding: 8, children: _jsx(BasePopover.Popup, { "data-component": componentScope, className: ['ui-popover', className].filter(Boolean).join(' '), "aria-label": ariaLabel, children: children }) }) })] }));
|
|
33
|
+
return (_jsxs(BasePopover.Root, { open: open, defaultOpen: defaultOpen, onOpenChange: onOpenChange && ((next, details) => onOpenChange(next, fromBaseUi(details, 'implicit'))), children: [_jsx(BasePopover.Trigger, { className: "ui-popover-trigger", render: triggerElement, ref: anchor }), _jsx(BasePopover.Portal, { container: container ?? popupContainer(), children: _jsx(BasePopover.Positioner, { anchor: () => (anchor.current ? zoomAnchor(anchor.current) : null), positionMethod: "fixed", sideOffset: 8, collisionBoundary: layoutViewport(), collisionPadding: 8, children: _jsx(BasePopover.Popup, { "data-component": componentScope, className: ['ui-popover', className].filter(Boolean).join(' '), "aria-label": ariaLabel, children: children }) }) })] }));
|
|
33
34
|
}
|
|
34
35
|
/* Slotted (UiKit.tsx): an App's control kit may draw its own in place of the default, with the same props. */
|
|
35
|
-
export const Popover = slotted('Popover', DefaultPopover);
|
|
36
|
+
export const Popover = slotted('Popover', DefaultPopover, { onOpenChange: [1, 'implicit'] });
|
package/dist/Resizable.d.ts
CHANGED
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
* a neighbour below its minimum stops at that neighbour's edge.
|
|
19
19
|
*/
|
|
20
20
|
import { type ReactNode } from 'react';
|
|
21
|
+
import { type ChangeDetails } from './changeDetails.js';
|
|
21
22
|
export interface ResizablePanel {
|
|
22
23
|
/** The pane's accessible name, said by its handle's controls. */
|
|
23
24
|
label?: string;
|
|
@@ -31,7 +32,7 @@ export interface ResizableProps {
|
|
|
31
32
|
panels: readonly ResizablePanel[];
|
|
32
33
|
direction?: 'horizontal' | 'vertical';
|
|
33
34
|
sizes?: readonly number[];
|
|
34
|
-
onSizesChange?: (sizes: number[]) => void;
|
|
35
|
+
onSizesChange?: (sizes: number[], details: ChangeDetails<'resize'>) => void;
|
|
35
36
|
/** The group's accessible name, where the panes need one ("Record and detail"). */
|
|
36
37
|
ariaLabel?: string;
|
|
37
38
|
/** Every word the handles say, in the caller's language; any left out are English. */
|
package/dist/Resizable.js
CHANGED
|
@@ -19,6 +19,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
19
19
|
* a neighbour below its minimum stops at that neighbour's edge.
|
|
20
20
|
*/
|
|
21
21
|
import { Fragment, useId, useRef, useState } from 'react';
|
|
22
|
+
import { changeDetails } from './changeDetails.js';
|
|
22
23
|
const ENGLISH = {
|
|
23
24
|
resize: (before, after) => `Resize ${before} and ${after}`,
|
|
24
25
|
panel: (number) => `panel ${number}`,
|
|
@@ -46,40 +47,40 @@ export function Resizable({ panels, direction = 'horizontal', sizes, onSizesChan
|
|
|
46
47
|
return null;
|
|
47
48
|
const current = clampSizes(panels, sizes ?? uncontrolled);
|
|
48
49
|
const mins = panels.map((panel) => panel.minSize ?? 10);
|
|
49
|
-
const setSizes = (next) => {
|
|
50
|
+
const setSizes = (next, event) => {
|
|
50
51
|
const clamped = clampSizes(panels, next);
|
|
51
52
|
if (sizes === undefined)
|
|
52
53
|
setUncontrolled(clamped);
|
|
53
|
-
onSizesChange?.(clamped);
|
|
54
|
+
onSizesChange?.(clamped, changeDetails('resize', event));
|
|
54
55
|
};
|
|
55
56
|
/** Move handle `i` so pane `i` grows by `delta` points and pane `i + 1` shrinks by the same. */
|
|
56
|
-
const move = (i, delta) => {
|
|
57
|
+
const move = (i, delta, event) => {
|
|
57
58
|
const next = [...current];
|
|
58
59
|
const low = mins[i] - current[i];
|
|
59
60
|
const high = current[i + 1] - mins[i + 1];
|
|
60
61
|
const applied = Math.min(Math.max(delta, low), high);
|
|
61
62
|
next[i] = current[i] + applied;
|
|
62
63
|
next[i + 1] = current[i + 1] - applied;
|
|
63
|
-
setSizes(next);
|
|
64
|
+
setSizes(next, event);
|
|
64
65
|
};
|
|
65
66
|
const onHandleKeyDown = (i) => (event) => {
|
|
66
67
|
const horizontal = direction === 'horizontal';
|
|
67
68
|
const step = event.shiftKey ? 10 : 5;
|
|
68
69
|
if (event.key === (horizontal ? 'ArrowRight' : 'ArrowDown')) {
|
|
69
70
|
event.preventDefault();
|
|
70
|
-
move(i, step);
|
|
71
|
+
move(i, step, event);
|
|
71
72
|
}
|
|
72
73
|
else if (event.key === (horizontal ? 'ArrowLeft' : 'ArrowUp')) {
|
|
73
74
|
event.preventDefault();
|
|
74
|
-
move(i, -step);
|
|
75
|
+
move(i, -step, event);
|
|
75
76
|
}
|
|
76
77
|
else if (event.key === 'Home') {
|
|
77
78
|
event.preventDefault();
|
|
78
|
-
move(i, -(current[i] - mins[i]));
|
|
79
|
+
move(i, -(current[i] - mins[i]), event);
|
|
79
80
|
}
|
|
80
81
|
else if (event.key === 'End') {
|
|
81
82
|
event.preventDefault();
|
|
82
|
-
move(i, current[i + 1] - mins[i + 1]);
|
|
83
|
+
move(i, current[i + 1] - mins[i + 1], event);
|
|
83
84
|
}
|
|
84
85
|
};
|
|
85
86
|
const onPointerDown = (i) => (event) => {
|
|
@@ -111,7 +112,7 @@ export function Resizable({ panels, direction = 'horizontal', sizes, onSizesChan
|
|
|
111
112
|
const applied = Math.min(Math.max(delta, low), high);
|
|
112
113
|
next[drag.handle] = drag.sizes[drag.handle] + applied;
|
|
113
114
|
next[drag.handle + 1] = drag.sizes[drag.handle + 1] - applied;
|
|
114
|
-
setSizes(next);
|
|
115
|
+
setSizes(next, event);
|
|
115
116
|
};
|
|
116
117
|
const onPointerUp = () => {
|
|
117
118
|
dragRef.current = null;
|
package/dist/Select.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* returns focus to the box. Props only. Preview: @mistriwork/ui is Preview at 1.0.
|
|
5
5
|
*/
|
|
6
6
|
import { type ReactNode, type Ref } from 'react';
|
|
7
|
-
import { type DropdownItem } from './Dropdown.js';
|
|
7
|
+
import { type DropdownChange, type DropdownItem } from './Dropdown.js';
|
|
8
8
|
import { type FieldFrame } from './fieldFrame.js';
|
|
9
9
|
interface ListFrame extends FieldFrame {
|
|
10
10
|
options: DropdownItem[];
|
|
@@ -16,12 +16,12 @@ interface ListFrame extends FieldFrame {
|
|
|
16
16
|
/** One choice from a list, under a field box. */
|
|
17
17
|
declare function DefaultSelect(props: ListFrame & {
|
|
18
18
|
value: string;
|
|
19
|
-
onChange: (value: string) => void;
|
|
19
|
+
onChange: (value: string, details: DropdownChange) => void;
|
|
20
20
|
}): ReactNode;
|
|
21
21
|
/** Several choices, each with a checkbox; the closed box says them as "Acura, Alfa Romeo". */
|
|
22
22
|
declare function DefaultMultiSelect(props: ListFrame & {
|
|
23
23
|
value: string[];
|
|
24
|
-
onChange: (value: string[]) => void;
|
|
24
|
+
onChange: (value: string[], details: DropdownChange) => void;
|
|
25
25
|
}): ReactNode;
|
|
26
26
|
export declare const Select: typeof DefaultSelect;
|
|
27
27
|
export declare const MultiSelect: typeof DefaultMultiSelect;
|
package/dist/Select.js
CHANGED
|
@@ -20,5 +20,5 @@ function DefaultMultiSelect(props) {
|
|
|
20
20
|
return (_jsx(Field, { ...frameOf(props), group: true, children: (control) => (_jsx(MultiDropdown, { items: props.options, value: props.value, onChange: props.onChange, id: control.id, ariaLabelledBy: `${control['aria-labelledby']} ${valueId}`, ariaDescribedBy: control['aria-describedby'], ariaInvalid: control['aria-invalid'], valueId: valueId, buttonClassName: "field-control field-select", listClassName: "field-list", buttonRef: props.buttonRef, placeholder: props.placeholder, disabled: props.disabled })) }));
|
|
21
21
|
}
|
|
22
22
|
/* Slotted (UiKit.tsx): an App's control kit may draw its own in place of the default, with the same props. */
|
|
23
|
-
export const Select = slotted('Select', DefaultSelect);
|
|
24
|
-
export const MultiSelect = slotted('MultiSelect', DefaultMultiSelect);
|
|
23
|
+
export const Select = slotted('Select', DefaultSelect, { onChange: [1, 'item-press'] });
|
|
24
|
+
export const MultiSelect = slotted('MultiSelect', DefaultMultiSelect, { onChange: [1, 'item-press'] });
|
package/dist/SensitiveField.d.ts
CHANGED
|
@@ -8,10 +8,11 @@
|
|
|
8
8
|
import { type ReactNode } from 'react';
|
|
9
9
|
import { type FieldFrame } from './fieldFrame.js';
|
|
10
10
|
import { type Mask } from './masks.js';
|
|
11
|
+
import { type ChangeDetails } from './changeDetails.js';
|
|
11
12
|
export interface SensitiveFieldProps extends FieldFrame {
|
|
12
13
|
/** The raw value. */
|
|
13
14
|
value: string;
|
|
14
|
-
onChange: (raw: string) => void;
|
|
15
|
+
onChange: (raw: string, details: ChangeDetails<'input-change'>) => void;
|
|
15
16
|
mask: Mask;
|
|
16
17
|
valid?: boolean;
|
|
17
18
|
validIcon?: ReactNode;
|
package/dist/SensitiveField.js
CHANGED
|
@@ -12,19 +12,20 @@ import { Field } from './Field.js';
|
|
|
12
12
|
import { frameOf } from './fieldFrame.js';
|
|
13
13
|
import { digits } from './masks.js';
|
|
14
14
|
import { ValidMark } from './TextField.js';
|
|
15
|
+
import { changeDetails } from './changeDetails.js';
|
|
15
16
|
import { slotted } from './internal/uiKitContext.js';
|
|
16
17
|
function DefaultSensitiveField(props) {
|
|
17
18
|
const [shown, setShown] = useState(false);
|
|
18
19
|
const formatted = props.mask.format(props.value);
|
|
19
20
|
const display = shown ? formatted : '•'.repeat(formatted.length);
|
|
20
|
-
const change = (typed) => {
|
|
21
|
+
const change = (typed, details) => {
|
|
21
22
|
if (shown)
|
|
22
|
-
return props.onChange(props.mask.parse(typed));
|
|
23
|
+
return props.onChange(props.mask.parse(typed), details);
|
|
23
24
|
// Hidden: what is left of the dots keeps that many characters of the number; a digit typed is added at the end.
|
|
24
25
|
const kept = formatted.slice(0, typed.replace(/[^•]/g, '').length);
|
|
25
|
-
props.onChange(props.mask.parse(digits(kept) + digits(typed)));
|
|
26
|
+
props.onChange(props.mask.parse(digits(kept) + digits(typed)), details);
|
|
26
27
|
};
|
|
27
|
-
return (_jsx(Field, { ...frameOf(props), children: (control) => (_jsxs(_Fragment, { children: [_jsxs("div", { className: "field-with-action", children: [_jsxs("div", { className: `field-box${props.valid === undefined ? '' : ' has-mark'}`, children: [_jsx("input", { ...control, className: `field-control${shown ? '' : ' field-hidden'}`, value: display, inputMode: props.mask.inputMode ?? 'numeric', autoComplete: "off", autoCorrect: "off", autoCapitalize: "off", spellCheck: false, "data-1p-ignore": true, "data-lpignore": "true", onChange: (e) => change(e.target.value), onBlur: props.onBlur }), props.valid ? _jsx(ValidMark, { icon: props.validIcon }) : null] }), _jsx(Button, { intent: "quiet", onClick: () => setShown(!shown), children: shown ? props.hideLabel : props.showLabel })] }), props.note ? (_jsxs("p", { className: "field-note", children: [props.noteIcon, props.note] })) : null] })) }));
|
|
28
|
+
return (_jsx(Field, { ...frameOf(props), children: (control) => (_jsxs(_Fragment, { children: [_jsxs("div", { className: "field-with-action", children: [_jsxs("div", { className: `field-box${props.valid === undefined ? '' : ' has-mark'}`, children: [_jsx("input", { ...control, className: `field-control${shown ? '' : ' field-hidden'}`, value: display, inputMode: props.mask.inputMode ?? 'numeric', autoComplete: "off", autoCorrect: "off", autoCapitalize: "off", spellCheck: false, "data-1p-ignore": true, "data-lpignore": "true", onChange: (e) => change(e.target.value, changeDetails('input-change', e)), onBlur: props.onBlur }), props.valid ? _jsx(ValidMark, { icon: props.validIcon }) : null] }), _jsx(Button, { intent: "quiet", onClick: () => setShown(!shown), children: shown ? props.hideLabel : props.showLabel })] }), props.note ? (_jsxs("p", { className: "field-note", children: [props.noteIcon, props.note] })) : null] })) }));
|
|
28
29
|
}
|
|
29
30
|
/* Slotted (UiKit.tsx): an App's control kit may draw its own in place of the default, with the same props. */
|
|
30
|
-
export const SensitiveField = slotted('SensitiveField', DefaultSensitiveField);
|
|
31
|
+
export const SensitiveField = slotted('SensitiveField', DefaultSensitiveField, { onChange: [1, 'input-change'] });
|
package/dist/Slider.d.ts
CHANGED
|
@@ -4,9 +4,10 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { ReactNode } from 'react';
|
|
6
6
|
import { type FieldFrame } from './fieldFrame.js';
|
|
7
|
+
import { type ChangeDetails } from './changeDetails.js';
|
|
7
8
|
export interface SliderProps extends FieldFrame {
|
|
8
9
|
value: number;
|
|
9
|
-
onChange: (value: number) => void;
|
|
10
|
+
onChange: (value: number, details: ChangeDetails<'slide'>) => void;
|
|
10
11
|
min: number;
|
|
11
12
|
max: number;
|
|
12
13
|
step?: number;
|
package/dist/Slider.js
CHANGED
|
@@ -2,12 +2,13 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
|
|
|
2
2
|
import { Field } from './Field.js';
|
|
3
3
|
import { frameOf } from './fieldFrame.js';
|
|
4
4
|
import { grouped } from './masks.js';
|
|
5
|
+
import { changeDetails } from './changeDetails.js';
|
|
5
6
|
import { slotted } from './internal/uiKitContext.js';
|
|
6
7
|
function DefaultSlider(props) {
|
|
7
8
|
const say = props.format ?? grouped;
|
|
8
9
|
const span = props.max - props.min;
|
|
9
10
|
const share = span > 0 ? ((props.value - props.min) / span) * 100 : 0;
|
|
10
|
-
return (_jsx(Field, { ...frameOf(props), children: (control) => (_jsxs(_Fragment, { children: [_jsx("div", { className: "field-control field-readout", "aria-hidden": "true", children: say(props.value) }), _jsx("input", { ...control, type: "range", className: "field-range", min: props.min, max: props.max, step: props.step, value: props.value, disabled: props.disabled, "aria-valuetext": say(props.value), style: { '--range-share': `${share}%` }, onChange: (e) => props.onChange(Number(e.target.value)) }), _jsxs("div", { className: "field-range-ends", "aria-hidden": "true", children: [_jsx("span", { children: say(props.min) }), _jsx("span", { children: say(props.max) })] })] })) }));
|
|
11
|
+
return (_jsx(Field, { ...frameOf(props), children: (control) => (_jsxs(_Fragment, { children: [_jsx("div", { className: "field-control field-readout", "aria-hidden": "true", children: say(props.value) }), _jsx("input", { ...control, type: "range", className: "field-range", min: props.min, max: props.max, step: props.step, value: props.value, disabled: props.disabled, "aria-valuetext": say(props.value), style: { '--range-share': `${share}%` }, onChange: (e) => props.onChange(Number(e.target.value), changeDetails('slide', e)) }), _jsxs("div", { className: "field-range-ends", "aria-hidden": "true", children: [_jsx("span", { children: say(props.min) }), _jsx("span", { children: say(props.max) })] })] })) }));
|
|
11
12
|
}
|
|
12
13
|
/* Slotted (UiKit.tsx): an App's control kit may draw its own in place of the default, with the same props. */
|
|
13
|
-
export const Slider = slotted('Slider', DefaultSlider);
|
|
14
|
+
export const Slider = slotted('Slider', DefaultSlider, { onChange: [1, 'slide'] });
|
package/dist/Switch.d.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
* and refuses the press itself.
|
|
10
10
|
*/
|
|
11
11
|
import { type ReactNode, type Ref } from 'react';
|
|
12
|
+
import { type ChangeDetails } from './changeDetails.js';
|
|
12
13
|
export interface SwitchProps {
|
|
13
14
|
/** The label beside the switch; its click toggles, as the switch's own does. */
|
|
14
15
|
label?: ReactNode;
|
|
@@ -16,8 +17,7 @@ export interface SwitchProps {
|
|
|
16
17
|
description?: ReactNode;
|
|
17
18
|
checked?: boolean;
|
|
18
19
|
defaultChecked?: boolean;
|
|
19
|
-
|
|
20
|
-
onCheckedChange?: (checked: boolean, event: unknown) => void;
|
|
20
|
+
onCheckedChange?: (checked: boolean, details: ChangeDetails<'toggle'>) => void;
|
|
21
21
|
disabled?: boolean;
|
|
22
22
|
/** Working: pressed once already. Says so and refuses another press, keeping the focus. */
|
|
23
23
|
busy?: boolean;
|
package/dist/Switch.js
CHANGED
|
@@ -11,17 +11,18 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
11
11
|
*/
|
|
12
12
|
import { useId } from 'react';
|
|
13
13
|
import { Switch as BaseSwitch } from '@base-ui/react/switch';
|
|
14
|
+
import { fromBaseUi } from './changeDetails.js';
|
|
14
15
|
import { slotted } from './internal/uiKitContext.js';
|
|
15
16
|
function DefaultSwitch({ label, description, checked, defaultChecked, onCheckedChange, disabled = false, busy = false, id, className, ref, }) {
|
|
16
17
|
/* The label names the switch by its id; a caller who gives none gets
|
|
17
18
|
a generated one, never Base UI's own, which the label cannot know. */
|
|
18
19
|
const generatedId = useId();
|
|
19
20
|
const switchId = id ?? generatedId;
|
|
20
|
-
return (_jsxs("span", { className: ['ui-switch-row', className].filter(Boolean).join(' '), children: [_jsx(BaseSwitch.Root, { id: switchId, ref: ref, className: "ui-switch", checked: checked, defaultChecked: defaultChecked, disabled: disabled, "aria-disabled": busy || undefined, onCheckedChange: (next,
|
|
21
|
+
return (_jsxs("span", { className: ['ui-switch-row', className].filter(Boolean).join(' '), children: [_jsx(BaseSwitch.Root, { id: switchId, ref: ref, className: "ui-switch", checked: checked, defaultChecked: defaultChecked, disabled: disabled, "aria-disabled": busy || undefined, onCheckedChange: (next, details) => {
|
|
21
22
|
if (busy)
|
|
22
23
|
return;
|
|
23
|
-
onCheckedChange?.(next,
|
|
24
|
+
onCheckedChange?.(next, fromBaseUi(details, 'toggle'));
|
|
24
25
|
}, children: _jsx(BaseSwitch.Thumb, { className: "ui-switch-thumb" }) }), label !== undefined || description !== undefined ? (_jsxs("span", { className: "ui-switch-copy", children: [label !== undefined ? (_jsx("label", { htmlFor: switchId, className: "ui-switch-label", children: label })) : null, description !== undefined ? _jsx("span", { className: "ui-switch-description", children: description }) : null] })) : null] }));
|
|
25
26
|
}
|
|
26
27
|
/* Slotted (UiKit.tsx): an App's control kit may draw its own in place of the default, with the same props. */
|
|
27
|
-
export const Switch = slotted('Switch', DefaultSwitch);
|
|
28
|
+
export const Switch = slotted('Switch', DefaultSwitch, { onCheckedChange: [1, 'toggle'] });
|
package/dist/Tabs.d.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* the caller keeps in step.
|
|
8
8
|
*/
|
|
9
9
|
import type { ReactNode } from 'react';
|
|
10
|
+
import { type ChangeDetails } from './changeDetails.js';
|
|
10
11
|
export interface TabItem {
|
|
11
12
|
value: string;
|
|
12
13
|
label: ReactNode;
|
|
@@ -17,9 +18,11 @@ export interface TabsProps {
|
|
|
17
18
|
tabs: readonly TabItem[];
|
|
18
19
|
value?: string;
|
|
19
20
|
defaultValue?: string;
|
|
20
|
-
|
|
21
|
+
/** `select` when a person chose the tab; Base UI's `disabled`, `missing` or `initial` when the chosen tab went away. */
|
|
22
|
+
onValueChange?: (value: string, details: ChangeDetails<'select' | 'disabled' | 'missing' | 'initial'>) => void;
|
|
21
23
|
className?: string;
|
|
22
|
-
/** The tablist's accessible name
|
|
24
|
+
/** The tablist's accessible name ("Settings sections"). Give one: a tab list without a name is read as "tab list" and
|
|
25
|
+
nothing more, and the conformance check (`checkPatterns`) reports it. */
|
|
23
26
|
ariaLabel?: string;
|
|
24
27
|
}
|
|
25
28
|
declare function DefaultTabs({ tabs, value, defaultValue, onValueChange, className, ariaLabel }: TabsProps): import("react").JSX.Element;
|
package/dist/Tabs.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Tabs as BaseTabs } from '@base-ui/react/tabs';
|
|
3
|
+
import { fromBaseUi } from './changeDetails.js';
|
|
3
4
|
import { slotted } from './internal/uiKitContext.js';
|
|
4
5
|
function DefaultTabs({ tabs, value, defaultValue, onValueChange, className, ariaLabel }) {
|
|
5
|
-
return (_jsxs(BaseTabs.Root, { className: ['ui-tabs', className].filter(Boolean).join(' '), value: value, defaultValue: defaultValue ?? tabs.find((tab) => !tab.disabled)?.value, onValueChange: onValueChange, children: [_jsx(BaseTabs.List, { className: "ui-tabs-list", "aria-label": ariaLabel, children: tabs.map((tab) => (_jsx(BaseTabs.Tab, { className: "ui-tab", value: tab.value, disabled: tab.disabled, children: tab.label }, tab.value))) }), tabs.map((tab) => (_jsx(BaseTabs.Panel, { className: "ui-tab-panel", value: tab.value, children: tab.children }, tab.value)))] }));
|
|
6
|
+
return (_jsxs(BaseTabs.Root, { className: ['ui-tabs', className].filter(Boolean).join(' '), value: value, defaultValue: defaultValue ?? tabs.find((tab) => !tab.disabled)?.value, onValueChange: onValueChange && ((next, details) => onValueChange(next, fromBaseUi(details, 'select'))), children: [_jsx(BaseTabs.List, { className: "ui-tabs-list", "aria-label": ariaLabel, children: tabs.map((tab) => (_jsx(BaseTabs.Tab, { className: "ui-tab", value: tab.value, disabled: tab.disabled, children: tab.label }, tab.value))) }), tabs.map((tab) => (_jsx(BaseTabs.Panel, { className: "ui-tab-panel", value: tab.value, children: tab.children }, tab.value)))] }));
|
|
6
7
|
}
|
|
7
8
|
/* Slotted (UiKit.tsx): an App's control kit may draw its own in place of the default, with the same props. */
|
|
8
|
-
export const Tabs = slotted('Tabs', DefaultTabs);
|
|
9
|
+
export const Tabs = slotted('Tabs', DefaultTabs, { onValueChange: [1, 'select'] });
|
package/dist/TextField.d.ts
CHANGED
|
@@ -6,13 +6,14 @@
|
|
|
6
6
|
import type { ReactNode, Ref } from 'react';
|
|
7
7
|
import { type FieldFrame } from './fieldFrame.js';
|
|
8
8
|
import { type Mask } from './masks.js';
|
|
9
|
+
import { type ChangeDetails } from './changeDetails.js';
|
|
9
10
|
/** The mark at a box's inline end: drawn in CSS unless a picture is lent. Decorative: validity is `aria-invalid`'s to say. */
|
|
10
11
|
export declare function ValidMark({ icon }: {
|
|
11
12
|
icon?: ReactNode;
|
|
12
13
|
}): ReactNode;
|
|
13
14
|
export interface TextFieldProps extends FieldFrame {
|
|
14
15
|
value: string;
|
|
15
|
-
onChange: (value: string) => void;
|
|
16
|
+
onChange: (value: string, details: ChangeDetails<'input-change'>) => void;
|
|
16
17
|
onBlur?: () => void;
|
|
17
18
|
/** Present, the box reserves room for the mark; true draws it. Leave it out for a box that never shows one. */
|
|
18
19
|
valid?: boolean;
|
|
@@ -34,7 +35,7 @@ export interface MaskedFieldProps extends Omit<TextFieldProps, 'value' | 'onChan
|
|
|
34
35
|
mask: Mask;
|
|
35
36
|
/** The raw value: the digits, usually. */
|
|
36
37
|
value: string;
|
|
37
|
-
onChange: (raw: string) => void;
|
|
38
|
+
onChange: (raw: string, details: ChangeDetails<'input-change'>) => void;
|
|
38
39
|
}
|
|
39
40
|
/** A box that shows its value through a mask and keeps the raw one: `masks.phone`, `masks.date` (typed MM/DD/YYYY), `masks.ssn`… */
|
|
40
41
|
declare function DefaultMaskedField({ mask, value, onChange, ...rest }: MaskedFieldProps): ReactNode;
|
package/dist/TextField.js
CHANGED
|
@@ -2,23 +2,24 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
|
|
|
2
2
|
import { Field } from './Field.js';
|
|
3
3
|
import { frameOf } from './fieldFrame.js';
|
|
4
4
|
import { masks } from './masks.js';
|
|
5
|
+
import { changeDetails } from './changeDetails.js';
|
|
5
6
|
import { slotted } from './internal/uiKitContext.js';
|
|
6
7
|
/** The mark at a box's inline end: drawn in CSS unless a picture is lent. Decorative: validity is `aria-invalid`'s to say. */
|
|
7
8
|
export function ValidMark({ icon }) {
|
|
8
9
|
return (_jsx("span", { className: "field-mark", "aria-hidden": "true", children: icon }));
|
|
9
10
|
}
|
|
10
11
|
function DefaultTextField(props) {
|
|
11
|
-
return (_jsx(Field, { ...frameOf(props), children: (control) => (_jsxs(_Fragment, { children: [_jsxs("div", { className: `field-box${props.valid === undefined ? '' : ' has-mark'}`, children: [_jsx("input", { ...control, ref: props.inputRef, className: "field-control", type: props.type ?? 'text', name: props.name, value: props.value, inputMode: props.inputMode, autoComplete: props.autoComplete ?? 'off', placeholder: props.placeholder, disabled: props.disabled, readOnly: props.readOnly, onChange: (e) => props.onChange(e.target.value), onBlur: props.onBlur }), props.valid ? _jsx(ValidMark, { icon: props.validIcon }) : null] }), props.after] })) }));
|
|
12
|
+
return (_jsx(Field, { ...frameOf(props), children: (control) => (_jsxs(_Fragment, { children: [_jsxs("div", { className: `field-box${props.valid === undefined ? '' : ' has-mark'}`, children: [_jsx("input", { ...control, ref: props.inputRef, className: "field-control", type: props.type ?? 'text', name: props.name, value: props.value, inputMode: props.inputMode, autoComplete: props.autoComplete ?? 'off', placeholder: props.placeholder, disabled: props.disabled, readOnly: props.readOnly, onChange: (e) => props.onChange(e.target.value, changeDetails('input-change', e)), onBlur: props.onBlur }), props.valid ? _jsx(ValidMark, { icon: props.validIcon }) : null] }), props.after] })) }));
|
|
12
13
|
}
|
|
13
14
|
/** A box that shows its value through a mask and keeps the raw one: `masks.phone`, `masks.date` (typed MM/DD/YYYY), `masks.ssn`… */
|
|
14
15
|
function DefaultMaskedField({ mask, value, onChange, ...rest }) {
|
|
15
|
-
return (_jsx(TextField, { ...rest, value: mask.format(value), onChange: (typed) => onChange(mask.parse(typed)), inputMode: rest.inputMode ?? mask.inputMode, placeholder: rest.placeholder ?? mask.placeholder }));
|
|
16
|
+
return (_jsx(TextField, { ...rest, value: mask.format(value), onChange: (typed, details) => onChange(mask.parse(typed), details), inputMode: rest.inputMode ?? mask.inputMode, placeholder: rest.placeholder ?? mask.placeholder }));
|
|
16
17
|
}
|
|
17
18
|
/** Whole money, drawn `$2,500` (or `25,000` with `symbol=""`). The value is the digits. */
|
|
18
19
|
function DefaultMoneyField({ symbol = '$', ...rest }) {
|
|
19
20
|
return _jsx(MaskedField, { kind: "money", ...rest, mask: masks.money(symbol) });
|
|
20
21
|
}
|
|
21
22
|
/* Slotted (UiKit.tsx): an App's control kit may draw its own in place of the default, with the same props. */
|
|
22
|
-
export const TextField = slotted('TextField', DefaultTextField);
|
|
23
|
-
export const MaskedField = slotted('MaskedField', DefaultMaskedField);
|
|
24
|
-
export const MoneyField = slotted('MoneyField', DefaultMoneyField);
|
|
23
|
+
export const TextField = slotted('TextField', DefaultTextField, { onChange: [1, 'input-change'] });
|
|
24
|
+
export const MaskedField = slotted('MaskedField', DefaultMaskedField, { onChange: [1, 'input-change'] });
|
|
25
|
+
export const MoneyField = slotted('MoneyField', DefaultMoneyField, { onChange: [1, 'input-change'] });
|
package/dist/Tooltip.d.ts
CHANGED
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
* the viewport, and inside an enclosing dialog.
|
|
20
20
|
*/
|
|
21
21
|
import { type ReactNode } from 'react';
|
|
22
|
+
import { type ChangeDetails } from './changeDetails.js';
|
|
22
23
|
export interface TooltipProps {
|
|
23
24
|
/** The element the note belongs to; a button, a word, an icon. */
|
|
24
25
|
trigger: ReactNode;
|
|
@@ -26,7 +27,7 @@ export interface TooltipProps {
|
|
|
26
27
|
children: ReactNode;
|
|
27
28
|
open?: boolean;
|
|
28
29
|
defaultOpen?: boolean;
|
|
29
|
-
onOpenChange?: (open: boolean) => void;
|
|
30
|
+
onOpenChange?: (open: boolean, details: ChangeDetails<'trigger-hover' | 'trigger-focus' | 'trigger-press' | 'outside-press' | 'escape-key' | 'disabled' | 'imperative-action' | 'implicit'>) => void;
|
|
30
31
|
className?: string;
|
|
31
32
|
}
|
|
32
33
|
declare function DefaultTooltip({ trigger, children, open, defaultOpen, onOpenChange, className }: TooltipProps): import("react").JSX.Element;
|
package/dist/Tooltip.js
CHANGED
|
@@ -24,6 +24,7 @@ import { Tooltip as BaseTooltip } from '@base-ui/react/tooltip';
|
|
|
24
24
|
import { layoutViewport, zoomAnchor } from './internal/anchor.js';
|
|
25
25
|
import { ComponentStyleScope } from './internal/ComponentStyleScope.js';
|
|
26
26
|
import { popupContainer, useDialogContainer } from './internal/popups.js';
|
|
27
|
+
import { fromBaseUi } from './changeDetails.js';
|
|
27
28
|
import { slotted } from './internal/uiKitContext.js';
|
|
28
29
|
function DefaultTooltip({ trigger, children, open, defaultOpen, onOpenChange, className }) {
|
|
29
30
|
const tooltipId = useId();
|
|
@@ -44,9 +45,8 @@ function DefaultTooltip({ trigger, children, open, defaultOpen, onOpenChange, cl
|
|
|
44
45
|
return (_jsxs(BaseTooltip.Root, { open: open, defaultOpen: defaultOpen, onOpenChange: (next, details) => {
|
|
45
46
|
if (open === undefined)
|
|
46
47
|
setUncontrolledOpen(next);
|
|
47
|
-
onOpenChange?.(next);
|
|
48
|
-
void details;
|
|
48
|
+
onOpenChange?.(next, fromBaseUi(details, 'implicit'));
|
|
49
49
|
}, children: [_jsx(BaseTooltip.Trigger, { className: "ui-tooltip-trigger", render: triggerElement, ref: anchor }), _jsx(BaseTooltip.Portal, { container: container ?? popupContainer(), children: _jsx(BaseTooltip.Positioner, { anchor: () => (anchor.current ? zoomAnchor(anchor.current) : null), positionMethod: "fixed", sideOffset: 8, collisionBoundary: layoutViewport(), collisionPadding: 8, children: _jsx(BaseTooltip.Popup, { "data-component": componentScope, id: tooltipId, role: "tooltip", className: ['ui-tooltip', className].filter(Boolean).join(' '), children: children }) }) })] }));
|
|
50
50
|
}
|
|
51
51
|
/* Slotted (UiKit.tsx): an App's control kit may draw its own in place of the default, with the same props. */
|
|
52
|
-
export const Tooltip = slotted('Tooltip', DefaultTooltip);
|
|
52
|
+
export const Tooltip = slotted('Tooltip', DefaultTooltip, { onOpenChange: [1, 'implicit'] });
|
package/dist/Typeahead.d.ts
CHANGED
|
@@ -19,9 +19,12 @@
|
|
|
19
19
|
* the enclosing dialog when there is one.
|
|
20
20
|
*/
|
|
21
21
|
import { type InputHTMLAttributes, type ReactNode, type Ref, type RefObject } from 'react';
|
|
22
|
+
import { type ChangeDetails } from './changeDetails.js';
|
|
23
|
+
/** Base UI's reasons for a combobox's text or list moving: typed, cleared, an option pressed, Escape, the focus gone… */
|
|
24
|
+
export type TypeaheadReason = 'trigger-press' | 'input-press' | 'outside-press' | 'item-press' | 'close-press' | 'escape-key' | 'list-navigation' | 'focus-out' | 'input-change' | 'input-clear' | 'clear-press' | 'chip-remove-press' | 'cancel-open' | 'implicit';
|
|
22
25
|
export interface TypeaheadProps<T> {
|
|
23
26
|
text: string;
|
|
24
|
-
onText: (text: string) => void;
|
|
27
|
+
onText: (text: string, details: ChangeDetails<TypeaheadReason>) => void;
|
|
25
28
|
/** Already ranked and bounded; drawn in this order. */
|
|
26
29
|
items: T[];
|
|
27
30
|
itemKey: (item: T) => string;
|
|
@@ -30,7 +33,7 @@ export interface TypeaheadProps<T> {
|
|
|
30
33
|
renderItem: (item: T) => ReactNode;
|
|
31
34
|
onPick: (item: T) => void;
|
|
32
35
|
open: boolean;
|
|
33
|
-
onOpenChange: (open: boolean) => void;
|
|
36
|
+
onOpenChange: (open: boolean, details: ChangeDetails<TypeaheadReason>) => void;
|
|
34
37
|
/** The `<input>`'s own attributes — class, label, placeholder, title, the caller's keys. */
|
|
35
38
|
inputProps: InputHTMLAttributes<HTMLInputElement>;
|
|
36
39
|
inputRef?: Ref<HTMLInputElement>;
|
package/dist/Typeahead.js
CHANGED
|
@@ -24,6 +24,7 @@ import { Autocomplete } from '@base-ui/react/autocomplete';
|
|
|
24
24
|
import { viewportBox } from './internal/ruler.js';
|
|
25
25
|
import { layoutViewport, zoomAnchor } from './internal/anchor.js';
|
|
26
26
|
import { popupContainer } from './internal/popups.js';
|
|
27
|
+
import { changeDetails, fromBaseUi } from './changeDetails.js';
|
|
27
28
|
import { slotted } from './internal/uiKitContext.js';
|
|
28
29
|
function DefaultTypeahead({ text, onText, items, itemKey, itemLabel, itemClassName, renderItem, onPick, open, onOpenChange, inputProps, inputRef, popupRef, anchorRef, fit = 'min-width', popupClassName, listClassName, empty, emptyClassName, portal = 'dialog', autoHighlight = true, onHighlight, }) {
|
|
29
30
|
const input = useRef(null);
|
|
@@ -60,20 +61,40 @@ function DefaultTypeahead({ text, onText, items, itemKey, itemLabel, itemClassNa
|
|
|
60
61
|
else if (inputRef)
|
|
61
62
|
inputRef.current = node;
|
|
62
63
|
};
|
|
64
|
+
/* The list is named as its box is. A box named by a `<label for>` has no name attribute to copy, and pointing the list's
|
|
65
|
+
aria-labelledby at the box itself would read its typed text (an embedded textbox contributes its value), so the
|
|
66
|
+
label's words are read off the input and given as the list's own aria-label; failing a label, the input's title. */
|
|
67
|
+
const [labelWords, setLabelWords] = useState();
|
|
68
|
+
const named = inputProps['aria-label'] !== undefined || inputProps['aria-labelledby'] !== undefined;
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
if (named)
|
|
71
|
+
return;
|
|
72
|
+
const words = [...(input.current?.labels ?? [])]
|
|
73
|
+
.map((label) => (label.textContent ?? '').replace(/\s+/g, ' ').trim())
|
|
74
|
+
.filter(Boolean)
|
|
75
|
+
.join(' ');
|
|
76
|
+
setLabelWords(words || inputProps.title || undefined);
|
|
77
|
+
});
|
|
78
|
+
const listName = {
|
|
79
|
+
label: named ? inputProps['aria-label'] : labelWords,
|
|
80
|
+
labelledBy: inputProps['aria-labelledby'],
|
|
81
|
+
};
|
|
63
82
|
const { onKeyDown, onFocus, ...rest } = inputProps;
|
|
64
83
|
return (_jsxs(Autocomplete.Root, { items: items, filteredItems: items, itemToStringValue: itemLabel, value: text, onValueChange: (next, details) => {
|
|
65
84
|
// Selection fills the input too; it is not a new search or a cleared key.
|
|
66
85
|
if (details.reason !== 'item-press')
|
|
67
|
-
onText(String(next ?? ''));
|
|
68
|
-
}, open: open, onOpenChange: onOpenChange, openOnInputClick: true, autoHighlight: autoHighlight, onItemHighlighted: onHighlight && ((item) => onHighlight(item)), children: [_jsx(Autocomplete.Input, { ...rest, ref: setInput, onFocus: onFocus, onKeyDown: (e) => {
|
|
86
|
+
onText(String(next ?? ''), fromBaseUi(details, 'input-change'));
|
|
87
|
+
}, open: open, onOpenChange: (next, details) => onOpenChange(next, fromBaseUi(details, 'implicit')), openOnInputClick: true, autoHighlight: autoHighlight, onItemHighlighted: onHighlight && ((item) => onHighlight(item)), children: [_jsx(Autocomplete.Input, { ...rest, ref: setInput, onFocus: onFocus, onKeyDown: (e) => {
|
|
69
88
|
onKeyDown?.(e);
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
89
|
+
/* Only this layer: a drawer under the list listens for Escape too. The key stops here while the popup is up even
|
|
90
|
+
when something before this handler already took it, as the caller or Base UI may when the popup holds only
|
|
91
|
+
its empty message — otherwise the drawer under it closes with it. */
|
|
73
92
|
if (e.key === 'Escape' && open) {
|
|
74
|
-
e.preventDefault();
|
|
75
93
|
e.stopPropagation();
|
|
76
|
-
|
|
94
|
+
if (e.defaultPrevented)
|
|
95
|
+
return;
|
|
96
|
+
e.preventDefault();
|
|
97
|
+
onOpenChange(false, changeDetails('escape-key', e));
|
|
77
98
|
}
|
|
78
99
|
} }), _jsx(Autocomplete.Portal, { container: container ?? popupContainer(), children: _jsx(Autocomplete.Positioner, { anchor: () => {
|
|
79
100
|
const el = anchorRef?.current ?? input.current;
|
|
@@ -85,9 +106,9 @@ function DefaultTypeahead({ text, onText, items, itemKey, itemLabel, itemClassNa
|
|
|
85
106
|
...(fit === 'width'
|
|
86
107
|
? { width: anchorWidth === null ? 'var(--anchor-width)' : `${anchorWidth}px`, maxWidth: 'var(--available-width)' }
|
|
87
108
|
: {}),
|
|
88
|
-
}, children:
|
|
109
|
+
}, children: _jsxs(Autocomplete.Popup, { ref: popupRef, className: popupClassName, style: {
|
|
89
110
|
...(fit === 'width' ? { width: '100%' } : { minWidth: 'var(--anchor-width)', maxWidth: 'var(--available-width)' }),
|
|
90
|
-
}, children:
|
|
111
|
+
}, children: [items.length > 0 ? (_jsx(Autocomplete.List, { className: listClassName, "aria-label": listName.label, "aria-labelledby": listName.labelledBy, children: items.map((item) => (_jsx(Autocomplete.Item, { value: item, className: (s) => itemClassName(item, s.highlighted), onClick: () => onPick(item), children: renderItem(item) }, itemKey(item)))) })) : null, empty !== undefined ? (_jsx("div", { className: items.length > 0 ? undefined : listClassName, children: _jsx(Autocomplete.Empty, { className: emptyClassName, children: empty }) })) : null] }) }) })] }));
|
|
91
112
|
}
|
|
92
113
|
/* Slotted (UiKit.tsx): an App's control kit may draw its own in place of the default, with the same props. */
|
|
93
|
-
export const Typeahead = slotted('Typeahead', DefaultTypeahead);
|
|
114
|
+
export const Typeahead = slotted('Typeahead', DefaultTypeahead, { onText: [1, 'input-change'], onOpenChange: [1, 'implicit'] });
|
package/dist/UiKit.d.ts
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
import { type ComponentProps, type ComponentType, type ReactNode } from 'react';
|
|
16
16
|
import type { Avatar } from './Avatar.js';
|
|
17
17
|
import type { Button, ButtonLink } from './Button.js';
|
|
18
|
+
import type { ChangeDetails } from './changeDetails.js';
|
|
18
19
|
import type { CheckCards, Checkbox, ChoiceCards, Consent, YesNo } from './Choices.js';
|
|
19
20
|
import type { DateField } from './DateField.js';
|
|
20
21
|
import type { Drawer } from './Drawer.js';
|
|
@@ -33,7 +34,12 @@ import type { Tooltip } from './Tooltip.js';
|
|
|
33
34
|
import type { TypeaheadProps } from './Typeahead.js';
|
|
34
35
|
import { installUiKit } from './internal/uiKitContext.js';
|
|
35
36
|
import { SLOT_NAMES, uiKitProblems, type SlotName } from './uiKitSlots.js';
|
|
36
|
-
type
|
|
37
|
+
type KitCallback<F> = F extends (...args: [...infer A, infer D extends ChangeDetails<string>]) => infer R ? (...args: A | [...A, D]) => R : F;
|
|
38
|
+
type KitProps<P> = {
|
|
39
|
+
[K in keyof P]: KitCallback<P[K]>;
|
|
40
|
+
};
|
|
41
|
+
type Slot<C extends ComponentType<any>> = ComponentType<KitProps<ComponentProps<C>>>;
|
|
42
|
+
type TypeaheadItemProps = 'itemKey' | 'itemLabel' | 'itemClassName' | 'renderItem' | 'onPick' | 'onHighlight';
|
|
37
43
|
/** Each slot's component, typed by the props the platform draws it with. */
|
|
38
44
|
export interface UiKitSlots {
|
|
39
45
|
Button: Slot<typeof Button>;
|
|
@@ -48,7 +54,7 @@ export interface UiKitSlots {
|
|
|
48
54
|
Dropdown: Slot<typeof Dropdown>;
|
|
49
55
|
MultiDropdown: Slot<typeof MultiDropdown>;
|
|
50
56
|
/** Generic in the item it lists, as the default is. */
|
|
51
|
-
Typeahead: <T>(props: TypeaheadProps<T>) => ReactNode;
|
|
57
|
+
Typeahead: <T>(props: KitProps<Omit<TypeaheadProps<T>, TypeaheadItemProps>> & Pick<TypeaheadProps<T>, TypeaheadItemProps>) => ReactNode;
|
|
52
58
|
DateField: Slot<typeof DateField>;
|
|
53
59
|
Checkbox: Slot<typeof Checkbox>;
|
|
54
60
|
YesNo: Slot<typeof YesNo>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What every change callback here hears second: why the value moved and what moved it. A caller that only wants the
|
|
3
|
+
* value ignores it; one that must tell a person's choice from its own (a filter that should not save when the page set
|
|
4
|
+
* it, a dialog closed by Escape rather than by Save) reads it instead of keeping a flag beside the control.
|
|
5
|
+
*
|
|
6
|
+
* `reason` is Base UI's word where Base UI gives one (`trigger-press`, `outside-press`, `escape-key`, `item-press`,
|
|
7
|
+
* `focus-out` …) and otherwise one short word per primitive; each callback's type lists the words it can hear.
|
|
8
|
+
* `source` is the hand that did it. `event` is the DOM event behind it, absent when the page made the change.
|
|
9
|
+
*/
|
|
10
|
+
export type ChangeSource = 'pointer' | 'keyboard' | 'program';
|
|
11
|
+
export interface ChangeDetails<Reason extends string = string> {
|
|
12
|
+
reason: Reason;
|
|
13
|
+
source: ChangeSource;
|
|
14
|
+
event?: Event;
|
|
15
|
+
}
|
|
16
|
+
/** The hand behind an event: `program` when there is none. */
|
|
17
|
+
export declare function changeSource(event: Event | undefined): ChangeSource;
|
|
18
|
+
/** Details for a change this module's own code makes: a React event's native event, or none when the page did it. */
|
|
19
|
+
export declare function changeDetails<Reason extends string>(reason: Reason, event?: Event | {
|
|
20
|
+
nativeEvent: Event;
|
|
21
|
+
}): ChangeDetails<Reason>;
|
|
22
|
+
export declare function keptDetails<Reason extends string>(reason: Reason): ChangeDetails<Reason>;
|
|
23
|
+
/** Base UI's details in this shape, its reason kept, or this primitive's own word where Base UI says only `none`: a raw
|
|
24
|
+
`none` never reaches a caller, who could not tell which of Base UI's unnamed changes it heard. */
|
|
25
|
+
export declare function fromBaseUi<Reason extends string, Own extends string>(details: {
|
|
26
|
+
reason: Reason;
|
|
27
|
+
event: Event;
|
|
28
|
+
}, own: Own): ChangeDetails<Exclude<Reason, 'none'> | Own>;
|