@glimstone/react 4.9.2 → 5.0.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 (81) hide show
  1. package/README.md +2 -2
  2. package/dist/AngleSlider.d.ts +1 -1
  3. package/dist/AngleSlider.js +17 -4
  4. package/dist/Avatar.js +1 -1
  5. package/dist/Badge.d.ts +3 -6
  6. package/dist/Badge.js +2 -2
  7. package/dist/Card.d.ts +4 -1
  8. package/dist/Card.js +2 -2
  9. package/dist/Chart.d.ts +30 -0
  10. package/dist/Chart.js +22 -0
  11. package/dist/Checkbox.js +1 -2
  12. package/dist/ColorPicker.d.ts +3 -1
  13. package/dist/ColorPicker.js +22 -5
  14. package/dist/Combobox.js +14 -4
  15. package/dist/ConfirmDialog.js +4 -2
  16. package/dist/ContextMenu.d.ts +3 -1
  17. package/dist/ContextMenu.js +3 -3
  18. package/dist/DatePicker.js +6 -1
  19. package/dist/FieldRow.d.ts +1 -1
  20. package/dist/FieldRow.js +8 -4
  21. package/dist/FileUpload.d.ts +3 -1
  22. package/dist/FileUpload.js +6 -3
  23. package/dist/FortressPermissions.js +3 -2
  24. package/dist/HoverCard.d.ts +13 -3
  25. package/dist/HoverCard.js +3 -3
  26. package/dist/IconTipButton.d.ts +4 -1
  27. package/dist/IconTipButton.js +3 -3
  28. package/dist/InfoBubble.js +1 -1
  29. package/dist/{AboutCard.d.ts → InfoTile.d.ts} +0 -44
  30. package/dist/{AboutCard.js → InfoTile.js} +1 -28
  31. package/dist/ListRow.d.ts +19 -4
  32. package/dist/ListRow.js +15 -2
  33. package/dist/ListTable.d.ts +6 -1
  34. package/dist/ListTable.js +18 -6
  35. package/dist/Meter.d.ts +5 -1
  36. package/dist/Meter.js +8 -3
  37. package/dist/MultiSelect.js +2 -1
  38. package/dist/NotifyCard.js +1 -1
  39. package/dist/NumberField.js +2 -2
  40. package/dist/PasswordField.js +10 -4
  41. package/dist/PinInput.js +3 -3
  42. package/dist/Rating.js +9 -3
  43. package/dist/Select.js +8 -4
  44. package/dist/Selector.d.ts +5 -4
  45. package/dist/Selector.js +21 -4
  46. package/dist/SettingsNav.d.ts +41 -0
  47. package/dist/SettingsNav.js +48 -0
  48. package/dist/SignInTile.js +16 -15
  49. package/dist/SkeletonRow.d.ts +5 -1
  50. package/dist/SkeletonRow.js +3 -3
  51. package/dist/Slider.js +1 -1
  52. package/dist/StatusSummary.d.ts +16 -0
  53. package/dist/StatusSummary.js +8 -0
  54. package/dist/SubCard.d.ts +6 -7
  55. package/dist/SubCard.js +4 -6
  56. package/dist/TextField.d.ts +1 -1
  57. package/dist/TextField.js +17 -6
  58. package/dist/TimePicker.d.ts +30 -0
  59. package/dist/TimePicker.js +146 -0
  60. package/dist/Timer.js +6 -1
  61. package/dist/Toast.d.ts +3 -1
  62. package/dist/Toast.js +9 -7
  63. package/dist/Toggle.js +1 -1
  64. package/dist/Tour.js +6 -3
  65. package/dist/Window.d.ts +3 -1
  66. package/dist/Window.js +2 -2
  67. package/dist/engines.d.ts +7 -1
  68. package/dist/engines.js +17 -2
  69. package/dist/fieldErrorLine.d.ts +4 -0
  70. package/dist/fieldErrorLine.js +18 -0
  71. package/dist/glyphs.d.ts +2 -0
  72. package/dist/glyphs.js +2 -0
  73. package/dist/index.d.ts +5 -2
  74. package/dist/index.js +5 -2
  75. package/dist/searchHit.d.ts +4 -0
  76. package/dist/searchHit.js +10 -0
  77. package/dist/useTipBubble.d.ts +11 -2
  78. package/dist/useTipBubble.js +14 -10
  79. package/package.json +3 -3
  80. package/dist/DropdownListbox.d.ts +0 -22
  81. package/dist/DropdownListbox.js +0 -190
