@glimstone/react 4.0.0 → 4.1.1

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 (76) hide show
  1. package/README.md +14 -0
  2. package/dist/Button.d.ts +19 -6
  3. package/dist/Button.js +10 -5
  4. package/dist/Card.d.ts +3 -1
  5. package/dist/Card.js +2 -2
  6. package/dist/Checkbox.d.ts +14 -0
  7. package/dist/Checkbox.js +7 -0
  8. package/dist/ColorPicker.d.ts +21 -0
  9. package/dist/ColorPicker.js +68 -0
  10. package/dist/Combobox.d.ts +1 -1
  11. package/dist/Combobox.js +3 -1
  12. package/dist/ContextMenu.d.ts +25 -0
  13. package/dist/ContextMenu.js +137 -0
  14. package/dist/CopyField.d.ts +17 -0
  15. package/dist/CopyField.js +26 -0
  16. package/dist/FieldRow.d.ts +20 -0
  17. package/dist/FieldRow.js +13 -0
  18. package/dist/FieldRowGroup.d.ts +9 -0
  19. package/dist/FieldRowGroup.js +5 -0
  20. package/dist/GlyphField.d.ts +16 -0
  21. package/dist/GlyphField.js +8 -0
  22. package/dist/GlyphTile.d.ts +12 -0
  23. package/dist/GlyphTile.js +5 -0
  24. package/dist/IconButton.d.ts +16 -0
  25. package/dist/IconButton.js +9 -0
  26. package/dist/IconTipButton.d.ts +6 -4
  27. package/dist/IconTipButton.js +4 -9
  28. package/dist/Kbd.d.ts +5 -0
  29. package/dist/Kbd.js +6 -0
  30. package/dist/ListRow.d.ts +16 -0
  31. package/dist/ListRow.js +14 -0
  32. package/dist/MenuBar.d.ts +20 -0
  33. package/dist/MenuBar.js +40 -0
  34. package/dist/Meter.d.ts +18 -0
  35. package/dist/Meter.js +9 -0
  36. package/dist/NumberField.d.ts +1 -1
  37. package/dist/NumberField.js +4 -2
  38. package/dist/PasswordField.d.ts +16 -0
  39. package/dist/PasswordField.js +11 -0
  40. package/dist/PathField.d.ts +28 -0
  41. package/dist/PathField.js +32 -0
  42. package/dist/Pill.d.ts +12 -0
  43. package/dist/Pill.js +5 -0
  44. package/dist/ProgressBar.d.ts +14 -0
  45. package/dist/ProgressBar.js +6 -0
  46. package/dist/RowMark.d.ts +5 -0
  47. package/dist/RowMark.js +6 -0
  48. package/dist/Select.d.ts +12 -6
  49. package/dist/Select.js +21 -15
  50. package/dist/Selector.d.ts +15 -11
  51. package/dist/Selector.js +11 -6
  52. package/dist/SidebarRow.d.ts +10 -2
  53. package/dist/SidebarRow.js +8 -3
  54. package/dist/Slider.d.ts +1 -1
  55. package/dist/Slider.js +3 -1
  56. package/dist/SubCard.d.ts +1 -1
  57. package/dist/SubCard.js +1 -1
  58. package/dist/Table.d.ts +14 -0
  59. package/dist/Table.js +6 -0
  60. package/dist/TextField.d.ts +23 -0
  61. package/dist/TextField.js +11 -0
  62. package/dist/Toast.d.ts +5 -2
  63. package/dist/Toast.js +9 -4
  64. package/dist/Toggle.d.ts +5 -4
  65. package/dist/Toggle.js +7 -2
  66. package/dist/Tree.d.ts +20 -0
  67. package/dist/Tree.js +59 -0
  68. package/dist/Window.d.ts +43 -0
  69. package/dist/Window.js +45 -0
  70. package/dist/fieldName.d.ts +4 -0
  71. package/dist/fieldName.js +9 -0
  72. package/dist/glyphs.d.ts +5 -0
  73. package/dist/glyphs.js +5 -0
  74. package/dist/index.d.ts +24 -0
  75. package/dist/index.js +23 -0
  76. package/package.json +2 -2
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
- if (strip.autoSelect && node.dataset.selId)
79
- choose(node.dataset.selId);
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": 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))) }));
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
  }
