@glimstone/react 4.1.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 (64) hide show
  1. package/README.md +7 -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/Combobox.d.ts +1 -1
  7. package/dist/Combobox.js +3 -1
  8. package/dist/ContextMenu.d.ts +3 -1
  9. package/dist/ContextMenu.js +3 -3
  10. package/dist/CopyField.d.ts +5 -3
  11. package/dist/CopyField.js +5 -3
  12. package/dist/FieldRow.d.ts +20 -0
  13. package/dist/FieldRow.js +13 -0
  14. package/dist/FieldRowGroup.d.ts +9 -0
  15. package/dist/FieldRowGroup.js +5 -0
  16. package/dist/GlyphField.d.ts +16 -0
  17. package/dist/GlyphField.js +8 -0
  18. package/dist/GlyphTile.d.ts +12 -0
  19. package/dist/GlyphTile.js +5 -0
  20. package/dist/IconButton.d.ts +16 -0
  21. package/dist/IconButton.js +9 -0
  22. package/dist/IconTipButton.d.ts +6 -4
  23. package/dist/IconTipButton.js +4 -9
  24. package/dist/ListRow.d.ts +16 -0
  25. package/dist/ListRow.js +14 -0
  26. package/dist/MenuBar.d.ts +2 -0
  27. package/dist/MenuBar.js +1 -1
  28. package/dist/NumberField.d.ts +1 -1
  29. package/dist/NumberField.js +4 -2
  30. package/dist/PasswordField.d.ts +6 -2
  31. package/dist/PasswordField.js +5 -2
  32. package/dist/PathField.d.ts +28 -0
  33. package/dist/PathField.js +32 -0
  34. package/dist/RowMark.d.ts +5 -0
  35. package/dist/RowMark.js +6 -0
  36. package/dist/Select.d.ts +12 -6
  37. package/dist/Select.js +21 -15
  38. package/dist/Selector.d.ts +15 -11
  39. package/dist/Selector.js +11 -6
  40. package/dist/SidebarRow.d.ts +10 -2
  41. package/dist/SidebarRow.js +8 -3
  42. package/dist/Slider.d.ts +1 -1
  43. package/dist/Slider.js +3 -1
  44. package/dist/SubCard.d.ts +1 -1
  45. package/dist/SubCard.js +1 -1
  46. package/dist/Table.d.ts +14 -0
  47. package/dist/Table.js +6 -0
  48. package/dist/TextField.d.ts +23 -0
  49. package/dist/TextField.js +11 -0
  50. package/dist/Toast.d.ts +5 -2
  51. package/dist/Toast.js +9 -4
  52. package/dist/Toggle.d.ts +5 -4
  53. package/dist/Toggle.js +7 -2
  54. package/dist/Tree.d.ts +20 -0
  55. package/dist/Tree.js +59 -0
  56. package/dist/Window.d.ts +9 -3
  57. package/dist/Window.js +7 -5
  58. package/dist/fieldName.d.ts +4 -0
  59. package/dist/fieldName.js +9 -0
  60. package/dist/glyphs.d.ts +1 -0
  61. package/dist/glyphs.js +1 -0
  62. package/dist/index.d.ts +13 -0
  63. package/dist/index.js +12 -0
  64. package/package.json +2 -2
package/README.md CHANGED
@@ -71,7 +71,14 @@ needs none of them.
71
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
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
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 |
74
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 |
75
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 |
76
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 |
77
84
  | `useLabelMode`, `useTipBubble`, `usePortalHue` | The small hooks the components need |
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
  }
@@ -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
  }
@@ -12,6 +12,8 @@ export interface ContextMenuProps {
12
12
  above?: boolean;
13
13
  /** The menu's accessible name. */
14
14
  label?: string;
15
+ /** The menu element's id, for a caller or a script that looks for it. */
16
+ id?: string;
15
17
  /** The control that opened the menu. A click on it is not a click outside,
16
18
  * and focus goes back to it; without one, focus goes back to wherever it was. */
17
19
  opener?: HTMLElement | null;
@@ -20,4 +22,4 @@ export interface ContextMenuProps {
20
22
  /** Left or right on a row without a submenu, for a bar that steps to the next menu. */
21
23
  onStep?: (direction: 1 | -1) => void;
22
24
  }
23
- export declare function ContextMenu({ x, y, items, above, label, opener, onClose, onStep }: ContextMenuProps): import("react").JSX.Element;
25
+ export declare function ContextMenu({ x, y, items, above, label, id, opener, onClose, onStep }: ContextMenuProps): import("react").JSX.Element;
@@ -28,7 +28,7 @@ function Rows({ entries, openAt, onPick, }) {
28
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
29
  });
