@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.
- package/README.md +2 -2
- package/dist/AngleSlider.d.ts +1 -1
- package/dist/AngleSlider.js +17 -4
- package/dist/Avatar.js +1 -1
- package/dist/Badge.d.ts +3 -6
- package/dist/Badge.js +2 -2
- package/dist/Card.d.ts +4 -1
- package/dist/Card.js +2 -2
- package/dist/Chart.d.ts +30 -0
- package/dist/Chart.js +22 -0
- package/dist/Checkbox.js +1 -2
- package/dist/ColorPicker.d.ts +3 -1
- package/dist/ColorPicker.js +22 -5
- package/dist/Combobox.js +14 -4
- package/dist/ConfirmDialog.js +4 -2
- package/dist/ContextMenu.d.ts +3 -1
- package/dist/ContextMenu.js +3 -3
- package/dist/DatePicker.js +6 -1
- package/dist/FieldRow.d.ts +1 -1
- package/dist/FieldRow.js +8 -4
- package/dist/FileUpload.d.ts +3 -1
- package/dist/FileUpload.js +6 -3
- package/dist/FortressPermissions.js +3 -2
- package/dist/HoverCard.d.ts +13 -3
- package/dist/HoverCard.js +3 -3
- package/dist/IconTipButton.d.ts +4 -1
- package/dist/IconTipButton.js +3 -3
- package/dist/InfoBubble.js +1 -1
- package/dist/{AboutCard.d.ts → InfoTile.d.ts} +0 -44
- package/dist/{AboutCard.js → InfoTile.js} +1 -28
- package/dist/ListRow.d.ts +19 -4
- package/dist/ListRow.js +15 -2
- package/dist/ListTable.d.ts +6 -1
- package/dist/ListTable.js +18 -6
- package/dist/Meter.d.ts +5 -1
- package/dist/Meter.js +8 -3
- package/dist/MultiSelect.js +2 -1
- package/dist/NotifyCard.js +1 -1
- package/dist/NumberField.js +2 -2
- package/dist/PasswordField.js +10 -4
- package/dist/PinInput.js +3 -3
- package/dist/Rating.js +9 -3
- package/dist/Select.js +8 -4
- package/dist/Selector.d.ts +5 -4
- package/dist/Selector.js +21 -4
- package/dist/SettingsNav.d.ts +41 -0
- package/dist/SettingsNav.js +48 -0
- package/dist/SignInTile.js +16 -15
- package/dist/SkeletonRow.d.ts +5 -1
- package/dist/SkeletonRow.js +3 -3
- package/dist/Slider.js +1 -1
- package/dist/StatusSummary.d.ts +16 -0
- package/dist/StatusSummary.js +8 -0
- package/dist/SubCard.d.ts +6 -7
- package/dist/SubCard.js +4 -6
- package/dist/TextField.d.ts +1 -1
- package/dist/TextField.js +17 -6
- package/dist/TimePicker.d.ts +30 -0
- package/dist/TimePicker.js +146 -0
- package/dist/Timer.js +6 -1
- package/dist/Toast.d.ts +3 -1
- package/dist/Toast.js +9 -7
- package/dist/Toggle.js +1 -1
- package/dist/Tour.js +6 -3
- package/dist/Window.d.ts +3 -1
- package/dist/Window.js +2 -2
- package/dist/engines.d.ts +7 -1
- package/dist/engines.js +17 -2
- package/dist/fieldErrorLine.d.ts +4 -0
- package/dist/fieldErrorLine.js +18 -0
- package/dist/glyphs.d.ts +2 -0
- package/dist/glyphs.js +2 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.js +5 -2
- package/dist/searchHit.d.ts +4 -0
- package/dist/searchHit.js +10 -0
- package/dist/useTipBubble.d.ts +11 -2
- package/dist/useTipBubble.js +14 -10
- package/package.json +3 -3
- package/dist/DropdownListbox.d.ts +0 -22
- package/dist/DropdownListbox.js +0 -190
package/dist/DropdownListbox.js
DELETED
|
@@ -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
|
-
}
|