@@ -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
- href: string;
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;
@@ -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
- 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] }));
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
@@ -1,5 +1,5 @@
1
1
  export interface SliderProps {
2
- label: string;
2
+ label?: string;
3
3
  value: number;
4
4
  onChange: (value: number) => void;
5
5
  min: number;
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: 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)))] })] }));
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: string;
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
  }
@@ -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 { TOAST_MARKS, MARKS } from "@glimstone/core";
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}` }), _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 }) })] }));
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
- export interface ToggleProps {
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: string;
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
- 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" }) })] }));
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;
package/dist/Tree.js ADDED
@@ -0,0 +1,59 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createElement as _createElement } from "react";
3
+ import { useEffect, useRef, useState } from "react";
4
+ import { focusTreeRow, treeRows, treeStep } from "@glimstone/core";
5
+ import { IconExpand } from "./glyphs.js";
6
+ export function Tree({ label, load, value, onChange, onActivate, open, onOpenChange, defaultOpen = [] }) {
7
+ const [ownOpen, setOwnOpen] = useState(defaultOpen);
8
+ const opened = open ?? ownOpen;
9
+ const [children, setChildren] = useState(new Map());
10
+ const asked = useRef(new Set());
11
+ const tree = useRef(null);
12
+ // The ids stand in for `opened` in the deps, since a caller may rebuild the array on every render.
13
+ const openKey = opened.join("\n");
14
+ useEffect(() => {
15
+ for (const id of [null, ...opened]) {
16
+ if (asked.current.has(id))
17
+ continue;
18
+ asked.current.add(id);
19
+ Promise.resolve(load(id)).then((nodes) => setChildren((known) => new Map(known).set(id, nodes)), () => asked.current.delete(id));
20
+ }
21
+ }, [openKey]); // eslint-disable-line react-hooks/exhaustive-deps
22
+ const rows = treeRows(children, opened);
23
+ const stop = Math.max(rows.findIndex((r) => r.node.id === value), 0);
24
+ function toggle(id) {
25
+ const next = opened.includes(id) ? opened.filter((o) => o !== id) : [...opened, id];
26
+ setOwnOpen(next);
27
+ onOpenChange?.(next);
28
+ }
29
+ function keys(e, at) {
30
+ if (e.ctrlKey || e.metaKey || e.altKey)
31
+ return;
32
+ const id = rows[at].node.id;
33
+ if (e.key === " " || e.key === "Enter") {
34
+ e.preventDefault();
35
+ onChange(id);
36
+ if (e.key === "Enter")
37
+ onActivate?.(id);
38
+ return;
39
+ }
40
+ const step = treeStep(rows, at, e.key, getComputedStyle(tree.current).direction === "rtl");
41
+ if (!step)
42
+ return;
43
+ e.preventDefault();
44
+ if ("focus" in step) {
45
+ onChange(step.focus);
46
+ focusTreeRow(tree.current, step.focus);
47
+ }
48
+ else
49
+ toggle("open" in step ? step.open : step.close);
50
+ }
51
+ return (_jsx("div", { ref: tree, role: "tree", "aria-label": label, className: "glim-tree", children: rows.map((r, i) => (_createElement("div", { ...r.node.attrs, key: r.node.id, role: "treeitem", "aria-level": r.level, "aria-posinset": r.position, "aria-setsize": r.siblings, "aria-expanded": r.node.hasChildren ? r.open : undefined, "aria-selected": r.node.id === value, tabIndex: i === stop ? 0 : -1, "data-tree-id": r.node.id, className: "glim-tree-row", style: { "--tree-level": r.level - 1 }, onClick: () => onChange(r.node.id), onDoubleClick: () => onActivate?.(r.node.id), onKeyDown: (e) => keys(e, i) },
52
+ _jsx("span", { className: "glim-tree-toggle", "aria-hidden": "true", onClick: (e) => {
53
+ e.stopPropagation();
54
+ if (r.node.hasChildren)
55
+ toggle(r.node.id);
56
+ }, onDoubleClick: (e) => e.stopPropagation(), children: r.node.hasChildren && _jsx(IconExpand, {}) }),
57
+ r.node.glyph && (_jsx("span", { className: "glim-tree-glyph", "aria-hidden": "true", children: (r.open && r.node.openGlyph) || r.node.glyph })),
58
+ _jsx("span", { className: "glim-tree-label", children: r.node.label })))) }));
59
+ }
@@ -0,0 +1,43 @@
1
+ import { type HTMLAttributes, type ReactNode, type Ref } from "react";
2
+ import { type WindowSize } from "@glimstone/core";
3
+ export type { WindowSize } from "@glimstone/core";
4
+ export interface WindowAction {
5
+ label: string;
6
+ /** The translation key behind `label`, which picks the glyph, or `null`. */
7
+ labelKey: string | null;
8
+ glyph?: ReactNode;
9
+ /** The forward action, filled with the accent and placed last. */
10
+ primary?: boolean;
11
+ /** This action already leaves the window, such as Done, so no Cancel or Close is added. */
12
+ wayOut?: boolean;
13
+ disabled?: boolean;
14
+ /** Attributes for the action's button, such as a data hook. */
15
+ attrs?: Record<string, string>;
16
+ /** Runs on press. The window closes afterwards unless it returns false. */
17
+ onClick?: () => void | false;
18
+ }
19
+ export interface WindowProps extends Omit<HTMLAttributes<HTMLDivElement>, "title" | "children"> {
20
+ /** The notch's words, also the window's accessible name. */
21
+ title: string;
22
+ /** Takes the words' place in the notch with markup, such as a count. `title` alone stays the name. */
23
+ drawn?: ReactNode;
24
+ children: ReactNode;
25
+ /** The foot's buttons, in reading order. Cancel or Close is added before
26
+ * them unless one of them is a way out itself. */
27
+ actions?: WindowAction[];
28
+ /** A quiet line at the start of the foot, such as where the work carries on. */
29
+ start?: ReactNode;
30
+ /** `normal` for a question or a form, `wide` for a list, `full` for a tool. */
31
+ size?: WindowSize;
32
+ /** The words of the way out the window adds. */
33
+ text: {
34
+ cancel: string;
35
+ close: string;
36
+ };
37
+ /** Called for every way out: the foot, Escape and a press beside the window. */
38
+ onClose: () => void;
39
+ className?: string;
40
+ /** The card element. */
41
+ ref?: Ref<HTMLDivElement>;
42
+ }
43
+ export declare function Window({ title, drawn, children, actions, start, size, text, onClose, className, ref, ...rest }: WindowProps): import("react").ReactPortal;
package/dist/Window.js ADDED
@@ -0,0 +1,45 @@
1
+ import { createElement as _createElement } from "react";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ // The general window: a notch with the title, a body for anything and a foot
4
+ // whose actions stand at the end. It owns the portal, its place on the stack,
5
+ // Escape, the Tab trap and the focus, so a caller only mounts it and unmounts
6
+ // it on onClose. The other props of a <div> go to the card.
7
+ import { useId, useImperativeHandle, useLayoutEffect, useRef, useState } from "react";
8
+ import { createPortal } from "react-dom";
9
+ import { focusedAsker, menuIsOpen, returnFocus, stackWindow, windowFocusTarget, windowFoot, } from "@glimstone/core";
10
+ import { Badge } from "./Badge.js";
11
+ import { Button } from "./Button.js";
12
+ import { IconCancel, IconClose } from "./glyphs.js";
13
+ export function Window({ title, drawn, children, actions = [], start, size = "normal", text, onClose, className, ref, ...rest }) {
14
+ const card = useRef(null);
15
+ useImperativeHandle(ref, () => card.current);
16
+ const titleId = useId();
17
+ // Read before the window takes the focus.
18
+ const [asker] = useState(focusedAsker);
19
+ const close = useRef(onClose);
20
+ useLayoutEffect(() => {
21
+ close.current = onClose;
22
+ });
23
+ useLayoutEffect(() => {
24
+ const unstack = stackWindow(() => card.current, () => close.current());
25
+ if (card.current)
26
+ windowFocusTarget(card.current)?.focus();
27
+ return () => {
28
+ unstack();
29
+ returnFocus(asker);
30
+ };
31
+ }, [asker]);
32
+ const foot = windowFoot(actions, start !== undefined, {
33
+ cancel: { label: text.cancel, labelKey: "common.cancel", glyph: _jsx(IconCancel, {}), wayOut: true },
34
+ close: { label: text.close, labelKey: "common.close", glyph: _jsx(IconClose, {}), wayOut: true },
35
+ });
36
+ return createPortal(_jsx("div", { className: "glim-modal-backdrop",
37
+ // A press beside an open menu only closes the menu, not the window under it.
38
+ onMouseDown: (e) => {
39
+ if (e.target === e.currentTarget && !menuIsOpen())
40
+ close.current();
41
+ }, children: _jsxs("div", { ...rest, ref: card, role: "dialog", "aria-modal": "true", "aria-labelledby": drawn ? undefined : titleId, "aria-label": drawn ? title : undefined, className: ["glim-modal-card", "glim-window", size !== "normal" && `glim-window--${size}`, className].filter(Boolean).join(" "), children: [_jsx("h2", { id: titleId, className: "glim-window-title", children: _jsx(Badge, { tone: "heading", size: "heading", wrap: true, insetStart: 5, children: drawn ?? title }) }), _jsx("div", { className: "glim-modal-body glim-window-body", children: children }), foot.length > 0 && (_jsxs("div", { className: "glim-modal-foot", children: [start !== undefined && _jsx("span", { className: "glim-window-start", children: start }), foot.map((a, i) => (_createElement(Button, { ...a.attrs, key: i, label: a.label, labelKey: a.labelKey, glyph: a.glyph, tone: a.primary ? "accent" : "neutral", disabled: a.disabled, onClick: () => {
42
+ if (a.onClick?.() !== false)
43
+ close.current();
44
+ } })))] }))] }) }), document.body);
45
+ }
@@ -0,0 +1,4 @@
1
+ export declare const FieldRowContext: import("react").Context<string | undefined>;
2
+ export declare const FieldRowGroupContext: import("react").Context<boolean>;
3
+ /** A control's accessible name: its own, or the label of the row it stands in. */
4
+ export declare function useFieldName(own: string | undefined): string | undefined;
@@ -0,0 +1,9 @@
1
+ // How a FieldRow names the control inside it.
2
+ import { createContext, useContext } from "react";
3
+ export const FieldRowContext = createContext(undefined);
4
+ export const FieldRowGroupContext = createContext(false);
5
+ /** A control's accessible name: its own, or the label of the row it stands in. */
6
+ export function useFieldName(own) {
7
+ const row = useContext(FieldRowContext);
8
+ return own ?? row;
9
+ }
package/dist/glyphs.d.ts CHANGED
@@ -17,6 +17,11 @@ export declare const IconClose: () => import("react").JSX.Element;
17
17
  export declare const IconCancel: () => import("react").JSX.Element;
18
18
  export declare const IconCheck: () => import("react").JSX.Element;
19
19
  export declare const IconExpand: () => import("react").JSX.Element;
20
+ export declare const IconFolderOpen: () => import("react").JSX.Element;
21
+ export declare const IconPencil: () => import("react").JSX.Element;
20
22
  export declare const IconWindowMinimise: () => import("react").JSX.Element;
21
23
  export declare const IconWindowMaximise: () => import("react").JSX.Element;
22
24
  export declare const IconWindowRestore: () => import("react").JSX.Element;
25
+ export declare const IconEye: () => import("react").JSX.Element;
26
+ export declare const IconEyeOff: () => import("react").JSX.Element;
27
+ export declare const IconCopy: () => import("react").JSX.Element;
package/dist/glyphs.js CHANGED
@@ -25,6 +25,11 @@ export const IconClose = () => _jsx(MarkSvg, { mark: MARKS.close, className: "gl
25
25
  export const IconCancel = () => _jsx(MarkSvg, { mark: MARKS.cancel, className: "glim-mark" });
26
26
  export const IconCheck = () => _jsx(MarkSvg, { mark: MARKS.check, className: "glim-mark" });
27
27
  export const IconExpand = () => _jsx(MarkSvg, { mark: MARKS.expand, className: "glim-mark" });
28
+ export const IconFolderOpen = () => _jsx(MarkSvg, { mark: MARKS.folderOpen, className: "glim-mark" });
29
+ export const IconPencil = () => _jsx(MarkSvg, { mark: MARKS.pencil, className: "glim-mark" });
28
30
  export const IconWindowMinimise = () => _jsx(MarkSvg, { mark: MARKS.windowMinimise, className: "glim-mark" });
29
31
  export const IconWindowMaximise = () => _jsx(MarkSvg, { mark: MARKS.windowMaximise, className: "glim-mark" });
30
32
  export const IconWindowRestore = () => _jsx(MarkSvg, { mark: MARKS.windowRestore, className: "glim-mark" });
33
+ export const IconEye = () => _jsx(MarkSvg, { mark: MARKS.eye, className: "glim-mark" });
34
+ export const IconEyeOff = () => _jsx(MarkSvg, { mark: MARKS.eyeOff, className: "glim-mark" });
35
+ export const IconCopy = () => _jsx(MarkSvg, { mark: MARKS.copy, className: "glim-mark" });
package/dist/index.d.ts CHANGED
@@ -2,22 +2,45 @@ export * from "./AboutCard.tsx";
2
2
  export * from "./Badge.tsx";
3
3
  export * from "./Button.tsx";
4
4
  export * from "./Card.tsx";
5
+ export * from "./Checkbox.tsx";
5
6
  export * from "./CoffeeDialog.tsx";
7
+ export * from "./ColorPicker.tsx";
6
8
  export * from "./ConfirmDialog.tsx";
9
+ export * from "./ContextMenu.tsx";
10
+ export * from "./CopyField.tsx";
7
11
  export * from "./CryptoDonateDialog.tsx";
8
12
  export * from "./DropdownListbox.tsx";
9
13
  export * from "./EmptyState.tsx";
14
+ export * from "./FieldRow.tsx";
15
+ export * from "./FieldRowGroup.tsx";
16
+ export * from "./GlyphField.tsx";
17
+ export * from "./GlyphTile.tsx";
18
+ export { useFieldName } from "./fieldName.ts";
19
+ export * from "./IconButton.tsx";
10
20
  export * from "./IconTipButton.tsx";
11
21
  export * from "./InfoBubble.tsx";
22
+ export * from "./Kbd.tsx";
23
+ export * from "./ListRow.tsx";
24
+ export * from "./MenuBar.tsx";
25
+ export * from "./Meter.tsx";
12
26
  export * from "./NumberField.tsx";
27
+ export * from "./PasswordField.tsx";
28
+ export * from "./PathField.tsx";
13
29
  export * from "./PaypalDialog.tsx";
30
+ export * from "./Pill.tsx";
31
+ export * from "./ProgressBar.tsx";
14
32
  export * from "./ReadmeButton.tsx";
33
+ export * from "./RowMark.tsx";
15
34
  export * from "./Selector.tsx";
16
35
  export * from "./SidebarRow.tsx";
17
36
  export * from "./SubCard.tsx";
37
+ export * from "./Table.tsx";
38
+ export * from "./TextField.tsx";
18
39
  export * from "./Toast.tsx";
19
40
  export * from "./Toggle.tsx";
41
+ export * from "./Tree.tsx";
20
42
  export * from "./UnavailableNotice.tsx";
43
+ export * from "./Window.tsx";
21
44
  export * from "./WindowBar.tsx";
22
45
  export * from "./glyphs.tsx";
23
46
  export * from "./portalHue.ts";
@@ -25,4 +48,5 @@ export * from "./useConfirm.tsx";
25
48
  export * from "./useLabelMode.ts";
26
49
  export * from "./usePaypalButtons.ts";
27
50
  export * from "./useTipBubble.tsx";
51
+ export type { ToastAction } from "@glimstone/core";
28
52
  export { GLIMSTONE_VERSION } from "@glimstone/core";