30
30
  }
31
- export function ContextMenu({ x, y, items, above = false, label, opener, onClose, onStep }) {
31
+ export function ContextMenu({ x, y, items, above = false, label, id, opener, onClose, onStep }) {
32
32
  const menu = useRef(null);
33
33
  const subMenu = useRef(null);
34
34
  const [asker] = useState(focusedAsker);
@@ -132,6 +132,6 @@ export function ContextMenu({ x, y, items, above = false, label, opener, onClose
132
132
  else if (!opens && sub)
133
133
  setSub(null);
134
134
  }
135
- return (_jsxs(_Fragment, { children: [createPortal(_jsx("div", { ref: menu, role: "menu", "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, 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)] }));
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
137
  }
@@ -1,7 +1,9 @@
1
+ import { type FieldWidth } from "@glimstone/core";
1
2
  export interface CopyFieldProps {
2
3
  value: string;
3
- /** The field's accessible name, such as "Token". */
4
- label: string;
4
+ /** The field's accessible name, such as "Token". Inside a FieldRow the row gives it. */
5
+ label?: string;
6
+ width?: FieldWidth;
5
7
  /** The button's words, before and for a moment after it copied. */
6
8
  text?: {
7
9
  copy: string;
@@ -12,4 +14,4 @@ export interface CopyFieldProps {
12
14
  /** Classes for the row, which carries the width. */
13
15
  className?: string;
14
16
  }
15
- export declare function CopyField({ value, label, text, onCopy, className }: CopyFieldProps): import("react").JSX.Element;
17
+ export declare function CopyField({ value, label, width, text, onCopy, className }: CopyFieldProps): import("react").JSX.Element;
package/dist/CopyField.js CHANGED
@@ -1,9 +1,11 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useEffect, useRef, useState } from "react";
3
- import { COPIED_MS, copyText } from "@glimstone/core";
3
+ import { COPIED_MS, copyText, fieldWidthClass } from "@glimstone/core";
4
4
  import { Button } from "./Button.js";
5
+ import { useFieldName } from "./fieldName.js";
5
6
  import { IconCheck, IconCopy } from "./glyphs.js";
6
- export function CopyField({ value, label, text = { copy: "Copy", copied: "Copied" }, onCopy, className }) {
7
+ export function CopyField({ value, label, width, text = { copy: "Copy", copied: "Copied" }, onCopy, className }) {
8
+ const name = useFieldName(label);
7
9
  const [copied, setCopied] = useState(false);
8
10
  const field = useRef(null);
9
11
  const timer = useRef(undefined);
@@ -20,5 +22,5 @@ export function CopyField({ value, label, text = { copy: "Copy", copied: "Copied
20
22
  clearTimeout(timer.current);
21
23
  timer.current = window.setTimeout(() => setCopied(false), COPIED_MS);
22
24
  }
23
- return (_jsxs("span", { className: className ? `glim-copy ${className}` : "glim-copy", children: [_jsx("input", { ref: field, readOnly: true, value: value, "aria-label": label, 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 : "" })] }));
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 : "" })] }));
24
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;
@@ -0,0 +1,9 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { takePageHue } from "@glimstone/core";
3
+ import { IconTipButton } from "./IconTipButton.js";
4
+ const reach = (e) => takePageHue(e.currentTarget);
5
+ export function IconButton({ tip, glyph, pressed, absent, className, ...rest }) {
6
+ if (absent)
7
+ return _jsx("span", { className: "glim-icon-btn-gap", "aria-hidden": "true" });
8
+ return (_jsx(IconTipButton, { ...rest, tip: tip, ariaPressed: pressed, className: `glim-btn-bare glim-icon-btn ${className ?? ""}`.trim(), onPointerEnter: reach, onFocusCapture: reach, children: glyph }));
9
+ }
@@ -1,8 +1,7 @@
1
- import type { CSSProperties, ReactNode } from "react";
2
- export declare function IconTipButton({ tip, onClick, disabled, className, style, children, type, ariaPressed, ariaExpanded, }: {
1
+ import type { ButtonHTMLAttributes, CSSProperties, ReactNode } from "react";
2
+ export interface IconTipButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, "children" | "type"> {
3
3
  /** The hover and focus explanation, and the button's `aria-label`. */
4
4
  tip: string;
5
- onClick?: () => void;
6
5
  disabled?: boolean;
7
6
  className?: string;
8
7
  /** `aria-pressed` for a trigger that toggles rather than acts once. Omitted,
@@ -14,5 +13,8 @@ export declare function IconTipButton({ tip, onClick, disabled, className, style
14
13
  /** Inline style, so a hued Badge can set its `--item-hue*` properties. */
15
14
  style?: CSSProperties;
16
15
  children: ReactNode;
16
+ /** Makes it a link. A disabled one stays a disabled button. */
17
+ href?: string;
17
18
  type?: "button" | "submit";
18
- }): import("react").JSX.Element;
19
+ }
20
+ export declare function IconTipButton({ tip, disabled, className, style, children, href, type, ariaPressed, ariaExpanded, ...rest }: IconTipButtonProps): import("react").JSX.Element;
@@ -1,13 +1,8 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useTipBubble } from "./useTipBubble.js";
3
- // An icon-only <button> whose accessible name and hover or focus explanation is
4
- // a `.glim-bubble` tooltip rather than the native `title=` balloon. `tip` is
5
- // required because an icon-only button has no other way to say what it does.
6
- //
7
- // Unlike Button, this control has no label to hide: a bare glyph in a box the
8
- // caller sizes, with no width stage, no tone fill and no place in the label
9
- // mode engine.
10
- export function IconTipButton({ tip, onClick, disabled, className, style, children, type = "button", ariaPressed, ariaExpanded, }) {
3
+ export function IconTipButton({ tip, disabled, className, style, children, href, type = "button", ariaPressed, ariaExpanded, ...rest }) {
11
4
  const tooltip = useTipBubble(tip, disabled);
12
- return (_jsxs(_Fragment, { children: [tooltip.wrap(_jsx("button", { ref: tooltip.ref, type: type, onClick: onClick, disabled: disabled, "aria-label": tip, "aria-pressed": ariaPressed, "aria-expanded": ariaExpanded, "aria-describedby": tooltip.describedBy, ...tooltip.handlers, className: className, style: style, children: children })), tooltip.bubble] }));
5
+ const Element = (href && !disabled ? "a" : "button");
6
+ const own = href && !disabled ? { href } : { type, disabled };
7
+ return (_jsxs(_Fragment, { children: [tooltip.wrap(_jsx(Element, { ...rest, ...own, ref: tooltip.ref, "aria-label": tip, "aria-pressed": ariaPressed, "aria-expanded": ariaExpanded, "aria-describedby": tooltip.describedBy, ...tooltip.handlers, className: className, style: style, children: children })), tooltip.bubble] }));
13
8
  }
@@ -0,0 +1,16 @@
1
+ import type { HTMLAttributes, ReactNode } from "react";
2
+ export interface ListRowProps extends Omit<HTMLAttributes<HTMLDivElement>, "children"> {
3
+ name: string;
4
+ /** More about the row, drawn as an "(i)" beside the name. */
5
+ tip?: string | null;
6
+ /** Sets the name in monospace, for a path. */
7
+ mono?: boolean;
8
+ /** The glyph at the row's start, which fills with the accent while the row is reached. */
9
+ tile?: ReactNode;
10
+ /** What stands at the row's end at rest. */
11
+ badges?: ReactNode;
12
+ /** The buttons that come in on hover and focus. A press on one does not open the row. */
13
+ actions?: ReactNode;
14
+ className?: string;
15
+ }
16
+ export declare function ListRow({ name, tip, mono, tile, badges, actions, className, onClick, onKeyDown, ...rest }: ListRowProps): import("react").JSX.Element;
@@ -0,0 +1,14 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { InfoBubble } from "./InfoBubble.js";
3
+ const stay = (e) => e.stopPropagation();
4
+ export function ListRow({ name, tip, mono, tile, badges, actions, className, onClick, onKeyDown, ...rest }) {
5
+ function keys(e) {
6
+ onKeyDown?.(e);
7
+ if (!onClick || e.target !== e.currentTarget || (e.key !== "Enter" && e.key !== " "))
8
+ return;
9
+ e.preventDefault();
10
+ e.currentTarget.click();
11
+ }
12
+ const classes = ["glim-list-row", onClick && "glim-list-row--opens", className].filter(Boolean).join(" ");
13
+ return (_jsxs("div", { role: "group", "aria-label": name, tabIndex: onClick ? 0 : undefined, ...rest, onClick: onClick, onKeyDown: keys, className: classes, children: [tile && _jsx("span", { className: "glim-list-row-tile", children: tile }), _jsxs("span", { className: mono ? "glim-list-row-name glim-list-row-name--mono" : "glim-list-row-name", children: [_jsx("span", { className: "glim-list-row-title", children: name }), tip && (_jsx("span", { className: "glim-list-row-tip", onClick: stay, children: _jsx(InfoBubble, { tip: tip }) }))] }), badges && _jsx("span", { className: "glim-list-row-badges", children: badges }), actions && (_jsx("span", { className: "glim-list-row-actions", onClick: stay, children: actions }))] }));
14
+ }
package/dist/MenuBar.d.ts CHANGED
@@ -3,6 +3,8 @@ import { type MenuEntry } from "./ContextMenu.tsx";
3
3
  export interface MenuBarMenu {
4
4
  label: string;
5
5
  items: MenuEntry[];
6
+ /** The id of the open menu, for a caller or a script that looks for it. */
7
+ id?: string;
6
8
  }
7
9
  export interface MenuBarHandle {
8
10
  /** Opens a menu by its index and puts the focus on its first row. */
package/dist/MenuBar.js CHANGED
@@ -36,5 +36,5 @@ export function MenuBar({ label, menus, ref, className }) {
36
36
  }
37
37
  return (_jsxs("div", { role: "menubar", "aria-label": label, className: className ? `glim-menubar ${className}` : "glim-menubar", children: [menus.map((m, i) => (_jsx("button", { ref: (el) => {
38
38
  buttons.current[i] = el;
39
- }, type: "button", role: "menuitem", "aria-haspopup": "menu", "aria-expanded": open?.at === i, tabIndex: i === stop ? 0 : -1, className: "glim-menubar-item", onClick: () => (open?.at === i ? setOpen(null) : show(i)), onMouseEnter: () => open && open.at !== i && show(i), onKeyDown: (e) => keys(e, i), onFocus: () => setStop(i), children: m.label }, i))), open && menus[open.at] && (_jsx(ContextMenu, { x: open.x, y: open.y, items: menus[open.at].items, label: menus[open.at].label, opener: buttons.current[open.at], onClose: () => setOpen(null), onStep: (d) => show((open.at + d + count) % count) }, open.at))] }));
39
+ }, type: "button", role: "menuitem", "aria-haspopup": "menu", "aria-expanded": open?.at === i, tabIndex: i === stop ? 0 : -1, className: "glim-menubar-item", onClick: () => (open?.at === i ? setOpen(null) : show(i)), onMouseEnter: () => open && open.at !== i && show(i), onKeyDown: (e) => keys(e, i), onFocus: () => setStop(i), children: m.label }, i))), open && menus[open.at] && (_jsx(ContextMenu, { x: open.x, y: open.y, items: menus[open.at].items, label: menus[open.at].label, id: menus[open.at].id, opener: buttons.current[open.at], onClose: () => setOpen(null), onStep: (d) => show((open.at + d + count) % count) }, open.at))] }));
40
40
  }
