@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/README.md CHANGED
@@ -67,6 +67,20 @@ needs none of them.
67
67
  | `SubCard` | A filled inset group inside a card, which replaces a fold-out |
68
68
  | `UnavailableNotice` | What stands where a control would be, when the environment forbids the thing entirely |
69
69
  | `WindowBar` | A desktop app's own title bar on Windows and Linux |
70
+ | `Window` | The general window: the title notch, a body for anything and a foot that adds Cancel or Close by itself; windows stack |
71
+ | `ContextMenu`, `MenuBar` | A menu at a point and the row of menus in a head bar, with submenus, rows that tick a box, choices, key caps and counts. Opened with the pointer, the first row shows its ring only once a key is pressed |
72
+ | `Checkbox` | The drawn box for "Don't show again" and for choices applied together, `slim` for the box alone in a dense row. Every setting is a `Toggle` |
73
+ | `Kbd`, `Pill` | A key cap, and the quiet data pill of a list row |
74
+ | `TextField`, `TextArea` | A line of text and a few lines of text, borderless and filled, in the widths a row needs |
75
+ | `FieldRow`, `FieldRowGroup` | One labelled row: the name at its start with an "(i)", the control at its end, named by the row, or a lone value as a pill, and rows that share one column for their names. `useFieldName` gives an app's own control the same name |
76
+ | `GlyphField` | A field with a glyph inside it, such as a filter, and controls after it in the box |
77
+ | `Table` | A short list of facts in columns |
78
+ | `PasswordField`, `CopyField` | A secret with the reveal eye inside the field, and a value in monospace with a button that copies it |
79
+ | `PathField`, `Tree` | A path with a button that asks the app for one, and a hierarchy loaded as it opens, for the picker behind that button |
80
+ | `ListRow`, `RowMark`, `GlyphTile` | One row of a list with a tile, badges and buttons that come in on hover, the round mark on a row picked for an action on many, and a small holder for a glyph |
81
+ | `IconButton` | A glyph in a square in every label mode, for a row that keeps its text, as a link with `href`, on or off with `pressed`, and `absent` to hold a missing button's place |
82
+ | `Meter`, `ProgressBar` | A level such as a disk's, red from a threshold and `quiet` for a footer line, and work toward its end with a sheen while it runs. Only the bar moves |
83
+ | `ColorPicker` | The square, the hue bar, a preview with the name the colour proposes, the hex field and Apply, in the page or floating beside its swatch |
70
84
  | `useLabelMode`, `useTipBubble`, `usePortalHue` | The small hooks the components need |
71
85
  | `glyphs` | The marks the components draw themselves, and `setGlyphResolver`, the seam an app registers its own icon set through |
72
86
 
package/dist/Button.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import type { ReactNode, Ref } from "react";
2
- import { type ButtonTone, type ButtonVariant, type WidthStage } from "@glimstone/core";
3
- export type { ButtonTone, ButtonVariant } from "@glimstone/core";
4
- export declare function Button({ label, labelKey, glyph, onClick, tone, variant, disabled, type, className, title, hueIndex, busy, autoFocus, stage: stageOverride, keepLabel, ref, }: {
1
+ import type { ButtonHTMLAttributes, ReactNode, Ref } from "react";
2
+ import { type ButtonSize, type ButtonTone, type ButtonVariant, type WidthStage } from "@glimstone/core";
3
+ export type { ButtonSize, ButtonTone, ButtonVariant } from "@glimstone/core";
4
+ export interface ButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, "children" | "className" | "disabled" | "onClick" | "title" | "type" | "autoFocus"> {
5
5
  /** The button's words, present in every mode: visible, or hidden but
6
6
  * announced and shown as the tooltip. Keep it stable, since a label that
7
7
  * changes while the button works would resize it; put changing state in
@@ -23,8 +23,13 @@ export declare function Button({ label, labelKey, glyph, onClick, tone, variant,
23
23
  /** "chip" inside a pill, "icon" for a row action; see ButtonVariant. */
24
24
  variant?: ButtonVariant;
25
25
  disabled?: boolean;
26
+ /** Makes it a link with the button's look. A disabled one stays a disabled button. */
27
+ href?: string;
28
+ /** What stands before the glyph, such as a count. */
29
+ before?: ReactNode;
30
+ /** What stands after the words, such as a key cap. */
31
+ after?: ReactNode;
26
32
  type?: "button" | "submit";
27
- className?: string;
28
33
  /** Extra explanation, and the place for anything that changes: the running
29
34
  * state, or why the button is unavailable. It shows in the hover and focus
30
35
  * bubble, joined with the label where the label is hidden, and still
@@ -47,8 +52,16 @@ export declare function Button({ label, labelKey, glyph, onClick, tone, variant,
47
52
  * `groupStage([labelA, labelB])` to both. Use it only for such a pair.
48
53
  * Ignored in glyph and reactive mode, which take no stage. */
49
54
  stage?: WidthStage;
55
+ /** Its glyph alone in a square in every label mode, where the words have no
56
+ * room. The label stays the name and the bubble. */
57
+ compact?: boolean;
58
+ /** Turns compact while the window is narrower than this many pixels. */
59
+ compactBelow?: number;
60
+ size?: ButtonSize;
50
61
  /** Keeps the label visible in every mode, for a button whose label is
51
62
  * content rather than a verb, such as a directory row in a folder browser.
52
63
  * The glyph still shows beside it. */
53
64
  keepLabel?: boolean;
54
- }): import("react").JSX.Element;
65
+ className?: string;
66
+ }
67
+ export declare function Button({ label, labelKey, glyph, onClick, tone, variant, disabled, type, className, title, hueIndex, busy, autoFocus, stage: stageOverride, keepLabel, compact, compactBelow, size, href, before, after, ref, ...rest }: ButtonProps): import("react").JSX.Element;
package/dist/Button.js CHANGED
@@ -1,12 +1,13 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { buttonView, takePageHue } from "@glimstone/core";
2
+ import { useSyncExternalStore } from "react";
3
+ import { buttonView, mediaMatches, narrowerThan, subscribeMedia, takePageHue } from "@glimstone/core";
3
4
  import { useLabelMode } from "./useLabelMode.js";
