@glimstone/react 0.0.0-stage → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/README.md +125 -2
  2. package/dist/AboutCard.d.ts +152 -0
  3. package/dist/AboutCard.js +82 -0
  4. package/dist/Badge.d.ts +47 -0
  5. package/dist/Badge.js +35 -0
  6. package/dist/Button.d.ts +54 -0
  7. package/dist/Button.js +52 -0
  8. package/dist/Card.d.ts +29 -0
  9. package/dist/Card.js +20 -0
  10. package/dist/Checkbox.d.ts +14 -0
  11. package/dist/Checkbox.js +7 -0
  12. package/dist/CoffeeDialog.d.ts +17 -0
  13. package/dist/CoffeeDialog.js +9 -0
  14. package/dist/ColorPicker.d.ts +21 -0
  15. package/dist/ColorPicker.js +68 -0
  16. package/dist/Combobox.d.ts +16 -0
  17. package/dist/Combobox.js +32 -0
  18. package/dist/ConfirmDialog.d.ts +29 -0
  19. package/dist/ConfirmDialog.js +15 -0
  20. package/dist/ContextMenu.d.ts +23 -0
  21. package/dist/ContextMenu.js +137 -0
  22. package/dist/CopyField.d.ts +15 -0
  23. package/dist/CopyField.js +24 -0
  24. package/dist/CryptoDonateDialog.d.ts +61 -0
  25. package/dist/CryptoDonateDialog.js +23 -0
  26. package/dist/DropdownListbox.d.ts +22 -0
  27. package/dist/DropdownListbox.js +182 -0
  28. package/dist/EmptyState.d.ts +19 -0
  29. package/dist/EmptyState.js +10 -0
  30. package/dist/IconTipButton.d.ts +18 -0
  31. package/dist/IconTipButton.js +13 -0
  32. package/dist/InfoBubble.d.ts +4 -0
  33. package/dist/InfoBubble.js +19 -0
  34. package/dist/Kbd.d.ts +5 -0
  35. package/dist/Kbd.js +6 -0
  36. package/dist/MenuBar.d.ts +18 -0
  37. package/dist/MenuBar.js +40 -0
  38. package/dist/Meter.d.ts +18 -0
  39. package/dist/Meter.js +9 -0
  40. package/dist/NumberField.d.ts +16 -0
  41. package/dist/NumberField.js +18 -0
  42. package/dist/PasswordField.d.ts +12 -0
  43. package/dist/PasswordField.js +8 -0
  44. package/dist/PaypalDialog.d.ts +51 -0
  45. package/dist/PaypalDialog.js +20 -0
  46. package/dist/Pill.d.ts +12 -0
  47. package/dist/Pill.js +5 -0
  48. package/dist/ProgressBar.d.ts +14 -0
  49. package/dist/ProgressBar.js +6 -0
  50. package/dist/ReadmeButton.d.ts +29 -0
  51. package/dist/ReadmeButton.js +27 -0
  52. package/dist/Select.d.ts +41 -0
  53. package/dist/Select.js +192 -0
  54. package/dist/Selector.d.ts +67 -0
  55. package/dist/Selector.js +128 -0
  56. package/dist/SidebarRow.d.ts +22 -0
  57. package/dist/SidebarRow.js +10 -0
  58. package/dist/Slider.d.ts +12 -0
  59. package/dist/Slider.js +18 -0
  60. package/dist/SubCard.d.ts +15 -0
  61. package/dist/SubCard.js +14 -0
  62. package/dist/Toast.d.ts +29 -0
  63. package/dist/Toast.js +24 -0
  64. package/dist/Toggle.d.ts +16 -0
  65. package/dist/Toggle.js +4 -0
  66. package/dist/UnavailableNotice.d.ts +15 -0
  67. package/dist/UnavailableNotice.js +12 -0
  68. package/dist/Window.d.ts +37 -0
  69. package/dist/Window.js +43 -0
  70. package/dist/WindowBar.d.ts +24 -0
  71. package/dist/WindowBar.js +31 -0
  72. package/dist/glyphs.d.ts +26 -0
  73. package/dist/glyphs.js +34 -0
  74. package/dist/index.d.ts +39 -0
  75. package/dist/index.js +39 -0
  76. package/dist/portalHue.d.ts +10 -0
  77. package/dist/portalHue.js +15 -0
  78. package/dist/useConfirm.d.ts +26 -0
  79. package/dist/useConfirm.js +39 -0
  80. package/dist/useLabelMode.d.ts +6 -0
  81. package/dist/useLabelMode.js +11 -0
  82. package/dist/usePaypalButtons.d.ts +15 -0
  83. package/dist/usePaypalButtons.js +42 -0
  84. package/dist/useTipBubble.d.ts +34 -0
  85. package/dist/useTipBubble.js +63 -0
  86. package/package.json +28 -4
