@glimstone/react 0.0.0-stage → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/README.md +125 -2
  2. package/dist/AboutCard.d.ts +152 -0
  3. package/dist/AboutCard.js +82 -0
  4. package/dist/Badge.d.ts +47 -0
  5. package/dist/Badge.js +35 -0
  6. package/dist/Button.d.ts +54 -0
  7. package/dist/Button.js +52 -0
  8. package/dist/Card.d.ts +29 -0
  9. package/dist/Card.js +20 -0
  10. package/dist/Checkbox.d.ts +14 -0
  11. package/dist/Checkbox.js +7 -0
  12. package/dist/CoffeeDialog.d.ts +17 -0
  13. package/dist/CoffeeDialog.js +9 -0
  14. package/dist/ColorPicker.d.ts +21 -0
  15. package/dist/ColorPicker.js +68 -0
  16. package/dist/Combobox.d.ts +16 -0
  17. package/dist/Combobox.js +32 -0
  18. package/dist/ConfirmDialog.d.ts +29 -0
  19. package/dist/ConfirmDialog.js +15 -0
  20. package/dist/ContextMenu.d.ts +23 -0
  21. package/dist/ContextMenu.js +137 -0
  22. package/dist/CopyField.d.ts +15 -0
  23. package/dist/CopyField.js +24 -0
  24. package/dist/CryptoDonateDialog.d.ts +61 -0
  25. package/dist/CryptoDonateDialog.js +23 -0
  26. package/dist/DropdownListbox.d.ts +22 -0
  27. package/dist/DropdownListbox.js +182 -0
  28. package/dist/EmptyState.d.ts +19 -0
  29. package/dist/EmptyState.js +10 -0
  30. package/dist/IconTipButton.d.ts +18 -0
  31. package/dist/IconTipButton.js +13 -0
  32. package/dist/InfoBubble.d.ts +4 -0
  33. package/dist/InfoBubble.js +19 -0
  34. package/dist/Kbd.d.ts +5 -0
  35. package/dist/Kbd.js +6 -0
  36. package/dist/MenuBar.d.ts +18 -0
  37. package/dist/MenuBar.js +40 -0
  38. package/dist/Meter.d.ts +18 -0
  39. package/dist/Meter.js +9 -0
  40. package/dist/NumberField.d.ts +16 -0
  41. package/dist/NumberField.js +18 -0
  42. package/dist/PasswordField.d.ts +12 -0
  43. package/dist/PasswordField.js +8 -0
  44. package/dist/PaypalDialog.d.ts +51 -0
  45. package/dist/PaypalDialog.js +20 -0
  46. package/dist/Pill.d.ts +12 -0
  47. package/dist/Pill.js +5 -0
  48. package/dist/ProgressBar.d.ts +14 -0
  49. package/dist/ProgressBar.js +6 -0
  50. package/dist/ReadmeButton.d.ts +29 -0
  51. package/dist/ReadmeButton.js +27 -0
  52. package/dist/Select.d.ts +41 -0
  53. package/dist/Select.js +192 -0
  54. package/dist/Selector.d.ts +67 -0
  55. package/dist/Selector.js +128 -0
  56. package/dist/SidebarRow.d.ts +22 -0
  57. package/dist/SidebarRow.js +10 -0
  58. package/dist/Slider.d.ts +12 -0
  59. package/dist/Slider.js +18 -0
  60. package/dist/SubCard.d.ts +15 -0
  61. package/dist/SubCard.js +14 -0
  62. package/dist/Toast.d.ts +29 -0
  63. package/dist/Toast.js +24 -0
  64. package/dist/Toggle.d.ts +16 -0
  65. package/dist/Toggle.js +4 -0
  66. package/dist/UnavailableNotice.d.ts +15 -0
  67. package/dist/UnavailableNotice.js +12 -0
  68. package/dist/Window.d.ts +37 -0
  69. package/dist/Window.js +43 -0
  70. package/dist/WindowBar.d.ts +24 -0
  71. package/dist/WindowBar.js +31 -0
  72. package/dist/glyphs.d.ts +26 -0
  73. package/dist/glyphs.js +34 -0
  74. package/dist/index.d.ts +39 -0
  75. package/dist/index.js +39 -0
  76. package/dist/portalHue.d.ts +10 -0
  77. package/dist/portalHue.js +15 -0
  78. package/dist/useConfirm.d.ts +26 -0
  79. package/dist/useConfirm.js +39 -0
  80. package/dist/useLabelMode.d.ts +6 -0
  81. package/dist/useLabelMode.js +11 -0
  82. package/dist/usePaypalButtons.d.ts +15 -0
  83. package/dist/usePaypalButtons.js +42 -0
  84. package/dist/useTipBubble.d.ts +34 -0
  85. package/dist/useTipBubble.js +63 -0
  86. package/package.json +28 -4
