actual-css 0.20.0 → 0.20.2
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/CHANGELOG.md +36 -0
- package/components.json +10 -3
- package/dist/actual.full.css +110 -20
- package/dist/actual.full.js +2 -2
- package/dist/actual.full.min.css +1 -1
- package/dist/types/tooltip.d.ts +4 -0
- package/docs/pages/components/button.md +10 -0
- package/docs/pages/components/meter.md +1 -0
- package/docs/pages/components/progress.md +1 -0
- package/docs/pages/components/timeline.md +32 -0
- package/docs/pages/enhancements/tooltip.md +5 -1
- package/docs/pages/examples/overview.md +1 -0
- package/docs/pages/forms/combobox.md +4 -2
- package/docs/pages/forms/range.md +3 -1
- package/docs/pages/guides/progressive-enhancement.md +22 -0
- package/package.json +3 -1
- package/reserved-classes.json +1 -0
- package/src/css/components/avatar.css +1 -0
- package/src/css/components/button.css +2 -2
- package/src/css/components/flyout.css +3 -0
- package/src/css/components/meter.css +21 -6
- package/src/css/components/progress.css +5 -4
- package/src/css/components/rating.css +2 -0
- package/src/css/components/timeline.css +53 -2
- package/src/css/core/tokens.css +4 -0
- package/src/css/forms/choice-card.css +2 -1
- package/src/css/forms/otp.css +5 -0
- package/src/css/forms/range.css +11 -5
- package/src/css/forms/select.css +1 -0
- package/src/js/dialog.js +19 -0
- package/src/js/tooltip.js +64 -2
- package/src/tooling/design-tokens.js +1 -1
- package/tokens.json +1 -0
package/src/js/tooltip.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* Explicit: <button data-tooltip aria-describedby="tooltip-id">
|
|
6
6
|
* <div role="tooltip" id="tooltip-id" hidden>Help <strong>text</strong></div>
|
|
7
7
|
* Options: data-tooltip-click toggles on click instead of hover/focus.
|
|
8
|
+
* data-tooltip-no-tap keeps a touch tap from opening it.
|
|
8
9
|
* data-tooltip-visible keeps the tooltip visible.
|
|
9
10
|
*
|
|
10
11
|
* Discovery: [data-tooltip] only. An empty data-tooltip marks an explicit
|
|
@@ -33,6 +34,11 @@
|
|
|
33
34
|
* visible. Focus counts only when it matches :focus-visible, so
|
|
34
35
|
* a pointer press, or focus handed back by a closing dialog after
|
|
35
36
|
* a pointer close, shows nothing.
|
|
37
|
+
* Touch: a tap shows the tip at once and pins it, so no tooltip is
|
|
38
|
+
* silently out of reach of a finger; the tap still activates the
|
|
39
|
+
* trigger. A second tap, a tap elsewhere, Escape, or a dialog or
|
|
40
|
+
* popover opening hides it. A scroll or drag ends in
|
|
41
|
+
* pointercancel, not pointerup, so it is never a tap.
|
|
36
42
|
* Hide: focus leaving the trigger (focusout), pointer leave, pressing
|
|
37
43
|
* the trigger, or Escape.
|
|
38
44
|
*
|
|
@@ -76,12 +82,15 @@ const HIDE_DELAY_MS = 100;
|
|
|
76
82
|
* @property {boolean} hovered Pointer is over the active trigger.
|
|
77
83
|
* @property {boolean} focused The active trigger has keyboard focus.
|
|
78
84
|
* @property {boolean} overTip Pointer is over the tooltip.
|
|
85
|
+
* @property {boolean} tapped A touch tap pinned the tip open.
|
|
79
86
|
*/
|
|
80
87
|
|
|
81
88
|
let uid = 0;
|
|
82
89
|
const triggerStates = new WeakMap(); // trigger -> { tip, cleanup }
|
|
83
90
|
/** @type {WeakMap<Element, TooltipState>} */
|
|
84
91
|
const tipStates = new WeakMap(); // tip -> { refs, activeRef, controller, stopTracking, generated, visible, timer }
|
|
92
|
+
/** @type {Element | null} The tip a tap pinned open; a tap elsewhere dismisses it. */
|
|
93
|
+
let tappedTip = null;
|
|
85
94
|
|
|
86
95
|
/*
|
|
87
96
|
* Transport, the same shape surface.js uses and for the same reason: the
|
|
@@ -157,6 +166,12 @@ function isClickTrigger(trigger) {
|
|
|
157
166
|
return hasOption(trigger, "data-tooltip-click");
|
|
158
167
|
}
|
|
159
168
|
|
|
169
|
+
// Taps open tooltips by default: the opt-out is explicit, so a tooltip never
|
|
170
|
+
// fails silently under a finger.
|
|
171
|
+
function isNoTapTrigger(trigger) {
|
|
172
|
+
return hasOption(trigger, "data-tooltip-no-tap");
|
|
173
|
+
}
|
|
174
|
+
|
|
160
175
|
function isAlwaysVisible(trigger) {
|
|
161
176
|
return hasOption(trigger, "data-tooltip-visible");
|
|
162
177
|
}
|
|
@@ -290,7 +305,9 @@ function hideTip(tip, force = false) {
|
|
|
290
305
|
if (state) {
|
|
291
306
|
state.wanted = false;
|
|
292
307
|
state.visible = false;
|
|
308
|
+
state.tapped = false;
|
|
293
309
|
}
|
|
310
|
+
if (tappedTip === tip) tappedTip = null;
|
|
294
311
|
hideTransport(tip);
|
|
295
312
|
state?.unregisterEscape?.();
|
|
296
313
|
if (state) {
|
|
@@ -311,11 +328,11 @@ function scheduleHide(tip) {
|
|
|
311
328
|
const state = tipStates.get(tip);
|
|
312
329
|
if (!state) return;
|
|
313
330
|
if (isClickTrigger(state.activeRef) || isAlwaysVisible(state.activeRef)) return;
|
|
314
|
-
if (state.hovered || state.focused || state.overTip) return;
|
|
331
|
+
if (state.hovered || state.focused || state.overTip || state.tapped) return;
|
|
315
332
|
if (state.hideTimer) clearTimeout(state.hideTimer);
|
|
316
333
|
state.hideTimer = setTimeout(() => {
|
|
317
334
|
state.hideTimer = null;
|
|
318
|
-
if (!state.hovered && !state.focused && !state.overTip) hideTip(tip);
|
|
335
|
+
if (!state.hovered && !state.focused && !state.overTip && !state.tapped) hideTip(tip);
|
|
319
336
|
}, HIDE_DELAY_MS);
|
|
320
337
|
}
|
|
321
338
|
|
|
@@ -344,6 +361,7 @@ function wireTip(tip, options = {}) {
|
|
|
344
361
|
hovered: false,
|
|
345
362
|
focused: false,
|
|
346
363
|
overTip: false,
|
|
364
|
+
tapped: false,
|
|
347
365
|
};
|
|
348
366
|
|
|
349
367
|
tip.addEventListener(
|
|
@@ -511,6 +529,8 @@ function show(tip, ref, immediate = false) {
|
|
|
511
529
|
const SEL = "[data-tooltip]";
|
|
512
530
|
/** @type {WeakRef<Element> | null} */
|
|
513
531
|
let pressedTrigger = null;
|
|
532
|
+
// The current press hid its trigger's tip: its release must not reopen it.
|
|
533
|
+
let pressDismissed = false;
|
|
514
534
|
|
|
515
535
|
function handleTriggerIntent(e) {
|
|
516
536
|
const trigger = e.target.closest?.(SEL);
|
|
@@ -542,6 +562,7 @@ function handleTriggerIntent(e) {
|
|
|
542
562
|
function handleTriggerPress(e) {
|
|
543
563
|
const trigger = e.target.closest?.(SEL);
|
|
544
564
|
pressedTrigger = trigger ? new WeakRef(trigger) : null;
|
|
565
|
+
pressDismissed = false;
|
|
545
566
|
if (!trigger || isClickTrigger(trigger) || isAlwaysVisible(trigger)) return;
|
|
546
567
|
|
|
547
568
|
const tip = triggerStates.get(trigger)?.tip;
|
|
@@ -554,6 +575,34 @@ function handleTriggerPress(e) {
|
|
|
554
575
|
state.focused = false;
|
|
555
576
|
state.overTip = false;
|
|
556
577
|
hideTip(tip, true);
|
|
578
|
+
pressDismissed = true;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
/*
|
|
582
|
+
* Touch has no hover, and a tap focuses without :focus-visible, so a finger
|
|
583
|
+
* reaches a tooltip only through this. Touch pointers are
|
|
584
|
+
* implicitly captured, so the release targets the element the press landed on.
|
|
585
|
+
* The outside dismissal runs for any pointer, so a hybrid device can close a
|
|
586
|
+
* pinned tip with the mouse too; it never stops the event.
|
|
587
|
+
*/
|
|
588
|
+
function handleTap(e) {
|
|
589
|
+
const target = /** @type {Element} */ (e.target);
|
|
590
|
+
if (tappedTip && !tappedTip.contains(target)) {
|
|
591
|
+
const ref = tipStates.get(tappedTip)?.activeRef;
|
|
592
|
+
if (!ref?.contains(target)) hideTip(tappedTip, true);
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
if (e.pointerType !== "touch") return;
|
|
596
|
+
const trigger = target.closest?.(SEL);
|
|
597
|
+
if (!trigger || pressDismissed || pressedTrigger?.deref() !== trigger) return;
|
|
598
|
+
if (isNoTapTrigger(trigger) || isClickTrigger(trigger) || isAlwaysVisible(trigger)) return;
|
|
599
|
+
|
|
600
|
+
const tip = ensureTip(trigger);
|
|
601
|
+
if (!tip) return;
|
|
602
|
+
const state = tipStates.get(tip);
|
|
603
|
+
state.tapped = true;
|
|
604
|
+
tappedTip = tip;
|
|
605
|
+
show(tip, trigger, true);
|
|
557
606
|
}
|
|
558
607
|
|
|
559
608
|
function handleTriggerClick(e) {
|
|
@@ -574,6 +623,19 @@ if (typeof document !== "undefined") {
|
|
|
574
623
|
document.addEventListener("focusin", handleTriggerIntent);
|
|
575
624
|
// A drag handler can stop the press before it bubbles to the document.
|
|
576
625
|
document.addEventListener("pointerdown", handleTriggerPress, { capture: true });
|
|
626
|
+
document.addEventListener("pointerup", handleTap, { capture: true });
|
|
627
|
+
// A tap that opens a dialog or a popover moved on from its trigger: the
|
|
628
|
+
// pinned label would linger under the new layer. toggle does not bubble.
|
|
629
|
+
document.addEventListener(
|
|
630
|
+
"toggle",
|
|
631
|
+
(e) => {
|
|
632
|
+
const opened = /** @type {ToggleEvent} */ (e).newState === "open";
|
|
633
|
+
if (opened && tappedTip && !e.target.matches?.('[role="tooltip"]')) {
|
|
634
|
+
hideTip(tappedTip, true);
|
|
635
|
+
}
|
|
636
|
+
},
|
|
637
|
+
{ capture: true },
|
|
638
|
+
);
|
|
577
639
|
document.addEventListener(
|
|
578
640
|
"keydown",
|
|
579
641
|
() => {
|
|
@@ -77,7 +77,7 @@ export const FOUNDATIONS = {
|
|
|
77
77
|
"control-pad-x-lg",
|
|
78
78
|
"control-pad-x",
|
|
79
79
|
],
|
|
80
|
-
radius: ["radius-sm", "radius", "radius-lg", "radius-full"],
|
|
80
|
+
radius: ["radius-sm", "radius", "radius-lg", "radius-full", "bar-radius"],
|
|
81
81
|
"border-width": ["border-width", "focus-ring-width"],
|
|
82
82
|
"font-size": [
|
|
83
83
|
"font-size-xs",
|