@glimstone/react 4.1.0 → 4.1.2
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/README.md +7 -0
- package/dist/Button.d.ts +19 -6
- package/dist/Button.js +10 -5
- package/dist/Card.d.ts +3 -1
- package/dist/Card.js +2 -2
- package/dist/Combobox.d.ts +1 -1
- package/dist/Combobox.js +3 -1
- package/dist/ContextMenu.d.ts +3 -1
- package/dist/ContextMenu.js +3 -3
- package/dist/CopyField.d.ts +5 -3
- package/dist/CopyField.js +5 -3
- package/dist/FieldRow.d.ts +20 -0
- package/dist/FieldRow.js +13 -0
- package/dist/FieldRowGroup.d.ts +9 -0
- package/dist/FieldRowGroup.js +5 -0
- package/dist/GlyphField.d.ts +16 -0
- package/dist/GlyphField.js +8 -0
- package/dist/GlyphTile.d.ts +12 -0
- package/dist/GlyphTile.js +5 -0
- package/dist/IconButton.d.ts +16 -0
- package/dist/IconButton.js +9 -0
- package/dist/IconTipButton.d.ts +6 -4
- package/dist/IconTipButton.js +4 -9
- package/dist/ListRow.d.ts +16 -0
- package/dist/ListRow.js +14 -0
- package/dist/MenuBar.d.ts +2 -0
- package/dist/MenuBar.js +1 -1
- package/dist/NumberField.d.ts +1 -1
- package/dist/NumberField.js +4 -2
- package/dist/PasswordField.d.ts +6 -2
- package/dist/PasswordField.js +5 -2
- package/dist/PathField.d.ts +28 -0
- package/dist/PathField.js +32 -0
- package/dist/RowMark.d.ts +5 -0
- package/dist/RowMark.js +6 -0
- package/dist/Select.d.ts +12 -6
- package/dist/Select.js +21 -15
- package/dist/Selector.d.ts +15 -11
- package/dist/Selector.js +11 -6
- package/dist/SidebarRow.d.ts +10 -2
- package/dist/SidebarRow.js +8 -3
- package/dist/Slider.d.ts +1 -1
- package/dist/Slider.js +3 -1
- package/dist/SubCard.d.ts +1 -1
- package/dist/SubCard.js +1 -1
- package/dist/Table.d.ts +14 -0
- package/dist/Table.js +6 -0
- package/dist/TextField.d.ts +23 -0
- package/dist/TextField.js +11 -0
- package/dist/Toast.d.ts +5 -2
- package/dist/Toast.js +9 -4
- package/dist/Toggle.d.ts +5 -4
- package/dist/Toggle.js +7 -2
- package/dist/Tree.d.ts +20 -0
- package/dist/Tree.js +59 -0
- package/dist/Window.d.ts +9 -3
- package/dist/Window.js +7 -5
- package/dist/fieldName.d.ts +4 -0
- package/dist/fieldName.js +9 -0
- package/dist/glyphs.d.ts +1 -0
- package/dist/glyphs.js +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +12 -0
- package/package.json +2 -2
package/dist/RowMark.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { IconCheck } from "./glyphs.js";
|
|
3
|
+
export function RowMark({ on, className }) {
|
|
4
|
+
const classes = ["glim-rowmark", on && "glim-rowmark--on", className].filter(Boolean).join(" ");
|
|
5
|
+
return (_jsx("span", { className: classes, "aria-hidden": "true", children: _jsx(IconCheck, {}) }));
|
|
6
|
+
}
|
package/dist/Select.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { type ReactNode, type Ref } from "react";
|
|
2
|
-
import { type SelectChoice, type SelectEntry as Entry, type SelectRun, type SelectSize, type SelectSubmenu as Submenu, type SelectWidth } from "@glimstone/core";
|
|
2
|
+
import { type SelectChoice, type SelectEntry as Entry, type SelectRows, type SelectRun, type SelectSize, type SelectSubmenu as Submenu, type SelectWidth } from "@glimstone/core";
|
|
3
3
|
export type SelectOption<T extends string = string> = SelectChoice<T, ReactNode>;
|
|
4
4
|
export type SelectSubmenu<T extends string = string> = Submenu<T, ReactNode>;
|
|
5
5
|
export type SelectEntry<T extends string = string> = Entry<T, ReactNode>;
|
|
6
6
|
export type SelectGroup<T extends string = string> = SelectRun<T, ReactNode>;
|
|
7
|
-
export type { SelectSize, SelectWidth } from "@glimstone/core";
|
|
7
|
+
export type { SelectRows, SelectSize, SelectWidth } from "@glimstone/core";
|
|
8
8
|
export interface SelectProps<T extends string = string> {
|
|
9
|
-
/** The field's name, always the accessible name. */
|
|
10
|
-
label
|
|
9
|
+
/** The field's name, always the accessible name. Inside a FieldRow the row gives it and draws the words. */
|
|
10
|
+
label?: string;
|
|
11
11
|
/** Draw the label off screen, for a settings row that names the field at its start. */
|
|
12
12
|
hideLabel?: boolean;
|
|
13
13
|
/** Every choice, in list order, for a list without groups. */
|
|
@@ -19,13 +19,19 @@ export interface SelectProps<T extends string = string> {
|
|
|
19
19
|
onChange: (value: T) => void;
|
|
20
20
|
/** Shown while the value is null. */
|
|
21
21
|
placeholder?: string;
|
|
22
|
-
/** Defaults to `fill` for a field and to `steady` for the smaller sizes. */
|
|
22
|
+
/** Defaults to `fill` for a field and to `steady` for the smaller sizes and inside a FieldRow. */
|
|
23
23
|
width?: SelectWidth;
|
|
24
24
|
size?: SelectSize;
|
|
25
|
+
/** `menu` draws the open list with a context menu's rows, so an app with both shows one kind of menu row. */
|
|
26
|
+
rows?: SelectRows;
|
|
25
27
|
/** Lets a long value run onto a second line instead of ending in an ellipsis, for one whose end says as much as its start, such as a path. */
|
|
26
28
|
wrap?: boolean;
|
|
27
29
|
/** The trigger's id, for a `<label htmlFor>` outside the select. */
|
|
28
30
|
id?: string;
|
|
31
|
+
/** Attributes for the trigger, such as a data hook that says the value. */
|
|
32
|
+
triggerAttrs?: Record<string, string>;
|
|
33
|
+
/** The open list's id. */
|
|
34
|
+
listId?: string;
|
|
29
35
|
/** The trigger's own node, for a caller that hands it the focus. */
|
|
30
36
|
ref?: Ref<HTMLButtonElement>;
|
|
31
37
|
disabled?: boolean;
|
|
@@ -38,4 +44,4 @@ export interface SelectProps<T extends string = string> {
|
|
|
38
44
|
/** Classes for the trigger, for a size the call site needs. */
|
|
39
45
|
className?: string;
|
|
40
46
|
}
|
|
41
|
-
export declare function Select<T extends string = string>({ size, width, wrap, className, options, groups, ...rest }: SelectProps<T>): import("react").JSX.Element;
|
|
47
|
+
export declare function Select<T extends string = string>({ size, rows, label, hideLabel, width, wrap, className, options, groups, ...rest }: SelectProps<T>): import("react").JSX.Element;
|
package/dist/Select.js
CHANGED
|
@@ -3,16 +3,20 @@ import { useEffect, useId, useRef } from "react";
|
|
|
3
3
|
import * as menu from "@zag-js/menu";
|
|
4
4
|
import * as select from "@zag-js/select";
|
|
5
5
|
import { normalizeProps, Portal, useMachine } from "@zag-js/react";
|
|
6
|
-
import { closeOnPageMove, defaultWidth, enableWheelStep, faceLabels, flattenRuns, hasSubmenu, homeRow, isSubmenu, pageDir, SELECT_POSITIONING,
|
|
6
|
+
import { closeOnPageMove, defaultWidth, enableWheelStep, faceLabels, flattenRuns, hasSubmenu, homeRow, isSubmenu, pageDir, SELECT_POSITIONING, selectRootClass, selectRowParts, selectTriggerClass, shake as shakeOnce, wheelValue, } from "@glimstone/core";
|
|
7
|
+
import { useFieldName } from "./fieldName.js";
|
|
7
8
|
import { IconCheck, IconExpand } from "./glyphs.js";
|
|
8
9
|
import { usePortalHue } from "./portalHue.js";
|
|
9
10
|
import { useTipBubble } from "./useTipBubble.js";
|
|
10
|
-
export function Select({ size = "field",
|
|
11
|
+
export function Select({ size = "field", rows = "list", label, hideLabel, width, wrap = false, className = "", options, groups, ...rest }) {
|
|
12
|
+
const name = useFieldName(label);
|
|
13
|
+
const fromRow = label === undefined;
|
|
14
|
+
const shared = { label: name ?? "", hideLabel: hideLabel || fromRow, width: width ?? (fromRow ? "steady" : defaultWidth(size)), rows };
|
|
11
15
|
const runs = groups ?? [{ entries: options ?? [] }];
|
|
12
16
|
const look = `${selectTriggerClass(size, wrap)} ${className}`.trim();
|
|
13
|
-
return hasSubmenu(runs) ? (_jsx(MenuSelect, { ...rest,
|
|
17
|
+
return hasSubmenu(runs) ? (_jsx(MenuSelect, { ...rest, ...shared, groups: runs, className: look })) : (_jsx(ListSelect, { ...rest, ...shared, groups: runs, className: look }));
|
|
14
18
|
}
|
|
15
|
-
function ListSelect({ label, hideLabel, groups, value, onChange, placeholder, width, disabled, busy, tip, shake, className, id, ref, }) {
|
|
19
|
+
function ListSelect({ label, hideLabel, groups, value, onChange, placeholder, width, rows, disabled, busy, tip, shake, className, id, triggerAttrs, listId, ref, }) {
|
|
16
20
|
const uid = useId();
|
|
17
21
|
const all = flattenRuns(groups);
|
|
18
22
|
const collection = select.collection({
|
|
@@ -23,7 +27,7 @@ function ListSelect({ label, hideLabel, groups, value, onChange, placeholder, wi
|
|
|
23
27
|
});
|
|
24
28
|
const service = useMachine(select.machine, {
|
|
25
29
|
id: uid,
|
|
26
|
-
ids:
|
|
30
|
+
ids: { trigger: id, content: listId },
|
|
27
31
|
dir: pageDir(),
|
|
28
32
|
collection,
|
|
29
33
|
value: value === null ? [] : [value],
|
|
@@ -41,21 +45,22 @@ function ListSelect({ label, hideLabel, groups, value, onChange, placeholder, wi
|
|
|
41
45
|
useEffect(() => (api.open ? closeOnPageMove(() => api.setOpen(false)) : undefined), [api.open]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
42
46
|
const hue = usePortalHue(api.open, trigger.ref);
|
|
43
47
|
const glyphs = all.some((o) => o.glyph);
|
|
48
|
+
const parts = selectRowParts(rows, glyphs);
|
|
44
49
|
const tp = api.getTriggerProps();
|
|
45
50
|
const positioner = api.getPositionerProps();
|
|
46
|
-
return (_jsxs("div", { ...api.getRootProps(), className: selectRootClass(width), children: [_jsx("label", { ...api.getLabelProps(), className: hideLabel ? "glim-sr-only" : "glim-field-label", children: label }), _jsx("div", { ...api.getControlProps(), children: trigger.tip.wrap(_jsxs("button", { ...tp, ref: trigger.attach, ...trigger.handlers(tp), "aria-busy": busy || undefined, className: className, children: [_jsx(Face, { all: all, value: value, placeholder: placeholder, width: width, glyphs: glyphs }), _jsx("span", { ...api.getIndicatorProps(), className: "glim-select-indicator", children: _jsx(IconExpand, {}) })] })) }), trigger.tip.bubble, _jsx(Portal, { children: _jsx("div", { ...positioner, style: { ...positioner.style, ...hue.style }, className: `glim-select-positioner ${hue.className}`.trim(), children: _jsx("div", { ...api.getContentProps(), className:
|
|
51
|
+
return (_jsxs("div", { ...api.getRootProps(), className: selectRootClass(width), children: [_jsx("label", { ...api.getLabelProps(), className: hideLabel ? "glim-sr-only" : "glim-field-label", children: label }), _jsx("div", { ...api.getControlProps(), children: trigger.tip.wrap(_jsxs("button", { ...triggerAttrs, ...tp, ref: trigger.attach, ...trigger.handlers(tp), "aria-busy": busy || undefined, className: className, children: [_jsx(Face, { all: all, value: value, placeholder: placeholder, width: width, glyphs: glyphs }), _jsx("span", { ...api.getIndicatorProps(), className: "glim-select-indicator", children: _jsx(IconExpand, {}) })] })) }), trigger.tip.bubble, _jsx(Portal, { children: _jsx("div", { ...positioner, style: { ...positioner.style, ...hue.style }, className: `glim-select-positioner ${hue.className}`.trim(), children: _jsx("div", { ...api.getContentProps(), className: parts.content, children: groups.map((g, gi) => {
|
|
47
52
|
const items = g.entries;
|
|
48
53
|
if (items.length === 0)
|
|
49
54
|
return null;
|
|
50
55
|
const id = `${uid}-g${gi}`;
|
|
51
|
-
return (_jsxs("div", { ...(g.heading ? api.getItemGroupProps({ id }) : {}), className: "glim-select-group", children: [g.heading && (_jsx("div", { ...api.getItemGroupLabelProps({ htmlFor: id }), className:
|
|
56
|
+
return (_jsxs("div", { ...(g.heading ? api.getItemGroupProps({ id }) : {}), className: "glim-select-group", children: [g.heading && (_jsx("div", { ...api.getItemGroupLabelProps({ htmlFor: id }), className: parts.heading, children: g.heading })), items.map((item) => (_jsxs("div", { ...api.getItemProps({ item }), className: parts.item, children: [parts.glyph && _jsx("span", { className: parts.glyph, children: item.glyph }), _jsx("span", { ...api.getItemTextProps({ item }), className: parts.label, children: item.label }), _jsx("span", { ...api.getItemIndicatorProps({ item }), className: parts.check, children: _jsx(IconCheck, {}) })] }, item.value)))] }, gi));
|
|
52
57
|
}) }) }) }), _jsx("select", { ...api.getHiddenSelectProps() })] }));
|
|
53
58
|
}
|
|
54
|
-
function MenuSelect({ label, hideLabel, groups, value, onChange, placeholder, width, disabled, busy, tip, shake, className, id, ref, }) {
|
|
59
|
+
function MenuSelect({ label, hideLabel, groups, value, onChange, placeholder, width, rows, disabled, busy, tip, shake, className, id, triggerAttrs, listId, ref, }) {
|
|
55
60
|
const uid = useId();
|
|
56
61
|
const service = useMachine(menu.machine, {
|
|
57
62
|
id: uid,
|
|
58
|
-
ids:
|
|
63
|
+
ids: { trigger: id, content: listId },
|
|
59
64
|
dir: pageDir(),
|
|
60
65
|
"aria-label": label,
|
|
61
66
|
positioning: SELECT_POSITIONING,
|
|
@@ -66,6 +71,7 @@ function MenuSelect({ label, hideLabel, groups, value, onChange, placeholder, wi
|
|
|
66
71
|
useEffect(() => (api.open ? closeOnPageMove(() => api.setOpen(false)) : undefined), [api.open]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
67
72
|
const hue = usePortalHue(api.open, trigger.ref);
|
|
68
73
|
const glyphs = all.some((o) => o.glyph);
|
|
74
|
+
const parts = selectRowParts(rows, glyphs);
|
|
69
75
|
const subId = (gi, ei) => `${uid}-sub-${gi}-${ei}`;
|
|
70
76
|
// Zag highlights on the frame after the list opens, so the home row goes one
|
|
71
77
|
// frame later still.
|
|
@@ -92,14 +98,14 @@ function MenuSelect({ label, hideLabel, groups, value, onChange, placeholder, wi
|
|
|
92
98
|
fn?.(e);
|
|
93
99
|
};
|
|
94
100
|
const positioner = api.getPositionerProps();
|
|
95
|
-
return (_jsxs("div", { className: selectRootClass(width), children: [!hideLabel && (_jsx("span", { "aria-hidden": "true", className: "glim-field-label", children: label })), _jsx("div", { children: trigger.tip.wrap(_jsxs("button", { ...tp, ref: trigger.attach, ...trigger.handlers(tp), onPointerDown: hold(tp.onPointerDown), onClick: hold(tp.onClick), onKeyDown: hold(tp.onKeyDown), disabled: disabled, "data-disabled": disabled ? "" : undefined, "data-readonly": busy ? "" : undefined, "aria-busy": busy || undefined, "aria-label": `${label}: ${text}`, className: className, children: [_jsx(Face, { all: all, value: value, placeholder: placeholder, width: width, glyphs: glyphs }), _jsx("span", { ...api.getIndicatorProps(), className: "glim-select-indicator", children: _jsx(IconExpand, {}) })] })) }), trigger.tip.bubble, _jsx(Portal, { children: _jsx("div", { ...positioner, style: { ...positioner.style, ...hue.style }, className: `glim-select-positioner ${hue.className}`.trim(), children: _jsx("div", { ...api.getContentProps(), className:
|
|
101
|
+
return (_jsxs("div", { className: selectRootClass(width), children: [!hideLabel && (_jsx("span", { "aria-hidden": "true", className: "glim-field-label", children: label })), _jsx("div", { children: trigger.tip.wrap(_jsxs("button", { ...triggerAttrs, ...tp, ref: trigger.attach, ...trigger.handlers(tp), onPointerDown: hold(tp.onPointerDown), onClick: hold(tp.onClick), onKeyDown: hold(tp.onKeyDown), disabled: disabled, "data-disabled": disabled ? "" : undefined, "data-readonly": busy ? "" : undefined, "aria-busy": busy || undefined, "aria-label": `${label}: ${text}`, className: className, children: [_jsx(Face, { all: all, value: value, placeholder: placeholder, width: width, glyphs: glyphs }), _jsx("span", { ...api.getIndicatorProps(), className: "glim-select-indicator", children: _jsx(IconExpand, {}) })] })) }), trigger.tip.bubble, _jsx(Portal, { children: _jsx("div", { ...positioner, style: { ...positioner.style, ...hue.style }, className: `glim-select-positioner ${hue.className}`.trim(), children: _jsx("div", { ...api.getContentProps(), className: parts.content, children: groups.map((g, gi) => {
|
|
96
102
|
if (g.entries.length === 0)
|
|
97
103
|
return null;
|
|
98
104
|
const id = `g${gi}`;
|
|
99
|
-
return (_jsxs("div", { ...(g.heading ? api.getItemGroupProps({ id }) : {}), className: "glim-select-group", children: [g.heading && (_jsx("div", { ...api.getItemGroupLabelProps({ htmlFor: id }), className:
|
|
105
|
+
return (_jsxs("div", { ...(g.heading ? api.getItemGroupProps({ id }) : {}), className: "glim-select-group", children: [g.heading && (_jsx("div", { ...api.getItemGroupLabelProps({ htmlFor: id }), className: parts.heading, children: g.heading })), g.entries.map((e, ei) => isSubmenu(e) ? (_jsx(SubmenuList, { parent: service, parentApi: api, triggerId: subId(gi, ei), entry: e, value: value, onChange: onChange, parts: parts, hue: hue }, `s${ei}`)) : (_jsx(Choice, { api: api, option: e, value: value, onChange: onChange, parts: parts }, e.value)))] }, gi));
|
|
100
106
|
}) }) }) })] }));
|
|
101
107
|
}
|
|
102
|
-
function SubmenuList({ parent, parentApi, triggerId, entry, value, onChange,
|
|
108
|
+
function SubmenuList({ parent, parentApi, triggerId, entry, value, onChange, parts, hue, }) {
|
|
103
109
|
const service = useMachine(menu.machine, {
|
|
104
110
|
id: useId(),
|
|
105
111
|
ids: { trigger: triggerId },
|
|
@@ -112,9 +118,9 @@ function SubmenuList({ parent, parentApi, triggerId, entry, value, onChange, gly
|
|
|
112
118
|
api.setParent(parent);
|
|
113
119
|
}, []); // eslint-disable-line react-hooks/exhaustive-deps
|
|
114
120
|
const positioner = api.getPositionerProps();
|
|
115
|
-
return (_jsxs(_Fragment, { children: [_jsxs("div", { ...parentApi.getTriggerItemProps(api), className:
|
|
121
|
+
return (_jsxs(_Fragment, { children: [_jsxs("div", { ...parentApi.getTriggerItemProps(api), className: parts.item, children: [parts.glyph && _jsx("span", { className: parts.glyph, children: entry.glyph }), _jsx("span", { className: parts.label, children: entry.label }), _jsx("span", { "aria-hidden": "true", className: parts.caret, children: _jsx(IconExpand, {}) })] }), _jsx(Portal, { children: _jsx("div", { ...positioner, style: { ...positioner.style, ...hue.style }, className: `glim-select-positioner ${hue.className}`.trim(), children: _jsx("div", { ...api.getContentProps(), className: parts.content, children: entry.options.map((o) => (_jsx(Choice, { api: api, option: o, value: value, onChange: onChange, parts: parts }, o.value))) }) }) })] }));
|
|
116
122
|
}
|
|
117
|
-
function Choice({ api, option, value, onChange,
|
|
123
|
+
function Choice({ api, option, value, onChange, parts, }) {
|
|
118
124
|
const checked = option.value === value;
|
|
119
125
|
const item = {
|
|
120
126
|
type: "radio",
|
|
@@ -127,7 +133,7 @@ function Choice({ api, option, value, onChange, glyphs, }) {
|
|
|
127
133
|
onChange(option.value);
|
|
128
134
|
},
|
|
129
135
|
};
|
|
130
|
-
return (_jsxs("div", { ...api.getOptionItemProps(item), className:
|
|
136
|
+
return (_jsxs("div", { ...api.getOptionItemProps(item), className: parts.item, children: [parts.glyph && _jsx("span", { className: parts.glyph, children: option.glyph }), _jsx("span", { ...api.getItemTextProps(item), className: parts.label, children: option.label }), _jsx("span", { "aria-hidden": "true", "data-state": checked ? "checked" : "unchecked", className: parts.check, children: _jsx(IconCheck, {}) })] }));
|
|
131
137
|
}
|
|
132
138
|
function Face({ all, value, placeholder, width, glyphs, }) {
|
|
133
139
|
const { text, labels } = faceLabels(all, value, placeholder, width);
|
package/dist/Selector.d.ts
CHANGED
|
@@ -2,9 +2,9 @@ import { type ReactNode } from "react";
|
|
|
2
2
|
import { type SelectMode, type SelectorActivation, type SelectorOrientation, type SelectorSize, type SelectorVariant } from "@glimstone/core";
|
|
3
3
|
export type { SelectMode, SelectorActivation, SelectorOrientation, SelectorSize, SelectorVariant } from "@glimstone/core";
|
|
4
4
|
export { selectorTabId } from "@glimstone/core";
|
|
5
|
-
export interface SelectorItem {
|
|
6
|
-
/** Stable id, handed back by onChange. */
|
|
7
|
-
id:
|
|
5
|
+
export interface SelectorItem<V extends string | number = string> {
|
|
6
|
+
/** Stable id, handed back by onChange as it stands here. */
|
|
7
|
+
id: V;
|
|
8
8
|
label: string;
|
|
9
9
|
/** Shown before the label; in a tab strip it is tinted with its tab's hue. */
|
|
10
10
|
glyph?: ReactNode;
|
|
@@ -20,17 +20,21 @@ export interface SelectorItem {
|
|
|
20
20
|
href?: string;
|
|
21
21
|
/** Tiles only: a page with nothing on it yet, dimmed rather than hidden. */
|
|
22
22
|
dim?: boolean;
|
|
23
|
+
/** Attributes for the item's own segment, such as a data hook. */
|
|
24
|
+
attrs?: Record<string, string>;
|
|
23
25
|
}
|
|
24
|
-
export interface SelectorProps<M extends SelectMode = "one"> {
|
|
25
|
-
items: SelectorItem[];
|
|
26
|
-
/** The accessible name of the strip, such as "Sort" or "Settings pages". */
|
|
27
|
-
label
|
|
26
|
+
export interface SelectorProps<M extends SelectMode = "one", V extends string | number = string> {
|
|
27
|
+
items: SelectorItem<V>[];
|
|
28
|
+
/** The accessible name of the strip, such as "Sort" or "Settings pages". Inside a FieldRow the row gives it. */
|
|
29
|
+
label?: string;
|
|
28
30
|
/** `one` picks a value, `many` toggles any number of them. Default `one`. */
|
|
29
31
|
select?: M;
|
|
30
32
|
/** The chosen id, or the chosen ids for `many`. */
|
|
31
|
-
value: M extends "many" ? readonly
|
|
33
|
+
value: M extends "many" ? readonly V[] : V | null;
|
|
32
34
|
/** Called with the new id, or the new list for `many`. */
|
|
33
|
-
onChange: (next: M extends "many" ?
|
|
35
|
+
onChange: (next: M extends "many" ? V[] : V) => void;
|
|
36
|
+
/** Called on every press and every arrow key that chooses, before the choice changes, also one on the segment already chosen. */
|
|
37
|
+
onPress?: (id: V) => void;
|
|
34
38
|
/** `vertical` is the column of tiles beside a settings area's pages. */
|
|
35
39
|
orientation?: SelectorOrientation;
|
|
36
40
|
size?: SelectorSize;
|
|
@@ -42,7 +46,7 @@ export interface SelectorProps<M extends SelectMode = "one"> {
|
|
|
42
46
|
* floor where the row has room; the page-level picker. */
|
|
43
47
|
equalWidth?: boolean;
|
|
44
48
|
/** Hug the segments instead of spanning the box, for a strip that shares a
|
|
45
|
-
* toolbar row. */
|
|
49
|
+
* toolbar row, as it does inside a FieldRow. */
|
|
46
50
|
inline?: boolean;
|
|
47
51
|
/** Keep every segment on one row, for page tabs: once the labels do not fit
|
|
48
52
|
* together every segment shows its glyph alone. */
|
|
@@ -64,4 +68,4 @@ export interface SelectorProps<M extends SelectMode = "one"> {
|
|
|
64
68
|
panelId?: string;
|
|
65
69
|
className?: string;
|
|
66
70
|
}
|
|
67
|
-
export declare function Selector<M extends SelectMode = "one">({ items, label, select, value, onChange, orientation, size, variant, activation, equalWidth, inline, fit, pairsOnPhone, buttonHeight, hue, hueOffset, disabled, panelId, className, }: SelectorProps<M>): import("react").JSX.Element;
|
|
71
|
+
export declare function Selector<M extends SelectMode = "one", V extends string | number = string>({ items, label, select, value, onChange, onPress, orientation, size, variant, activation, equalWidth, inline: ownInline, fit, pairsOnPhone, buttonHeight, hue, hueOffset, disabled, panelId, className, }: SelectorProps<M, V>): import("react").JSX.Element;
|
package/dist/Selector.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useId, useLayoutEffect, useRef, useState, useSyncExternalStore, } from "react";
|
|
3
3
|
import { countSelector, DESKTOP_QUERY, mediaMatches, roveSelector, rovedIndex, segmentView, selectorAxis, selectorFlex, selectorTabId, selectorView, subscribeMedia, toggleSelection, watchSelectorFit, watchSelectorRows, WIDE_QUERY, } from "@glimstone/core";
|
|
4
|
+
import { useFieldName } from "./fieldName.js";
|
|
4
5
|
import { useLabelMode } from "./useLabelMode.js";
|
|
5
6
|
import { useTipBubble } from "./useTipBubble.js";
|
|
6
7
|
export { selectorTabId } from "@glimstone/core";
|
|
7
8
|
function useMedia(query) {
|
|
8
9
|
return useSyncExternalStore((fn) => subscribeMedia(query, fn), () => mediaMatches(query), () => true);
|
|
9
10
|
}
|
|
10
|
-
export function Selector({ items, label, select, value, onChange, orientation = "horizontal", size = "md", variant = "well", activation = "auto", equalWidth = false, inline = false, fit = false, pairsOnPhone = false, buttonHeight = false, hue = true, hueOffset, disabled = false, panelId, className = "", }) {
|
|
11
|
+
export function Selector({ items, label, select, value, onChange, onPress, orientation = "horizontal", size = "md", variant = "well", activation = "auto", equalWidth = false, inline: ownInline = false, fit = false, pairsOnPhone = false, buttonHeight = false, hue = true, hueOffset, disabled = false, panelId, className = "", }) {
|
|
12
|
+
const name = useFieldName(label);
|
|
13
|
+
const inline = ownInline || (label === undefined && name !== undefined);
|
|
11
14
|
const vertical = orientation === "vertical";
|
|
12
15
|
const many = select === "many";
|
|
13
16
|
const mode = useLabelMode(selectorAxis(size, orientation));
|
|
@@ -61,6 +64,7 @@ export function Selector({ items, label, select, value, onChange, orientation =
|
|
|
61
64
|
const disabledFlags = items.map((it) => disabled || !!it.disabled);
|
|
62
65
|
const roved = rovedIndex(disabledFlags, items.findIndex((it) => isOn(it.id)));
|
|
63
66
|
function choose(id) {
|
|
67
|
+
onPress?.(id);
|
|
64
68
|
const change = onChange;
|
|
65
69
|
change(chosen ? toggleSelection(chosen, id, items.map((it) => it.id)) : id);
|
|
66
70
|
}
|
|
@@ -75,10 +79,11 @@ export function Selector({ items, label, select, value, onChange, orientation =
|
|
|
75
79
|
if (!node)
|
|
76
80
|
return;
|
|
77
81
|
e.preventDefault();
|
|
78
|
-
|
|
79
|
-
|
|
82
|
+
const item = items.find((it) => String(it.id) === node.dataset.selId);
|
|
83
|
+
if (strip.autoSelect && item)
|
|
84
|
+
choose(item.id);
|
|
80
85
|
}
|
|
81
|
-
return (_jsx("div", { ref: track, role: strip.role, "aria-label":
|
|
86
|
+
return (_jsx("div", { ref: track, role: strip.role, "aria-label": name, "aria-orientation": strip.role === "group" ? undefined : orientation, onKeyDown: onKeyDown, className: `${strip.className} ${className}`.trim(), style: layout.track, children: items.map((item, i) => (_jsx(Segment, { item: item, index: i, strip: strip, on: isOn(item.id), disabled: disabledFlags[i], roved: i === roved, share: vertical ? undefined : layout.segment, squeezed: strip.canSqueeze && fitMode === "squeezed", orientation: orientation, size: size, variant: variant, equalWidth: equalWidth, buttonHeight: buttonHeight, pairsOnPhone: pairsOnPhone, hue: hue, hueOffset: hueOffset, panelId: panelId, onSelect: () => choose(item.id) }, item.id))) }));
|
|
82
87
|
}
|
|
83
88
|
// One segment or tile, a component of its own so each holds its own bubble.
|
|
84
89
|
function Segment({ item, index, strip, on, disabled, roved, share, squeezed, orientation, size, variant, equalWidth, buttonHeight, pairsOnPhone, hue, hueOffset, panelId, onSelect, }) {
|
|
@@ -121,8 +126,8 @@ function Segment({ item, index, strip, on, disabled, roved, share, squeezed, ori
|
|
|
121
126
|
e.preventDefault();
|
|
122
127
|
onSelect();
|
|
123
128
|
};
|
|
124
|
-
return (_jsxs(_Fragment, { children: [_jsx("a", { ref: tooltip.ref, href: item.href, "data-sel-id": item.id, role: "tab", "aria-selected": on, "aria-current": on ? "page" : undefined, "aria-describedby": described, tabIndex: roved ? 0 : -1, className: view.className, style: style, onClick: open, ...tooltip.handlers, children: content }), tooltip.bubble] }));
|
|
129
|
+
return (_jsxs(_Fragment, { children: [_jsx("a", { ...item.attrs, ref: tooltip.ref, href: item.href, "data-sel-id": item.id, role: "tab", "aria-selected": on, "aria-current": on ? "page" : undefined, "aria-describedby": described, tabIndex: roved ? 0 : -1, className: view.className, style: style, onClick: open, ...tooltip.handlers, children: content }), tooltip.bubble] }));
|
|
125
130
|
}
|
|
126
|
-
const button = (_jsx("button", { ref: tooltip.ref, type: "button", "data-sel-id": item.id, id: panelId && tab ? selectorTabId(panelId, item.id) : undefined, role: strip.kind === "toggle" ? undefined : strip.kind, "aria-selected": tab ? on : undefined, "aria-controls": panelId && tab && on ? panelId : undefined, "aria-checked": strip.kind === "radio" ? on : undefined, "aria-pressed": strip.kind === "toggle" ? on : undefined, "aria-label": view.ariaLabel, "aria-describedby": described, disabled: disabled, tabIndex: roved ? 0 : -1, className: view.className, style: style, onClick: onSelect, ...tooltip.handlers, children: content }));
|
|
131
|
+
const button = (_jsx("button", { ...item.attrs, ref: tooltip.ref, type: "button", "data-sel-id": item.id, id: panelId && tab ? selectorTabId(panelId, item.id) : undefined, role: strip.kind === "toggle" ? undefined : strip.kind, "aria-selected": tab ? on : undefined, "aria-controls": panelId && tab && on ? panelId : undefined, "aria-checked": strip.kind === "radio" ? on : undefined, "aria-pressed": strip.kind === "toggle" ? on : undefined, "aria-label": view.ariaLabel, "aria-describedby": described, disabled: disabled, tabIndex: roved ? 0 : -1, className: view.className, style: style, onClick: onSelect, ...tooltip.handlers, children: content }));
|
|
127
132
|
return (_jsxs(_Fragment, { children: [disabled && view.tip ? (_jsx("span", { className: "glim-tip-wrap", style: share, onMouseEnter: tooltip.show, onMouseLeave: tooltip.hide, children: button })) : (button), disabled && view.tip && (_jsx("span", { id: descId, hidden: true, children: view.tip })), tooltip.bubble] }));
|
|
128
133
|
}
|
package/dist/SidebarRow.d.ts
CHANGED
|
@@ -10,7 +10,8 @@ export interface SidebarRowProps extends Omit<AnchorHTMLAttributes<HTMLAnchorEle
|
|
|
10
10
|
label: string;
|
|
11
11
|
/** The destination's glyph. Without one the row shows its name in every mode. */
|
|
12
12
|
glyph?: ReactNode;
|
|
13
|
-
|
|
13
|
+
/** Without one the row is a button. */
|
|
14
|
+
href?: string;
|
|
14
15
|
/** This destination is showing; the row is filled and marked as the current page. */
|
|
15
16
|
active?: boolean;
|
|
16
17
|
/** The row's rainbow position: its rank among the rows the rail shows, so a
|
|
@@ -18,5 +19,12 @@ export interface SidebarRowProps extends Omit<AnchorHTMLAttributes<HTMLAnchorEle
|
|
|
18
19
|
hueIndex?: number;
|
|
19
20
|
/** The figure on the row, such as items that need attention. Nothing shows at zero. */
|
|
20
21
|
count?: SidebarCount;
|
|
22
|
+
/** A tree's row at this level, stepped in with a smaller glyph and gap. */
|
|
23
|
+
depth?: number;
|
|
24
|
+
/** What stands in the row before the link, such as a tree's toggle. */
|
|
25
|
+
before?: ReactNode;
|
|
26
|
+
/** What stands in the row after the link, such as a meter or a pin. The link's
|
|
27
|
+
* press still covers the rest of the row. */
|
|
28
|
+
after?: ReactNode;
|
|
21
29
|
}
|
|
22
|
-
export declare function SidebarRow({ label, glyph, href, active, hueIndex, count, className, ...rest }: SidebarRowProps): import("react").JSX.Element;
|
|
30
|
+
export declare function SidebarRow({ label, glyph, href, active, hueIndex, count, depth, before, after, className, style, ...rest }: SidebarRowProps): import("react").JSX.Element;
|
package/dist/SidebarRow.js
CHANGED
|
@@ -2,9 +2,14 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
|
|
|
2
2
|
import { sidebarRowView } from "@glimstone/core";
|
|
3
3
|
import { useLabelMode } from "./useLabelMode.js";
|
|
4
4
|
import { useTipBubble } from "./useTipBubble.js";
|
|
5
|
-
export function SidebarRow({ label, glyph, href, active = false, hueIndex, count, className = "", ...rest }) {
|
|
5
|
+
export function SidebarRow({ label, glyph, href, active = false, hueIndex, count, depth, before, after, className = "", style, ...rest }) {
|
|
6
6
|
const mode = useLabelMode("sidebar");
|
|
7
|
-
const view = sidebarRowView({ mode, label, hasGlyph: !!glyph, active, hueIndex, count: count?.value });
|
|
7
|
+
const view = sidebarRowView({ mode, label, hasGlyph: !!glyph, active, hueIndex, count: count?.value, framed: !!(before || after), depth });
|
|
8
8
|
const tooltip = useTipBubble(view.tip);
|
|
9
|
-
|
|
9
|
+
const framed = before || after;
|
|
10
|
+
const Element = (href ? "a" : "button");
|
|
11
|
+
const own = href ? { href } : { type: "button" };
|
|
12
|
+
const viewStyle = { ...view.style, ...style };
|
|
13
|
+
const link = (_jsxs(Element, { ...rest, ...own, ref: tooltip.ref, "aria-current": active ? "page" : undefined, "aria-describedby": tooltip.describedBy, ...tooltip.handlers, className: framed ? "glim-nav-row-main" : `${view.className} ${className}`.trim(), style: framed ? undefined : viewStyle, children: [view.showGlyph && glyph, _jsx("span", { className: view.labelClass, children: label }), view.countClass && (_jsxs(_Fragment, { children: [_jsx("span", { className: view.countClass, "aria-hidden": "true", children: count.value }), _jsx("span", { className: "glim-sr-only", children: count.label })] }))] }));
|
|
14
|
+
return (_jsxs(_Fragment, { children: [framed ? (_jsxs("div", { className: `${view.className} glim-nav-row--slots ${className}`.trim(), style: viewStyle, children: [before && _jsx("span", { className: "glim-nav-row-slot", children: before }), link, after && _jsx("span", { className: "glim-nav-row-slot", children: after })] })) : (link), tooltip.bubble] }));
|
|
10
15
|
}
|
package/dist/Slider.d.ts
CHANGED
package/dist/Slider.js
CHANGED
|
@@ -2,7 +2,9 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { useId } from "react";
|
|
3
3
|
import * as slider from "@zag-js/slider";
|
|
4
4
|
import { normalizeProps, useMachine } from "@zag-js/react";
|
|
5
|
+
import { useFieldName } from "./fieldName.js";
|
|
5
6
|
export function Slider({ label, value, onChange, min, max, step = 1, format, disabled }) {
|
|
7
|
+
const name = useFieldName(label);
|
|
6
8
|
const service = useMachine(slider.machine, {
|
|
7
9
|
id: useId(),
|
|
8
10
|
value: [value],
|
|
@@ -14,5 +16,5 @@ export function Slider({ label, value, onChange, min, max, step = 1, format, dis
|
|
|
14
16
|
getAriaValueText: (d) => format(d.value),
|
|
15
17
|
});
|
|
16
18
|
const api = slider.connect(service, normalizeProps);
|
|
17
|
-
return (_jsxs("div", { ...api.getRootProps(), className: "glim-slider", children: [_jsxs("div", { className: "glim-slider-head", children: [_jsx("label", { ...api.getLabelProps(), className: "glim-field-label", children:
|
|
19
|
+
return (_jsxs("div", { ...api.getRootProps(), className: "glim-slider", children: [_jsxs("div", { className: "glim-slider-head", children: [_jsx("label", { ...api.getLabelProps(), className: label === undefined ? "glim-sr-only" : "glim-field-label", children: name }), _jsx("output", { ...api.getValueTextProps(), className: "glim-slider-value", children: format(api.value[0]) })] }), _jsxs("div", { ...api.getControlProps(), className: "glim-slider-control", children: [_jsx("div", { ...api.getTrackProps(), className: "glim-slider-track", children: _jsx("div", { ...api.getRangeProps(), className: "glim-slider-range" }) }), api.value.map((_, index) => (_jsx("div", { ...api.getThumbProps({ index }), className: "glim-slider-thumb", children: _jsx("input", { ...api.getHiddenInputProps({ index }) }) }, index)))] })] }));
|
|
18
20
|
}
|
package/dist/SubCard.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { type ReactNode } from "react";
|
|
|
8
8
|
*/
|
|
9
9
|
export declare function SubCard({ title, hint, children, }: {
|
|
10
10
|
/** The group's name, set small and uppercase above it. */
|
|
11
|
-
title
|
|
11
|
+
title?: string;
|
|
12
12
|
/** One line on what the group does, drawn as an "(i)" beside the title. */
|
|
13
13
|
hint?: string;
|
|
14
14
|
children: ReactNode;
|
package/dist/SubCard.js
CHANGED
|
@@ -10,5 +10,5 @@ import { InfoBubble } from "./InfoBubble.js";
|
|
|
10
10
|
*/
|
|
11
11
|
export function SubCard({ title, hint, children, }) {
|
|
12
12
|
const titleId = useId();
|
|
13
|
-
return (_jsxs("section", { className: "glim-subcard", "aria-labelledby": titleId, children: [_jsxs("h3", { className: "glim-subcard-title", children: [_jsx("span", { id: titleId, children: title }), hint && _jsx(InfoBubble, { tip: hint })] }), children] }));
|
|
13
|
+
return (_jsxs("section", { className: "glim-subcard", "aria-labelledby": title ? titleId : undefined, children: [title && (_jsxs("h3", { className: "glim-subcard-title", children: [_jsx("span", { id: titleId, children: title }), hint && _jsx(InfoBubble, { tip: hint })] })), children] }));
|
|
14
14
|
}
|
package/dist/Table.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import { type TableColumn } from "@glimstone/core";
|
|
3
|
+
export type { TableColumn } from "@glimstone/core";
|
|
4
|
+
export interface TableProps<T extends object> {
|
|
5
|
+
/** The table's accessible name. */
|
|
6
|
+
label: string;
|
|
7
|
+
columns: readonly TableColumn[];
|
|
8
|
+
rows: readonly T[];
|
|
9
|
+
/** One quiet line under the last row, such as how many more there are. */
|
|
10
|
+
more?: string;
|
|
11
|
+
/** Draws a cell of its own. Nothing returned shows the value. */
|
|
12
|
+
cell?: (row: T, column: TableColumn) => ReactNode;
|
|
13
|
+
}
|
|
14
|
+
export declare function Table<T extends object>({ label, columns, rows, more, cell }: TableProps<T>): import("react").JSX.Element;
|
package/dist/Table.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { tableCellClass } from "@glimstone/core";
|
|
3
|
+
export function Table({ label, columns, rows, more, cell }) {
|
|
4
|
+
const value = (row, column) => row[column.key];
|
|
5
|
+
return (_jsxs("table", { className: "glim-table", "aria-label": label, children: [columns.some((c) => c.label) && (_jsx("thead", { children: _jsx("tr", { children: columns.map((c) => (_jsx("th", { scope: "col", className: c.end ? "glim-table-end" : undefined, children: c.label }, c.key))) }) })), _jsxs("tbody", { children: [rows.map((row, i) => (_jsx("tr", { children: columns.map((c) => (_jsx("td", { className: tableCellClass(c) || undefined, children: cell?.(row, c) ?? value(row, c) }, c.key))) }, i))), more && (_jsx("tr", { children: _jsx("td", { colSpan: columns.length, className: "glim-table-muted", children: more }) }))] })] }));
|
|
6
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { InputHTMLAttributes, Ref, TextareaHTMLAttributes } from "react";
|
|
2
|
+
import { type FieldWidth } from "@glimstone/core";
|
|
3
|
+
export type { FieldWidth } from "@glimstone/core";
|
|
4
|
+
export interface TextFieldProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "width"> {
|
|
5
|
+
/** The accessible name. Inside a FieldRow the row gives it. */
|
|
6
|
+
label?: string;
|
|
7
|
+
/** Sets a path or a token in monospace. */
|
|
8
|
+
mono?: boolean;
|
|
9
|
+
width?: FieldWidth;
|
|
10
|
+
className?: string;
|
|
11
|
+
ref?: Ref<HTMLInputElement>;
|
|
12
|
+
}
|
|
13
|
+
export declare function TextField({ label, mono, width, className, type, ...rest }: TextFieldProps): import("react").JSX.Element;
|
|
14
|
+
export interface TextAreaProps extends TextareaHTMLAttributes<HTMLTextAreaElement> {
|
|
15
|
+
/** The accessible name. Inside a FieldRow the row gives it. */
|
|
16
|
+
label?: string;
|
|
17
|
+
/** Sets the text in monospace. */
|
|
18
|
+
mono?: boolean;
|
|
19
|
+
width?: FieldWidth;
|
|
20
|
+
className?: string;
|
|
21
|
+
ref?: Ref<HTMLTextAreaElement>;
|
|
22
|
+
}
|
|
23
|
+
export declare function TextArea({ label, mono, width, className, ...rest }: TextAreaProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { textFieldClass } from "@glimstone/core";
|
|
3
|
+
import { useFieldName } from "./fieldName.js";
|
|
4
|
+
export function TextField({ label, mono, width, className, type = "text", ...rest }) {
|
|
5
|
+
const name = useFieldName(label);
|
|
6
|
+
return _jsx("input", { "aria-label": name, ...rest, type: type, className: `${textFieldClass({ width, mono })} ${className ?? ""}`.trim() });
|
|
7
|
+
}
|
|
8
|
+
export function TextArea({ label, mono, width, className, ...rest }) {
|
|
9
|
+
const name = useFieldName(label);
|
|
10
|
+
return _jsx("textarea", { "aria-label": name, ...rest, className: `${textFieldClass({ width, mono, area: true })} ${className ?? ""}`.trim() });
|
|
11
|
+
}
|
package/dist/Toast.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { type ToastSeverity } from "@glimstone/core";
|
|
1
|
+
import { type ToastAction, type ToastSeverity } from "@glimstone/core";
|
|
2
2
|
export interface ToastCardProps {
|
|
3
3
|
id: string;
|
|
4
4
|
message: string;
|
|
5
5
|
severity: ToastSeverity;
|
|
6
|
+
/** A button such as Undo. A press runs it and dismisses the toast. */
|
|
7
|
+
action?: ToastAction;
|
|
6
8
|
/** Accessible name for the dismiss button, the same for every toast. */
|
|
7
9
|
dismissLabel: string;
|
|
8
10
|
onDismiss: (id: string) => void;
|
|
@@ -11,11 +13,12 @@ export interface ToastCardProps {
|
|
|
11
13
|
onFocus: (id: string) => void;
|
|
12
14
|
onBlur: (id: string) => void;
|
|
13
15
|
}
|
|
14
|
-
export declare function ToastCard({ id, message, severity, dismissLabel, onDismiss, onMouseEnter, onMouseLeave, onFocus, onBlur, }: ToastCardProps): import("react").JSX.Element;
|
|
16
|
+
export declare function ToastCard({ id, message, severity, action, dismissLabel, onDismiss, onMouseEnter, onMouseLeave, onFocus, onBlur, }: ToastCardProps): import("react").JSX.Element;
|
|
15
17
|
export interface ToastViewportEntry {
|
|
16
18
|
id: string;
|
|
17
19
|
message: string;
|
|
18
20
|
severity: ToastSeverity;
|
|
21
|
+
action?: ToastAction;
|
|
19
22
|
}
|
|
20
23
|
export interface ToastViewportProps {
|
|
21
24
|
toasts: ToastViewportEntry[];
|
package/dist/Toast.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { Fragment } from "react";
|
|
3
|
+
import { MARKS, softBreaks, TOAST_MARKS } from "@glimstone/core";
|
|
4
|
+
import { Button } from "./Button.js";
|
|
3
5
|
import { MarkSvg } from "./glyphs.js";
|
|
4
6
|
// "alert" is assertive, so a failure interrupts the screen reader; "status" is
|
|
5
7
|
// polite. Each toast is a new element, which both roles announce on insertion,
|
|
@@ -7,7 +9,7 @@ import { MarkSvg } from "./glyphs.js";
|
|
|
7
9
|
function roleFor(severity) {
|
|
8
10
|
return severity === "success" ? "status" : "alert";
|
|
9
11
|
}
|
|
10
|
-
export function ToastCard({ id, message, severity, dismissLabel, onDismiss, onMouseEnter, onMouseLeave, onFocus, onBlur, }) {
|
|
12
|
+
export function ToastCard({ id, message, severity, action, dismissLabel, onDismiss, onMouseEnter, onMouseLeave, onFocus, onBlur, }) {
|
|
11
13
|
return (_jsxs("div", { role: roleFor(severity),
|
|
12
14
|
// React's onFocus and onBlur bubble, so tabbing onto the dismiss button
|
|
13
15
|
// pauses the countdown like a hover does.
|
|
@@ -16,9 +18,12 @@ export function ToastCard({ id, message, severity, dismissLabel, onDismiss, onMo
|
|
|
16
18
|
e.stopPropagation();
|
|
17
19
|
onDismiss(id);
|
|
18
20
|
}
|
|
19
|
-
}, className: "glim-toast glim-toast-card", children: [_jsx(MarkSvg, { mark: TOAST_MARKS[severity], className: `glim-toast-glyph glim-toast-glyph--${severity}` }),
|
|
21
|
+
}, className: "glim-toast glim-toast-card", children: [_jsx(MarkSvg, { mark: TOAST_MARKS[severity], className: `glim-toast-glyph glim-toast-glyph--${severity}` }), _jsxs("div", { className: "glim-toast-body", children: [_jsx("p", { className: "glim-toast-message", children: softBreaks(message).map((part, i) => (_jsxs(Fragment, { children: [i > 0 && _jsx("wbr", {}), part] }, i))) }), action && (_jsx(Button, { className: "glim-toast-action", tone: "subtle", label: action.label, labelKey: null, onClick: () => {
|
|
22
|
+
action.onClick();
|
|
23
|
+
onDismiss(id);
|
|
24
|
+
} }))] }), _jsx("button", { type: "button", onClick: () => onDismiss(id), "aria-label": dismissLabel, className: "glim-btn-bare glim-toast-dismiss", children: _jsx(MarkSvg, { mark: MARKS.dismiss }) })] }));
|
|
20
25
|
}
|
|
21
26
|
// Toasts render in array order, so the newest sits nearest the bottom edge.
|
|
22
27
|
export function ToastViewport({ toasts, dismissLabel, onDismiss, onMouseEnter, onMouseLeave, onFocus, onBlur }) {
|
|
23
|
-
return (_jsx("div", { className: "glim-toast-stack", children: toasts.map((t) => (_jsx(ToastCard, { id: t.id, message: t.message, severity: t.severity, dismissLabel: dismissLabel, onDismiss: onDismiss, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, onFocus: onFocus, onBlur: onBlur }, t.id))) }));
|
|
28
|
+
return (_jsx("div", { className: "glim-toast-stack", children: toasts.map((t) => (_jsx(ToastCard, { id: t.id, message: t.message, severity: t.severity, action: t.action, dismissLabel: dismissLabel, onDismiss: onDismiss, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, onFocus: onFocus, onBlur: onBlur }, t.id))) }));
|
|
24
29
|
}
|
package/dist/Toggle.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import type { ButtonHTMLAttributes } from "react";
|
|
2
|
+
export interface ToggleProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, "onChange" | "children" | "type" | "role"> {
|
|
2
3
|
/** Current on/off state. */
|
|
3
4
|
checked: boolean;
|
|
4
5
|
/** Called with the flipped value when the switch is activated. */
|
|
5
6
|
onChange: (next: boolean) => void;
|
|
6
|
-
/** Always used as the accessible name; shown as visible text unless hideLabel. */
|
|
7
|
-
label
|
|
7
|
+
/** Always used as the accessible name; shown as visible text unless hideLabel. Inside a FieldRow the row gives it. */
|
|
8
|
+
label?: string;
|
|
8
9
|
/** Suppress the visible caption; the text stays as aria-label. Use it only
|
|
9
10
|
* when the caller draws the same text right next to the switch, never
|
|
10
11
|
* because a card title further up already says it. */
|
|
@@ -13,4 +14,4 @@ export interface ToggleProps {
|
|
|
13
14
|
/** Extra classes for the outer wrapper (e.g. row-alignment nudges). */
|
|
14
15
|
className?: string;
|
|
15
16
|
}
|
|
16
|
-
export declare function Toggle({ checked, onChange, label, hideLabel, disabled, className }: ToggleProps): import("react").JSX.Element;
|
|
17
|
+
export declare function Toggle({ checked, onChange, label, hideLabel, disabled, className, style, onClick, ...rest }: ToggleProps): import("react").JSX.Element;
|
package/dist/Toggle.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import { useFieldName } from "./fieldName.js";
|
|
3
|
+
export function Toggle({ checked, onChange, label, hideLabel = false, disabled, className, style, onClick, ...rest }) {
|
|
4
|
+
const name = useFieldName(label);
|
|
5
|
+
return (_jsxs("span", { className: `glim-toggle${className ? ` ${className}` : ""}`, style: style, children: [label !== undefined && !hideLabel && _jsx("span", { className: "glim-toggle-label", children: label }), _jsx("button", { ...rest, type: "button", role: "switch", "aria-checked": checked, "aria-label": name, disabled: disabled, onClick: (e) => {
|
|
6
|
+
onClick?.(e);
|
|
7
|
+
onChange(!checked);
|
|
8
|
+
}, className: "glim-toggle-track", children: _jsx("span", { className: "glim-toggle-thumb" }) })] }));
|
|
4
9
|
}
|
package/dist/Tree.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { type TreeNode as CoreTreeNode } from "@glimstone/core";
|
|
3
|
+
export type TreeNode = CoreTreeNode<ReactNode>;
|
|
4
|
+
export interface TreeProps {
|
|
5
|
+
/** The tree's accessible name. */
|
|
6
|
+
label: string;
|
|
7
|
+
/** Asked once for the children of a row, and for the top with null. A list that fails is asked for again on the next opening. */
|
|
8
|
+
load: (id: string | null) => readonly TreeNode[] | Promise<readonly TreeNode[]>;
|
|
9
|
+
/** The chosen row's id. */
|
|
10
|
+
value: string | null;
|
|
11
|
+
onChange: (id: string) => void;
|
|
12
|
+
/** Called on a double click or Enter on a row, for a picker that takes it at once. */
|
|
13
|
+
onActivate?: (id: string) => void;
|
|
14
|
+
/** The open rows' ids, for a caller that holds them. */
|
|
15
|
+
open?: string[];
|
|
16
|
+
onOpenChange?: (open: string[]) => void;
|
|
17
|
+
/** The rows open from the start, for a tree that holds them itself. */
|
|
18
|
+
defaultOpen?: string[];
|
|
19
|
+
}
|
|
20
|
+
export declare function Tree({ label, load, value, onChange, onActivate, open, onOpenChange, defaultOpen }: TreeProps): import("react").JSX.Element;
|