@@ -0,0 +1,41 @@
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";
3
+ export type SelectOption<T extends string = string> = SelectChoice<T, ReactNode>;
4
+ export type SelectSubmenu<T extends string = string> = Submenu<T, ReactNode>;
5
+ export type SelectEntry<T extends string = string> = Entry<T, ReactNode>;
6
+ export type SelectGroup<T extends string = string> = SelectRun<T, ReactNode>;
7
+ export type { SelectSize, SelectWidth } from "@glimstone/core";
8
+ export interface SelectProps<T extends string = string> {
9
+ /** The field's name, always the accessible name. */
10
+ label: string;
11
+ /** Draw the label off screen, for a settings row that names the field at its start. */
12
+ hideLabel?: boolean;
13
+ /** Every choice, in list order, for a list without groups. */
14
+ options?: SelectOption<T>[];
15
+ /** The list in runs, with headings and submenus. The wheel steps through every option in list order. */
16
+ groups?: SelectGroup<T>[];
17
+ /** Null when there is no one value, such as over a selection whose rows disagree. */
18
+ value: T | null;
19
+ onChange: (value: T) => void;
20
+ /** Shown while the value is null. */
21
+ placeholder?: string;
22
+ /** Defaults to `fill` for a field and to `steady` for the smaller sizes. */
23
+ width?: SelectWidth;
24
+ size?: SelectSize;
25
+ /** 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
+ wrap?: boolean;
27
+ /** The trigger's id, for a `<label htmlFor>` outside the select. */
28
+ id?: string;
29
+ /** The trigger's own node, for a caller that hands it the focus. */
30
+ ref?: Ref<HTMLButtonElement>;
31
+ disabled?: boolean;
32
+ /** A choice is out and its answer not back yet: the trigger keeps its focus but takes no input. */
33
+ busy?: boolean;
34
+ /** A hover bubble, for a trigger with no label beside it whose value does not say what it picks. */
35
+ tip?: string;
36
+ /** The caller's failure counter. Each bump shakes the trigger once, as the value snaps back. */
37
+ shake?: number;
38
+ /** Classes for the trigger, for a size the call site needs. */
39
+ className?: string;
40
+ }
41
+ export declare function Select<T extends string = string>({ size, width, wrap, className, options, groups, ...rest }: SelectProps<T>): import("react").JSX.Element;
package/dist/Select.js ADDED
@@ -0,0 +1,192 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useId, useRef } from "react";
3
+ import * as menu from "@zag-js/menu";
4
+ import * as select from "@zag-js/select";
5
+ import { normalizeProps, Portal, useMachine } from "@zag-js/react";
6
+ import { closeOnPageMove, defaultWidth, enableWheelStep, faceLabels, flattenRuns, hasSubmenu, homeRow, isSubmenu, pageDir, SELECT_POSITIONING, selectContentClass, selectRootClass, selectTriggerClass, shake as shakeOnce, wheelValue, } from "@glimstone/core";
7
+ import { IconCheck, IconExpand } from "./glyphs.js";
8
+ import { usePortalHue } from "./portalHue.js";
9
+ import { useTipBubble } from "./useTipBubble.js";
10
+ export function Select({ size = "field", width = defaultWidth(size), wrap = false, className = "", options, groups, ...rest }) {
11
+ const runs = groups ?? [{ entries: options ?? [] }];
12
+ const look = `${selectTriggerClass(size, wrap)} ${className}`.trim();
13
+ return hasSubmenu(runs) ? (_jsx(MenuSelect, { ...rest, width: width, groups: runs, className: look })) : (_jsx(ListSelect, { ...rest, width: width, groups: runs, className: look }));
14
+ }
15
+ function ListSelect({ label, hideLabel, groups, value, onChange, placeholder, width, disabled, busy, tip, shake, className, id, ref, }) {
16
+ const uid = useId();
17
+ const all = flattenRuns(groups);
18
+ const collection = select.collection({
19
+ items: all,
20
+ itemToValue: (o) => o.value,
21
+ itemToString: (o) => o.label,
22
+ isItemDisabled: (o) => !!o.disabled,
23
+ });
24
+ const service = useMachine(select.machine, {
25
+ id: uid,
26
+ ids: id ? { trigger: id } : undefined,
27
+ dir: pageDir(),
28
+ collection,
29
+ value: value === null ? [] : [value],
30
+ disabled,
31
+ readOnly: busy,
32
+ onValueChange: (d) => {
33
+ const next = d.value[0];
34
+ if (next !== undefined && next !== value)
35
+ onChange(next);
36
+ },
37
+ positioning: SELECT_POSITIONING,
38
+ });
39
+ const api = select.connect(service, normalizeProps);
40
+ const trigger = useTrigger({ all, value, onChange, inert: !!(disabled || busy), tip, disabled, shake, outer: ref });
41
+ useEffect(() => (api.open ? closeOnPageMove(() => api.setOpen(false)) : undefined), [api.open]); // eslint-disable-line react-hooks/exhaustive-deps
42
+ const hue = usePortalHue(api.open, trigger.ref);
43
+ const glyphs = all.some((o) => o.glyph);
44
+ const tp = api.getTriggerProps();
45
+ 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: selectContentClass(glyphs), children: groups.map((g, gi) => {
47
+ const items = g.entries;
48
+ if (items.length === 0)
49
+ return null;
50
+ 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: "glim-select-heading", children: g.heading })), items.map((item) => (_jsxs("div", { ...api.getItemProps({ item }), className: "glim-select-item", children: [glyphs && _jsx("span", { className: "glim-select-glyph", children: item.glyph }), _jsx("span", { ...api.getItemTextProps({ item }), className: "glim-select-label", children: item.label }), _jsx("span", { ...api.getItemIndicatorProps({ item }), className: "glim-select-check", children: _jsx(IconCheck, {}) })] }, item.value)))] }, gi));
52
+ }) }) }) }), _jsx("select", { ...api.getHiddenSelectProps() })] }));
53
+ }
54
+ function MenuSelect({ label, hideLabel, groups, value, onChange, placeholder, width, disabled, busy, tip, shake, className, id, ref, }) {
55
+ const uid = useId();
56
+ const service = useMachine(menu.machine, {
57
+ id: uid,
58
+ ids: id ? { trigger: id } : undefined,
59
+ dir: pageDir(),
60
+ "aria-label": label,
61
+ positioning: SELECT_POSITIONING,
62
+ });
63
+ const api = menu.connect(service, normalizeProps);
64
+ const all = flattenRuns(groups);
65
+ const trigger = useTrigger({ all, value, onChange, inert: !!(disabled || busy), tip, disabled, shake, outer: ref });
66
+ useEffect(() => (api.open ? closeOnPageMove(() => api.setOpen(false)) : undefined), [api.open]); // eslint-disable-line react-hooks/exhaustive-deps
67
+ const hue = usePortalHue(api.open, trigger.ref);
68
+ const glyphs = all.some((o) => o.glyph);
69
+ const subId = (gi, ei) => `${uid}-sub-${gi}-${ei}`;
70
+ // Zag highlights on the frame after the list opens, so the home row goes one
71
+ // frame later still.
72
+ const home = homeRow(groups, value, subId);
73
+ useEffect(() => {
74
+ if (!api.open || home === null)
75
+ return;
76
+ let inner = 0;
77
+ const outer = requestAnimationFrame(() => {
78
+ inner = requestAnimationFrame(() => api.setHighlightedValue(home));
79
+ });
80
+ return () => {
81
+ cancelAnimationFrame(outer);
82
+ cancelAnimationFrame(inner);
83
+ };
84
+ }, [api.open]); // eslint-disable-line react-hooks/exhaustive-deps
85
+ const tp = api.getTriggerProps();
86
+ const { text } = faceLabels(all, value, placeholder, width);
87
+ // While busy the trigger keeps focus but nothing reaches the machine.
88
+ const hold = (fn) => (e) => {
89
+ if (busy)
90
+ e.preventDefault();
91
+ else
92
+ fn?.(e);
93
+ };
94
+ 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: selectContentClass(glyphs), children: groups.map((g, gi) => {
96
+ if (g.entries.length === 0)
97
+ return null;
98
+ 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: "glim-select-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, glyphs: glyphs, hue: hue }, `s${ei}`)) : (_jsx(Choice, { api: api, option: e, value: value, onChange: onChange, glyphs: glyphs }, e.value)))] }, gi));
100
+ }) }) }) })] }));
101
+ }
102
+ function SubmenuList({ parent, parentApi, triggerId, entry, value, onChange, glyphs, hue, }) {
103
+ const service = useMachine(menu.machine, {
104
+ id: useId(),
105
+ ids: { trigger: triggerId },
106
+ dir: pageDir(),
107
+ "aria-label": entry.label,
108
+ });
109
+ const api = menu.connect(service, normalizeProps);
110
+ useEffect(() => {
111
+ parentApi.setChild(service);
112
+ api.setParent(parent);
113
+ }, []); // eslint-disable-line react-hooks/exhaustive-deps
114
+ const positioner = api.getPositionerProps();
115
+ return (_jsxs(_Fragment, { children: [_jsxs("div", { ...parentApi.getTriggerItemProps(api), className: "glim-select-item", children: [glyphs && _jsx("span", { className: "glim-select-glyph", children: entry.glyph }), _jsx("span", { className: "glim-select-label", children: entry.label }), _jsx("span", { "aria-hidden": "true", className: "glim-select-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: selectContentClass(glyphs), children: entry.options.map((o) => (_jsx(Choice, { api: api, option: o, value: value, onChange: onChange, glyphs: glyphs }, o.value))) }) }) })] }));
116
+ }
117
+ function Choice({ api, option, value, onChange, glyphs, }) {
118
+ const checked = option.value === value;
119
+ const item = {
120
+ type: "radio",
121
+ value: option.value,
122
+ valueText: option.label,
123
+ checked,
124
+ disabled: option.disabled,
125
+ onCheckedChange: () => {
126
+ if (!checked)
127
+ onChange(option.value);
128
+ },
129
+ };
130
+ return (_jsxs("div", { ...api.getOptionItemProps(item), className: "glim-select-item", children: [glyphs && _jsx("span", { className: "glim-select-glyph", children: option.glyph }), _jsx("span", { ...api.getItemTextProps(item), className: "glim-select-label", children: option.label }), _jsx("span", { "aria-hidden": "true", "data-state": checked ? "checked" : "unchecked", className: "glim-select-check", children: _jsx(IconCheck, {}) })] }));
131
+ }
132
+ function Face({ all, value, placeholder, width, glyphs, }) {
133
+ const { text, labels } = faceLabels(all, value, placeholder, width);
134
+ return (_jsxs(_Fragment, { children: [glyphs && _jsx("span", { className: "glim-select-glyph", children: all.find((o) => o.value === value)?.glyph }), _jsx("span", { className: "glim-select-value", children: labels.map((l) => (_jsx("span", { "aria-hidden": l !== text || undefined, className: l === text ? undefined : "glim-select-ghost", children: l }, l))) })] }));
135
+ }
136
+ /** What the two triggers share: the wheel, the tip bubble and the shake. */
137
+ function useTrigger(o) {
138
+ const ref = useRef(null);
139
+ const tip = useTipBubble(o.tip, o.disabled);
140
+ // Read through a ref, so the listener is attached once per trigger node.
141
+ const live = useRef(o);
142
+ live.current = o;
143
+ useEffect(() => {
144
+ const el = ref.current;
145
+ if (!el)
146
+ return;
147
+ return enableWheelStep(el, (delta) => {
148
+ const { all, value, onChange, inert } = live.current;
149
+ if (inert)
150
+ return;
151
+ const next = wheelValue(all, value, delta);
152
+ if (next !== undefined)
153
+ onChange(next);
154
+ });
155
+ }, []);
156
+ const count = o.shake ?? 0;
157
+ useEffect(() => (ref.current && count > 0 ? shakeOnce(ref.current) : undefined), [count]);
158
+ return {
159
+ ref: ref,
160
+ tip,
161
+ attach: (el) => {
162
+ ref.current = el;
163
+ tip.ref(el);
164
+ if (typeof o.outer === "function")
165
+ o.outer(el);
166
+ else if (o.outer)
167
+ o.outer.current = el;
168
+ },
169
+ /** The bubble's handlers chained after the machine's own. */
170
+ handlers: (tp) => {
171
+ if (!o.tip)
172
+ return {};
173
+ const run = (fn, e) => {
174
+ if (typeof fn === "function")
175
+ fn(e);
176
+ };
177
+ return {
178
+ onFocus: (e) => {
179
+ run(tp.onFocus, e);
180
+ tip.handlers.onFocus();
181
+ },
182
+ onBlur: (e) => {
183
+ run(tp.onBlur, e);
184
+ tip.handlers.onBlur();
185
+ },
186
+ onMouseEnter: tip.handlers.onMouseEnter,
187
+ onMouseLeave: tip.handlers.onMouseLeave,
188
+ "aria-describedby": tip.describedBy,
189
+ };
190
+ },
191
+ };
192
+ }
@@ -0,0 +1,67 @@
1
+ import { type ReactNode } from "react";
2
+ import { type SelectMode, type SelectorActivation, type SelectorOrientation, type SelectorSize, type SelectorVariant } from "@glimstone/core";
3
+ export type { SelectMode, SelectorActivation, SelectorOrientation, SelectorSize, SelectorVariant } from "@glimstone/core";
4
+ export { selectorTabId } from "@glimstone/core";
5
+ export interface SelectorItem {
6
+ /** Stable id, handed back by onChange. */
7
+ id: string;
8
+ label: string;
9
+ /** Shown before the label; in a tab strip it is tinted with its tab's hue. */
10
+ glyph?: ReactNode;
11
+ disabled?: boolean;
12
+ /** Why the segment is in its state, such as "Pick a folder first" on a
13
+ * disabled one. It goes into the bubble, which a keyboard reaches. */
14
+ title?: string;
15
+ /** The fuller version of a terse label, shown in the bubble. */
16
+ tip?: string;
17
+ /** Shows the glyph alone in every mode but text; the label stays the name. */
18
+ iconOnly?: boolean;
19
+ /** Tiles only: the page's own address, so a tile can open in a new tab. */
20
+ href?: string;
21
+ /** Tiles only: a page with nothing on it yet, dimmed rather than hidden. */
22
+ dim?: boolean;
23
+ }
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: string;
28
+ /** `one` picks a value, `many` toggles any number of them. Default `one`. */
29
+ select?: M;
30
+ /** The chosen id, or the chosen ids for `many`. */
31
+ value: M extends "many" ? readonly string[] : string | null;
32
+ /** Called with the new id, or the new list for `many`. */
33
+ onChange: (next: M extends "many" ? string[] : string) => void;
34
+ /** `vertical` is the column of tiles beside a settings area's pages. */
35
+ orientation?: SelectorOrientation;
36
+ size?: SelectorSize;
37
+ variant?: SelectorVariant;
38
+ /** "manual" moves the focus with the arrows and chooses on Space, Enter or a
39
+ * click, as a radio group; for a strip that saves a setting. */
40
+ activation?: SelectorActivation;
41
+ /** Pin every segment to the widest one's measured width, at least the shared
42
+ * floor where the row has room; the page-level picker. */
43
+ equalWidth?: boolean;
44
+ /** Hug the segments instead of spanning the box, for a strip that shares a
45
+ * toolbar row. */
46
+ inline?: boolean;
47
+ /** Keep every segment on one row, for page tabs: once the labels do not fit
48
+ * together every segment shows its glyph alone. */
49
+ fit?: boolean;
50
+ /** Below 600px, two segments to a row with labels that wrap. */
51
+ pairsOnPhone?: boolean;
52
+ /** The button height for every segment, for a strip beside a Button. */
53
+ buttonHeight?: boolean;
54
+ /** Take a colour under rainbow. Turn it off where the colour means nothing,
55
+ * such as a strip of one, not for looks. */
56
+ hue?: boolean;
57
+ /** Makes the strip a tab strip for colour: each segment keeps its own
58
+ * palette position, counting from here. */
59
+ hueOffset?: number;
60
+ /** Disables every item; an item's own `disabled` applies on top. */
61
+ disabled?: boolean;
62
+ /** The id of the panel a tab strip switches. The chosen tab controls it, and
63
+ * the panel names itself with `aria-labelledby={selectorTabId(panelId, id)}`. */
64
+ panelId?: string;
65
+ className?: string;
66
+ }
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;
@@ -0,0 +1,128 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useId, useLayoutEffect, useRef, useState, useSyncExternalStore, } from "react";
3
+ import { countSelector, DESKTOP_QUERY, mediaMatches, roveSelector, rovedIndex, segmentView, selectorAxis, selectorFlex, selectorTabId, selectorView, subscribeMedia, toggleSelection, watchSelectorFit, watchSelectorRows, WIDE_QUERY, } from "@glimstone/core";
4
+ import { useLabelMode } from "./useLabelMode.js";
5
+ import { useTipBubble } from "./useTipBubble.js";
6
+ export { selectorTabId } from "@glimstone/core";
7
+ function useMedia(query) {
8
+ return useSyncExternalStore((fn) => subscribeMedia(query, fn), () => mediaMatches(query), () => true);
9
+ }
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
+ const vertical = orientation === "vertical";
12
+ const many = select === "many";
13
+ const mode = useLabelMode(selectorAxis(size, orientation));
14
+ const strip = selectorView({
15
+ mode,
16
+ select: many ? "many" : "one",
17
+ activation,
18
+ orientation,
19
+ size,
20
+ variant,
21
+ equalWidth,
22
+ inline,
23
+ fit,
24
+ pairsOnPhone,
25
+ hue,
26
+ hueOffset,
27
+ desktop: useMedia(DESKTOP_QUERY),
28
+ wide: useMedia(WIDE_QUERY),
29
+ items: items.map((it) => ({ hasGlyph: !!it.glyph, iconOnly: !!it.iconOnly })),
30
+ });
31
+ const track = useRef(null);
32
+ useLayoutEffect(() => {
33
+ if (strip.counted)
34
+ return countSelector(track.current);
35
+ }, [strip.counted]);
36
+ // The labels stand in for `items` in the deps: callers rebuild the array on
37
+ // every render, and measuring each time would be wasted work. A segment that
38
+ // turns disabled with a tip is mounted afresh inside the bubble's box, so the
39
+ // watch moves to it through disabledKey.
40
+ const itemsKey = items.map((it) => it.label).join("\n");
41
+ const disabledKey = items.map((it) => (disabled || it.disabled ? "1" : "0")).join("");
42
+ const [rows, setRows] = useState(null);
43
+ useLayoutEffect(() => {
44
+ if (!strip.pinWidth) {
45
+ setRows(null);
46
+ return;
47
+ }
48
+ return watchSelectorRows(track.current, { inline, equalWidth }, setRows);
49
+ }, [strip.pinWidth, equalWidth, inline, itemsKey, disabledKey, size, strip.mode]);
50
+ const [fitMode, setFitMode] = useState("even");
51
+ useLayoutEffect(() => {
52
+ if (!strip.canSqueeze) {
53
+ setFitMode("even");
54
+ return;
55
+ }
56
+ return watchSelectorFit(track.current, setFitMode);
57
+ }, [strip.canSqueeze, itemsKey, disabledKey, size]);
58
+ const layout = selectorFlex({ rows, pinWidth: strip.pinWidth, inline, fit, fitMode, pairsOnPhone });
59
+ const chosen = many ? value : null;
60
+ const isOn = (id) => (chosen ? chosen.includes(id) : value === id);
61
+ const disabledFlags = items.map((it) => disabled || !!it.disabled);
62
+ const roved = rovedIndex(disabledFlags, items.findIndex((it) => isOn(it.id)));
63
+ function choose(id) {
64
+ const change = onChange;
65
+ change(chosen ? toggleSelection(chosen, id, items.map((it) => it.id)) : id);
66
+ }
67
+ function onKeyDown(e) {
68
+ // A tile is a link, and Space does not follow a link on its own.
69
+ if (vertical && e.key === " " && e.target.dataset.selId) {
70
+ e.preventDefault();
71
+ e.target.click();
72
+ return;
73
+ }
74
+ const node = roveSelector(track.current, e.key, orientation);
75
+ if (!node)
76
+ return;
77
+ e.preventDefault();
78
+ if (strip.autoSelect && node.dataset.selId)
79
+ choose(node.dataset.selId);
80
+ }
81
+ return (_jsx("div", { ref: track, role: strip.role, "aria-label": label, "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
+ }
83
+ // One segment or tile, a component of its own so each holds its own bubble.
84
+ function Segment({ item, index, strip, on, disabled, roved, share, squeezed, orientation, size, variant, equalWidth, buttonHeight, pairsOnPhone, hue, hueOffset, panelId, onSelect, }) {
85
+ const view = segmentView({
86
+ strip,
87
+ orientation,
88
+ size,
89
+ variant,
90
+ equalWidth,
91
+ buttonHeight,
92
+ pairsOnPhone,
93
+ hue,
94
+ hueOffset,
95
+ index,
96
+ label: item.label,
97
+ hasGlyph: !!item.glyph,
98
+ iconOnly: !!item.iconOnly,
99
+ tip: item.tip,
100
+ title: item.title,
101
+ on,
102
+ disabled,
103
+ dim: item.dim,
104
+ squeezed,
105
+ });
106
+ const tooltip = useTipBubble(view.tip, disabled);
107
+ // A disabled segment takes no hover or focus, so its reason is a
108
+ // description from the start rather than one that exists only while the
109
+ // bubble is open.
110
+ const descId = useId();
111
+ const described = disabled && view.tip ? descId : tooltip.describedBy;
112
+ const tab = strip.kind === "tab";
113
+ const content = (_jsxs(_Fragment, { children: [view.showGlyph && item.glyph, view.labelClass !== null && (_jsx("span", { "data-sel-label": true, className: view.labelClass, children: item.label }))] }));
114
+ const style = { ...view.style, ...share };
115
+ if (orientation === "vertical") {
116
+ const open = (e) => {
117
+ // A plain click stays in the app; a modified one opens the address
118
+ // beside it, as a link does.
119
+ if (e.ctrlKey || e.metaKey || e.shiftKey || e.altKey || e.button !== 0)
120
+ return;
121
+ e.preventDefault();
122
+ onSelect();
123
+ };
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] }));
125
+ }
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 }));
127
+ 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
+ }
@@ -0,0 +1,22 @@
1
+ import type { AnchorHTMLAttributes, ReactNode } from "react";
2
+ export interface SidebarCount {
3
+ value: number;
4
+ /** The figure in words, such as "3 need attention", because a bare number
5
+ * names nothing. */
6
+ label: string;
7
+ }
8
+ export interface SidebarRowProps extends Omit<AnchorHTMLAttributes<HTMLAnchorElement>, "children"> {
9
+ /** The destination's name: shown, or hidden but still the link's name. */
10
+ label: string;
11
+ /** The destination's glyph. Without one the row shows its name in every mode. */
12
+ glyph?: ReactNode;
13
+ href: string;
14
+ /** This destination is showing; the row is filled and marked as the current page. */
15
+ active?: boolean;
16
+ /** The row's rainbow position: its rank among the rows the rail shows, so a
17
+ * hidden row leaves no gap. */
18
+ hueIndex?: number;
19
+ /** The figure on the row, such as items that need attention. Nothing shows at zero. */
20
+ count?: SidebarCount;
21
+ }
22
+ export declare function SidebarRow({ label, glyph, href, active, hueIndex, count, className, ...rest }: SidebarRowProps): import("react").JSX.Element;
@@ -0,0 +1,10 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { sidebarRowView } from "@glimstone/core";
3
+ import { useLabelMode } from "./useLabelMode.js";
4
+ import { useTipBubble } from "./useTipBubble.js";
5
+ export function SidebarRow({ label, glyph, href, active = false, hueIndex, count, className = "", ...rest }) {
6
+ const mode = useLabelMode("sidebar");
7
+ const view = sidebarRowView({ mode, label, hasGlyph: !!glyph, active, hueIndex, count: count?.value });
8
+ const tooltip = useTipBubble(view.tip);
9
+ return (_jsxs(_Fragment, { children: [_jsxs("a", { ...rest, ref: tooltip.ref, href: href, "aria-current": active ? "page" : undefined, "aria-describedby": tooltip.describedBy, ...tooltip.handlers, className: `${view.className} ${className}`.trim(), style: view.style, 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 })] }))] }), tooltip.bubble] }));
10
+ }
@@ -0,0 +1,12 @@
1
+ export interface SliderProps {
2
+ label: string;
3
+ value: number;
4
+ onChange: (value: number) => void;
5
+ min: number;
6
+ max: number;
7
+ step?: number;
8
+ /** How the value reads, on screen and to a screen reader. */
9
+ format: (value: number) => string;
10
+ disabled?: boolean;
11
+ }
12
+ export declare function Slider({ label, value, onChange, min, max, step, format, disabled }: SliderProps): import("react").JSX.Element;
package/dist/Slider.js ADDED
@@ -0,0 +1,18 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useId } from "react";
3
+ import * as slider from "@zag-js/slider";
4
+ import { normalizeProps, useMachine } from "@zag-js/react";
5
+ export function Slider({ label, value, onChange, min, max, step = 1, format, disabled }) {
6
+ const service = useMachine(slider.machine, {
7
+ id: useId(),
8
+ value: [value],
9
+ min,
10
+ max,
11
+ step,
12
+ disabled,
13
+ onValueChange: (d) => onChange(d.value[0]),
14
+ getAriaValueText: (d) => format(d.value),
15
+ });
16
+ 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: label }), _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
+ }
@@ -0,0 +1,15 @@
1
+ import { type ReactNode } from "react";
2
+ /**
3
+ * A flat, filled group inside a card under a small uppercase title. It groups
4
+ * what belongs together without a second raised surface, and it takes the
5
+ * place of a fold-out: what used to hide behind a click stays in view. Fields
6
+ * and quiet buttons inside it step up one surface, so they do not vanish into
7
+ * its fill.
8
+ */
9
+ export declare function SubCard({ title, hint, children, }: {
10
+ /** The group's name, set small and uppercase above it. */
11
+ title: string;
12
+ /** One line on what the group does, drawn as an "(i)" beside the title. */
13
+ hint?: string;
14
+ children: ReactNode;
15
+ }): import("react").JSX.Element;
@@ -0,0 +1,14 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useId } from "react";
3
+ import { InfoBubble } from "./InfoBubble.js";
4
+ /**
5
+ * A flat, filled group inside a card under a small uppercase title. It groups
6
+ * what belongs together without a second raised surface, and it takes the
7
+ * place of a fold-out: what used to hide behind a click stays in view. Fields
8
+ * and quiet buttons inside it step up one surface, so they do not vanish into
9
+ * its fill.
10
+ */
11
+ export function SubCard({ title, hint, children, }) {
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] }));
14
+ }
@@ -0,0 +1,29 @@
1
+ import { type ToastSeverity } from "@glimstone/core";
2
+ export interface ToastCardProps {
3
+ id: string;
4
+ message: string;
5
+ severity: ToastSeverity;
6
+ /** Accessible name for the dismiss button, the same for every toast. */
7
+ dismissLabel: string;
8
+ onDismiss: (id: string) => void;
9
+ onMouseEnter: (id: string) => void;
10
+ onMouseLeave: (id: string) => void;
11
+ onFocus: (id: string) => void;
12
+ onBlur: (id: string) => void;
13
+ }
14
+ export declare function ToastCard({ id, message, severity, dismissLabel, onDismiss, onMouseEnter, onMouseLeave, onFocus, onBlur, }: ToastCardProps): import("react").JSX.Element;
15
+ export interface ToastViewportEntry {
16
+ id: string;
17
+ message: string;
18
+ severity: ToastSeverity;
19
+ }
20
+ export interface ToastViewportProps {
21
+ toasts: ToastViewportEntry[];
22
+ dismissLabel: string;
23
+ onDismiss: (id: string) => void;
24
+ onMouseEnter: (id: string) => void;
25
+ onMouseLeave: (id: string) => void;
26
+ onFocus: (id: string) => void;
27
+ onBlur: (id: string) => void;
28
+ }
29
+ export declare function ToastViewport({ toasts, dismissLabel, onDismiss, onMouseEnter, onMouseLeave, onFocus, onBlur }: ToastViewportProps): import("react").JSX.Element;
package/dist/Toast.js ADDED
@@ -0,0 +1,24 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { TOAST_MARKS, MARKS } from "@glimstone/core";
3
+ import { MarkSvg } from "./glyphs.js";
4
+ // "alert" is assertive, so a failure interrupts the screen reader; "status" is
5
+ // polite. Each toast is a new element, which both roles announce on insertion,
6
+ // so no separate aria-live wrapper is needed.
7
+ function roleFor(severity) {
8
+ return severity === "success" ? "status" : "alert";
9
+ }
10
+ export function ToastCard({ id, message, severity, dismissLabel, onDismiss, onMouseEnter, onMouseLeave, onFocus, onBlur, }) {
11
+ return (_jsxs("div", { role: roleFor(severity),
12
+ // React's onFocus and onBlur bubble, so tabbing onto the dismiss button
13
+ // pauses the countdown like a hover does.
14
+ onMouseEnter: () => onMouseEnter(id), onMouseLeave: () => onMouseLeave(id), onFocus: () => onFocus(id), onBlur: () => onBlur(id), onKeyDown: (e) => {
15
+ if (e.key === "Escape") {
16
+ e.stopPropagation();
17
+ onDismiss(id);
18
+ }
19
+ }, className: "glim-toast glim-toast-card", children: [_jsx(MarkSvg, { mark: TOAST_MARKS[severity], className: `glim-toast-glyph glim-toast-glyph--${severity}` }), _jsx("p", { className: "glim-toast-message", children: message }), _jsx("button", { type: "button", onClick: () => onDismiss(id), "aria-label": dismissLabel, className: "glim-btn-bare glim-toast-dismiss", children: _jsx(MarkSvg, { mark: MARKS.dismiss }) })] }));
20
+ }
21
+ // Toasts render in array order, so the newest sits nearest the bottom edge.
22
+ 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))) }));
24
+ }
@@ -0,0 +1,16 @@
1
+ export interface ToggleProps {
2
+ /** Current on/off state. */
3
+ checked: boolean;
4
+ /** Called with the flipped value when the switch is activated. */
5
+ onChange: (next: boolean) => void;
6
+ /** Always used as the accessible name; shown as visible text unless hideLabel. */
7
+ label: string;
8
+ /** Suppress the visible caption; the text stays as aria-label. Use it only
9
+ * when the caller draws the same text right next to the switch, never
10
+ * because a card title further up already says it. */
11
+ hideLabel?: boolean;
12
+ disabled?: boolean;
13
+ /** Extra classes for the outer wrapper (e.g. row-alignment nudges). */
14
+ className?: string;
15
+ }
16
+ export declare function Toggle({ checked, onChange, label, hideLabel, disabled, className }: ToggleProps): import("react").JSX.Element;
package/dist/Toggle.js ADDED
@@ -0,0 +1,4 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ export function Toggle({ checked, onChange, label, hideLabel = false, disabled, className }) {
3
+ return (_jsxs("span", { className: `glim-toggle${className ? ` ${className}` : ""}`, children: [!hideLabel && _jsx("span", { className: "glim-toggle-label", children: label }), _jsx("button", { type: "button", role: "switch", "aria-checked": checked, "aria-label": label, disabled: disabled, onClick: () => onChange(!checked), className: "glim-toggle-track", children: _jsx("span", { className: "glim-toggle-thumb" }) })] }));
4
+ }
@@ -0,0 +1,15 @@
1
+ import type { ReactNode } from "react";
2
+ export declare function UnavailableNotice({ title, reason, action, }: {
3
+ /** One line saying what is unavailable. Already translated. */
4
+ title: string;
5
+ /**
6
+ * Why, and ideally what would change it. Already translated. A node lets a
7
+ * caller mark up a hostname or a path inside it.
8
+ */
9
+ reason: ReactNode;
10
+ /**
11
+ * A control for what somebody can do from here, such as opening the setting
12
+ * that fixes the cause. Never the control that was refused.
13
+ */
14
+ action?: ReactNode;
15
+ }): import("react").JSX.Element;