4
5
  import { useTipBubble } from "./useTipBubble.js";
5
6
  import { glyphFor, IconClose } from "./glyphs.js";
6
- // The one clickable control; what it shows and how wide it is come from
7
- // buttonView() in the core.
8
- export function Button({ label, labelKey, glyph, onClick, tone = "neutral", variant = "default", disabled = false, type = "button", className = "", title, hueIndex, busy = false, autoFocus = false, stage: stageOverride, keepLabel = false, ref, }) {
7
+ export function Button({ label, labelKey, glyph, onClick, tone = "neutral", variant = "default", disabled = false, type = "button", className = "", title, hueIndex, busy = false, autoFocus = false, stage: stageOverride, keepLabel = false, compact = false, compactBelow, size, href, before, after, ref, ...rest }) {
9
8
  const mode = useLabelMode("buttons");
9
+ const query = compactBelow === undefined ? null : narrowerThan(compactBelow);
10
+ const narrow = useSyncExternalStore((fn) => (query ? subscribeMedia(query, fn) : () => { }), () => (query ? mediaMatches(query) : false), () => false);
10
11
  // A chip always closes, so it has a glyph even when no call site passes one.
11
12
  const resolved = glyph ?? (labelKey ? glyphFor(labelKey) : undefined) ?? (variant === "chip" ? _jsx(IconClose, {}) : undefined);
12
13
  const view = buttonView({
@@ -17,11 +18,15 @@ export function Button({ label, labelKey, glyph, onClick, tone = "neutral", vari
17
18
  variant,
18
19
  disabled,
19
20
  keepLabel,
21
+ compact: compact || narrow,
22
+ size,
20
23
  title,
21
24
  hueIndex,
22
25
  stage: stageOverride,
23
26
  });
24
27
  const tooltip = useTipBubble(view.tip, disabled);
28
+ const Element = (href && !disabled ? "a" : "button");
29
+ const own = href && !disabled ? { href } : { type, disabled, autoFocus };
25
30
  const handlers = view.pageHue
26
31
  ? {
27
32
  ...tooltip.handlers,
@@ -35,7 +40,7 @@ export function Button({ label, labelKey, glyph, onClick, tone = "neutral", vari
35
40
  },
36
41
  }
37
42
  : tooltip.handlers;
38
- return (_jsxs(_Fragment, { children: [tooltip.wrap(_jsxs("button", { ref: mergeRefs(ref, tooltip.ref), type: type, onClick: onClick, disabled: disabled, autoFocus: autoFocus, "aria-busy": busy || undefined, "aria-describedby": tooltip.describedBy, ...handlers, style: view.style, className: `${view.className} ${className}`.trim(), children: [view.showGlyph && (_jsx("span", { className: "glim-btn-glyph", children: busy ? _jsx("span", { className: "glim-spinner" }) : resolved })), _jsx("span", { className: view.labelClass, children: label })] })), tooltip.bubble] }));
43
+ return (_jsxs(_Fragment, { children: [tooltip.wrap(_jsxs(Element, { ...rest, ...own, ref: mergeRefs(ref, tooltip.ref), onClick: onClick, "aria-busy": busy || undefined, "aria-describedby": tooltip.describedBy, ...handlers, style: view.style, className: `${view.className} ${className}`.trim(), children: [before, view.showGlyph && (_jsx("span", { className: "glim-btn-glyph", children: busy ? _jsx("span", { className: "glim-spinner" }) : resolved })), _jsx("span", { className: view.labelClass, children: label }), after] })), tooltip.bubble] }));
39
44
  }
40
45
  /**
41
46
  * Feeds one element to both the caller's `ref`, a callback or an object, and
package/dist/Card.d.ts CHANGED
@@ -12,10 +12,12 @@ import type { ReactNode } from "react";
12
12
  *
13
13
  * A card with neither `title` nor `hint` draws no heading.
14
14
  */
15
- export declare function Card({ title, hint, children, hueIndex, nested, }: {
15
+ export declare function Card({ title, drawn, hint, children, hueIndex, nested, }: {
16
16
  /** The section name. Omit it where a control inside already carries the same
17
17
  * name; the badge still renders to keep the card's hue notch. */
18
18
  title?: string;
19
+ /** Takes the title's place in the notch with markup, such as an unsaved dot. */
20
+ drawn?: ReactNode;
19
21
  /** One line saying what this whole card does, drawn as an "(i)" beside the
20
22
  * title. */
21
23
  hint?: string;
package/dist/Card.js CHANGED
@@ -15,6 +15,6 @@ import { InfoBubble } from "./InfoBubble.js";
15
15
  *
16
16
  * A card with neither `title` nor `hint` draws no heading.
17
17
  */
18
- export function Card({ title, hint, children, hueIndex, nested, }) {
19
- return (_jsxs("div", { className: `glim-panel glim-notch-card${nested ? " glim-panel--nested" : ""}${hueIndex !== undefined ? " glim-hue" : ""}`, style: hueIndex !== undefined ? hueVars(hueIndex) : undefined, children: [(title || hint) && (_jsx("h2", { className: "glim-panel-heading", children: _jsxs(Badge, { tone: "heading", size: "heading", wrap: true, hueIndex: hueIndex, children: [title, hint && _jsx(InfoBubble, { tip: hint, onAccent: true })] }) })), children] }));
18
+ export function Card({ title, drawn, hint, children, hueIndex, nested, }) {
19
+ return (_jsxs("div", { className: `glim-panel glim-notch-card${nested ? " glim-panel--nested" : ""}${hueIndex !== undefined ? " glim-hue" : ""}`, style: hueIndex !== undefined ? hueVars(hueIndex) : undefined, children: [(title || drawn || hint) && (_jsx("h2", { className: "glim-panel-heading", children: _jsxs(Badge, { tone: "heading", size: "heading", wrap: true, hueIndex: hueIndex, children: [drawn ?? title, hint && _jsx(InfoBubble, { tip: hint, onAccent: true })] }) })), children] }));
20
20
  }
@@ -0,0 +1,14 @@
1
+ export interface CheckboxProps {
2
+ checked: boolean;
3
+ /** Called with the flipped value when the box is activated. */
4
+ onChange: (next: boolean) => void;
5
+ /** Always the accessible name; shown beside the box unless hideLabel. */
6
+ label: string;
7
+ /** For a grid whose row and column headings already say it, such as permissions. */
8
+ hideLabel?: boolean;
9
+ /** The box alone, without the frame and its hover ground, for a row or a cell of a dense list. Hides the label. */
10
+ slim?: boolean;
11
+ disabled?: boolean;
12
+ className?: string;
13
+ }
14
+ export declare function Checkbox({ checked, onChange, label, hideLabel, slim, disabled, className }: CheckboxProps): import("react").JSX.Element;
@@ -0,0 +1,7 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { IconCheck } from "./glyphs.js";
3
+ export function Checkbox({ checked, onChange, label, hideLabel = false, slim = false, disabled, className }) {
4
+ const bare = hideLabel || slim;
5
+ const classes = ["glim-checkbox", slim && "glim-checkbox--slim", className].filter(Boolean).join(" ");
6
+ return (_jsxs("button", { type: "button", role: "checkbox", "aria-checked": checked, "aria-label": bare ? label : undefined, disabled: disabled, onClick: () => onChange(!checked), className: classes, children: [_jsx("span", { className: "glim-checkbox-box", "aria-hidden": "true", children: _jsx(IconCheck, {}) }), !bare && _jsx("span", { children: label })] }));
7
+ }
@@ -0,0 +1,21 @@
1
+ import { type ColorName, type ColorPickerPanelText } from "@glimstone/core";
2
+ export type { ColorName, ColorPickerPanelText } from "@glimstone/core";
3
+ export interface ColorPickerProps {
4
+ /** The colour the picker starts from, as `#rrggbb`. */
5
+ value: string;
6
+ /** Apply or Enter, with the colour and the name it proposes. */
7
+ onApply: (hex: string, name: string | null) => void;
8
+ /** Every step of a drag, a key or a valid hex, for a live preview. */
9
+ onInput?: (hex: string) => void;
10
+ /** The control that opened the picker. With it the picker floats beside it
11
+ * and closes on Escape, on a click beside it and after Apply. */
12
+ anchor?: HTMLElement | null;
13
+ /** Called when a floating picker closes, however it closes. */
14
+ onClose?: () => void;
15
+ /** The names a colour is matched against, nearest in OKLab. `false` shows none. */
16
+ names?: readonly ColorName[] | false;
17
+ /** The words, read when the picker opens. */
18
+ text?: Partial<ColorPickerPanelText>;
19
+ className?: string;
20
+ }
21
+ export declare function ColorPicker({ value, onApply, onInput, anchor, onClose, names, text, className }: ColorPickerProps): import("react").JSX.Element;
@@ -0,0 +1,68 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useLayoutEffect, useRef, useState } from "react";
3
+ import { createPortal } from "react-dom";
4
+ import { COLOR_NAMES_DE, COLOR_PICKER_TEXT, colorPicker, floatColorPicker, nearestColorName, normalizeHex, } from "@glimstone/core";
5
+ import { Button } from "./Button.js";
6
+ import { IconCheck } from "./glyphs.js";
7
+ export function ColorPicker({ value, onApply, onInput, anchor, onClose, names = COLOR_NAMES_DE, text, className }) {
8
+ const words = { ...COLOR_PICKER_TEXT, ...text };
9
+ const panel = useRef(null);
10
+ const host = useRef(null);
11
+ const widget = useRef(null);
12
+ const [draft, setDraft] = useState(() => normalizeHex(value) ?? "#000000");
13
+ const [typed, setTyped] = useState(draft);
14
+ const latest = useRef({ onInput, onClose });
15
+ useLayoutEffect(() => {
16
+ latest.current = { onInput, onClose };
17
+ });
18
+ useLayoutEffect(() => {
19
+ const picker = colorPicker(draft, (hex) => {
20
+ setDraft(hex);
21
+ setTyped(hex);
22
+ latest.current.onInput?.(hex);
23
+ }, { text: words });
24
+ host.current.appendChild(picker.el);
25
+ widget.current = picker;
26
+ return () => picker.el.remove();
27
+ // Built once; a new value reaches it through setValue below.
28
+ }, []);
29
+ useEffect(() => {
30
+ const hex = normalizeHex(value);
31
+ if (!hex)
32
+ return;
33
+ setDraft(hex);
34
+ setTyped(hex);
35
+ widget.current?.setValue(hex);
36
+ }, [value]);
37
+ useLayoutEffect(() => {
38
+ if (!anchor || !panel.current)
39
+ return;
40
+ const done = floatColorPicker(panel.current, anchor, () => latest.current.onClose?.());
41
+ widget.current?.focus();
42
+ return done;
43
+ }, [anchor]);
44
+ const name = names === false ? null : nearestColorName(draft, names);
45
+ function apply() {
46
+ onApply(draft, name);
47
+ if (anchor) {
48
+ anchor.focus();
49
+ onClose?.();
50
+ }
51
+ }
52
+ function onKeyDown(e) {
53
+ if (e.key === "Enter" && !(e.target instanceof HTMLButtonElement)) {
54
+ e.preventDefault();
55
+ apply();
56
+ }
57
+ }
58
+ const body = (_jsxs("div", { ref: panel, className: ["glim-picker-panel", anchor && "glim-picker-panel--float", className].filter(Boolean).join(" "), style: { "--glim-picker-colour": draft }, onKeyDown: onKeyDown, children: [_jsx("div", { ref: host, style: { display: "contents" } }), _jsxs("div", { className: "glim-picker-foot", children: [_jsx("span", { className: "glim-picker-swatch", "aria-hidden": "true" }), name !== null && _jsx("span", { className: "glim-picker-name", children: name }), _jsx("input", { className: "glim-picker-hex", value: typed, maxLength: 7, spellCheck: false, "aria-label": words.hex, onChange: (e) => {
59
+ setTyped(e.target.value);
60
+ const hex = normalizeHex(e.target.value);
61
+ if (!hex)
62
+ return;
63
+ setDraft(hex);
64
+ widget.current?.setValue(hex);
65
+ onInput?.(hex);
66
+ } })] }), _jsx("div", { className: "glim-picker-actions", children: _jsx(Button, { label: words.apply, labelKey: "apply", glyph: _jsx(IconCheck, {}), tone: "accent", onClick: apply }) })] }));
67
+ return anchor ? createPortal(body, document.body) : body;
68
+ }
@@ -1,6 +1,6 @@
1
1
  import type { SelectOption } from "./Select.tsx";
2
2
  export interface ComboboxProps {
3
- label: string;
3
+ label?: string;
4
4
  hideLabel?: boolean;
5
5
  options: SelectOption[];
6
6
  /** The chosen value, or "" while nothing is chosen. */
package/dist/Combobox.js CHANGED
@@ -1,9 +1,11 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useId, useState } from "react";
3
3
  import * as combobox from "@zag-js/combobox";
4
+ import { useFieldName } from "./fieldName.js";
4
5
  import { normalizeProps, Portal, useMachine } from "@zag-js/react";
5
6
  import { IconCheck, IconExpand } from "./glyphs.js";
6
7
  export function Combobox({ label, hideLabel, options, value, onChange, placeholder, empty, toggleLabel, disabled }) {
8
+ const name = useFieldName(label);
7
9
  const [shown, setShown] = useState(options);
8
10
  const collection = combobox.collection({
9
11
  items: shown,
@@ -28,5 +30,5 @@ export function Combobox({ label, hideLabel, options, value, onChange, placehold
28
30
  onValueChange: (d) => onChange(d.value[0] ?? ""),
29
31
  });
30
32
  const api = combobox.connect(service, normalizeProps);
31
- return (_jsxs("div", { ...api.getRootProps(), className: "glim-combobox", children: [_jsx("label", { ...api.getLabelProps(), className: hideLabel ? "glim-sr-only" : "glim-field-label", children: label }), _jsxs("div", { ...api.getControlProps(), className: "glim-combobox-control", children: [_jsx("input", { ...api.getInputProps(), className: "glim-combobox-input" }), _jsx("button", { ...api.getTriggerProps(), "aria-label": toggleLabel, className: "glim-combobox-toggle", children: _jsx("span", { className: "glim-select-indicator", "data-state": api.open ? "open" : "closed", children: _jsx(IconExpand, {}) }) })] }), _jsx(Portal, { children: _jsx("div", { ...api.getPositionerProps(), className: "glim-select-positioner", children: _jsxs("ul", { ...api.getContentProps(), className: "glim-select-content", children: [shown.length === 0 && _jsx("li", { className: "glim-select-empty", children: empty }), shown.map((item) => (_jsxs("li", { ...api.getItemProps({ item }), className: "glim-select-item", children: [_jsx("span", { ...api.getItemTextProps({ item }), children: item.label }), _jsx("span", { ...api.getItemIndicatorProps({ item }), className: "glim-select-check", children: _jsx(IconCheck, {}) })] }, item.value)))] }) }) })] }));
33
+ return (_jsxs("div", { ...api.getRootProps(), className: "glim-combobox", children: [_jsx("label", { ...api.getLabelProps(), className: hideLabel || label === undefined ? "glim-sr-only" : "glim-field-label", children: name }), _jsxs("div", { ...api.getControlProps(), className: "glim-combobox-control", children: [_jsx("input", { ...api.getInputProps(), className: "glim-combobox-input" }), _jsx("button", { ...api.getTriggerProps(), "aria-label": toggleLabel, className: "glim-combobox-toggle", children: _jsx("span", { className: "glim-select-indicator", "data-state": api.open ? "open" : "closed", children: _jsx(IconExpand, {}) }) })] }), _jsx(Portal, { children: _jsx("div", { ...api.getPositionerProps(), className: "glim-select-positioner", children: _jsxs("ul", { ...api.getContentProps(), className: "glim-select-content", children: [shown.length === 0 && _jsx("li", { className: "glim-select-empty", children: empty }), shown.map((item) => (_jsxs("li", { ...api.getItemProps({ item }), className: "glim-select-item", children: [_jsx("span", { ...api.getItemTextProps({ item }), children: item.label }), _jsx("span", { ...api.getItemIndicatorProps({ item }), className: "glim-select-check", children: _jsx(IconCheck, {}) })] }, item.value)))] }) }) })] }));
32
34
  }
@@ -0,0 +1,25 @@
1
+ import { type ReactNode } from "react";
2
+ import { type MenuEntry as CoreMenuEntry, type MenuHead as CoreMenuHead, type MenuItem as CoreMenuItem } from "@glimstone/core";
3
+ export type MenuEntry = CoreMenuEntry<ReactNode>;
4
+ export type MenuItem = CoreMenuItem<ReactNode>;
5
+ export type MenuHead = CoreMenuHead<ReactNode>;
6
+ export interface ContextMenuProps {
7
+ /** The point the menu hangs from, in viewport pixels, such as the pointer's. */
8
+ x: number;
9
+ y: number;
10
+ items: MenuEntry[];
11
+ /** Stand the menu on the point instead, for a menu opened from a bar at the bottom. */
12
+ above?: boolean;
13
+ /** The menu's accessible name. */
14
+ label?: string;
15
+ /** The menu element's id, for a caller or a script that looks for it. */
16
+ id?: string;
17
+ /** The control that opened the menu. A click on it is not a click outside,
18
+ * and focus goes back to it; without one, focus goes back to wherever it was. */
19
+ opener?: HTMLElement | null;
20
+ /** Called on every way out: a choice, Escape, Tab or a click outside. */
21
+ onClose: () => void;
22
+ /** Left or right on a row without a submenu, for a bar that steps to the next menu. */
23
+ onStep?: (direction: 1 | -1) => void;
24
+ }
25
+ export declare function ContextMenu({ x, y, items, above, label, id, opener, onClose, onStep }: ContextMenuProps): import("react").JSX.Element;
@@ -0,0 +1,137 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // A menu at a point: a right-click on a row, the More button of a list, or a
3
+ // menu of the bar. Mount it to open it and unmount it on onClose. The model,
4
+ // the placing and the keys come from menu.ts in the core.
5
+ //
6
+ // A submenu opens beside its row as a second menu on the body, one level deep.
7
+ // A checkbox item leaves the menu open, so several can be ticked in a row; the
8
+ // caller flips `checked` and the row follows.
9
+ import { useLayoutEffect, useRef, useState } from "react";
10
+ import { createPortal } from "react-dom";
11
+ import { claimMenu, closeMenuOutside, focusedAsker, focusFirstMenuRow, focusMenuRow, isMenuHead, menuMove, menuRowView, placeMenu, placeSubmenu, returnFocus, tidyMenu, } from "@glimstone/core";
12
+ import { IconCheck, IconExpand, IconPencil } from "./glyphs.js";
13
+ import { Kbd } from "./Kbd.js";
14
+ import { useTipBubble } from "./useTipBubble.js";
15
+ const viewport = () => ({ width: innerWidth, height: innerHeight });
16
+ function HeadEdit({ tip, glyph, row, onPress }) {
17
+ const tooltip = useTipBubble(tip);
18
+ return (_jsxs(_Fragment, { children: [_jsx("button", { ref: tooltip.ref, type: "button", role: "menuitem", tabIndex: -1, "aria-label": tip, "aria-describedby": tooltip.describedBy, ...tooltip.handlers, className: "glim-menu-head-edit", "data-row": row, onClick: onPress, children: glyph ?? _jsx(IconPencil, {}) }), tooltip.bubble] }));
19
+ }
20
+ function Rows({ entries, openAt, onPick, }) {
21
+ return entries.map((entry, i) => {
22
+ if (entry === "-")
23
+ return _jsx("div", { className: "glim-menu-sep", role: "separator" }, i);
24
+ if (isMenuHead(entry)) {
25
+ return (_jsxs("div", { className: "glim-menu-head", role: "presentation", children: [_jsx("span", { children: entry.head }), entry.edit && _jsx(HeadEdit, { tip: entry.edit.tip, glyph: entry.edit.glyph, row: i, onPress: () => onPick(i) })] }, i));
26
+ }
27
+ const view = menuRowView(entry);
28
+ return (_jsxs("button", { type: "button", role: view.role, tabIndex: -1, "aria-checked": view.role === "menuitem" ? undefined : entry.checked, "aria-haspopup": entry.sub ? "menu" : undefined, "aria-expanded": entry.sub ? openAt === i : undefined, disabled: entry.disabled, className: view.current ? "glim-menu-item glim-menu-item--current" : "glim-menu-item", "data-row": i, onClick: () => onPick(i), children: [view.lead === "box" ? (_jsx("span", { className: "glim-checkbox-box", "aria-hidden": "true", children: _jsx(IconCheck, {}) })) : view.lead === "dot" ? (_jsx("span", { className: "glim-menu-dot", style: { backgroundColor: entry.color }, "aria-hidden": "true" })) : (_jsx("span", { className: "glim-menu-glyph", "aria-hidden": "true", children: view.lead === "glyph" && entry.glyph })), _jsx("span", { className: "glim-menu-label", children: entry.label }), view.end === "submenu" && (_jsx("span", { className: "glim-menu-end glim-menu-caret", "aria-hidden": "true", children: _jsx(IconExpand, {}) })), view.end === "tick" && (_jsx("span", { className: "glim-menu-end glim-menu-tick", "aria-hidden": "true", children: _jsx(IconCheck, {}) })), view.end === "shortcut" && _jsx(Kbd, { className: "glim-menu-end", children: entry.shortcut }), view.end === "count" && _jsx("span", { className: "glim-menu-end glim-menu-count glim-num", children: entry.count })] }, i));
29
+ });
30
+ }
31
+ export function ContextMenu({ x, y, items, above = false, label, id, opener, onClose, onStep }) {
32
+ const menu = useRef(null);
33
+ const subMenu = useRef(null);
34
+ const [asker] = useState(focusedAsker);
35
+ const [pos, setPos] = useState({ left: x, top: y });
36
+ const [sub, setSub] = useState(null);
37
+ const [subPos, setSubPos] = useState(null);
38
+ const latest = useRef({ onClose, onStep, opener });
39
+ useLayoutEffect(() => {
40
+ latest.current = { onClose, onStep, opener };
41
+ });
42
+ const rows = tidyMenu(items);
43
+ const host = sub ? rows[sub.at] : undefined;
44
+ const subRows = host && !isMenuHead(host) && host !== "-" && host.sub ? tidyMenu(host.sub) : null;
45
+ // Focus goes back only on a way out somebody chose; a click elsewhere keeps
46
+ // the focus it gave. It reads only refs, so the first render's copy serves
47
+ // the listeners too.
48
+ const finish = (handBack) => {
49
+ latest.current.onClose();
50
+ if (handBack)
51
+ returnFocus(latest.current.opener ?? asker);
52
+ };
53
+ useLayoutEffect(() => {
54
+ const el = menu.current;
55
+ setPos(placeMenu(x, y, { width: el.offsetWidth, height: el.offsetHeight }, viewport(), above));
56
+ }, [x, y, above]);
57
+ useLayoutEffect(() => {
58
+ const release = claimMenu(finish);
59
+ const outside = closeMenuOutside(() => [menu.current, subMenu.current, latest.current.opener], () => finish(false));
60
+ focusFirstMenuRow(menu.current);
61
+ return () => {
62
+ release();
63
+ outside();
64
+ };
65
+ // eslint-disable-next-line react-hooks/exhaustive-deps
66
+ }, []);
67
+ useLayoutEffect(() => {
68
+ const row = sub && menu.current?.querySelector(`[data-row="${sub.at}"]`);
69
+ if (!sub || !row || !subMenu.current) {
70
+ setSubPos(null);
71
+ return;
72
+ }
73
+ const rtl = getComputedStyle(menu.current).direction === "rtl";
74
+ const el = subMenu.current;
75
+ setSubPos(placeSubmenu(row.getBoundingClientRect(), { width: el.offsetWidth, height: el.offsetHeight }, viewport(), rtl));
76
+ if (sub.focus)
77
+ focusFirstMenuRow(el);
78
+ }, [sub]);
79
+ function pick(list, at) {
80
+ const entry = list[at];
81
+ if (entry === "-")
82
+ return;
83
+ if (isMenuHead(entry)) {
84
+ finish(true);
85
+ entry.edit?.onSelect();
86
+ return;
87
+ }
88
+ if (entry.sub && list === rows) {
89
+ setSub({ at, focus: true });
90
+ return;
91
+ }
92
+ if (menuRowView(entry).staysOpen) {
93
+ entry.onSelect?.();
94
+ return;
95
+ }
96
+ finish(true);
97
+ entry.onSelect?.();
98
+ }
99
+ function keys(e, inSub) {
100
+ if (e.key === "Tab")
101
+ return finish(false);
102
+ const move = menuMove(e.key, getComputedStyle(e.currentTarget).direction === "rtl");
103
+ if (!move)
104
+ return;
105
+ e.preventDefault();
106
+ if (move !== "in" && move !== "out")
107
+ return focusMenuRow(e.currentTarget, move);
108
+ if (inSub) {
109
+ if (move === "out" && sub) {
110
+ menu.current?.querySelector(`[data-row="${sub.at}"]`)?.focus();
111
+ setSub(null);
112
+ }
113
+ return;
114
+ }
115
+ const at = Number(document.activeElement?.dataset.row);
116
+ const entry = rows[at];
117
+ if (move === "in" && entry && entry !== "-" && !isMenuHead(entry) && entry.sub && !entry.disabled)
118
+ setSub({ at, focus: true });
119
+ else
120
+ latest.current.onStep?.(move === "in" ? 1 : -1);
121
+ }
122
+ // The pointer opens a submenu by resting on its row and closes it on any other row.
123
+ function hover(e) {
124
+ const row = e.target.closest("[data-row]");
125
+ if (!row)
126
+ return;
127
+ const at = Number(row.dataset.row);
128
+ const entry = rows[at];
129
+ const opens = entry !== "-" && !isMenuHead(entry) && !!entry.sub && !entry.disabled;
130
+ if (opens && sub?.at !== at)
131
+ setSub({ at, focus: false });
132
+ else if (!opens && sub)
133
+ setSub(null);
134
+ }
135
+ return (_jsxs(_Fragment, { children: [createPortal(_jsx("div", { ref: menu, role: "menu", id: id, "aria-label": label, className: "glim-menu", style: pos, onKeyDown: (e) => keys(e, false), onMouseOver: hover, onContextMenu: (e) => e.preventDefault(), children: _jsx(Rows, { entries: rows, openAt: sub?.at, onPick: (i) => pick(rows, i) }) }), document.body), subRows &&
136
+ createPortal(_jsx("div", { ref: subMenu, id: host.subId, role: "menu", "aria-label": host.label, className: "glim-menu", style: subPos ?? { left: 0, top: 0 }, onKeyDown: (e) => keys(e, true), onContextMenu: (e) => e.preventDefault(), children: _jsx(Rows, { entries: subRows, onPick: (i) => pick(subRows, i) }) }), document.body)] }));
137
+ }
@@ -0,0 +1,17 @@
1
+ import { type FieldWidth } from "@glimstone/core";
2
+ export interface CopyFieldProps {
3
+ value: string;
4
+ /** The field's accessible name, such as "Token". Inside a FieldRow the row gives it. */
5
+ label?: string;
6
+ width?: FieldWidth;
7
+ /** The button's words, before and for a moment after it copied. */
8
+ text?: {
9
+ copy: string;
10
+ copied: string;
11
+ };
12
+ /** Called after every press, with whether the value reached the clipboard. */
13
+ onCopy?: (done: boolean) => void;
14
+ /** Classes for the row, which carries the width. */
15
+ className?: string;
16
+ }
17
+ export declare function CopyField({ value, label, width, text, onCopy, className }: CopyFieldProps): import("react").JSX.Element;
@@ -0,0 +1,26 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useRef, useState } from "react";
3
+ import { COPIED_MS, copyText, fieldWidthClass } from "@glimstone/core";
4
+ import { Button } from "./Button.js";
5
+ import { useFieldName } from "./fieldName.js";
6
+ import { IconCheck, IconCopy } from "./glyphs.js";
7
+ export function CopyField({ value, label, width, text = { copy: "Copy", copied: "Copied" }, onCopy, className }) {
8
+ const name = useFieldName(label);
9
+ const [copied, setCopied] = useState(false);
10
+ const field = useRef(null);
11
+ const timer = useRef(undefined);
12
+ useEffect(() => () => clearTimeout(timer.current), []);
13
+ async function copy() {
14
+ const done = await copyText(value);
15
+ onCopy?.(done);
16
+ if (!done) {
17
+ field.current?.focus();
18
+ field.current?.select();
19
+ return;
20
+ }
21
+ setCopied(true);
22
+ clearTimeout(timer.current);
23
+ timer.current = window.setTimeout(() => setCopied(false), COPIED_MS);
24
+ }
25
+ return (_jsxs("span", { className: ["glim-copy", fieldWidthClass(width), className].filter(Boolean).join(" "), children: [_jsx("input", { ref: field, readOnly: true, value: value, "aria-label": name, spellCheck: false, className: "glim-input glim-input--mono" }), _jsx(Button, { label: copied ? text.copied : text.copy, labelKey: copied ? "copied" : "copy", glyph: copied ? _jsx(IconCheck, {}) : _jsx(IconCopy, {}), variant: "icon", onClick: copy }), _jsx("span", { role: "status", className: "glim-sr-only", children: copied ? text.copied : "" })] }));
26
+ }
@@ -0,0 +1,20 @@
1
+ import { type HTMLAttributes, type ReactNode } from "react";
2
+ import { type PillTone } from "@glimstone/core";
3
+ export interface FieldRowProps extends Omit<HTMLAttributes<HTMLDivElement>, "children"> {
4
+ /** The row's name, and the accessible name of the control in it. */
5
+ label: string;
6
+ /** Draws the words in other markup, such as a quiet "optional". The name stays `label`. */
7
+ drawn?: ReactNode;
8
+ /** What the row does, drawn as an "(i)" beside the name. */
9
+ hint?: string;
10
+ /** A row with only a value to show holds it as a pill. */
11
+ value?: string | number;
12
+ /** The pill's tone. */
13
+ tone?: PillTone;
14
+ /** In a FieldRowGroup with columns, spans all of them. */
15
+ wide?: boolean;
16
+ /** The control. */
17
+ children?: ReactNode;
18
+ className?: string;
19
+ }
20
+ export declare function FieldRow({ label, drawn, hint, value, tone, wide, children, className, ...rest }: FieldRowProps): import("react").JSX.Element;
@@ -0,0 +1,13 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useContext, useRef } from "react";
3
+ import { pressRowControl } from "@glimstone/core";
4
+ import { FieldRowContext, FieldRowGroupContext } from "./fieldName.js";
5
+ import { InfoBubble } from "./InfoBubble.js";
6
+ import { Pill } from "./Pill.js";
7
+ export function FieldRow({ label, drawn, hint, value, tone, wide, children, className, ...rest }) {
8
+ const row = useRef(null);
9
+ const inGroup = useContext(FieldRowGroupContext);
10
+ const control = children ??
11
+ (value !== undefined && (_jsx(Pill, { className: "glim-num", tone: tone, children: value })));
12
+ return (_jsx(FieldRowContext.Provider, { value: label, children: _jsxs("div", { ...rest, ref: row, className: ["glim-field-row", wide && "glim-field-row--wide", className].filter(Boolean).join(" "), children: [_jsxs("span", { className: "glim-field-row-name", children: [_jsx("span", { className: "glim-field-row-label", onClick: () => pressRowControl(row.current), children: drawn ?? label }), hint && _jsx(InfoBubble, { tip: hint })] }), inGroup ? _jsx("span", { className: "glim-field-row-controls", children: control }) : control] }) }));
13
+ }
@@ -0,0 +1,9 @@
1
+ import type { HTMLAttributes, ReactNode } from "react";
2
+ export interface FieldRowGroupProps extends HTMLAttributes<HTMLDivElement> {
3
+ /** The FieldRows. */
4
+ children: ReactNode;
5
+ /** Rows side by side, each column lining up its own names. A `wide` row spans them all. */
6
+ columns?: 1 | 2;
7
+ className?: string;
8
+ }
9
+ export declare function FieldRowGroup({ children, columns, className, style, ...rest }: FieldRowGroupProps): import("react").JSX.Element;
@@ -0,0 +1,5 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { FieldRowGroupContext } from "./fieldName.js";
3
+ export function FieldRowGroup({ children, columns, className, style, ...rest }) {
4
+ return (_jsx(FieldRowGroupContext.Provider, { value: true, children: _jsx("div", { ...rest, style: columns ? { ...style, "--field-columns": columns } : style, className: className ? `glim-field-row-group ${className}` : "glim-field-row-group", children: children }) }));
5
+ }
@@ -0,0 +1,16 @@
1
+ import type { InputHTMLAttributes, ReactNode, Ref } from "react";
2
+ import { type FieldWidth } from "@glimstone/core";
3
+ export interface GlyphFieldProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "width"> {
4
+ glyph: ReactNode;
5
+ /** The accessible name. Inside a FieldRow the row gives it. */
6
+ label?: string;
7
+ /** Controls inside the box, after the field, such as a clear button. */
8
+ after?: ReactNode;
9
+ /** Sets a path or a token in monospace. */
10
+ mono?: boolean;
11
+ width?: FieldWidth;
12
+ /** Classes for the box, which carries the width. */
13
+ className?: string;
14
+ ref?: Ref<HTMLInputElement>;
15
+ }
16
+ export declare function GlyphField({ glyph, label, after, mono, width, className, style, type, ...rest }: GlyphFieldProps): import("react").JSX.Element;
@@ -0,0 +1,8 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { fieldWidthClass } from "@glimstone/core";
3
+ import { useFieldName } from "./fieldName.js";
4
+ export function GlyphField({ glyph, label, after, mono, width, className, style, type = "text", ...rest }) {
5
+ const name = useFieldName(label);
6
+ const classes = ["glim-input", "glim-glyph-field", fieldWidthClass(width), mono && "glim-input--mono", className].filter(Boolean).join(" ");
7
+ return (_jsxs("label", { className: classes, style: style, children: [_jsx("span", { className: "glim-glyph-field-glyph", "aria-hidden": "true", children: glyph }), _jsx("input", { "aria-label": name, ...rest, type: type, className: "glim-glyph-field-input" }), after] }));
8
+ }
@@ -0,0 +1,12 @@
1
+ import type { ReactNode } from "react";
2
+ export interface GlyphTileProps {
3
+ glyph: ReactNode;
4
+ /** Takes the accent off the glyph, such as for a file among folders. */
5
+ quiet?: boolean;
6
+ /** Sets it on the third surface, for a place where a bare glyph gets lost. */
7
+ ground?: boolean;
8
+ /** Fills it with the accent, as a row around it being reached does. */
9
+ active?: boolean;
10
+ className?: string;
11
+ }
12
+ export declare function GlyphTile({ glyph, quiet, ground, active, className }: GlyphTileProps): import("react").JSX.Element;
@@ -0,0 +1,5 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ export function GlyphTile({ glyph, quiet, ground, active, className }) {
3
+ const classes = ["glim-tile", quiet && "glim-tile--quiet", ground && "glim-tile--ground", active && "glim-tile--active", className].filter(Boolean).join(" ");
4
+ return (_jsx("span", { className: classes, "aria-hidden": "true", children: glyph }));
5
+ }
@@ -0,0 +1,16 @@
1
+ import type { ButtonHTMLAttributes, ReactNode } from "react";
2
+ export interface IconButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, "children" | "type"> {
3
+ /** The hover and focus explanation, and the button's accessible name. */
4
+ tip: string;
5
+ glyph: ReactNode;
6
+ /** Makes it a link in the same square. */
7
+ href?: string;
8
+ /** Set for a button that stays on or off: it says so, and the accent washes it while it is on. */
9
+ pressed?: boolean;
10
+ /** Draws no button and keeps its square, so the others of a row stay where they are. */
11
+ absent?: boolean;
12
+ disabled?: boolean;
13
+ type?: "button" | "submit";
14
+ className?: string;
15
+ }
16
+ export declare function IconButton({ tip, glyph, pressed, absent, className, ...rest }: IconButtonProps): import("react").JSX.Element;