@@ -13,4 +13,4 @@ export interface NumberFieldProps extends Omit<InputHTMLAttributes<HTMLInputElem
13
13
  className?: string;
14
14
  ref?: Ref<HTMLInputElement>;
15
15
  }
16
- export declare function NumberField({ className, ref, ...rest }: NumberFieldProps): import("react").JSX.Element;
16
+ export declare function NumberField({ className, ref, "aria-label": ariaLabel, ...rest }: NumberFieldProps): import("react").JSX.Element;
@@ -1,14 +1,16 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useEffect, useRef } from "react";
3
3
  import { attachNumberSteppers, syncNumberSteppers } from "@glimstone/core";
4
- export function NumberField({ className = "", ref, ...rest }) {
4
+ import { useFieldName } from "./fieldName.js";
5
+ export function NumberField({ className = "", ref, "aria-label": ariaLabel, ...rest }) {
6
+ const name = useFieldName(ariaLabel);
5
7
  const own = useRef(null);
6
8
  useEffect(() => attachNumberSteppers(own.current), []);
7
9
  // A value the app sets fires no input event, so the arrows look again.
8
10
  useEffect(() => {
9
11
  syncNumberSteppers(own.current);
10
12
  }, [rest.value, rest.min, rest.max, rest.step, rest.disabled, rest.readOnly]);
11
- return (_jsx("span", { className: "glim-num-wrap", children: _jsx("input", { ...rest, ref: (el) => {
13
+ return (_jsx("span", { className: "glim-num-wrap", children: _jsx("input", { ...rest, "aria-label": name, ref: (el) => {
12
14
  own.current = el;
13
15
  if (typeof ref === "function")
14
16
  ref(el);
@@ -1,5 +1,9 @@
1
1
  import { type InputHTMLAttributes, type Ref } from "react";
2
- export interface PasswordFieldProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "type"> {
2
+ import { type FieldWidth } from "@glimstone/core";
3
+ export interface PasswordFieldProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "type" | "width"> {
4
+ width?: FieldWidth;
5
+ /** Attributes for the eye, such as a data hook. */
6
+ eyeAttrs?: Record<string, string>;
3
7
  /** The eye's name and bubble while the secret is hidden, and once it shows. */
4
8
  text?: {
5
9
  show: string;
@@ -9,4 +13,4 @@ export interface PasswordFieldProps extends Omit<InputHTMLAttributes<HTMLInputEl
9
13
  className?: string;
10
14
  ref?: Ref<HTMLInputElement>;
11
15
  }
12
- export declare function PasswordField({ text, className, ref, disabled, ...rest }: PasswordFieldProps): import("react").JSX.Element;
16
+ export declare function PasswordField({ width, eyeAttrs, text, className, ref, disabled, "aria-label": ariaLabel, ...rest }: PasswordFieldProps): import("react").JSX.Element;
@@ -1,8 +1,11 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useState } from "react";
3
+ import { fieldWidthClass } from "@glimstone/core";
4
+ import { useFieldName } from "./fieldName.js";
3
5
  import { IconEye, IconEyeOff } from "./glyphs.js";
4
6
  import { IconTipButton } from "./IconTipButton.js";
5
- export function PasswordField({ text = { show: "Show", hide: "Hide" }, className, ref, disabled, ...rest }) {
7
+ export function PasswordField({ width, eyeAttrs, text = { show: "Show", hide: "Hide" }, className, ref, disabled, "aria-label": ariaLabel, ...rest }) {
6
8
  const [shown, setShown] = useState(false);
7
- return (_jsxs("span", { className: className ? `glim-secret ${className}` : "glim-secret", children: [_jsx("input", { autoComplete: "current-password", spellCheck: false, ...rest, ref: ref, disabled: disabled, type: shown ? "text" : "password", className: "glim-input" }), _jsx(IconTipButton, { tip: shown ? text.hide : text.show, className: "glim-secret-eye", disabled: disabled, onClick: () => setShown(!shown), children: shown ? _jsx(IconEyeOff, {}) : _jsx(IconEye, {}) })] }));
9
+ const name = useFieldName(ariaLabel);
10
+ return (_jsxs("span", { className: ["glim-secret", fieldWidthClass(width), className].filter(Boolean).join(" "), children: [_jsx("input", { autoComplete: "current-password", spellCheck: false, ...rest, "aria-label": name, ref: ref, disabled: disabled, type: shown ? "text" : "password", className: "glim-input" }), _jsx(IconTipButton, { ...eyeAttrs, tip: shown ? text.hide : text.show, className: "glim-secret-eye", disabled: disabled, onClick: () => setShown(!shown), children: shown ? _jsx(IconEyeOff, {}) : _jsx(IconEye, {}) })] }));
8
11
  }
@@ -0,0 +1,28 @@
1
+ import { type InputHTMLAttributes, type ReactNode, type Ref } from "react";
2
+ import { type FieldWidth } from "@glimstone/core";
3
+ export interface PathFieldProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "value" | "onChange" | "type" | "width"> {
4
+ value: string;
5
+ /** Called with the path as it is typed and as the picker answers. */
6
+ onChange: (path: string) => void;
7
+ /** Handed the path in the field. Answers with a path, or with nothing when the person left. */
8
+ pick: (current: string) => string | null | undefined | Promise<string | null | undefined>;
9
+ /** Called with a path the picker answered with, after onChange. */
10
+ onPicked?: (path: string) => void;
11
+ /** The accessible name. Inside a FieldRow the row gives it. */
12
+ label?: string;
13
+ width?: FieldWidth;
14
+ /** The button's words. */
15
+ text?: {
16
+ pick: string;
17
+ };
18
+ /** The button's glyph, an open folder unless set, such as a file for a picker of files. */
19
+ glyph?: ReactNode;
20
+ /** Shows the button's glyph alone, as it does by itself with less than 20rem of room. */
21
+ compact?: boolean;
22
+ /** Attributes for the button, such as a data hook. */
23
+ buttonAttrs?: Record<string, string>;
24
+ /** Classes for the wrapper, which carries the width. */
25
+ className?: string;
26
+ ref?: Ref<HTMLInputElement>;
27
+ }
28
+ export declare function PathField({ value, onChange, pick, onPicked, label, width, text, glyph, compact, buttonAttrs, className, style, disabled, ref, ...rest }: PathFieldProps): import("react").JSX.Element;
@@ -0,0 +1,32 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useRef, useState } from "react";
3
+ import { fieldWidthClass, PATH_ROOM_PX } from "@glimstone/core";
4
+ import { Button } from "./Button.js";
5
+ import { useFieldName } from "./fieldName.js";
6
+ import { IconFolderOpen } from "./glyphs.js";
7
+ export function PathField({ value, onChange, pick, onPicked, label, width, text = { pick: "Choose" }, glyph = _jsx(IconFolderOpen, {}), compact = false, buttonAttrs, className, style, disabled, ref, ...rest }) {
8
+ const name = useFieldName(label);
9
+ const own = useRef(null);
10
+ const box = useRef(null);
11
+ const [tight, setTight] = useState(false);
12
+ useEffect(() => {
13
+ const watcher = new ResizeObserver(([entry]) => setTight(entry.contentRect.width < PATH_ROOM_PX));
14
+ watcher.observe(box.current);
15
+ return () => watcher.disconnect();
16
+ }, []);
17
+ async function ask() {
18
+ const answer = await pick(value);
19
+ own.current?.focus();
20
+ if (!answer)
21
+ return;
22
+ onChange(answer);
23
+ onPicked?.(answer);
24
+ }
25
+ return (_jsxs("span", { ref: box, className: ["glim-path", fieldWidthClass(width), className].filter(Boolean).join(" "), style: style, children: [_jsx("input", { spellCheck: false, autoComplete: "off", "aria-label": name, ...rest, ref: (el) => {
26
+ own.current = el;
27
+ if (typeof ref === "function")
28
+ ref(el);
29
+ else if (ref)
30
+ ref.current = el;
31
+ }, type: "text", value: value, disabled: disabled, onChange: (e) => onChange(e.target.value), className: "glim-input glim-input--mono" }), _jsx(Button, { ...buttonAttrs, variant: "icon", label: text.pick, labelKey: null, glyph: glyph, compact: compact || tight, disabled: disabled, onClick: ask })] }));
32
+ }