@allxsmith/bestax-bulma 5.27.7 → 5.28.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/dist/bestax.css +1 -1
- package/dist/bestax.css.map +1 -1
- package/dist/esm/components/HoverCard.js +127 -0
- package/dist/esm/components/HoverCard.js.map +1 -0
- package/dist/esm/form/DateInput.js.map +1 -1
- package/dist/esm/form/DateInputBase.js +2 -3
- package/dist/esm/form/DateInputBase.js.map +1 -1
- package/dist/esm/form/DateTimeInput.js.map +1 -1
- package/dist/esm/form/DateTimeInputBase.js +2 -3
- package/dist/esm/form/DateTimeInputBase.js.map +1 -1
- package/dist/esm/form/Field.js +36 -5
- package/dist/esm/form/Field.js.map +1 -1
- package/dist/esm/form/File.js.map +1 -1
- package/dist/esm/form/FormContext.js +53 -9
- package/dist/esm/form/FormContext.js.map +1 -1
- package/dist/esm/form/Input.js.map +1 -1
- package/dist/esm/form/InputBase.js +6 -5
- package/dist/esm/form/InputBase.js.map +1 -1
- package/dist/esm/form/Numberinput.js.map +1 -1
- package/dist/esm/form/Select.js.map +1 -1
- package/dist/esm/form/SelectBase.js +7 -5
- package/dist/esm/form/SelectBase.js.map +1 -1
- package/dist/esm/form/Slider.js.map +1 -1
- package/dist/esm/form/Taginput.js.map +1 -1
- package/dist/esm/form/TextArea.js.map +1 -1
- package/dist/esm/form/TextAreaBase.js +6 -5
- package/dist/esm/form/TextAreaBase.js.map +1 -1
- package/dist/esm/form/TimeInput.js.map +1 -1
- package/dist/esm/form/TimeInputBase.js +2 -3
- package/dist/esm/form/TimeInputBase.js.map +1 -1
- package/dist/esm/form/useAutoLabelId.js +8 -3
- package/dist/esm/form/useAutoLabelId.js.map +1 -1
- package/dist/esm/helpers/Theme.js +87 -17
- package/dist/esm/helpers/Theme.js.map +1 -1
- package/dist/esm/helpers/devWarnings.js +8 -3
- package/dist/esm/helpers/devWarnings.js.map +1 -1
- package/dist/esm/helpers/useFlexboxClasses.js +1 -1
- package/dist/esm/helpers/useFocusTrap.js +2 -1
- package/dist/esm/helpers/useFocusTrap.js.map +1 -1
- package/dist/esm/helpers/useHoverOpen.js +390 -0
- package/dist/esm/helpers/useHoverOpen.js.map +1 -0
- package/dist/esm/helpers/useOtherClasses.js +1 -1
- package/dist/esm/helpers/useSpacingClasses.js +1 -1
- package/dist/esm/helpers/useTypographyClasses.js +1 -1
- package/dist/esm/helpers/useVisibilityClasses.js +1 -1
- package/dist/extras.css +1 -1
- package/dist/extras.css.map +1 -1
- package/dist/index.cjs +700 -48
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +1 -0
- package/dist/index.esm.js.map +1 -1
- package/dist/types/components/HoverCard.d.ts +136 -0
- package/dist/types/form/DateInput.d.ts +1 -1
- package/dist/types/form/DateTimeInput.d.ts +1 -1
- package/dist/types/form/Field.d.ts +2 -2
- package/dist/types/form/File.d.ts +1 -1
- package/dist/types/form/FormContext.d.ts +47 -8
- package/dist/types/form/Input.d.ts +1 -1
- package/dist/types/form/Numberinput.d.ts +1 -1
- package/dist/types/form/Select.d.ts +1 -1
- package/dist/types/form/Slider.d.ts +1 -1
- package/dist/types/form/Taginput.d.ts +1 -1
- package/dist/types/form/TextArea.d.ts +1 -1
- package/dist/types/form/TimeInput.d.ts +1 -1
- package/dist/types/form/useAutoLabelId.d.ts +4 -2
- package/dist/types/helpers/Theme.d.ts +15 -1
- package/dist/types/helpers/devWarnings.d.ts +8 -0
- package/dist/types/helpers/useFocusTrap.d.ts +9 -0
- package/dist/types/helpers/useHoverOpen.d.ts +98 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types-cjs/components/HoverCard.d.ts +136 -0
- package/dist/types-cjs/form/DateInput.d.ts +1 -1
- package/dist/types-cjs/form/DateTimeInput.d.ts +1 -1
- package/dist/types-cjs/form/Field.d.ts +2 -2
- package/dist/types-cjs/form/File.d.ts +1 -1
- package/dist/types-cjs/form/FormContext.d.ts +47 -8
- package/dist/types-cjs/form/Input.d.ts +1 -1
- package/dist/types-cjs/form/Numberinput.d.ts +1 -1
- package/dist/types-cjs/form/Select.d.ts +1 -1
- package/dist/types-cjs/form/Slider.d.ts +1 -1
- package/dist/types-cjs/form/Taginput.d.ts +1 -1
- package/dist/types-cjs/form/TextArea.d.ts +1 -1
- package/dist/types-cjs/form/TimeInput.d.ts +1 -1
- package/dist/types-cjs/form/useAutoLabelId.d.ts +4 -2
- package/dist/types-cjs/helpers/Theme.d.ts +15 -1
- package/dist/types-cjs/helpers/devWarnings.d.ts +8 -0
- package/dist/types-cjs/helpers/useFocusTrap.d.ts +9 -0
- package/dist/types-cjs/helpers/useHoverOpen.d.ts +98 -0
- package/dist/types-cjs/index.d.ts +1 -0
- package/dist/versions/bestax-no-dark-mode.css +1 -1
- package/dist/versions/bestax-no-dark-mode.css.map +1 -1
- package/dist/versions/bestax-no-helpers-prefixed.css +1 -1
- package/dist/versions/bestax-no-helpers-prefixed.css.map +1 -1
- package/dist/versions/bestax-no-helpers.css +1 -1
- package/dist/versions/bestax-no-helpers.css.map +1 -1
- package/dist/versions/bestax-prefixed.css +1 -1
- package/dist/versions/bestax-prefixed.css.map +1 -1
- package/package.json +18 -18
- package/src/scss/components/_hovercard.scss +118 -0
- package/src/scss/components/_index.scss +1 -0
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
/* @allxsmith/bestax-bulma — AI agents: see AGENTS.md in the package root, or https://bestax.io/llms.txt */
|
|
2
|
+
import { useRef, useCallback, useMemo } from 'react';
|
|
3
|
+
import { useClientLayoutEffect } from './useClientLayoutEffect.js';
|
|
4
|
+
import { isEventInside, getDeepestActiveElement } from './shadowDom.js';
|
|
5
|
+
|
|
6
|
+
// INTERNAL: deliberately not exported from src/index.ts.
|
|
7
|
+
/**
|
|
8
|
+
* Whether focus that just arrived on `el` is keyboard focus, as the browser
|
|
9
|
+
* decides it for `:focus-visible`: focus from a key or from the browser's
|
|
10
|
+
* own controls is, focus a press brings isn't, and focus a script moves
|
|
11
|
+
* follows whichever came last. A browser that can't match the selector
|
|
12
|
+
* throws, and then every focus counts, so keyboard users can still open it.
|
|
13
|
+
*/
|
|
14
|
+
function isKeyboardFocus(el) {
|
|
15
|
+
try {
|
|
16
|
+
return el.matches(':focus-visible');
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/** Whether `node` is `container` or inside it, when there are both. */
|
|
23
|
+
const within = (container, node) => Boolean(container && node && container.contains(node));
|
|
24
|
+
/**
|
|
25
|
+
* Per document, the hooks that want Escape and the one listener they share
|
|
26
|
+
* while there are any, so a card inside another card doesn't add a second
|
|
27
|
+
* listener that closes both on one keypress.
|
|
28
|
+
*/
|
|
29
|
+
const escapeListeners = new Map();
|
|
30
|
+
/** Counts openings across the page, so the most recent one is known. */
|
|
31
|
+
let openings = 0;
|
|
32
|
+
/**
|
|
33
|
+
* Adds `entry` to the hooks that want Escape on `doc`, starting the shared
|
|
34
|
+
* listener when it is the first.
|
|
35
|
+
*
|
|
36
|
+
* Escape takes back every open that is on its way, so nothing appears right
|
|
37
|
+
* after it, and closes one open floating element, chosen by these rules in
|
|
38
|
+
* turn:
|
|
39
|
+
*
|
|
40
|
+
* 1. One that focus is in, on its trigger or inside it, when there is one.
|
|
41
|
+
* 2. The innermost: one whose floating element holds no other's trigger.
|
|
42
|
+
* That follows nesting whether either one is portaled, since an inner
|
|
43
|
+
* trigger sits in the outer floating element either way.
|
|
44
|
+
* 3. The one that opened last.
|
|
45
|
+
*
|
|
46
|
+
* The keypress belongs to whatever has focus. When that is one of the open
|
|
47
|
+
* floating elements or their triggers, or nothing, the listener stops it in
|
|
48
|
+
* the capture phase, before anything around (a Popover, a Modal) sees it.
|
|
49
|
+
* When focus is anywhere else, such as a combobox or a dialog of its own,
|
|
50
|
+
* the floating element still closes, since hover put it there without
|
|
51
|
+
* focus, and the key goes on to that owner.
|
|
52
|
+
*
|
|
53
|
+
* @returns What to call when the hook stops wanting Escape.
|
|
54
|
+
*/
|
|
55
|
+
function wantEscape(doc, entry) {
|
|
56
|
+
let listener = escapeListeners.get(doc);
|
|
57
|
+
if (!listener) {
|
|
58
|
+
const entries = new Set();
|
|
59
|
+
const handleKeyDown = (event) => {
|
|
60
|
+
if (event.key !== 'Escape')
|
|
61
|
+
return;
|
|
62
|
+
const open = [];
|
|
63
|
+
// A copy, since taking an open back can take its hook out of the set.
|
|
64
|
+
for (const each of [...entries]) {
|
|
65
|
+
if (each.openedAt)
|
|
66
|
+
open.push(each);
|
|
67
|
+
else
|
|
68
|
+
each.cancel();
|
|
69
|
+
}
|
|
70
|
+
const focused = getDeepestActiveElement(doc);
|
|
71
|
+
const holding = open.filter(each => within(each.trigger(), focused) || within(each.floating(), focused));
|
|
72
|
+
const pool = holding.length > 0 ? holding : open;
|
|
73
|
+
let top;
|
|
74
|
+
for (const each of pool) {
|
|
75
|
+
const holdsAnother = pool.some(other => other !== each && within(each.floating(), other.trigger()));
|
|
76
|
+
if (!holdsAnother && (!top || each.openedAt > top.openedAt)) {
|
|
77
|
+
top = each;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (!top)
|
|
81
|
+
return;
|
|
82
|
+
if (holding.length > 0 || !focused || focused === doc.body) {
|
|
83
|
+
event.preventDefault();
|
|
84
|
+
event.stopPropagation();
|
|
85
|
+
}
|
|
86
|
+
top.close();
|
|
87
|
+
};
|
|
88
|
+
doc.addEventListener('keydown', handleKeyDown, true);
|
|
89
|
+
listener = {
|
|
90
|
+
entries,
|
|
91
|
+
stop: () => {
|
|
92
|
+
doc.removeEventListener('keydown', handleKeyDown, true);
|
|
93
|
+
escapeListeners.delete(doc);
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
escapeListeners.set(doc, listener);
|
|
97
|
+
}
|
|
98
|
+
const shared = listener;
|
|
99
|
+
shared.entries.add(entry);
|
|
100
|
+
return () => {
|
|
101
|
+
shared.entries.delete(entry);
|
|
102
|
+
if (shared.entries.size === 0)
|
|
103
|
+
shared.stop();
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Decides when a floating element that opens on hover or keyboard focus asks
|
|
108
|
+
* to open and to close. It renders nothing, and leaves roles, ARIA and
|
|
109
|
+
* placement to the component that calls it.
|
|
110
|
+
*
|
|
111
|
+
* - The pointer entering, or keyboard focus arriving on the trigger, asks to
|
|
112
|
+
* open after `openDelay`. A touch pointer doesn't count. Neither does focus
|
|
113
|
+
* that a press brings to the trigger: it counts when the browser shows it
|
|
114
|
+
* as `:focus-visible`.
|
|
115
|
+
* - Focus in the floating element holds it open however it got there,
|
|
116
|
+
* including focus in content it portals elsewhere, such as a nested card.
|
|
117
|
+
* Whether a click focuses what it lands on is up to the browser: Safari
|
|
118
|
+
* and Firefox on macOS don't focus a button on click, so there a clicked
|
|
119
|
+
* button doesn't hold it once the pointer leaves.
|
|
120
|
+
* - Once the pointer and focus have both left, it asks to close after
|
|
121
|
+
* `closeDelay`, and either coming back before then keeps it open. Nothing
|
|
122
|
+
* else closes it on a timer.
|
|
123
|
+
* - Escape closes it at once, wherever focus is, and stops there when focus
|
|
124
|
+
* is in it, on its trigger or nowhere, so a `Popover` or `Modal` around it
|
|
125
|
+
* keeps its own. With focus somewhere else, the key goes on after closing
|
|
126
|
+
* it. Inside another one, the inner one closes first. Escape before it
|
|
127
|
+
* opens takes the opening back and goes on its way. One key listener per
|
|
128
|
+
* document serves every hook on it, there only while one of them is open
|
|
129
|
+
* or on its way to open.
|
|
130
|
+
* - With `openOnTap`, a tap on the trigger opens it at once and the next tap
|
|
131
|
+
* on the trigger closes it. While a tap holds it open, a press outside the
|
|
132
|
+
* trigger and the floating element closes it, from a listener on the
|
|
133
|
+
* document that is there only then. Taps never count as hover, and mouse
|
|
134
|
+
* and pen work the same with it or without.
|
|
135
|
+
* - Once it closes, for any reason, whatever was holding it open has to
|
|
136
|
+
* leave and come back to open it again.
|
|
137
|
+
* - When the floating element closes with focus inside it, focus goes back
|
|
138
|
+
* to the trigger, unless the same update put it somewhere else. Handing it
|
|
139
|
+
* back doesn't count as focus arriving.
|
|
140
|
+
*
|
|
141
|
+
* Nothing it scheduled runs after the component unmounts.
|
|
142
|
+
*
|
|
143
|
+
* @function useHoverOpen
|
|
144
|
+
* @param options - The open state, how to ask for another, the delays, and the two elements.
|
|
145
|
+
* @returns Handlers for the element that holds the trigger.
|
|
146
|
+
*/
|
|
147
|
+
function useHoverOpen(options) {
|
|
148
|
+
const latestRef = useRef(options);
|
|
149
|
+
const stateRef = useRef({
|
|
150
|
+
pointerIn: false,
|
|
151
|
+
focusIn: false,
|
|
152
|
+
focusInFloating: false,
|
|
153
|
+
held: false,
|
|
154
|
+
opening: false,
|
|
155
|
+
asked: false,
|
|
156
|
+
restoring: false,
|
|
157
|
+
});
|
|
158
|
+
// In the hooks that want Escape from the moment an open is on its way until
|
|
159
|
+
// the floating element closes, and out otherwise. Stamped with the order it
|
|
160
|
+
// opened in.
|
|
161
|
+
const listenForEscape = useCallback(function listen() {
|
|
162
|
+
const s = stateRef.current;
|
|
163
|
+
const entry = entryRef.current;
|
|
164
|
+
const { open, triggerRef } = latestRef.current;
|
|
165
|
+
if (!open)
|
|
166
|
+
entry.openedAt = 0;
|
|
167
|
+
else if (!entry.openedAt) {
|
|
168
|
+
openings += 1;
|
|
169
|
+
entry.openedAt = openings;
|
|
170
|
+
}
|
|
171
|
+
const wanted = open || s.opening || s.asked;
|
|
172
|
+
if (wanted === Boolean(s.releaseEscape))
|
|
173
|
+
return;
|
|
174
|
+
if (s.releaseEscape) {
|
|
175
|
+
s.releaseEscape();
|
|
176
|
+
s.releaseEscape = undefined;
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const doc = triggerRef.current?.ownerDocument ?? document;
|
|
180
|
+
s.releaseEscape = wantEscape(doc, entry);
|
|
181
|
+
}, []);
|
|
182
|
+
const entryRef = useRef({
|
|
183
|
+
openedAt: 0,
|
|
184
|
+
trigger: () => latestRef.current.triggerRef.current,
|
|
185
|
+
floating: () => latestRef.current.floatingRef.current,
|
|
186
|
+
// Only ever called while an open is on its way, so it is one or the
|
|
187
|
+
// other: still waiting on its delay, or asked for already.
|
|
188
|
+
cancel: () => {
|
|
189
|
+
const s = stateRef.current;
|
|
190
|
+
clearTimeout(s.timer);
|
|
191
|
+
// An ask already made is taken back by asking the other way.
|
|
192
|
+
if (s.asked)
|
|
193
|
+
latestRef.current.onOpenChange(false);
|
|
194
|
+
s.opening = false;
|
|
195
|
+
s.asked = false;
|
|
196
|
+
listenForEscape();
|
|
197
|
+
},
|
|
198
|
+
close: () => {
|
|
199
|
+
clearTimeout(stateRef.current.timer);
|
|
200
|
+
latestRef.current.onOpenChange(false);
|
|
201
|
+
},
|
|
202
|
+
});
|
|
203
|
+
// Asks to open or to close. Escape can take an ask to open back until it is
|
|
204
|
+
// answered: by the commit that follows it, or, when the caller keeps it
|
|
205
|
+
// closed without rendering at all, once the event that asked is over, by
|
|
206
|
+
// which time React has rendered any answer the caller set.
|
|
207
|
+
const ask = useCallback((next) => {
|
|
208
|
+
const s = stateRef.current;
|
|
209
|
+
s.asked = next;
|
|
210
|
+
latestRef.current.onOpenChange(next);
|
|
211
|
+
listenForEscape();
|
|
212
|
+
if (!next)
|
|
213
|
+
return;
|
|
214
|
+
clearTimeout(s.askTimer);
|
|
215
|
+
s.askTimer = setTimeout(() => {
|
|
216
|
+
// Still closed: the caller turned it down.
|
|
217
|
+
if (latestRef.current.open)
|
|
218
|
+
return;
|
|
219
|
+
s.asked = false;
|
|
220
|
+
s.tappedIn = undefined;
|
|
221
|
+
listenForEscape();
|
|
222
|
+
});
|
|
223
|
+
}, [listenForEscape]);
|
|
224
|
+
// Asks for what the pointer and focus call for, after its delay, when that
|
|
225
|
+
// changed since the last time and isn't the state already.
|
|
226
|
+
const settle = useCallback(() => {
|
|
227
|
+
const s = stateRef.current;
|
|
228
|
+
const held = s.pointerIn || s.focusIn;
|
|
229
|
+
if (held !== s.held) {
|
|
230
|
+
s.held = held;
|
|
231
|
+
clearTimeout(s.timer);
|
|
232
|
+
const { open, openDelay, closeDelay } = latestRef.current;
|
|
233
|
+
s.opening = held && !open;
|
|
234
|
+
if (held !== open) {
|
|
235
|
+
s.timer = setTimeout(() => {
|
|
236
|
+
s.opening = false;
|
|
237
|
+
if (latestRef.current.open !== held)
|
|
238
|
+
ask(held);
|
|
239
|
+
else
|
|
240
|
+
listenForEscape();
|
|
241
|
+
}, held ? openDelay : closeDelay);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
listenForEscape();
|
|
245
|
+
}, [listenForEscape, ask]);
|
|
246
|
+
// While a tap holds the floating element open, a press outside the trigger
|
|
247
|
+
// and the floating element closes it. Set up again each time it opens or
|
|
248
|
+
// closes.
|
|
249
|
+
const listenForPress = useCallback(() => {
|
|
250
|
+
const s = stateRef.current;
|
|
251
|
+
s.stopPress?.();
|
|
252
|
+
s.stopPress = undefined;
|
|
253
|
+
const doc = latestRef.current.open ? s.tappedIn : undefined;
|
|
254
|
+
if (!doc)
|
|
255
|
+
return;
|
|
256
|
+
const handlePointerDown = (event) => {
|
|
257
|
+
// Inside is a press React brought to the holder, which covers content
|
|
258
|
+
// the floating element portals elsewhere, or one whose path runs
|
|
259
|
+
// through the trigger or the floating element, which covers a press
|
|
260
|
+
// that something inside stopped before React got it to the holder.
|
|
261
|
+
const { triggerRef, floatingRef } = latestRef.current;
|
|
262
|
+
if (event === s.pressedInside ||
|
|
263
|
+
isEventInside(event, triggerRef.current) ||
|
|
264
|
+
isEventInside(event, floatingRef.current)) {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
latestRef.current.onOpenChange(false);
|
|
268
|
+
};
|
|
269
|
+
doc.addEventListener('pointerdown', handlePointerDown);
|
|
270
|
+
s.stopPress = () => doc.removeEventListener('pointerdown', handlePointerDown);
|
|
271
|
+
}, []);
|
|
272
|
+
useClientLayoutEffect(() => {
|
|
273
|
+
latestRef.current = options;
|
|
274
|
+
// The commit after an ask to open answers it, open or still closed. A
|
|
275
|
+
// tap that asked and still finds it closed was turned down.
|
|
276
|
+
const s = stateRef.current;
|
|
277
|
+
if (s.asked) {
|
|
278
|
+
s.asked = false;
|
|
279
|
+
if (!options.open)
|
|
280
|
+
s.tappedIn = undefined;
|
|
281
|
+
listenForEscape();
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
useClientLayoutEffect(() => {
|
|
285
|
+
const s = stateRef.current;
|
|
286
|
+
return () => {
|
|
287
|
+
clearTimeout(s.timer);
|
|
288
|
+
clearTimeout(s.askTimer);
|
|
289
|
+
s.opening = false;
|
|
290
|
+
s.asked = false;
|
|
291
|
+
s.releaseEscape?.();
|
|
292
|
+
s.releaseEscape = undefined;
|
|
293
|
+
s.stopPress?.();
|
|
294
|
+
s.stopPress = undefined;
|
|
295
|
+
};
|
|
296
|
+
}, []);
|
|
297
|
+
const { open } = options;
|
|
298
|
+
// Before paint, so a pointer or a key arriving next finds this settled.
|
|
299
|
+
useClientLayoutEffect(() => {
|
|
300
|
+
const s = stateRef.current;
|
|
301
|
+
if (!open) {
|
|
302
|
+
// The floating element left from under the pointer, if it was there,
|
|
303
|
+
// and no leave event says so. Focus resting on the trigger has done
|
|
304
|
+
// its job too, so neither opens it again until it comes back.
|
|
305
|
+
s.pointerIn = false;
|
|
306
|
+
s.focusIn = false;
|
|
307
|
+
s.tappedIn = undefined;
|
|
308
|
+
if (s.focusInFloating) {
|
|
309
|
+
s.focusInFloating = false;
|
|
310
|
+
const trigger = latestRef.current.triggerRef.current;
|
|
311
|
+
// Focus that went down with the floating element sits on <body>.
|
|
312
|
+
// Focus somewhere else was put there by the same update, so it stays.
|
|
313
|
+
if (trigger &&
|
|
314
|
+
trigger.ownerDocument.activeElement === trigger.ownerDocument.body) {
|
|
315
|
+
s.restoring = true;
|
|
316
|
+
trigger.focus();
|
|
317
|
+
s.restoring = false;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
settle();
|
|
322
|
+
listenForPress();
|
|
323
|
+
}, [open, settle, listenForPress]);
|
|
324
|
+
return useMemo(() => {
|
|
325
|
+
const inTrigger = (node) => within(latestRef.current.triggerRef.current, node);
|
|
326
|
+
return {
|
|
327
|
+
onPointerEnter: event => {
|
|
328
|
+
if (event.pointerType === 'touch')
|
|
329
|
+
return;
|
|
330
|
+
stateRef.current.pointerIn = true;
|
|
331
|
+
settle();
|
|
332
|
+
},
|
|
333
|
+
onPointerLeave: event => {
|
|
334
|
+
// A touch pointer never set pointerIn, so its leave has nothing to
|
|
335
|
+
// clear, and on a device with a mouse too it would close a card the
|
|
336
|
+
// mouse is still holding open.
|
|
337
|
+
if (event.pointerType === 'touch')
|
|
338
|
+
return;
|
|
339
|
+
stateRef.current.pointerIn = false;
|
|
340
|
+
settle();
|
|
341
|
+
},
|
|
342
|
+
onFocus: event => {
|
|
343
|
+
const s = stateRef.current;
|
|
344
|
+
// React brings focus here from the trigger and from the floating
|
|
345
|
+
// element's whole tree, portals included, so focus not in the
|
|
346
|
+
// trigger is in the floating element, wherever its DOM is.
|
|
347
|
+
s.focusInFloating = !inTrigger(event.target);
|
|
348
|
+
if (s.restoring)
|
|
349
|
+
return;
|
|
350
|
+
// Any focus in the floating element holds it. On the trigger, only
|
|
351
|
+
// keyboard focus does, so a click there opens nothing.
|
|
352
|
+
s.focusIn = s.focusInFloating || isKeyboardFocus(event.target);
|
|
353
|
+
settle();
|
|
354
|
+
},
|
|
355
|
+
onBlur: event => {
|
|
356
|
+
const s = stateRef.current;
|
|
357
|
+
const next = event.relatedTarget;
|
|
358
|
+
// Where focus goes next, as far as the DOM can say. Focus going into
|
|
359
|
+
// content the floating element portals elsewhere reads as leaving,
|
|
360
|
+
// and the focus event that follows straight after brings it back.
|
|
361
|
+
s.focusInFloating = within(latestRef.current.floatingRef.current, next);
|
|
362
|
+
// Moving between the trigger and the floating element isn't leaving.
|
|
363
|
+
if (s.focusInFloating || within(event.currentTarget, next))
|
|
364
|
+
return;
|
|
365
|
+
s.focusIn = false;
|
|
366
|
+
settle();
|
|
367
|
+
},
|
|
368
|
+
onPointerDown: event => {
|
|
369
|
+
stateRef.current.pressedInside = event.nativeEvent;
|
|
370
|
+
},
|
|
371
|
+
onPointerUp: event => {
|
|
372
|
+
const now = latestRef.current;
|
|
373
|
+
// With openOnTap, a tap on the trigger opens it at once, and the
|
|
374
|
+
// next one closes it. A tap anywhere else does nothing here.
|
|
375
|
+
if (!now.openOnTap ||
|
|
376
|
+
event.pointerType !== 'touch' ||
|
|
377
|
+
!inTrigger(event.target)) {
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
stateRef.current.tappedIn = now.open
|
|
381
|
+
? undefined
|
|
382
|
+
: event.target.ownerDocument;
|
|
383
|
+
ask(!now.open);
|
|
384
|
+
},
|
|
385
|
+
};
|
|
386
|
+
}, [settle, ask]);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
export { useHoverOpen };
|
|
390
|
+
//# sourceMappingURL=useHoverOpen.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useHoverOpen.js","sources":["../../../src/helpers/useHoverOpen.ts"],"sourcesContent":["// INTERNAL: deliberately not exported from src/index.ts.\nimport { useCallback, useMemo, useRef } from 'react';\nimport type { FocusEvent, PointerEvent, RefObject } from 'react';\nimport { useClientLayoutEffect } from './useClientLayoutEffect';\nimport { getDeepestActiveElement, isEventInside } from './shadowDom';\n\n/**\n * Options for `useHoverOpen`.\n */\nexport interface UseHoverOpenOptions {\n /** Whether the floating element is open now, controlled or not. */\n open: boolean;\n /**\n * Asks for the floating element to open or close: when a delay runs out,\n * and at once on Escape. It isn't asked for the state it is already in,\n * except that an Escape between asking to open and the open showing takes\n * the ask back by asking to close.\n */\n onOpenChange: (open: boolean) => void;\n /** How long hover or keyboard focus waits before asking to open, in milliseconds. */\n openDelay: number;\n /**\n * How long it waits once the pointer and focus have both left before\n * asking to close, in milliseconds. Coming back in that time keeps it open,\n * which is how the pointer crosses a gap to the floating element.\n */\n closeDelay: number;\n /**\n * The element that opens it, which has to take focus itself. The Escape\n * listener goes on its document, an iframe's when it renders into one, and\n * focus left in the floating element comes back here when the floating\n * element closes.\n */\n triggerRef: RefObject<HTMLElement | null>;\n /** The floating element, while it is open. */\n floatingRef: RefObject<HTMLElement | null>;\n /**\n * Whether a tap on the trigger opens it at once, with the next tap closing\n * it. Without it, a touch pointer never opens it. While a tap holds it\n * open, no hover timer closes it, and a press outside the trigger and the\n * floating element does, as Escape does. The trigger's own tap action\n * still runs.\n * @defaultValue false\n */\n openOnTap?: boolean;\n}\n\n/**\n * Pointer and focus handlers for the element that holds the trigger. The\n * floating element has to be inside it in React's tree, in place or through\n * a portal, since React's events reach it from there either way, and it\n * should hold nothing else: focus inside it that isn't on the trigger counts\n * as focus in the floating element.\n */\nexport interface HoverOpenHandlers {\n onPointerEnter: (event: PointerEvent<HTMLElement>) => void;\n onPointerLeave: (event: PointerEvent<HTMLElement>) => void;\n onFocus: (event: FocusEvent<HTMLElement>) => void;\n onBlur: (event: FocusEvent<HTMLElement>) => void;\n onPointerDown: (event: PointerEvent<HTMLElement>) => void;\n onPointerUp: (event: PointerEvent<HTMLElement>) => void;\n}\n\n/**\n * Whether focus that just arrived on `el` is keyboard focus, as the browser\n * decides it for `:focus-visible`: focus from a key or from the browser's\n * own controls is, focus a press brings isn't, and focus a script moves\n * follows whichever came last. A browser that can't match the selector\n * throws, and then every focus counts, so keyboard users can still open it.\n */\nfunction isKeyboardFocus(el: Element): boolean {\n try {\n return el.matches(':focus-visible');\n } catch {\n return true;\n }\n}\n\n/** Whether `node` is `container` or inside it, when there are both. */\nconst within = (container: Node | null, node: Node | null): boolean =>\n Boolean(container && node && container.contains(node));\n\n/** A hook that wants Escape: its floating element is open, or an open is on its way. */\ninterface EscapeEntry {\n /** When its floating element opened, counted across the page, or 0 while it is closed. */\n openedAt: number;\n trigger: () => HTMLElement | null;\n floating: () => HTMLElement | null;\n /** Takes back an open that is on its way: waiting on its delay, or asked for and not showing yet. */\n cancel: () => void;\n /** Asks to close. */\n close: () => void;\n}\n\n/**\n * Per document, the hooks that want Escape and the one listener they share\n * while there are any, so a card inside another card doesn't add a second\n * listener that closes both on one keypress.\n */\nconst escapeListeners = new Map<\n Document,\n { entries: Set<EscapeEntry>; stop: () => void }\n>();\n\n/** Counts openings across the page, so the most recent one is known. */\nlet openings = 0;\n\n/**\n * Adds `entry` to the hooks that want Escape on `doc`, starting the shared\n * listener when it is the first.\n *\n * Escape takes back every open that is on its way, so nothing appears right\n * after it, and closes one open floating element, chosen by these rules in\n * turn:\n *\n * 1. One that focus is in, on its trigger or inside it, when there is one.\n * 2. The innermost: one whose floating element holds no other's trigger.\n * That follows nesting whether either one is portaled, since an inner\n * trigger sits in the outer floating element either way.\n * 3. The one that opened last.\n *\n * The keypress belongs to whatever has focus. When that is one of the open\n * floating elements or their triggers, or nothing, the listener stops it in\n * the capture phase, before anything around (a Popover, a Modal) sees it.\n * When focus is anywhere else, such as a combobox or a dialog of its own,\n * the floating element still closes, since hover put it there without\n * focus, and the key goes on to that owner.\n *\n * @returns What to call when the hook stops wanting Escape.\n */\nfunction wantEscape(doc: Document, entry: EscapeEntry): () => void {\n let listener = escapeListeners.get(doc);\n if (!listener) {\n const entries = new Set<EscapeEntry>();\n const handleKeyDown = (event: KeyboardEvent) => {\n if (event.key !== 'Escape') return;\n const open: EscapeEntry[] = [];\n // A copy, since taking an open back can take its hook out of the set.\n for (const each of [...entries]) {\n if (each.openedAt) open.push(each);\n else each.cancel();\n }\n const focused = getDeepestActiveElement(doc);\n const holding = open.filter(\n each =>\n within(each.trigger(), focused) || within(each.floating(), focused)\n );\n const pool = holding.length > 0 ? holding : open;\n let top: EscapeEntry | undefined;\n for (const each of pool) {\n const holdsAnother = pool.some(\n other => other !== each && within(each.floating(), other.trigger())\n );\n if (!holdsAnother && (!top || each.openedAt > top.openedAt)) {\n top = each;\n }\n }\n if (!top) return;\n if (holding.length > 0 || !focused || focused === doc.body) {\n event.preventDefault();\n event.stopPropagation();\n }\n top.close();\n };\n doc.addEventListener('keydown', handleKeyDown, true);\n listener = {\n entries,\n stop: () => {\n doc.removeEventListener('keydown', handleKeyDown, true);\n escapeListeners.delete(doc);\n },\n };\n escapeListeners.set(doc, listener);\n }\n const shared = listener;\n shared.entries.add(entry);\n return () => {\n shared.entries.delete(entry);\n if (shared.entries.size === 0) shared.stop();\n };\n}\n\ninterface HoverOpenState {\n /** The pointer, other than a touch, is over the trigger or the floating element. */\n pointerIn: boolean;\n /** Focus holds it open: any focus in the floating element, or keyboard focus on the trigger. */\n focusIn: boolean;\n /** Focus, however it got there, is in the floating element. */\n focusInFloating: boolean;\n /** Whether the pointer or focus was holding it open when last settled. */\n held: boolean;\n /** An open is waiting on its delay. */\n opening: boolean;\n /**\n * An open was asked for and isn't showing yet: no commit has answered it,\n * and the event that asked isn't over.\n */\n asked: boolean;\n /** Focus is on its way back to the trigger, which isn't focus arriving. */\n restoring: boolean;\n timer?: ReturnType<typeof setTimeout>;\n /** Ends an ask to open that no commit answered, once the event that made it is over. */\n askTimer?: ReturnType<typeof setTimeout>;\n /** Takes this hook out of the ones that want Escape, while it is in. */\n releaseEscape?: () => void;\n /**\n * The document of the tap that opened it, or asked to: a press outside in\n * that document closes it while it is open.\n */\n tappedIn?: Document;\n /** The last press React brought to the holder: on the trigger or in the floating element's tree. */\n pressedInside?: Event;\n /** Takes the listener for a press outside off its document, while it is on. */\n stopPress?: () => void;\n}\n\n/**\n * Decides when a floating element that opens on hover or keyboard focus asks\n * to open and to close. It renders nothing, and leaves roles, ARIA and\n * placement to the component that calls it.\n *\n * - The pointer entering, or keyboard focus arriving on the trigger, asks to\n * open after `openDelay`. A touch pointer doesn't count. Neither does focus\n * that a press brings to the trigger: it counts when the browser shows it\n * as `:focus-visible`.\n * - Focus in the floating element holds it open however it got there,\n * including focus in content it portals elsewhere, such as a nested card.\n * Whether a click focuses what it lands on is up to the browser: Safari\n * and Firefox on macOS don't focus a button on click, so there a clicked\n * button doesn't hold it once the pointer leaves.\n * - Once the pointer and focus have both left, it asks to close after\n * `closeDelay`, and either coming back before then keeps it open. Nothing\n * else closes it on a timer.\n * - Escape closes it at once, wherever focus is, and stops there when focus\n * is in it, on its trigger or nowhere, so a `Popover` or `Modal` around it\n * keeps its own. With focus somewhere else, the key goes on after closing\n * it. Inside another one, the inner one closes first. Escape before it\n * opens takes the opening back and goes on its way. One key listener per\n * document serves every hook on it, there only while one of them is open\n * or on its way to open.\n * - With `openOnTap`, a tap on the trigger opens it at once and the next tap\n * on the trigger closes it. While a tap holds it open, a press outside the\n * trigger and the floating element closes it, from a listener on the\n * document that is there only then. Taps never count as hover, and mouse\n * and pen work the same with it or without.\n * - Once it closes, for any reason, whatever was holding it open has to\n * leave and come back to open it again.\n * - When the floating element closes with focus inside it, focus goes back\n * to the trigger, unless the same update put it somewhere else. Handing it\n * back doesn't count as focus arriving.\n *\n * Nothing it scheduled runs after the component unmounts.\n *\n * @function useHoverOpen\n * @param options - The open state, how to ask for another, the delays, and the two elements.\n * @returns Handlers for the element that holds the trigger.\n */\nexport function useHoverOpen(options: UseHoverOpenOptions): HoverOpenHandlers {\n const latestRef = useRef(options);\n const stateRef = useRef<HoverOpenState>({\n pointerIn: false,\n focusIn: false,\n focusInFloating: false,\n held: false,\n opening: false,\n asked: false,\n restoring: false,\n });\n\n // In the hooks that want Escape from the moment an open is on its way until\n // the floating element closes, and out otherwise. Stamped with the order it\n // opened in.\n const listenForEscape = useCallback(function listen() {\n const s = stateRef.current;\n const entry = entryRef.current;\n const { open, triggerRef } = latestRef.current;\n if (!open) entry.openedAt = 0;\n else if (!entry.openedAt) {\n openings += 1;\n entry.openedAt = openings;\n }\n const wanted = open || s.opening || s.asked;\n if (wanted === Boolean(s.releaseEscape)) return;\n if (s.releaseEscape) {\n s.releaseEscape();\n s.releaseEscape = undefined;\n return;\n }\n const doc = triggerRef.current?.ownerDocument ?? document;\n s.releaseEscape = wantEscape(doc, entry);\n }, []);\n\n const entryRef = useRef<EscapeEntry>({\n openedAt: 0,\n trigger: () => latestRef.current.triggerRef.current,\n floating: () => latestRef.current.floatingRef.current,\n // Only ever called while an open is on its way, so it is one or the\n // other: still waiting on its delay, or asked for already.\n cancel: () => {\n const s = stateRef.current;\n clearTimeout(s.timer);\n // An ask already made is taken back by asking the other way.\n if (s.asked) latestRef.current.onOpenChange(false);\n s.opening = false;\n s.asked = false;\n listenForEscape();\n },\n close: () => {\n clearTimeout(stateRef.current.timer);\n latestRef.current.onOpenChange(false);\n },\n });\n\n // Asks to open or to close. Escape can take an ask to open back until it is\n // answered: by the commit that follows it, or, when the caller keeps it\n // closed without rendering at all, once the event that asked is over, by\n // which time React has rendered any answer the caller set.\n const ask = useCallback(\n (next: boolean) => {\n const s = stateRef.current;\n s.asked = next;\n latestRef.current.onOpenChange(next);\n listenForEscape();\n if (!next) return;\n clearTimeout(s.askTimer);\n s.askTimer = setTimeout(() => {\n // Still closed: the caller turned it down.\n if (latestRef.current.open) return;\n s.asked = false;\n s.tappedIn = undefined;\n listenForEscape();\n });\n },\n [listenForEscape]\n );\n\n // Asks for what the pointer and focus call for, after its delay, when that\n // changed since the last time and isn't the state already.\n const settle = useCallback(() => {\n const s = stateRef.current;\n const held = s.pointerIn || s.focusIn;\n if (held !== s.held) {\n s.held = held;\n clearTimeout(s.timer);\n const { open, openDelay, closeDelay } = latestRef.current;\n s.opening = held && !open;\n if (held !== open) {\n s.timer = setTimeout(\n () => {\n s.opening = false;\n if (latestRef.current.open !== held) ask(held);\n else listenForEscape();\n },\n held ? openDelay : closeDelay\n );\n }\n }\n listenForEscape();\n }, [listenForEscape, ask]);\n\n // While a tap holds the floating element open, a press outside the trigger\n // and the floating element closes it. Set up again each time it opens or\n // closes.\n const listenForPress = useCallback(() => {\n const s = stateRef.current;\n s.stopPress?.();\n s.stopPress = undefined;\n const doc = latestRef.current.open ? s.tappedIn : undefined;\n if (!doc) return;\n const handlePointerDown = (event: Event) => {\n // Inside is a press React brought to the holder, which covers content\n // the floating element portals elsewhere, or one whose path runs\n // through the trigger or the floating element, which covers a press\n // that something inside stopped before React got it to the holder.\n const { triggerRef, floatingRef } = latestRef.current;\n if (\n event === s.pressedInside ||\n isEventInside(event, triggerRef.current) ||\n isEventInside(event, floatingRef.current)\n ) {\n return;\n }\n latestRef.current.onOpenChange(false);\n };\n doc.addEventListener('pointerdown', handlePointerDown);\n s.stopPress = () =>\n doc.removeEventListener('pointerdown', handlePointerDown);\n }, []);\n\n useClientLayoutEffect(() => {\n latestRef.current = options;\n // The commit after an ask to open answers it, open or still closed. A\n // tap that asked and still finds it closed was turned down.\n const s = stateRef.current;\n if (s.asked) {\n s.asked = false;\n if (!options.open) s.tappedIn = undefined;\n listenForEscape();\n }\n });\n\n useClientLayoutEffect(() => {\n const s = stateRef.current;\n return () => {\n clearTimeout(s.timer);\n clearTimeout(s.askTimer);\n s.opening = false;\n s.asked = false;\n s.releaseEscape?.();\n s.releaseEscape = undefined;\n s.stopPress?.();\n s.stopPress = undefined;\n };\n }, []);\n\n const { open } = options;\n // Before paint, so a pointer or a key arriving next finds this settled.\n useClientLayoutEffect(() => {\n const s = stateRef.current;\n if (!open) {\n // The floating element left from under the pointer, if it was there,\n // and no leave event says so. Focus resting on the trigger has done\n // its job too, so neither opens it again until it comes back.\n s.pointerIn = false;\n s.focusIn = false;\n s.tappedIn = undefined;\n if (s.focusInFloating) {\n s.focusInFloating = false;\n const trigger = latestRef.current.triggerRef.current;\n // Focus that went down with the floating element sits on <body>.\n // Focus somewhere else was put there by the same update, so it stays.\n if (\n trigger &&\n trigger.ownerDocument.activeElement === trigger.ownerDocument.body\n ) {\n s.restoring = true;\n trigger.focus();\n s.restoring = false;\n }\n }\n }\n settle();\n listenForPress();\n }, [open, settle, listenForPress]);\n\n return useMemo<HoverOpenHandlers>(() => {\n const inTrigger = (node: EventTarget | null) =>\n within(latestRef.current.triggerRef.current, node as Node | null);\n return {\n onPointerEnter: event => {\n if (event.pointerType === 'touch') return;\n stateRef.current.pointerIn = true;\n settle();\n },\n onPointerLeave: event => {\n // A touch pointer never set pointerIn, so its leave has nothing to\n // clear, and on a device with a mouse too it would close a card the\n // mouse is still holding open.\n if (event.pointerType === 'touch') return;\n stateRef.current.pointerIn = false;\n settle();\n },\n onFocus: event => {\n const s = stateRef.current;\n // React brings focus here from the trigger and from the floating\n // element's whole tree, portals included, so focus not in the\n // trigger is in the floating element, wherever its DOM is.\n s.focusInFloating = !inTrigger(event.target);\n if (s.restoring) return;\n // Any focus in the floating element holds it. On the trigger, only\n // keyboard focus does, so a click there opens nothing.\n s.focusIn = s.focusInFloating || isKeyboardFocus(event.target);\n settle();\n },\n onBlur: event => {\n const s = stateRef.current;\n const next = event.relatedTarget as Node | null;\n // Where focus goes next, as far as the DOM can say. Focus going into\n // content the floating element portals elsewhere reads as leaving,\n // and the focus event that follows straight after brings it back.\n s.focusInFloating = within(latestRef.current.floatingRef.current, next);\n // Moving between the trigger and the floating element isn't leaving.\n if (s.focusInFloating || within(event.currentTarget, next)) return;\n s.focusIn = false;\n settle();\n },\n onPointerDown: event => {\n stateRef.current.pressedInside = event.nativeEvent;\n },\n onPointerUp: event => {\n const now = latestRef.current;\n // With openOnTap, a tap on the trigger opens it at once, and the\n // next one closes it. A tap anywhere else does nothing here.\n if (\n !now.openOnTap ||\n event.pointerType !== 'touch' ||\n !inTrigger(event.target)\n ) {\n return;\n }\n stateRef.current.tappedIn = now.open\n ? undefined\n : (event.target as Element).ownerDocument;\n ask(!now.open);\n },\n };\n }, [settle, ask]);\n}\n"],"names":[],"mappings":";;;;;AAAA;AA+DA;;;;;;AAMG;AACH,SAAS,eAAe,CAAC,EAAW,EAAA;AAClC,IAAA,IAAI;AACF,QAAA,OAAO,EAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC;IACrC;AAAE,IAAA,MAAM;AACN,QAAA,OAAO,IAAI;IACb;AACF;AAEA;AACA,MAAM,MAAM,GAAG,CAAC,SAAsB,EAAE,IAAiB,KACvD,OAAO,CAAC,SAAS,IA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,EACxB;oBACA;gBACF;AACA,gBAAA,QAAQ,CAAC,OAAO,CAAC,QAAQ,GAAG,GAAG,CAAC;AAC9B,sBAAE;AACF,sBAAG,KAAK,CAAC,MAAkB,CAAC,aAAa;AAC3C,gBAAA,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC;YAChB,CAAC;SACF;AACH,IAAA,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AACnB;;"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { useMemo } from 'react';
|
|
3
3
|
import { classNames } from './classNames.js';
|
|
4
4
|
import { useConfig } from './Config.js';
|
|
5
|
-
import {
|
|
5
|
+
import { validCursors, validPositions, createBulmaClassHelpers, validAxisOverflows, validFloats, validInteractions, cursorClasses, validRadii, validShadows, validResponsives, validAspectRatios } from './bulmaClassHelpers.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* A hook that generates miscellaneous Bulma helper classes (float, overflow,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { useMemo } from 'react';
|
|
3
3
|
import { classNames } from './classNames.js';
|
|
4
4
|
import { useConfig } from './Config.js';
|
|
5
|
-
import {
|
|
5
|
+
import { createBulmaClassHelpers, validGaps, validSizes } from './bulmaClassHelpers.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* A gap step as the class reads it. Numbers are accepted for the steps, so
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { useMemo } from 'react';
|
|
3
3
|
import { classNames } from './classNames.js';
|
|
4
4
|
import { useConfig } from './Config.js';
|
|
5
|
-
import { validTextSizes, validAlignments, validTextTransforms, validTextWeights, validFontFamilies
|
|
5
|
+
import { createBulmaClassHelpers, validTextSizes, validAlignments, validTextTransforms, validTextWeights, validFontFamilies } from './bulmaClassHelpers.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Viewports Bulma generates `is-size-*` classes for. Unlike text alignment,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { useMemo } from 'react';
|
|
3
3
|
import { classNames } from './classNames.js';
|
|
4
4
|
import { useConfig } from './Config.js';
|
|
5
|
-
import { validViewports,
|
|
5
|
+
import { validViewports, validVisibilities, validDisplays, createBulmaClassHelpers } from './bulmaClassHelpers.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* A hook that generates Bulma visibility and display helper classes. This hook
|