@brightlocal/ui-components 2.19.0 → 2.21.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/AI_USAGE.md +2 -0
- package/README.md +27 -14
- package/component-meta.json +27 -11
- package/dist/alert-dialog.cjs +1 -1
- package/dist/alert-dialog.d.ts.map +1 -1
- package/dist/alert-dialog.js +34 -33
- package/dist/blocks/data-table.cjs +1 -1
- package/dist/blocks/data-table.d.ts.map +1 -1
- package/dist/blocks/data-table.js +14 -16
- package/dist/blocks/sidebar.cjs +1 -1
- package/dist/blocks/sidebar.d.ts +20 -2
- package/dist/blocks/sidebar.d.ts.map +1 -1
- package/dist/blocks/sidebar.js +99 -89
- package/dist/breadcrumb.cjs +1 -1
- package/dist/breadcrumb.d.ts +1 -1
- package/dist/breadcrumb.d.ts.map +1 -1
- package/dist/breadcrumb.js +9 -6
- package/dist/browser-entry.d.ts +2 -0
- package/dist/browser-entry.d.ts.map +1 -1
- package/dist/button.cjs +1 -1
- package/dist/button.d.ts.map +1 -1
- package/dist/button.js +12 -12
- package/dist/context-menu.cjs +1 -1
- package/dist/context-menu.d.ts.map +1 -1
- package/dist/context-menu.js +47 -46
- package/dist/dialog.cjs +1 -1
- package/dist/dialog.d.ts.map +1 -1
- package/dist/dialog.js +35 -34
- package/dist/dropdown-menu.cjs +1 -1
- package/dist/dropdown-menu.d.ts.map +1 -1
- package/dist/dropdown-menu.js +48 -47
- package/dist/hooks/use-overlay-pointer-lock.cjs +1 -0
- package/dist/hooks/use-overlay-pointer-lock.d.ts +20 -0
- package/dist/hooks/use-overlay-pointer-lock.d.ts.map +1 -0
- package/dist/hooks/use-overlay-pointer-lock.js +39 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +88 -86
- package/dist/logo.cjs +1 -1
- package/dist/logo.d.ts +1 -1
- package/dist/logo.js +2 -2
- package/dist/navigation-menu.cjs +1 -1
- package/dist/navigation-menu.d.ts +19 -0
- package/dist/navigation-menu.d.ts.map +1 -1
- package/dist/navigation-menu.js +134 -96
- package/dist/pagination.cjs +1 -1
- package/dist/pagination.d.ts +12 -8
- package/dist/pagination.d.ts.map +1 -1
- package/dist/pagination.js +117 -113
- package/dist/popover.cjs +1 -1
- package/dist/popover.d.ts.map +1 -1
- package/dist/popover.js +21 -20
- package/dist/progress.cjs +1 -1
- package/dist/progress.d.ts +28 -2
- package/dist/progress.d.ts.map +1 -1
- package/dist/progress.js +90 -49
- package/dist/select.cjs +1 -1
- package/dist/select.d.ts.map +1 -1
- package/dist/select.js +25 -23
- package/dist/separator.cjs +1 -1
- package/dist/separator.d.ts +14 -0
- package/dist/separator.d.ts.map +1 -1
- package/dist/separator.js +90 -44
- package/dist/sheet.cjs +1 -1
- package/dist/sheet.d.ts.map +1 -1
- package/dist/sheet.js +29 -28
- package/dist/skeleton.cjs +1 -1
- package/dist/skeleton.js +1 -1
- package/dist/sonner.d.ts +1 -1
- package/package.json +5 -1
- package/src/blocks/data-table.tsx +0 -2
- package/src/blocks/sidebar.tsx +40 -13
- package/src/browser-entry.ts +10 -0
- package/src/components/alert-dialog.tsx +20 -14
- package/src/components/breadcrumb.tsx +6 -3
- package/src/components/button.tsx +7 -1
- package/src/components/context-menu.tsx +19 -13
- package/src/components/dialog.tsx +4 -0
- package/src/components/dropdown-menu.tsx +4 -0
- package/src/components/logo.tsx +3 -3
- package/src/components/navigation-menu.tsx +134 -32
- package/src/components/pagination.tsx +47 -67
- package/src/components/popover.tsx +22 -16
- package/src/components/progress.tsx +118 -14
- package/src/components/select.tsx +4 -0
- package/src/components/separator.tsx +91 -23
- package/src/components/sheet.tsx +4 -0
- package/src/components/skeleton.tsx +1 -1
- package/src/components/sonner.tsx +1 -1
- package/src/hooks/use-overlay-pointer-lock.ts +128 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Elements that indicate an overlay is genuinely open and may therefore
|
|
7
|
+
* legitimately hold the `document.body` pointer-events lock.
|
|
8
|
+
*
|
|
9
|
+
* Keyed on `data-state="open"` so a closing/orphaned overlay remnant — the very
|
|
10
|
+
* thing DS-634 leaves behind ("the menu is still tearing down") — is treated as
|
|
11
|
+
* NOT open and cannot block the release. The DS `data-slot` entries give precise
|
|
12
|
+
* coverage (including Popover/Select, whose content carries no ARIA role), and
|
|
13
|
+
* the generic `role` entries are a safety net so the guard also refuses to clear
|
|
14
|
+
* a lock owned by a non-DS Radix overlay, or by a DS overlay whose `data-slot`
|
|
15
|
+
* was overridden via props (e.g. Combobox's `combobox-popover`). It never clears
|
|
16
|
+
* a lock it cannot see is open.
|
|
17
|
+
*/
|
|
18
|
+
const OPEN_OVERLAY_SELECTOR = [
|
|
19
|
+
'[data-slot="dialog-content"][data-state="open"]',
|
|
20
|
+
'[data-slot="alert-dialog-content"][data-state="open"]',
|
|
21
|
+
'[data-slot="sheet-content"][data-state="open"]',
|
|
22
|
+
'[data-slot="dropdown-menu-content"][data-state="open"]',
|
|
23
|
+
'[data-slot="dropdown-menu-sub-content"][data-state="open"]',
|
|
24
|
+
'[data-slot="context-menu-content"][data-state="open"]',
|
|
25
|
+
'[data-slot="context-menu-sub-content"][data-state="open"]',
|
|
26
|
+
'[data-slot="popover-content"][data-state="open"]',
|
|
27
|
+
'[data-slot="select-content"][data-state="open"]',
|
|
28
|
+
// Generic fallbacks: any open Radix overlay (or overridden DS one) by role.
|
|
29
|
+
'[role="dialog"][data-state="open"]',
|
|
30
|
+
'[role="alertdialog"][data-state="open"]',
|
|
31
|
+
'[role="menu"][data-state="open"]',
|
|
32
|
+
'[role="listbox"][data-state="open"]',
|
|
33
|
+
].join(",");
|
|
34
|
+
|
|
35
|
+
/** Whether the one-time global watchers (observer + listeners) are installed. */
|
|
36
|
+
let watchersInstalled = false;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Clears a residual `pointer-events: none` inline lock from `document.body`,
|
|
40
|
+
* but only when no overlay is open.
|
|
41
|
+
*
|
|
42
|
+
* Radix's `react-dismissable-layer` stores the body's "original" pointer-events
|
|
43
|
+
* in a single module-level variable shared across every layer. When one overlay
|
|
44
|
+
* opens another (e.g. a `DropdownMenu` item opens a `Dialog`) that variable can
|
|
45
|
+
* capture `none`, so a later cleanup restores the body to `none` and the whole
|
|
46
|
+
* page becomes unclickable until reload (DS-634).
|
|
47
|
+
*
|
|
48
|
+
* The release is conservative: it acts only when the body is actually stuck at
|
|
49
|
+
* `none` AND nothing that could own the lock is on screen, so it never fights a
|
|
50
|
+
* genuinely open modal (DS or otherwise). Erring toward leaving a lock in place
|
|
51
|
+
* is safe; clearing one that is still owned is not.
|
|
52
|
+
*/
|
|
53
|
+
function releaseBodyPointerLockIfIdle() {
|
|
54
|
+
if (typeof document === "undefined") return;
|
|
55
|
+
if (document.body.style.pointerEvents !== "none") return;
|
|
56
|
+
if (document.querySelector(OPEN_OVERLAY_SELECTOR) !== null) return;
|
|
57
|
+
document.body.style.pointerEvents = "";
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Defer a release so Radix's own (buggy) cleanup runs first, then we correct it.
|
|
62
|
+
* Falls back to a timeout where `requestAnimationFrame` is unavailable (SSR,
|
|
63
|
+
* some test runners) so the release still fires.
|
|
64
|
+
*/
|
|
65
|
+
function scheduleRelease() {
|
|
66
|
+
if (typeof requestAnimationFrame === "function") {
|
|
67
|
+
requestAnimationFrame(releaseBodyPointerLockIfIdle);
|
|
68
|
+
} else if (typeof setTimeout === "function") {
|
|
69
|
+
setTimeout(releaseBodyPointerLockIfIdle, 0);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function handleReturnToPage() {
|
|
74
|
+
// `window.open` / new-tab from a menu item can leave the lock stuck; re-check
|
|
75
|
+
// when the user comes back to the page (bfcache restore included).
|
|
76
|
+
if (typeof document === "undefined") return;
|
|
77
|
+
if (document.visibilityState === "visible") releaseBodyPointerLockIfIdle();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function installGlobalWatchers() {
|
|
81
|
+
if (watchersInstalled || typeof document === "undefined") return;
|
|
82
|
+
watchersInstalled = true;
|
|
83
|
+
|
|
84
|
+
document.addEventListener("visibilitychange", handleReturnToPage);
|
|
85
|
+
// `pageshow` fires on bfcache restore where `visibilitychange` may not.
|
|
86
|
+
window.addEventListener("pageshow", handleReturnToPage);
|
|
87
|
+
|
|
88
|
+
// The observer and the per-unmount rAF (below) are complementary, not
|
|
89
|
+
// redundant: the rAF handles the common case where the last overlay unmounts
|
|
90
|
+
// leaving the body stuck at `none` with no further style write, while the
|
|
91
|
+
// observer catches Radix re-writing `none` in a *later* deferred cleanup that
|
|
92
|
+
// the single rAF would miss. Because the release is gated on
|
|
93
|
+
// OPEN_OVERLAY_SELECTOR, the observer only ever undoes an orphaned lock and
|
|
94
|
+
// never one an open overlay owns. Setting the value back to "" is a no-op for
|
|
95
|
+
// the guard (it early-returns unless the value is "none"), so no feedback loop.
|
|
96
|
+
if (typeof MutationObserver !== "undefined") {
|
|
97
|
+
const observer = new MutationObserver(releaseBodyPointerLockIfIdle);
|
|
98
|
+
observer.observe(document.body, {
|
|
99
|
+
attributes: true,
|
|
100
|
+
attributeFilter: ["style"],
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Safety net for a long-standing Radix `react-dismissable-layer` bug where
|
|
107
|
+
* nested overlays can leave `document.body { pointer-events: none }` stuck,
|
|
108
|
+
* freezing the entire page (see DS-634).
|
|
109
|
+
*
|
|
110
|
+
* Each DS overlay whose content can lock outside pointer events calls this hook
|
|
111
|
+
* while it is open. It installs one set of global watchers (a `MutationObserver`
|
|
112
|
+
* on the body's inline style plus tab-return listeners) and, on unmount, clears
|
|
113
|
+
* a residual body lock — but only once no overlay (DS or otherwise) remains on
|
|
114
|
+
* screen, so legitimate modal behaviour (scroll-lock, focus containment,
|
|
115
|
+
* outside-click/Escape) is untouched.
|
|
116
|
+
*
|
|
117
|
+
* Automatically wired into the DS overlay components, so consumers get the fix
|
|
118
|
+
* with no code changes. It is also safe to call from a custom overlay that
|
|
119
|
+
* exposes a standard `role` (dialog/alertdialog/menu/listbox) with
|
|
120
|
+
* `data-state="open"` while open — the guard will not clear a lock it can see is
|
|
121
|
+
* still owned.
|
|
122
|
+
*/
|
|
123
|
+
export function useOverlayPointerLock(): void {
|
|
124
|
+
React.useEffect(() => {
|
|
125
|
+
installGlobalWatchers();
|
|
126
|
+
return scheduleRelease;
|
|
127
|
+
}, []);
|
|
128
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -74,6 +74,7 @@ export * from "./blocks/sidebar";
|
|
|
74
74
|
export * from "./hooks/use-debounce";
|
|
75
75
|
export * from "./hooks/use-breakpoint";
|
|
76
76
|
export * from "./hooks/use-mobile";
|
|
77
|
+
export * from "./hooks/use-overlay-pointer-lock";
|
|
77
78
|
export * from "./hooks/use-prefers-reduced-motion";
|
|
78
79
|
|
|
79
80
|
// Utils
|