@brightlocal/ui-components 2.19.0 → 2.20.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 +1 -1
- package/component-meta.json +8 -2
- 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/sidebar.cjs +1 -1
- package/dist/blocks/sidebar.d.ts +18 -0
- package/dist/blocks/sidebar.d.ts.map +1 -1
- package/dist/blocks/sidebar.js +84 -74
- package/dist/browser-entry.d.ts +2 -0
- package/dist/browser-entry.d.ts.map +1 -1
- 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/popover.cjs +1 -1
- package/dist/popover.d.ts.map +1 -1
- package/dist/popover.js +21 -20
- 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/package.json +3 -3
- package/src/blocks/sidebar.tsx +35 -8
- package/src/browser-entry.ts +10 -0
- package/src/components/alert-dialog.tsx +20 -14
- 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/popover.tsx +22 -16
- package/src/components/select.tsx +4 -0
- package/src/components/separator.tsx +91 -23
- package/src/components/sheet.tsx +4 -0
- package/src/hooks/use-overlay-pointer-lock.ts +128 -0
- package/src/index.ts +1 -0
package/src/blocks/sidebar.tsx
CHANGED
|
@@ -703,20 +703,34 @@ SidebarHeader.displayName = "SidebarHeader";
|
|
|
703
703
|
interface SidebarFooterProps extends React.ComponentProps<"footer"> {
|
|
704
704
|
/** Data hook for automated testing */
|
|
705
705
|
dataHook?: string;
|
|
706
|
+
/**
|
|
707
|
+
* Whether to render a separator at the top of the footer.
|
|
708
|
+
* @default true
|
|
709
|
+
*/
|
|
710
|
+
separator?: boolean;
|
|
706
711
|
}
|
|
707
712
|
|
|
708
713
|
const SidebarFooter = React.forwardRef<HTMLElement, SidebarFooterProps>(
|
|
709
|
-
({ className, dataHook, ...props }, ref) => {
|
|
714
|
+
({ className, dataHook, separator = true, ...props }, ref) => {
|
|
710
715
|
const { footerPortalEl } = useSidebar();
|
|
711
716
|
|
|
712
717
|
const footer = (
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
718
|
+
<>
|
|
719
|
+
{separator && (
|
|
720
|
+
<Separator
|
|
721
|
+
className="group-data-[collapsible=icon]:mx-0"
|
|
722
|
+
data-slot="sidebar-footer-separator"
|
|
723
|
+
spacing="md"
|
|
724
|
+
/>
|
|
725
|
+
)}
|
|
726
|
+
<footer
|
|
727
|
+
ref={ref}
|
|
728
|
+
className={cn("flex shrink-0 flex-col gap-1 p-1", className)}
|
|
729
|
+
data-hook={dataHook}
|
|
730
|
+
data-slot="sidebar-footer"
|
|
731
|
+
{...props}
|
|
732
|
+
/>
|
|
733
|
+
</>
|
|
720
734
|
);
|
|
721
735
|
|
|
722
736
|
if (footerPortalEl) {
|
|
@@ -730,9 +744,22 @@ SidebarFooter.displayName = "SidebarFooter";
|
|
|
730
744
|
|
|
731
745
|
/**
|
|
732
746
|
* Props for the SidebarSeparator component
|
|
747
|
+
* @deprecated Use `Separator` from `@brightlocal/ui-components/separator` with `spacing="md"` instead. SidebarSeparator will be removed in the next major version.
|
|
733
748
|
*/
|
|
734
749
|
type SidebarSeparatorProps = React.ComponentProps<typeof Separator>;
|
|
735
750
|
|
|
751
|
+
/**
|
|
752
|
+
* @deprecated Use `Separator` from `@brightlocal/ui-components/separator` with `spacing="md"` instead.
|
|
753
|
+
*
|
|
754
|
+
* ```tsx
|
|
755
|
+
* // Before
|
|
756
|
+
* <SidebarSeparator />
|
|
757
|
+
*
|
|
758
|
+
* // After
|
|
759
|
+
* import { Separator } from "@brightlocal/ui-components/separator";
|
|
760
|
+
* <Separator spacing="md" dataHook="sidebar-separator" />
|
|
761
|
+
* ```
|
|
762
|
+
*/
|
|
736
763
|
const SidebarSeparator = React.forwardRef<
|
|
737
764
|
React.ComponentRef<typeof Separator>,
|
|
738
765
|
SidebarSeparatorProps
|
package/src/browser-entry.ts
CHANGED
|
@@ -21,6 +21,16 @@ export const useReducer = React.useReducer;
|
|
|
21
21
|
export const useLayoutEffect = React.useLayoutEffect;
|
|
22
22
|
export const Fragment = React.Fragment;
|
|
23
23
|
|
|
24
|
+
// --- Build metadata ---
|
|
25
|
+
// Injected by vite.config.browser.ts at build time. Lets consumers read
|
|
26
|
+
// window.BrightLocalDS.version to verify which release a bundle was built from.
|
|
27
|
+
declare const __DS_VERSION__: string;
|
|
28
|
+
declare const __DS_BUILD_TIME__: string;
|
|
29
|
+
export const version =
|
|
30
|
+
typeof __DS_VERSION__ === "string" ? __DS_VERSION__ : "0.0.0-dev";
|
|
31
|
+
export const buildTime =
|
|
32
|
+
typeof __DS_BUILD_TIME__ === "string" ? __DS_BUILD_TIME__ : "";
|
|
33
|
+
|
|
24
34
|
// --- Mount API for IIFE consumers ---
|
|
25
35
|
|
|
26
36
|
const roots = new WeakMap<HTMLElement, Root>();
|
|
@@ -4,6 +4,7 @@ import * as React from "react";
|
|
|
4
4
|
import * as AlertDialogPrimitive from "@radix-ui/react-alert-dialog";
|
|
5
5
|
|
|
6
6
|
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
7
|
+
import { useOverlayPointerLock } from "@brightlocal/ui-components/hooks/use-overlay-pointer-lock";
|
|
7
8
|
import { ButtonVariants } from "@brightlocal/ui-components/button";
|
|
8
9
|
|
|
9
10
|
interface AlertDialogProps extends React.ComponentProps<
|
|
@@ -83,20 +84,25 @@ AlertDialogOverlay.displayName = "AlertDialogOverlay";
|
|
|
83
84
|
const AlertDialogContent = React.forwardRef<
|
|
84
85
|
React.ComponentRef<typeof AlertDialogPrimitive.Content>,
|
|
85
86
|
React.ComponentProps<typeof AlertDialogPrimitive.Content>
|
|
86
|
-
>(({ className, ...props }, ref) =>
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
87
|
+
>(({ className, ...props }, ref) => {
|
|
88
|
+
// Safety net for the Radix dismissable-layer body-lock leak (DS-634).
|
|
89
|
+
useOverlayPointerLock();
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<AlertDialogPortal>
|
|
93
|
+
<AlertDialogOverlay />
|
|
94
|
+
<AlertDialogPrimitive.Content
|
|
95
|
+
ref={ref}
|
|
96
|
+
className={cn(
|
|
97
|
+
"border-border bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 sm:max-w-lg",
|
|
98
|
+
className
|
|
99
|
+
)}
|
|
100
|
+
data-slot="alert-dialog-content"
|
|
101
|
+
{...props}
|
|
102
|
+
/>
|
|
103
|
+
</AlertDialogPortal>
|
|
104
|
+
);
|
|
105
|
+
});
|
|
100
106
|
|
|
101
107
|
AlertDialogContent.displayName = "AlertDialogContent";
|
|
102
108
|
|
|
@@ -4,6 +4,7 @@ import * as ContextMenuPrimitive from "@radix-ui/react-context-menu";
|
|
|
4
4
|
import { Check, ChevronRight, Circle } from "@brightlocal/icons";
|
|
5
5
|
|
|
6
6
|
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
7
|
+
import { useOverlayPointerLock } from "@brightlocal/ui-components/hooks/use-overlay-pointer-lock";
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Props for the ContextMenu component
|
|
@@ -220,19 +221,24 @@ export type ContextMenuContentProps = React.ComponentPropsWithoutRef<
|
|
|
220
221
|
const ContextMenuContent = React.forwardRef<
|
|
221
222
|
React.ComponentRef<typeof ContextMenuPrimitive.Content>,
|
|
222
223
|
ContextMenuContentProps
|
|
223
|
-
>(({ className, ...props }, ref) =>
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
224
|
+
>(({ className, ...props }, ref) => {
|
|
225
|
+
// Safety net for the Radix dismissable-layer body-lock leak (DS-634).
|
|
226
|
+
useOverlayPointerLock();
|
|
227
|
+
|
|
228
|
+
return (
|
|
229
|
+
<ContextMenuPrimitive.Portal>
|
|
230
|
+
<ContextMenuPrimitive.Content
|
|
231
|
+
ref={ref}
|
|
232
|
+
className={cn(
|
|
233
|
+
"border-border bg-popover text-popover-foreground animate-in fade-in-80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] overflow-hidden rounded-md border p-1 shadow-md",
|
|
234
|
+
className
|
|
235
|
+
)}
|
|
236
|
+
data-slot="context-menu-content"
|
|
237
|
+
{...props}
|
|
238
|
+
/>
|
|
239
|
+
</ContextMenuPrimitive.Portal>
|
|
240
|
+
);
|
|
241
|
+
});
|
|
236
242
|
ContextMenuContent.displayName = "ContextMenuContent";
|
|
237
243
|
|
|
238
244
|
/**
|
|
@@ -5,6 +5,7 @@ import * as DialogPrimitive from "@radix-ui/react-dialog";
|
|
|
5
5
|
import { X } from "@brightlocal/icons";
|
|
6
6
|
|
|
7
7
|
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
8
|
+
import { useOverlayPointerLock } from "@brightlocal/ui-components/hooks/use-overlay-pointer-lock";
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Dialog - Root component for modal dialogs
|
|
@@ -127,6 +128,9 @@ const DialogContent = React.forwardRef<HTMLDivElement, DialogContentProps>(
|
|
|
127
128
|
},
|
|
128
129
|
ref
|
|
129
130
|
) => {
|
|
131
|
+
// Safety net for the Radix dismissable-layer body-lock leak (DS-634).
|
|
132
|
+
useOverlayPointerLock();
|
|
133
|
+
|
|
130
134
|
return (
|
|
131
135
|
<DialogPortal>
|
|
132
136
|
<DialogOverlay />
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
} from "@brightlocal/icons";
|
|
11
11
|
|
|
12
12
|
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
13
|
+
import { useOverlayPointerLock } from "@brightlocal/ui-components/hooks/use-overlay-pointer-lock";
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Root component for dropdown menu (context provider, does not render to DOM)
|
|
@@ -108,6 +109,9 @@ const DropdownMenuContent = React.forwardRef<
|
|
|
108
109
|
},
|
|
109
110
|
ref
|
|
110
111
|
) => {
|
|
112
|
+
// Safety net for the Radix dismissable-layer body-lock leak (DS-634).
|
|
113
|
+
useOverlayPointerLock();
|
|
114
|
+
|
|
111
115
|
return (
|
|
112
116
|
<DropdownMenuPrimitive.Portal>
|
|
113
117
|
<DropdownMenuPrimitive.Content
|
|
@@ -4,6 +4,7 @@ import * as React from "react";
|
|
|
4
4
|
import * as PopoverPrimitive from "@radix-ui/react-popover";
|
|
5
5
|
|
|
6
6
|
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
7
|
+
import { useOverlayPointerLock } from "@brightlocal/ui-components/hooks/use-overlay-pointer-lock";
|
|
7
8
|
|
|
8
9
|
export interface PopoverProps extends React.ComponentProps<
|
|
9
10
|
typeof PopoverPrimitive.Root
|
|
@@ -82,22 +83,27 @@ const PopoverContent = React.forwardRef<
|
|
|
82
83
|
(
|
|
83
84
|
{ className, align = "center", sideOffset = 4, dataHook, ...props },
|
|
84
85
|
ref
|
|
85
|
-
) =>
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
86
|
+
) => {
|
|
87
|
+
// Safety net for the Radix dismissable-layer body-lock leak (DS-634).
|
|
88
|
+
useOverlayPointerLock();
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<PopoverPrimitive.Portal>
|
|
92
|
+
<PopoverPrimitive.Content
|
|
93
|
+
ref={ref}
|
|
94
|
+
align={align}
|
|
95
|
+
className={cn(
|
|
96
|
+
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border p-4 shadow-md outline-hidden",
|
|
97
|
+
className
|
|
98
|
+
)}
|
|
99
|
+
data-hook={dataHook}
|
|
100
|
+
data-slot="popover-content"
|
|
101
|
+
sideOffset={sideOffset}
|
|
102
|
+
{...props}
|
|
103
|
+
/>
|
|
104
|
+
</PopoverPrimitive.Portal>
|
|
105
|
+
);
|
|
106
|
+
}
|
|
101
107
|
);
|
|
102
108
|
PopoverContent.displayName = "PopoverContent";
|
|
103
109
|
|
|
@@ -7,6 +7,7 @@ import { cva } from "class-variance-authority";
|
|
|
7
7
|
|
|
8
8
|
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
9
9
|
import { useDevWarning } from "../lib/use-dev-warning";
|
|
10
|
+
import { useOverlayPointerLock } from "@brightlocal/ui-components/hooks/use-overlay-pointer-lock";
|
|
10
11
|
|
|
11
12
|
// ============================================================================
|
|
12
13
|
// Types
|
|
@@ -206,6 +207,9 @@ function SelectContent({
|
|
|
206
207
|
style,
|
|
207
208
|
...props
|
|
208
209
|
}: SelectContentProps) {
|
|
210
|
+
// Safety net for the Radix dismissable-layer body-lock leak (DS-634).
|
|
211
|
+
useOverlayPointerLock();
|
|
212
|
+
|
|
209
213
|
const viewportRef = React.useRef<HTMLDivElement>(null);
|
|
210
214
|
|
|
211
215
|
useDevWarning(
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
import * as React from "react";
|
|
4
|
+
import { cva } from "class-variance-authority";
|
|
4
5
|
|
|
5
6
|
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
6
7
|
|
|
@@ -9,6 +10,54 @@ import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
|
9
10
|
*/
|
|
10
11
|
export type SeparatorOrientation = "horizontal" | "vertical";
|
|
11
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Spacing variants for Separator
|
|
15
|
+
*/
|
|
16
|
+
export type SeparatorSpacing = "default" | "sm" | "md" | "lg";
|
|
17
|
+
|
|
18
|
+
const separatorStyles = cva("bg-border shrink-0", {
|
|
19
|
+
variants: {
|
|
20
|
+
orientation: {
|
|
21
|
+
horizontal: "h-px border-0",
|
|
22
|
+
vertical: "w-px",
|
|
23
|
+
},
|
|
24
|
+
spacing: {
|
|
25
|
+
default: "",
|
|
26
|
+
sm: "",
|
|
27
|
+
md: "",
|
|
28
|
+
lg: "",
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
compoundVariants: [
|
|
32
|
+
{ orientation: "horizontal", spacing: "default", className: "w-full" },
|
|
33
|
+
{ orientation: "horizontal", spacing: "sm", className: "my-2 mx-6 w-auto" },
|
|
34
|
+
{ orientation: "horizontal", spacing: "md", className: "my-4 mx-6 w-auto" },
|
|
35
|
+
{ orientation: "horizontal", spacing: "lg", className: "m-6 w-auto" },
|
|
36
|
+
{ orientation: "vertical", spacing: "default", className: "h-full" },
|
|
37
|
+
{ orientation: "vertical", spacing: "sm", className: "self-stretch mx-2" },
|
|
38
|
+
{ orientation: "vertical", spacing: "md", className: "self-stretch mx-4" },
|
|
39
|
+
{ orientation: "vertical", spacing: "lg", className: "self-stretch mx-6" },
|
|
40
|
+
],
|
|
41
|
+
defaultVariants: {
|
|
42
|
+
orientation: "horizontal",
|
|
43
|
+
spacing: "default",
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const separatorWithTextStyles = cva("flex items-center gap-2", {
|
|
48
|
+
variants: {
|
|
49
|
+
spacing: {
|
|
50
|
+
default: "",
|
|
51
|
+
sm: "py-2 px-6",
|
|
52
|
+
md: "py-4 px-6",
|
|
53
|
+
lg: "p-6",
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
defaultVariants: {
|
|
57
|
+
spacing: "default",
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
|
|
12
61
|
/**
|
|
13
62
|
* Props for the Separator component.
|
|
14
63
|
*/
|
|
@@ -19,6 +68,11 @@ interface SeparatorProps extends React.ComponentPropsWithoutRef<"div"> {
|
|
|
19
68
|
* @default "horizontal"
|
|
20
69
|
*/
|
|
21
70
|
orientation?: SeparatorOrientation;
|
|
71
|
+
/**
|
|
72
|
+
* Controls the spacing around the separator.
|
|
73
|
+
* @default "default"
|
|
74
|
+
*/
|
|
75
|
+
spacing?: SeparatorSpacing;
|
|
22
76
|
/**
|
|
23
77
|
* When true, the separator is purely decorative (role="none").
|
|
24
78
|
* When false, it carries separator semantics for assistive technology.
|
|
@@ -49,6 +103,7 @@ const Separator = React.forwardRef<HTMLElement, SeparatorProps>(
|
|
|
49
103
|
{
|
|
50
104
|
className,
|
|
51
105
|
orientation = "horizontal",
|
|
106
|
+
spacing = "default",
|
|
52
107
|
decorative = true,
|
|
53
108
|
dataHook,
|
|
54
109
|
trackingEl,
|
|
@@ -68,11 +123,7 @@ const Separator = React.forwardRef<HTMLElement, SeparatorProps>(
|
|
|
68
123
|
|
|
69
124
|
return React.createElement(orientation === "horizontal" ? "hr" : "div", {
|
|
70
125
|
ref,
|
|
71
|
-
className: cn(
|
|
72
|
-
"bg-border shrink-0",
|
|
73
|
-
orientation === "horizontal" ? "h-px w-full border-0" : "h-full w-px",
|
|
74
|
-
className
|
|
75
|
-
),
|
|
126
|
+
className: cn(separatorStyles({ orientation, spacing }), className),
|
|
76
127
|
"data-hook": dataHook,
|
|
77
128
|
"data-orientation": orientation,
|
|
78
129
|
"data-slot": "separator",
|
|
@@ -98,6 +149,11 @@ interface SeparatorWithTextProps {
|
|
|
98
149
|
* Text content to display between separators
|
|
99
150
|
*/
|
|
100
151
|
children: React.ReactNode;
|
|
152
|
+
/**
|
|
153
|
+
* Controls the spacing around the separator.
|
|
154
|
+
* @default "default"
|
|
155
|
+
*/
|
|
156
|
+
spacing?: SeparatorSpacing;
|
|
101
157
|
/**
|
|
102
158
|
* Data hook for automated testing
|
|
103
159
|
*/
|
|
@@ -119,24 +175,36 @@ interface SeparatorWithTextProps {
|
|
|
119
175
|
const SeparatorWithText = React.forwardRef<
|
|
120
176
|
HTMLDivElement,
|
|
121
177
|
SeparatorWithTextProps
|
|
122
|
-
>(
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
178
|
+
>(
|
|
179
|
+
(
|
|
180
|
+
{
|
|
181
|
+
className,
|
|
182
|
+
children,
|
|
183
|
+
spacing = "default",
|
|
184
|
+
dataHook,
|
|
185
|
+
trackingEl,
|
|
186
|
+
trackingLabel,
|
|
187
|
+
},
|
|
188
|
+
ref
|
|
189
|
+
) => {
|
|
190
|
+
return (
|
|
191
|
+
<div
|
|
192
|
+
ref={ref}
|
|
193
|
+
className={cn(separatorWithTextStyles({ spacing }), className)}
|
|
194
|
+
data-hook={dataHook}
|
|
195
|
+
data-slot="separator-with-text"
|
|
196
|
+
data-tracking-el={trackingEl}
|
|
197
|
+
data-tracking-label={trackingLabel}
|
|
198
|
+
>
|
|
199
|
+
<Separator className="flex-1" />
|
|
200
|
+
<span className="text-muted-foreground shrink-0 text-sm leading-none font-medium whitespace-nowrap">
|
|
201
|
+
{children}
|
|
202
|
+
</span>
|
|
203
|
+
<Separator className="flex-1" />
|
|
204
|
+
</div>
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
);
|
|
140
208
|
|
|
141
209
|
SeparatorWithText.displayName = "SeparatorWithText";
|
|
142
210
|
|
package/src/components/sheet.tsx
CHANGED
|
@@ -6,6 +6,7 @@ import { cva, type VariantProps } from "class-variance-authority";
|
|
|
6
6
|
import { X } from "@brightlocal/icons";
|
|
7
7
|
|
|
8
8
|
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
9
|
+
import { useOverlayPointerLock } from "@brightlocal/ui-components/hooks/use-overlay-pointer-lock";
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Available sheet side variants
|
|
@@ -213,6 +214,9 @@ const SheetContent = React.forwardRef<
|
|
|
213
214
|
},
|
|
214
215
|
ref
|
|
215
216
|
) => {
|
|
217
|
+
// Safety net for the Radix dismissable-layer body-lock leak (DS-634).
|
|
218
|
+
useOverlayPointerLock();
|
|
219
|
+
|
|
216
220
|
return (
|
|
217
221
|
<SheetPortal>
|
|
218
222
|
<SheetOverlay />
|
|
@@ -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
|