@@ -0,0 +1,182 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useEffect, useLayoutEffect, useRef, useState, } from "react";
3
+ import { createPortal } from "react-dom";
4
+ import { computeBubblePosition } from "@glimstone/core";
5
+ import { usePortalHue } from "./portalHue.js";
6
+ // The `role="listbox"` panel a button-opens-a-list picker drops open. It is
7
+ // portalled to document.body, because a card with `overflow: hidden` clips an
8
+ // absolutely positioned panel whatever its z-index, and placed with
9
+ // computeBubblePosition, which clamps it into the viewport and flips it above
10
+ // the trigger when needed.
11
+ //
12
+ // The panel takes the trigger's width and is centred on it with
13
+ // `translateX(-50%)`, since computeBubblePosition returns the centre. Equal
14
+ // widths look start-aligned and need no RTL branch.
15
+ /** The gap to the trigger and the minimum distance from the viewport edge,
16
+ * 4px to match `mt-1`. */
17
+ const DROPDOWN_GAP = 4;
18
+ /** @deprecated Use Select, which keeps focus on its trigger and adds typeahead. */
19
+ export function DropdownListbox({ open, onClose, triggerRef, label, multiselectable, children, }) {
20
+ const panelRef = useRef(null);
21
+ const [pos, setPos] = useState(null);
22
+ // One focus move per opening, once the panel sits at its real coordinates.
23
+ const focusedOnOpen = useRef(false);
24
+ // Whether focus is inside the panel, tracked as it moves because it cannot be
25
+ // read at teardown.
26
+ const focusInsideRef = useRef(false);
27
+ useEffect(() => {
28
+ if (!open)
29
+ focusedOnOpen.current = false;
30
+ }, [open]);
31
+ // Read through a ref so an inline onClose does not re-attach every listener
32
+ // on each render, which happens on every toggle in a multi-select list.
33
+ const onCloseRef = useRef(onClose);
34
+ onCloseRef.current = onClose;
35
+ // The next open re-measures instead of flashing at the old coordinates.
36
+ useLayoutEffect(() => {
37
+ if (!open)
38
+ setPos(null);
39
+ }, [open]);
40
+ // The portal leaves the trigger's rainbow subtree, so the panel copies the
41
+ // trigger's hue.
42
+ const hue = usePortalHue(open, triggerRef);
43
+ // Measured and placed before paint, so the panel never jumps from its
44
+ // off-screen parking spot.
45
+ useLayoutEffect(() => {
46
+ if (!open)
47
+ return;
48
+ const trigger = triggerRef.current;
49
+ const panel = panelRef.current;
50
+ if (!trigger || !panel)
51
+ return;
52
+ const rect = trigger.getBoundingClientRect();
53
+ // The width is written to the node before the height is read, because
54
+ // option labels wrap against it. `pos` receives the same value below.
55
+ panel.style.width = `${rect.width}px`;
56
+ const viewport = {
57
+ width: document.documentElement.clientWidth || window.innerWidth,
58
+ height: document.documentElement.clientHeight || window.innerHeight,
59
+ };
60
+ const { left, top } = computeBubblePosition(rect, { width: rect.width, height: panel.offsetHeight }, viewport, DROPDOWN_GAP);
61
+ // `children` is a dependency so a list that changes length while open is
62
+ // re-measured. Its identity changes on every render, so returning the
63
+ // previous object when nothing moved is what stops an endless loop.
64
+ setPos((prev) => prev && prev.left === left && prev.top === top && prev.width === rect.width
65
+ ? prev
66
+ : { left, top, width: rect.width });
67
+ }, [open, triggerRef, children]);
68
+ // A fixed panel that has lost its trigger reads as broken, so an outside
69
+ // press, Escape, scroll or resize closes it. The panel itself is exempt from
70
+ // the outside press, or pressing an option would unmount the list before its
71
+ // click landed. The scroll listener captures on `window` to see nested
72
+ // scroll containers, and ignores scrolls inside the panel, which scrolls a
73
+ // long list itself.
74
+ useEffect(() => {
75
+ if (!open)
76
+ return;
77
+ function onPointerDown(e) {
78
+ const target = e.target;
79
+ if (panelRef.current?.contains(target))
80
+ return;
81
+ if (triggerRef.current?.contains(target))
82
+ return;
83
+ onCloseRef.current();
84
+ }
85
+ function onKeyDown(e) {
86
+ if (e.key === "Escape")
87
+ onCloseRef.current();
88
+ }
89
+ function onScroll(e) {
90
+ const target = e.target;
91
+ if (target instanceof Node && panelRef.current?.contains(target))
92
+ return;
93
+ onCloseRef.current();
94
+ }
95
+ function onResize() {
96
+ onCloseRef.current();
97
+ }
98
+ document.addEventListener("mousedown", onPointerDown);
99
+ document.addEventListener("keydown", onKeyDown);
100
+ window.addEventListener("scroll", onScroll, true);
101
+ window.addEventListener("resize", onResize);
102
+ return () => {
103
+ document.removeEventListener("mousedown", onPointerDown);
104
+ document.removeEventListener("keydown", onKeyDown);
105
+ window.removeEventListener("scroll", onScroll, true);
106
+ window.removeEventListener("resize", onResize);
107
+ };
108
+ }, [open, triggerRef]);
109
+ // The options are the caller's children, so they are found in the DOM by
110
+ // their role.
111
+ function options() {
112
+ const panel = panelRef.current;
113
+ if (!panel)
114
+ return [];
115
+ return Array.from(panel.querySelectorAll('[role="option"]'));
116
+ }
117
+ // Focus moves to the selected option on open, so a keyboard user reaches the
118
+ // list. It waits for `pos`: focusing an option parked at -9999px makes the
119
+ // browser scroll to it, and that scroll closes the panel.
120
+ useLayoutEffect(() => {
121
+ if (!open || !pos || focusedOnOpen.current)
122
+ return;
123
+ const opts = options();
124
+ if (opts.length === 0)
125
+ return;
126
+ const active = opts.find((o) => o.getAttribute("aria-selected") === "true") ?? opts[0];
127
+ focusedOnOpen.current = true;
128
+ active.scrollIntoView?.({ block: "nearest" });
129
+ active.focus();
130
+ }, [open, pos]);
131
+ // Focus returns to the trigger on close only if it was inside the panel; a
132
+ // click elsewhere has already put it where the user wants. By cleanup time
133
+ // the portal is gone and focus sits on <body>, hence the tracked flag. The
134
+ // panel's onBlur clears it only when focus leaves the panel, so arrowing
135
+ // between options keeps it.
136
+ useLayoutEffect(() => {
137
+ const trigger = triggerRef.current;
138
+ return () => {
139
+ if (focusInsideRef.current)
140
+ trigger?.focus();
141
+ focusInsideRef.current = false;
142
+ };
143
+ }, [open, triggerRef]);
144
+ // Arrows, Home and End move between options here so every listbox behaves
145
+ // alike. Enter and Space need nothing: the options are real buttons.
146
+ function onPanelKeyDown(e) {
147
+ if (e.key !== "ArrowDown" && e.key !== "ArrowUp" && e.key !== "Home" && e.key !== "End")
148
+ return;
149
+ const opts = options();
150
+ if (opts.length === 0)
151
+ return;
152
+ e.preventDefault();
153
+ const at = opts.indexOf(document.activeElement);
154
+ let next;
155
+ if (e.key === "Home")
156
+ next = 0;
157
+ else if (e.key === "End")
158
+ next = opts.length - 1;
159
+ else {
160
+ const dir = e.key === "ArrowDown" ? 1 : -1;
161
+ next = at < 0 ? (dir === 1 ? 0 : opts.length - 1) : (at + dir + opts.length) % opts.length;
162
+ }
163
+ opts[next].scrollIntoView?.({ block: "nearest" });
164
+ opts[next].focus();
165
+ }
166
+ if (!open)
167
+ return null;
168
+ return createPortal(_jsx("div", { ref: panelRef, role: "listbox", onKeyDown: onPanelKeyDown, onFocus: () => {
169
+ focusInsideRef.current = true;
170
+ }, onBlur: (e) => {
171
+ if (!e.currentTarget.contains(e.relatedTarget))
172
+ focusInsideRef.current = false;
173
+ }, "aria-multiselectable": multiselectable ? "true" : undefined, "aria-label": label, className: `glim-listbox glim-fade${hue.className ? ` ${hue.className}` : ""}`, style: {
174
+ // Parked off-screen until measured, since the panel needs to be in the
175
+ // DOM at its real width to have a height.
176
+ left: pos?.left ?? -9999,
177
+ top: pos?.top ?? -9999,
178
+ width: pos?.width,
179
+ transform: "translateX(-50%)",
180
+ ...(hue.style ?? {}),
181
+ }, children: children }), document.body);
182
+ }
@@ -0,0 +1,19 @@
1
+ import type { ReactNode } from "react";
2
+ /**
3
+ * What a list, table or panel shows when it holds nothing: a muted, oversized
4
+ * glyph, a title, an optional hint and an optional action. "Nothing here yet"
5
+ * and "nothing matches the filter" take the same shape with different words,
6
+ * so somebody is not sent looking for a filter that was never set.
7
+ */
8
+ export declare function EmptyState({ glyph, title, hint, action, nested, }: {
9
+ /** The page's own glyph, so the empty state echoes the place it is on. */
10
+ glyph?: ReactNode;
11
+ /** What is missing, such as "No backups yet" or "No backups match the filter". */
12
+ title: string;
13
+ /** One line on how to get there; anything longer goes into a bubble or a window. */
14
+ hint?: string;
15
+ /** A Button that gets out of the empty state, such as "Add a backup" or "Clear the filter". */
16
+ action?: ReactNode;
17
+ /** It stands inside a card, which already provides the surface. */
18
+ nested?: boolean;
19
+ }): import("react").JSX.Element;
@@ -0,0 +1,10 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * What a list, table or panel shows when it holds nothing: a muted, oversized
4
+ * glyph, a title, an optional hint and an optional action. "Nothing here yet"
5
+ * and "nothing matches the filter" take the same shape with different words,
6
+ * so somebody is not sent looking for a filter that was never set.
7
+ */
8
+ export function EmptyState({ glyph, title, hint, action, nested = false, }) {
9
+ return (_jsxs("div", { className: nested ? "glim-empty" : "glim-card glim-empty", children: [glyph && (_jsx("span", { className: "glim-empty-glyph", "aria-hidden": "true", children: glyph })), _jsx("p", { className: "glim-empty-title", children: title }), hint && _jsx("p", { className: "glim-empty-hint", children: hint }), action] }));
10
+ }
@@ -0,0 +1,18 @@
1
+ import type { CSSProperties, ReactNode } from "react";
2
+ export declare function IconTipButton({ tip, onClick, disabled, className, style, children, type, ariaPressed, ariaExpanded, }: {
3
+ /** The hover and focus explanation, and the button's `aria-label`. */
4
+ tip: string;
5
+ onClick?: () => void;
6
+ disabled?: boolean;
7
+ className?: string;
8
+ /** `aria-pressed` for a trigger that toggles rather than acts once. Omitted,
9
+ * no attribute is rendered. */
10
+ ariaPressed?: boolean;
11
+ /** `aria-expanded` for a trigger that opens a disclosure panel. Omitted, no
12
+ * attribute is rendered. */
13
+ ariaExpanded?: boolean;
14
+ /** Inline style, so a hued Badge can set its `--item-hue*` properties. */
15
+ style?: CSSProperties;
16
+ children: ReactNode;
17
+ type?: "button" | "submit";
18
+ }): import("react").JSX.Element;
@@ -0,0 +1,13 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
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, }) {
11
+ 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] }));
13
+ }
@@ -0,0 +1,4 @@
1
+ export declare function InfoBubble({ tip, onAccent }: {
2
+ tip: string;
3
+ onAccent?: boolean;
4
+ }): import("react").JSX.Element;
@@ -0,0 +1,19 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useTipBubble } from "./useTipBubble.js";
3
+ // A neutral (i) icon beside a label that reveals a short help text on hover and
4
+ // keyboard focus. Explanations live here rather than as a permanent grey
5
+ // paragraph under the control. The icon never takes the accent colour, which
6
+ // means "active"; the bubble itself comes from useTipBubble.
7
+ //
8
+ // `onAccent` is for an icon inside a filled accent badge such as a card heading:
9
+ // it inherits the badge's --accent-contrast ink and drops the idle opacity, which
10
+ // has less margin on a busy fill.
11
+ export function InfoBubble({ tip, onAccent = false }) {
12
+ const tooltip = useTipBubble(tip);
13
+ return (_jsxs(_Fragment, { children: [_jsx("span", { ref: tooltip.ref, "aria-label": tip, "aria-describedby": tooltip.describedBy, tabIndex: 0, ...tooltip.handlers,
14
+ // Inside a <label>, a click on a span is forwarded to the label's field,
15
+ // which takes focus and closes the bubble at once. stopPropagation does
16
+ // not stop the native forwarding; preventDefault does, and the span
17
+ // keeps the focus it took on mousedown.
18
+ onClick: (e) => e.preventDefault(), className: onAccent ? "glim-info-icon glim-info-icon--on-accent" : "glim-info-icon", children: _jsxs("svg", { viewBox: "0 0 16 16", width: "15", height: "15", fill: "none", "aria-hidden": "true", children: [_jsx("circle", { cx: "8", cy: "8", r: "7", stroke: "currentColor", strokeWidth: "1.3" }), _jsx("circle", { cx: "8", cy: "4.6", r: "0.9", fill: "currentColor" }), _jsx("path", { d: "M8 7v4.4", stroke: "currentColor", strokeWidth: "1.3", strokeLinecap: "round" })] }) }), tooltip.bubble] }));
19
+ }
package/dist/Kbd.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import type { ReactNode } from "react";
2
+ export declare function Kbd({ children, className }: {
3
+ children: ReactNode;
4
+ className?: string;
5
+ }): import("react").JSX.Element;
package/dist/Kbd.js ADDED
@@ -0,0 +1,6 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ // A key or a key combination as it is written on the keys, such as "Ctrl+K".
3
+ // The words are the app's, so a German app writes "Strg".
4
+ export function Kbd({ children, className }) {
5
+ return _jsx("kbd", { className: className ? `glim-kbd ${className}` : "glim-kbd", children: children });
6
+ }
@@ -0,0 +1,18 @@
1
+ import { type Ref } from "react";
2
+ import { type MenuEntry } from "./ContextMenu.tsx";
3
+ export interface MenuBarMenu {
4
+ label: string;
5
+ items: MenuEntry[];
6
+ }
7
+ export interface MenuBarHandle {
8
+ /** Opens a menu by its index and puts the focus on its first row. */
9
+ open: (index: number) => void;
10
+ }
11
+ export interface MenuBarProps {
12
+ /** The bar's accessible name, such as "Menu". */
13
+ label: string;
14
+ menus: MenuBarMenu[];
15
+ ref?: Ref<MenuBarHandle>;
16
+ className?: string;
17
+ }
18
+ export declare function MenuBar({ label, menus, ref, className }: MenuBarProps): import("react").JSX.Element;
@@ -0,0 +1,40 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // The menu bar of a desktop-style app: a row of words, each opening its menu
3
+ // below it. While one is open the pointer and the arrow keys move between
4
+ // them, as in a desktop program. The app opens the first one on F10 through
5
+ // the ref, since which key does it is the app's keymap.
6
+ import { useImperativeHandle, useRef, useState } from "react";
7
+ import { ContextMenu } from "./ContextMenu.js";
8
+ export function MenuBar({ label, menus, ref, className }) {
9
+ const buttons = useRef([]);
10
+ const [open, setOpen] = useState(null);
11
+ const [stop, setStop] = useState(0);
12
+ const count = menus.length;
13
+ function show(at) {
14
+ const button = buttons.current[at];
15
+ if (!button)
16
+ return;
17
+ button.focus();
18
+ setStop(at);
19
+ const r = button.getBoundingClientRect();
20
+ setOpen({ at, x: r.left, y: r.bottom + 6 });
21
+ }
22
+ useImperativeHandle(ref, () => ({ open: show }));
23
+ function keys(e, at) {
24
+ const rtl = getComputedStyle(e.currentTarget).direction === "rtl";
25
+ const step = { ArrowRight: rtl ? -1 : 1, ArrowLeft: rtl ? 1 : -1 }[e.key];
26
+ if (step !== undefined) {
27
+ e.preventDefault();
28
+ const next = (at + step + count) % count;
29
+ setStop(next);
30
+ buttons.current[next]?.focus();
31
+ }
32
+ else if (e.key === "ArrowDown") {
33
+ e.preventDefault();
34
+ show(at);
35
+ }
36
+ }
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
+ 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))] }));
40
+ }
@@ -0,0 +1,18 @@
1
+ import { type MeterSize } from "@glimstone/core";
2
+ export type { MeterSize } from "@glimstone/core";
3
+ export interface MeterProps {
4
+ /** From 0 to 1. Without it the meter shows stripes while the level is still being read. */
5
+ value?: number | null;
6
+ /** The accessible name, such as the disk's. */
7
+ label: string;
8
+ /** `small` sits beside a row's name, `medium` is as wide as its column. */
9
+ size?: MeterSize;
10
+ /** From here on the fill is the fault colour. */
11
+ threshold?: number;
12
+ /** Slim and grey, for a footer line or a dense list. Inside a button it takes the accent when the button is reached. */
13
+ quiet?: boolean;
14
+ /** The level in words, such as "120 GB free of 4 TB": read out, and shown in the bubble. */
15
+ valueText?: string;
16
+ className?: string;
17
+ }
18
+ export declare function Meter({ value, label, size, threshold, quiet, valueText, className }: MeterProps): import("react").JSX.Element;
package/dist/Meter.js ADDED
@@ -0,0 +1,9 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { meterView } from "@glimstone/core";
3
+ import { useTipBubble } from "./useTipBubble.js";
4
+ export function Meter({ value, label, size = "medium", threshold, quiet, valueText, className }) {
5
+ const view = meterView(value, { size, threshold, quiet });
6
+ const tip = useTipBubble(valueText);
7
+ const busy = view.percent === null;
8
+ return (_jsxs(_Fragment, { children: [_jsx("span", { ref: tip.ref, ...tip.handlers, role: busy ? "progressbar" : "meter", "aria-label": label, "aria-valuemin": busy ? undefined : 0, "aria-valuemax": busy ? undefined : 100, "aria-valuenow": view.percent ?? undefined, "aria-valuetext": valueText, "aria-busy": busy || undefined, className: className ? `${view.className} ${className}` : view.className, children: _jsx("span", { className: "glim-meter-fill", style: view.width ? { width: view.width } : undefined }) }), tip.bubble] }));
9
+ }
@@ -0,0 +1,16 @@
1
+ import { type ChangeEventHandler, type InputHTMLAttributes, type Ref } from "react";
2
+ export interface NumberFieldProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "type"> {
3
+ /** The bounds and the step. The steppers, the arrow keys and the wheel all
4
+ * go through the input's own stepUp(), so the range lives here alone. */
5
+ min?: number | string;
6
+ max?: number | string;
7
+ step?: number | string;
8
+ /** Called alike for typing, the arrow keys, the steppers and the wheel,
9
+ * which steps the value only while the field has focus. */
10
+ onChange?: ChangeEventHandler<HTMLInputElement>;
11
+ /** Classes for the input. A width set here has to be definite, since the
12
+ * arrows sit against the input's end. */
13
+ className?: string;
14
+ ref?: Ref<HTMLInputElement>;
15
+ }
16
+ export declare function NumberField({ className, ref, ...rest }: NumberFieldProps): import("react").JSX.Element;
@@ -0,0 +1,18 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useEffect, useRef } from "react";
3
+ import { attachNumberSteppers, syncNumberSteppers } from "@glimstone/core";
4
+ export function NumberField({ className = "", ref, ...rest }) {
5
+ const own = useRef(null);
6
+ useEffect(() => attachNumberSteppers(own.current), []);
7
+ // A value the app sets fires no input event, so the arrows look again.
8
+ useEffect(() => {
9
+ syncNumberSteppers(own.current);
10
+ }, [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) => {
12
+ own.current = el;
13
+ if (typeof ref === "function")
14
+ ref(el);
15
+ else if (ref)
16
+ ref.current = el;
17
+ }, type: "number", className: `glim-num-input glim-num-field glim-num ${className}`.trim() }) }));
18
+ }
@@ -0,0 +1,12 @@
1
+ import { type InputHTMLAttributes, type Ref } from "react";
2
+ export interface PasswordFieldProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "type"> {
3
+ /** The eye's name and bubble while the secret is hidden, and once it shows. */
4
+ text?: {
5
+ show: string;
6
+ hide: string;
7
+ };
8
+ /** Classes for the wrapper, which carries the field's width. */
9
+ className?: string;
10
+ ref?: Ref<HTMLInputElement>;
11
+ }
12
+ export declare function PasswordField({ text, className, ref, disabled, ...rest }: PasswordFieldProps): import("react").JSX.Element;
@@ -0,0 +1,8 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ import { IconEye, IconEyeOff } from "./glyphs.js";
4
+ import { IconTipButton } from "./IconTipButton.js";
5
+ export function PasswordField({ text = { show: "Show", hide: "Hide" }, className, ref, disabled, ...rest }) {
6
+ 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, {}) })] }));
8
+ }
@@ -0,0 +1,51 @@
1
+ import type { ReactNode, Ref, RefObject } from "react";
2
+ import type { GiveFrequency } from "@glimstone/core";
3
+ export interface PaypalSelectorProps {
4
+ labelledBy: string;
5
+ options: {
6
+ value: string;
7
+ label: string;
8
+ }[];
9
+ /** Null when no segment is picked, as while a typed amount applies. */
10
+ value: string | null;
11
+ onChange: (value: string) => void;
12
+ }
13
+ export interface PaypalDialogProps {
14
+ text: {
15
+ title: string;
16
+ /** The app's appeal, the same in every giving window. */
17
+ appeal: string;
18
+ /** One sentence: the payment happens at PayPal, by account or by card. */
19
+ intro: string;
20
+ frequencyLabel: string;
21
+ frequencies: Record<GiveFrequency, string>;
22
+ amountLabel: string;
23
+ /** Placeholder and accessible name of the free amount. */
24
+ otherAmount: string;
25
+ loading: string;
26
+ thanks: string;
27
+ failed: string;
28
+ closeLabel: string;
29
+ };
30
+ frequency: GiveFrequency;
31
+ onFrequency: (frequency: GiveFrequency) => void;
32
+ /** The preset amounts, as whole numbers in the currency. */
33
+ amounts: string[];
34
+ currencySymbol: string;
35
+ /** The picked preset, or null while the free amount is in use. */
36
+ preset: string | null;
37
+ onPreset: (amount: string) => void;
38
+ typed: string;
39
+ /** Whether `typed` parses as an amount PayPal accepts. */
40
+ typedValid: boolean;
41
+ onTyped: (text: string) => void;
42
+ /** The app's own horizontal selector. */
43
+ renderSelector: (props: PaypalSelectorProps) => ReactNode;
44
+ /** From usePaypalButtons. */
45
+ buttonsRef: RefObject<HTMLDivElement | null>;
46
+ status: "idle" | "done" | "failed";
47
+ onClose: () => void;
48
+ /** The window's own card, for the app's Escape handling and focus trap. */
49
+ ref?: Ref<HTMLDivElement>;
50
+ }
51
+ export declare function PaypalDialog({ text, frequency, onFrequency, amounts, currencySymbol, preset, onPreset, typed, typedValid, onTyped, renderSelector, buttonsRef, status, onClose, ref, }: PaypalDialogProps): import("react").JSX.Element;
@@ -0,0 +1,20 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Badge } from "./Badge.js";
3
+ import { Button } from "./Button.js";
4
+ export function PaypalDialog({ text, frequency, onFrequency, amounts, currencySymbol, preset, onPreset, typed, typedValid, onTyped, renderSelector, buttonsRef, status, onClose, ref, }) {
5
+ const frequencies = ["once", "month", "year"];
6
+ return (_jsx("div", { className: "glim-modal-backdrop", onClick: (e) => {
7
+ if (e.target === e.currentTarget)
8
+ onClose();
9
+ }, children: _jsxs("div", { ref: ref, tabIndex: -1, role: "dialog", "aria-modal": "true", "aria-labelledby": "paypal-window-title", className: "glim-modal-card glim-modal-card--wide", children: [_jsx("div", { className: "glim-modal-head", children: _jsx("h2", { id: "paypal-window-title", className: "glim-modal-title", children: _jsx(Badge, { tone: "heading", size: "heading", wrap: true, children: text.title }) }) }), _jsxs("div", { className: "glim-give-body glim-give-body--scroll", children: [_jsx("p", { className: "glim-give-appeal", children: text.appeal }), _jsx("p", { className: "glim-give-intro", children: text.intro }), _jsxs("div", { className: "glim-give-group", children: [_jsx("span", { id: "paypal-frequency", className: "glim-eyebrow", children: text.frequencyLabel }), renderSelector({
10
+ labelledBy: "paypal-frequency",
11
+ options: frequencies.map((f) => ({ value: f, label: text.frequencies[f] })),
12
+ value: frequency,
13
+ onChange: (v) => onFrequency(v),
14
+ })] }), _jsxs("div", { className: "glim-give-group", children: [_jsx("span", { id: "paypal-amount", className: "glim-eyebrow", children: text.amountLabel }), _jsxs("div", { className: "glim-give-amounts", children: [_jsx("div", { children: renderSelector({
15
+ labelledBy: "paypal-amount",
16
+ options: amounts.map((a) => ({ value: a, label: `${a} ${currencySymbol}` })),
17
+ value: preset,
18
+ onChange: onPreset,
19
+ }) }), _jsx("input", { type: "text", inputMode: "decimal", value: typed, placeholder: text.otherAmount, "aria-label": text.otherAmount, "aria-invalid": typed !== "" && !typedValid, onChange: (e) => onTyped(e.target.value), className: `glim-give-amount${typedValid ? " glim-give-amount--valid" : ""}` })] })] }), _jsx("div", { ref: buttonsRef, className: "glim-give-wallet", children: _jsx("p", { className: "glim-give-loading", children: text.loading }) }), status === "done" && _jsx("p", { className: "glim-give-status glim-give-status--ok", children: text.thanks }), status === "failed" && _jsx("p", { className: "glim-give-status glim-give-status--fail", children: text.failed })] }), _jsx("div", { className: "glim-give-foot", children: _jsx(Button, { label: text.closeLabel, labelKey: "common.close", tone: "neutral", onClick: onClose }) })] }) }));
20
+ }
package/dist/Pill.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import type { ReactNode } from "react";
2
+ import { type PillTone } from "@glimstone/core";
3
+ export type { PillTone } from "@glimstone/core";
4
+ export interface PillProps {
5
+ children: ReactNode;
6
+ /** `state` lifts a word that says what the row is doing; the other three
7
+ * wash the pill in their state colour. */
8
+ tone?: PillTone;
9
+ /** Extra classes, such as `glim-num` for figures that line up in a column. */
10
+ className?: string;
11
+ }
12
+ export declare function Pill({ children, tone, className }: PillProps): import("react").JSX.Element;
package/dist/Pill.js ADDED
@@ -0,0 +1,5 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { pillClassName } from "@glimstone/core";
3
+ export function Pill({ children, tone = "neutral", className }) {
4
+ return _jsx("span", { className: className ? `${pillClassName(tone)} ${className}` : pillClassName(tone), children: children });
5
+ }
@@ -0,0 +1,14 @@
1
+ export interface ProgressBarProps {
2
+ /** From 0 to 1. Without it the bar runs indeterminate, while the work has no measure yet. */
3
+ value?: number | null;
4
+ /** The accessible name, such as what is being copied. */
5
+ label: string;
6
+ /** The work waits: the fill takes the waiting tone and the sheen stops. */
7
+ paused?: boolean;
8
+ /** The work stopped on an error: the fill takes the fault colour. */
9
+ failed?: boolean;
10
+ /** The progress in words, such as "1.2 GB of 4 GB", read out instead of the percentage. */
11
+ valueText?: string;
12
+ className?: string;
13
+ }
14
+ export declare function ProgressBar({ value, label, paused, failed, valueText, className }: ProgressBarProps): import("react").JSX.Element;
@@ -0,0 +1,6 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { progressView } from "@glimstone/core";
3
+ export function ProgressBar({ value, label, paused, failed, valueText, className }) {
4
+ const view = progressView(value, { paused, failed });
5
+ return (_jsx("span", { role: "progressbar", "aria-label": label, "aria-valuemin": view.percent === null ? undefined : 0, "aria-valuemax": view.percent === null ? undefined : 100, "aria-valuenow": view.percent ?? undefined, "aria-valuetext": valueText, className: className ? `${view.className} ${className}` : view.className, children: _jsx("span", { className: "glim-progress-fill", style: view.width ? { width: view.width } : undefined }) }));
6
+ }
@@ -0,0 +1,29 @@
1
+ import { type MouseEvent, type ReactNode } from "react";
2
+ import { type ReadmeBrand, type ReadmePart } from "@glimstone/core";
3
+ export type { ReadmeBrand, ReadmePart } from "@glimstone/core";
4
+ export interface ReadmeButtonProps {
5
+ /** The brand whose colour the unit lights up in. */
6
+ brand: ReadmeBrand;
7
+ /** The button, then its segments. */
8
+ parts: [ReadmePart, ...ReadmePart[]];
9
+ mark?: ReactNode;
10
+ /** The class that paints the mark at rest, such as `glim-windows-mark`. It
11
+ * sits on the mark's box, where the lit unit's ink can override it. */
12
+ markClass?: string;
13
+ /** A vendor's own button artwork, which replaces the first part's mark and words. */
14
+ art?: ReactNode;
15
+ /** The "(i)" at the end of the unit, for what the name cannot say. */
16
+ hint?: string;
17
+ /** Holds the second lines in view while one reports what it did, such as "Copied". */
18
+ note?: boolean;
19
+ /** The second line of a unit whose first part has neither `href` nor `onClick`. */
20
+ soonLabel?: string;
21
+ /** Runs on a click on a part's link, for an app whose webview has no browser
22
+ * behind it to open the address in. */
23
+ onLinkClick?: (e: MouseEvent<HTMLAnchorElement>) => void;
24
+ }
25
+ export declare function ReadmeButton({ brand, parts, mark, markClass, art, hint, note, soonLabel, onLinkClick }: ReadmeButtonProps): import("react").JSX.Element;
26
+ /** A vendor mark kept as its own markup, from appMarks.ts. */
27
+ export declare function BrandMark({ svg }: {
28
+ svg: string;
29
+ }): import("react").JSX.Element;
@@ -0,0 +1,27 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useLayoutEffect, useRef } from "react";
3
+ import { keepReadmeFit, readmePartClass, readmeSoon, readmeUnitClass, } from "@glimstone/core";
4
+ import { InfoBubble } from "./InfoBubble.js";
5
+ export function ReadmeButton({ brand, parts, mark, markClass, art, hint, note, soonLabel, onLinkClick }) {
6
+ const ref = useRef(null);
7
+ const soon = readmeSoon(parts);
8
+ const words = parts.map((p) => `${p.name}\n${p.sub ?? ""}`).join("\n") + (soon ? soonLabel : "");
9
+ useLayoutEffect(() => (ref.current ? keepReadmeFit(ref.current) : undefined), [words]);
10
+ return (_jsxs("div", { ref: ref, className: readmeUnitClass(brand, parts.length, !!note, soon), children: [parts.map((part, i) => {
11
+ const sub = soon ? soonLabel : part.sub;
12
+ const label = sub ? `${part.name} ${sub}` : part.name;
13
+ const className = readmePartClass(i, soon);
14
+ const face = i === 0 && art ? (_jsx("span", { className: "glim-readme-btn-art", "aria-hidden": true, children: art })) : (_jsxs(_Fragment, { children: [i === 0 && mark && (_jsx("span", { className: `glim-readme-btn-mark ${markClass ?? ""}`, "aria-hidden": true, children: mark })), _jsxs("span", { className: "glim-readme-btn-text", children: [_jsx("span", { className: "glim-readme-btn-name", children: part.name }), sub && _jsx("span", { className: "glim-readme-btn-sub", children: sub })] })] }));
15
+ if (soon) {
16
+ return (_jsx("span", { className: className, "aria-disabled": true, "aria-label": label, children: face }, i));
17
+ }
18
+ if (part.href) {
19
+ return (_jsx("a", { href: part.href, target: "_blank", rel: "noreferrer noopener", onClick: onLinkClick, "aria-label": label, className: className, children: face }, i));
20
+ }
21
+ return (_jsx("button", { type: "button", onClick: part.onClick, "aria-label": label, className: className, children: face }, i));
22
+ }), !soon && _jsx("span", { className: "glim-readme-btn-sheen", "aria-hidden": true }), hint && (_jsx("span", { className: "glim-readme-btn-hint", children: _jsx(InfoBubble, { tip: hint }) }))] }));
23
+ }
24
+ /** A vendor mark kept as its own markup, from appMarks.ts. */
25
+ export function BrandMark({ svg }) {
26
+ return _jsx("span", { className: "glim-brand-svg", "aria-hidden": true, dangerouslySetInnerHTML: { __html: svg } });
27
+ }