@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
package/src/blocks/sidebar.tsx
CHANGED
|
@@ -520,7 +520,7 @@ interface SidebarTriggerProps extends Omit<
|
|
|
520
520
|
dataHook?: string;
|
|
521
521
|
/**
|
|
522
522
|
* Accessible label for the toggle button.
|
|
523
|
-
* @default "Toggle
|
|
523
|
+
* @default "Toggle sidebar"
|
|
524
524
|
*/
|
|
525
525
|
toggleAriaLabel?: string;
|
|
526
526
|
}
|
|
@@ -541,14 +541,14 @@ const SidebarTrigger = React.forwardRef<
|
|
|
541
541
|
ref
|
|
542
542
|
) => {
|
|
543
543
|
const { toggleSidebar } = useSidebar();
|
|
544
|
-
const resolvedLabel = toggleAriaLabel ?? "Toggle
|
|
544
|
+
const resolvedLabel = toggleAriaLabel ?? "Toggle sidebar";
|
|
545
545
|
|
|
546
546
|
return (
|
|
547
547
|
<Button
|
|
548
548
|
ref={ref}
|
|
549
549
|
iconOnly
|
|
550
550
|
aria-label={resolvedLabel}
|
|
551
|
-
className={cn("h-7 w-7", className)}
|
|
551
|
+
className={cn("relative h-7 w-7", className)}
|
|
552
552
|
data-slot="sidebar-trigger"
|
|
553
553
|
dataHook={dataHook}
|
|
554
554
|
size="sm"
|
|
@@ -573,7 +573,7 @@ SidebarTrigger.displayName = "SidebarTrigger";
|
|
|
573
573
|
interface SidebarRailProps extends React.ComponentProps<"button"> {
|
|
574
574
|
/**
|
|
575
575
|
* Accessible label and tooltip for the rail toggle.
|
|
576
|
-
* @default "Toggle
|
|
576
|
+
* @default "Toggle sidebar"
|
|
577
577
|
*/
|
|
578
578
|
toggleAriaLabel?: string;
|
|
579
579
|
}
|
|
@@ -581,7 +581,7 @@ interface SidebarRailProps extends React.ComponentProps<"button"> {
|
|
|
581
581
|
const SidebarRail = React.forwardRef<HTMLButtonElement, SidebarRailProps>(
|
|
582
582
|
({ className, toggleAriaLabel, ...props }, ref) => {
|
|
583
583
|
const { toggleSidebar } = useSidebar();
|
|
584
|
-
const resolvedLabel = toggleAriaLabel ?? "Toggle
|
|
584
|
+
const resolvedLabel = toggleAriaLabel ?? "Toggle sidebar";
|
|
585
585
|
|
|
586
586
|
return (
|
|
587
587
|
<button
|
|
@@ -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
|
|
|
@@ -22,7 +22,7 @@ interface BreadcrumbProps extends React.ComponentProps<"nav"> {
|
|
|
22
22
|
trackingLabel?: string;
|
|
23
23
|
/**
|
|
24
24
|
* Accessible label for the breadcrumb navigation.
|
|
25
|
-
* @default "
|
|
25
|
+
* @default "Breadcrumb"
|
|
26
26
|
*/
|
|
27
27
|
ariaLabel?: string;
|
|
28
28
|
}
|
|
@@ -36,7 +36,7 @@ const Breadcrumb = React.forwardRef<HTMLElement, BreadcrumbProps>(
|
|
|
36
36
|
return (
|
|
37
37
|
<nav
|
|
38
38
|
ref={ref}
|
|
39
|
-
aria-label={ariaLabel ?? "
|
|
39
|
+
aria-label={ariaLabel ?? "Breadcrumb"}
|
|
40
40
|
data-hook={dataHook}
|
|
41
41
|
data-slot="breadcrumb"
|
|
42
42
|
data-tracking-el={trackingEl}
|
|
@@ -181,7 +181,10 @@ const BreadcrumbEllipsis = React.forwardRef<
|
|
|
181
181
|
<span
|
|
182
182
|
ref={ref}
|
|
183
183
|
aria-hidden="true"
|
|
184
|
-
className={cn(
|
|
184
|
+
className={cn(
|
|
185
|
+
"relative flex size-9 items-center justify-center",
|
|
186
|
+
className
|
|
187
|
+
)}
|
|
185
188
|
data-slot="breadcrumb-ellipsis"
|
|
186
189
|
role="presentation"
|
|
187
190
|
{...props}
|
|
@@ -203,9 +203,15 @@ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
|
|
203
203
|
else if (disabled) visualState = "disabled";
|
|
204
204
|
|
|
205
205
|
// Ensure we always have an accessible label
|
|
206
|
+
const childrenIsPrimitive =
|
|
207
|
+
typeof children === "string" || typeof children === "number";
|
|
206
208
|
const effectiveAriaLabel =
|
|
207
209
|
ariaLabel ??
|
|
208
|
-
(loading
|
|
210
|
+
(loading
|
|
211
|
+
? childrenIsPrimitive
|
|
212
|
+
? `Loading: ${children}`
|
|
213
|
+
: "Loading"
|
|
214
|
+
: undefined);
|
|
209
215
|
|
|
210
216
|
// When asChild is used, render a simplified version that only forwards props
|
|
211
217
|
if (asChild) {
|
|
@@ -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
|
package/src/components/logo.tsx
CHANGED
|
@@ -30,7 +30,7 @@ interface LogoProps
|
|
|
30
30
|
dataHook: string;
|
|
31
31
|
/**
|
|
32
32
|
* Accessible label for the logo image.
|
|
33
|
-
* @default "BrightLocal
|
|
33
|
+
* @default "BrightLocal logo"
|
|
34
34
|
*/
|
|
35
35
|
ariaLabel?: string;
|
|
36
36
|
/**
|
|
@@ -64,7 +64,7 @@ function Logo({
|
|
|
64
64
|
>
|
|
65
65
|
{variant === "logotype" && (
|
|
66
66
|
<svg
|
|
67
|
-
aria-label={ariaLabel ?? "BrightLocal
|
|
67
|
+
aria-label={ariaLabel ?? "BrightLocal logo"}
|
|
68
68
|
fill="none"
|
|
69
69
|
height="24"
|
|
70
70
|
role="img"
|
|
@@ -82,7 +82,7 @@ function Logo({
|
|
|
82
82
|
)}
|
|
83
83
|
{variant === "mark" && (
|
|
84
84
|
<svg
|
|
85
|
-
aria-label={ariaLabel ?? "BrightLocal
|
|
85
|
+
aria-label={ariaLabel ?? "BrightLocal logo"}
|
|
86
86
|
fill="none"
|
|
87
87
|
height="21"
|
|
88
88
|
role="img"
|
|
@@ -15,12 +15,20 @@ interface NavigationMenuProps extends React.ComponentPropsWithoutRef<
|
|
|
15
15
|
> {
|
|
16
16
|
dataHook: string;
|
|
17
17
|
className?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Delay in ms before a hovered trigger opens its menu. Overrides Radix's
|
|
20
|
+
* laggy 200ms default with Base UI's snappier value.
|
|
21
|
+
* @default 50
|
|
22
|
+
*/
|
|
23
|
+
delayDuration?: number;
|
|
18
24
|
}
|
|
19
25
|
|
|
20
26
|
const NavigationMenu = React.forwardRef<
|
|
21
27
|
React.ElementRef<typeof NavigationMenuPrimitive.Root>,
|
|
22
28
|
NavigationMenuProps
|
|
23
|
-
>(({ className, children, dataHook, ...props }, ref) => (
|
|
29
|
+
>(({ className, children, dataHook, delayDuration = 50, ...props }, ref) => (
|
|
30
|
+
// Radix defaults delayDuration to 200ms, which reads as a laggy hover-open.
|
|
31
|
+
// Match Base UI's snappier 50ms default (still overridable via props).
|
|
24
32
|
<NavigationMenuPrimitive.Root
|
|
25
33
|
ref={ref}
|
|
26
34
|
className={cn(
|
|
@@ -29,6 +37,7 @@ const NavigationMenu = React.forwardRef<
|
|
|
29
37
|
)}
|
|
30
38
|
data-hook={dataHook}
|
|
31
39
|
data-slot="navigation-menu"
|
|
40
|
+
delayDuration={delayDuration}
|
|
32
41
|
{...props}
|
|
33
42
|
>
|
|
34
43
|
{children}
|
|
@@ -82,42 +91,125 @@ type NavigationMenuTriggerProps = React.ComponentPropsWithoutRef<
|
|
|
82
91
|
typeof NavigationMenuPrimitive.Trigger
|
|
83
92
|
>;
|
|
84
93
|
|
|
94
|
+
/**
|
|
95
|
+
* Window (ms) after the menu opens during which a mouse click is treated as
|
|
96
|
+
* instinctive and is NOT allowed to close the menu. Mirrors Base UI's
|
|
97
|
+
* "patient click" threshold (PATIENT_CLICK_THRESHOLD).
|
|
98
|
+
*/
|
|
99
|
+
const PATIENT_CLICK_THRESHOLD_MS = 500;
|
|
100
|
+
|
|
85
101
|
/**
|
|
86
102
|
* Trigger button that opens a dropdown menu
|
|
87
103
|
* Includes chevron icon that rotates when open
|
|
104
|
+
*
|
|
105
|
+
* Radix opens the menu on hover and then *toggles it closed* on the next click.
|
|
106
|
+
* Mouse users routinely click a trigger they have just hovered open, which
|
|
107
|
+
* closes it immediately (see radix-ui/primitives#1630).
|
|
108
|
+
*
|
|
109
|
+
* We port Base UI's "patient click" behaviour: an instinctive mouse click made
|
|
110
|
+
* within {@link PATIENT_CLICK_THRESHOLD_MS} of the menu opening keeps it open
|
|
111
|
+
* (calling `preventDefault()` makes Radix's internal `composeEventHandlers`
|
|
112
|
+
* skip its toggle). The window is measured from the `data-state` open
|
|
113
|
+
* transition — not the pointer enter — so it stays correct no matter how large
|
|
114
|
+
* `delayDuration` is. A deliberate click after that window still toggles the
|
|
115
|
+
* menu shut, and touch taps and keyboard activation are left untouched so they
|
|
116
|
+
* can toggle it too.
|
|
88
117
|
*/
|
|
89
118
|
const NavigationMenuTrigger = React.forwardRef<
|
|
90
119
|
React.ElementRef<typeof NavigationMenuPrimitive.Trigger>,
|
|
91
120
|
NavigationMenuTriggerProps
|
|
92
|
-
>(({ className, children, ...props }, ref) =>
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
)
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
)
|
|
121
|
+
>(({ className, children, onClick, onPointerDown, ...props }, ref) => {
|
|
122
|
+
// Pointer type of the interaction, so the keep-open behaviour only applies to
|
|
123
|
+
// mouse (the only input that hover-opens before a click).
|
|
124
|
+
const lastPointerTypeRef = React.useRef<string>("");
|
|
125
|
+
// Timestamp (event clock) of the last open transition, used to measure whether
|
|
126
|
+
// a click is "instinctive" (right after the menu opened) or "patient"
|
|
127
|
+
// (deliberate). Measuring from the open — not the pointer enter — keeps the
|
|
128
|
+
// window correct regardless of `delayDuration`. Starts at -Infinity so a click
|
|
129
|
+
// on a trigger that was already open at mount (no observed transition) is never
|
|
130
|
+
// misclassified as instinctive.
|
|
131
|
+
const openedAtRef = React.useRef(-Infinity);
|
|
132
|
+
const observerRef = React.useRef<MutationObserver | null>(null);
|
|
133
|
+
|
|
134
|
+
// Merge the forwarded ref with a `data-state` observer that stamps the open
|
|
135
|
+
// time. A callback ref (stable via useCallback) attaches once on mount and
|
|
136
|
+
// tears the observer down on unmount.
|
|
137
|
+
const composedRef = React.useCallback(
|
|
138
|
+
(node: React.ElementRef<typeof NavigationMenuPrimitive.Trigger> | null) => {
|
|
139
|
+
if (typeof ref === "function") {
|
|
140
|
+
ref(node);
|
|
141
|
+
} else if (ref) {
|
|
142
|
+
ref.current = node;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
observerRef.current?.disconnect();
|
|
146
|
+
if (node) {
|
|
147
|
+
const observer = new MutationObserver(() => {
|
|
148
|
+
if (node.getAttribute("data-state") === "open") {
|
|
149
|
+
openedAtRef.current = performance.now();
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
observer.observe(node, {
|
|
153
|
+
attributes: true,
|
|
154
|
+
attributeFilter: ["data-state"],
|
|
155
|
+
});
|
|
156
|
+
observerRef.current = observer;
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
[ref]
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
return (
|
|
163
|
+
<NavigationMenuPrimitive.Trigger
|
|
164
|
+
ref={composedRef}
|
|
165
|
+
className={cn(
|
|
166
|
+
[
|
|
167
|
+
"group inline-flex h-9 w-max items-center justify-center gap-1",
|
|
168
|
+
"rounded-md px-4 py-2",
|
|
169
|
+
"text-sm font-medium",
|
|
170
|
+
"text-foreground",
|
|
171
|
+
"transition-colors",
|
|
172
|
+
"hover:bg-accent hover:text-accent-foreground",
|
|
173
|
+
"focus:bg-accent focus:text-accent-foreground",
|
|
174
|
+
"focus-visible:bg-accent focus-visible:ring-ring focus-visible:shadow-[0_0_0_4px_rgba(163,163,163,0.1)] focus-visible:ring-1 focus-visible:outline-none",
|
|
175
|
+
"disabled:pointer-events-none disabled:opacity-50",
|
|
176
|
+
"data-[state=open]:bg-accent/50",
|
|
177
|
+
],
|
|
178
|
+
className
|
|
179
|
+
)}
|
|
180
|
+
data-slot="navigation-menu-trigger"
|
|
181
|
+
onClick={(event) => {
|
|
182
|
+
// `data-state` is "open" only when hover already opened this trigger.
|
|
183
|
+
// `event.detail > 0` excludes keyboard-synthesised clicks (detail === 0).
|
|
184
|
+
const isOpen =
|
|
185
|
+
event.currentTarget.getAttribute("data-state") === "open";
|
|
186
|
+
const isInstinctiveClick =
|
|
187
|
+
event.timeStamp - openedAtRef.current < PATIENT_CLICK_THRESHOLD_MS;
|
|
188
|
+
if (
|
|
189
|
+
lastPointerTypeRef.current === "mouse" &&
|
|
190
|
+
event.detail > 0 &&
|
|
191
|
+
isOpen &&
|
|
192
|
+
isInstinctiveClick
|
|
193
|
+
) {
|
|
194
|
+
event.preventDefault();
|
|
195
|
+
}
|
|
196
|
+
onClick?.(event);
|
|
197
|
+
}}
|
|
198
|
+
onPointerDown={(event) => {
|
|
199
|
+
lastPointerTypeRef.current = event.pointerType;
|
|
200
|
+
onPointerDown?.(event);
|
|
201
|
+
}}
|
|
202
|
+
{...props}
|
|
203
|
+
>
|
|
204
|
+
{children}
|
|
205
|
+
<ChevronDown
|
|
206
|
+
aria-hidden="true"
|
|
207
|
+
className="relative top-[1px] ml-1 transition duration-300 group-data-[state=open]:rotate-180"
|
|
208
|
+
size={12}
|
|
209
|
+
/>
|
|
210
|
+
</NavigationMenuPrimitive.Trigger>
|
|
211
|
+
);
|
|
212
|
+
});
|
|
121
213
|
|
|
122
214
|
NavigationMenuTrigger.displayName = "NavigationMenuTrigger";
|
|
123
215
|
|
|
@@ -144,6 +236,10 @@ const NavigationMenuContent = React.forwardRef<
|
|
|
144
236
|
"data-[motion^=from-]:fade-in data-[motion^=to-]:fade-out",
|
|
145
237
|
"data-[motion=from-end]:slide-in-from-right-52 data-[motion=from-start]:slide-in-from-left-52",
|
|
146
238
|
"data-[motion=to-end]:slide-out-to-right-52 data-[motion=to-start]:slide-out-to-left-52",
|
|
239
|
+
// Match the viewport's easeOutQuint timing so the directional slide and
|
|
240
|
+
// the container morph feel like one motion (kept snappy so content
|
|
241
|
+
// appears without a perceptible fade-in delay).
|
|
242
|
+
"duration-200 ease-[cubic-bezier(0.22,1,0.36,1)]",
|
|
147
243
|
"md:absolute md:w-auto",
|
|
148
244
|
],
|
|
149
245
|
className
|
|
@@ -205,8 +301,14 @@ const NavigationMenuViewport = React.forwardRef<
|
|
|
205
301
|
[
|
|
206
302
|
"origin-top-center relative mt-1.5 h-[var(--radix-navigation-menu-viewport-height)]",
|
|
207
303
|
"bg-popover text-popover-foreground w-full overflow-hidden rounded-md border shadow-sm",
|
|
208
|
-
|
|
209
|
-
|
|
304
|
+
// Base UI-style size morph: smoothly animate width/height between items
|
|
305
|
+
// with an easeOutQuint curve. The enter/exit stays snappy (200ms in,
|
|
306
|
+
// 150ms out) so the panel and its content appear immediately rather
|
|
307
|
+
// than fading in slowly. Reduced motion is neutralised globally by the
|
|
308
|
+
// token preset, so no per-element motion-reduce guard is needed.
|
|
309
|
+
"transition-[width,height] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)]",
|
|
310
|
+
"data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",
|
|
311
|
+
"data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=closed]:duration-150",
|
|
210
312
|
"md:w-[var(--radix-navigation-menu-viewport-width)]",
|
|
211
313
|
],
|
|
212
314
|
className
|