@@ -1,190 +0,0 @@
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, focusByLetter, isTypeahead, portalTarget, warnDeprecated } 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 <body> (portalTarget), 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. Removed in 5.0.0. */
19
- export function DropdownListbox({ open, onClose, triggerRef, label, multiselectable, children, }) {
20
- warnDeprecated("DropdownListbox");
21
- const panelRef = useRef(null);
22
- const [pos, setPos] = useState(null);
23
- // One focus move per opening, once the panel sits at its real coordinates.
24
- const focusedOnOpen = useRef(false);
25
- // Whether focus is inside the panel, tracked as it moves because it cannot be
26
- // read at teardown.
27
- const focusInsideRef = useRef(false);
28
- useEffect(() => {
29
- if (!open)
30
- focusedOnOpen.current = false;
31
- }, [open]);
32
- // Read through a ref so an inline onClose does not re-attach every listener
33
- // on each render, which happens on every toggle in a multi-select list.
34
- const onCloseRef = useRef(onClose);
35
- onCloseRef.current = onClose;
36
- // The next open re-measures instead of flashing at the old coordinates.
37
- useLayoutEffect(() => {
38
- if (!open)
39
- setPos(null);
40
- }, [open]);
41
- // The portal leaves the trigger's rainbow subtree, so the panel copies the
42
- // trigger's hue.
43
- const hue = usePortalHue(open, triggerRef);
44
- // Measured and placed before paint, so the panel never jumps from its
45
- // off-screen parking spot.
46
- useLayoutEffect(() => {
47
- if (!open)
48
- return;
49
- const trigger = triggerRef.current;
50
- const panel = panelRef.current;
51
- if (!trigger || !panel)
52
- return;
53
- const rect = trigger.getBoundingClientRect();
54
- // The width is written to the node before the height is read, because
55
- // option labels wrap against it. `pos` receives the same value below.
56
- panel.style.width = `${rect.width}px`;
57
- const viewport = {
58
- width: document.documentElement.clientWidth || window.innerWidth,
59
- height: document.documentElement.clientHeight || window.innerHeight,
60
- };
61
- const { left, top } = computeBubblePosition(rect, { width: rect.width, height: panel.offsetHeight }, viewport, DROPDOWN_GAP);
62
- // `children` is a dependency so a list that changes length while open is
63
- // re-measured. Its identity changes on every render, so returning the
64
- // previous object when nothing moved is what stops an endless loop.
65
- setPos((prev) => prev && prev.left === left && prev.top === top && prev.width === rect.width
66
- ? prev
67
- : { left, top, width: rect.width });
68
- }, [open, triggerRef, children]);
69
- // A fixed panel that has lost its trigger reads as broken, so an outside
70
- // press, Escape, scroll or resize closes it. The panel itself is exempt from
71
- // the outside press, or pressing an option would unmount the list before its
72
- // click landed. The scroll listener captures on `window` to see nested
73
- // scroll containers, and ignores scrolls inside the panel, which scrolls a
74
- // long list itself.
75
- useEffect(() => {
76
- if (!open)
77
- return;
78
- function onPointerDown(e) {
79
- const target = e.target;
80
- if (panelRef.current?.contains(target))
81
- return;
82
- if (triggerRef.current?.contains(target))
83
- return;
84
- onCloseRef.current();
85
- }
86
- function onKeyDown(e) {
87
- if (e.key === "Escape")
88
- onCloseRef.current();
89
- }
90
- function onScroll(e) {
91
- const target = e.target;
92
- if (target instanceof Node && panelRef.current?.contains(target))
93
- return;
94
- onCloseRef.current();
95
- }
96
- function onResize() {
97
- onCloseRef.current();
98
- }
99
- document.addEventListener("mousedown", onPointerDown);
100
- document.addEventListener("keydown", onKeyDown);
101
- window.addEventListener("scroll", onScroll, true);
102
- window.addEventListener("resize", onResize);
103
- return () => {
104
- document.removeEventListener("mousedown", onPointerDown);
105
- document.removeEventListener("keydown", onKeyDown);
106
- window.removeEventListener("scroll", onScroll, true);
107
- window.removeEventListener("resize", onResize);
108
- };
109
- }, [open, triggerRef]);
110
- // The options are the caller's children, so they are found in the DOM by
111
- // their role.
112
- function options() {
113
- const panel = panelRef.current;
114
- if (!panel)
115
- return [];
116
- return Array.from(panel.querySelectorAll('[role="option"]'));
117
- }
118
- // Focus moves to the selected option on open, so a keyboard user reaches the
119
- // list. It waits for `pos`: focusing an option parked at -9999px makes the
120
- // browser scroll to it, and that scroll closes the panel.
121
- useLayoutEffect(() => {
122
- if (!open || !pos || focusedOnOpen.current)
123
- return;
124
- const opts = options();
125
- if (opts.length === 0)
126
- return;
127
- const active = opts.find((o) => o.getAttribute("aria-selected") === "true") ?? opts[0];
128
- focusedOnOpen.current = true;
129
- active.scrollIntoView?.({ block: "nearest" });
130
- active.focus();
131
- }, [open, pos]);
132
- // Focus returns to the trigger on close only if it was inside the panel; a
133
- // click elsewhere has already put it where the user wants. By cleanup time
134
- // the portal is gone and focus sits on <body>, hence the tracked flag. The
135
- // panel's onBlur clears it only when focus leaves the panel, so arrowing
136
- // between options keeps it.
137
- useLayoutEffect(() => {
138
- const trigger = triggerRef.current;
139
- return () => {
140
- if (focusInsideRef.current)
141
- trigger?.focus();
142
- focusInsideRef.current = false;
143
- };
144
- }, [open, triggerRef]);
145
- // Arrows, Home, End and a typed letter move between options here so every
146
- // listbox behaves alike. Enter and Space need nothing: the options are real
147
- // buttons.
148
- function onPanelKeyDown(e) {
149
- if (isTypeahead(e.nativeEvent)) {
150
- if (focusByLetter(options(), e.key))
151
- e.preventDefault();
152
- return;
153
- }
154
- if (e.key !== "ArrowDown" && e.key !== "ArrowUp" && e.key !== "Home" && e.key !== "End")
155
- return;
156
- const opts = options();
157
- if (opts.length === 0)
158
- return;
159
- e.preventDefault();
160
- const at = opts.indexOf(document.activeElement);
161
- let next;
162
- if (e.key === "Home")
163
- next = 0;
164
- else if (e.key === "End")
165
- next = opts.length - 1;
166
- else {
167
- const dir = e.key === "ArrowDown" ? 1 : -1;
168
- next = at < 0 ? (dir === 1 ? 0 : opts.length - 1) : (at + dir + opts.length) % opts.length;
169
- }
170
- const option = opts[next];
171
- option.scrollIntoView?.({ block: "nearest" });
172
- option.focus();
173
- }
174
- if (!open)
175
- return null;
176
- return createPortal(_jsx("div", { "data-glim": "DropdownListbox", ref: panelRef, role: "listbox", onKeyDown: onPanelKeyDown, onFocus: () => {
177
- focusInsideRef.current = true;
178
- }, onBlur: (e) => {
179
- if (!e.currentTarget.contains(e.relatedTarget))
180
- focusInsideRef.current = false;
181
- }, "aria-multiselectable": multiselectable ? "true" : undefined, "aria-label": label, className: `glim-listbox glim-fade${hue.className ? ` ${hue.className}` : ""}`, style: {
182
- // Parked off-screen until measured, since the panel needs to be in the
183
- // DOM at its real width to have a height.
184
- left: pos?.left ?? -9999,
185
- top: pos?.top ?? -9999,
186
- width: pos?.width,
187
- transform: "translateX(-50%)",
188
- ...(hue.style ?? {}),
189
- }, children: children }), portalTarget());
190
- }