Open History to see the last commit
1"use client";
2
3import { Popover as PopoverPrimitive } from "@base-ui/react/popover";
4
5import { cn } from "~/lib/utils";
6
7const PopoverCreateHandle = PopoverPrimitive.createHandle;
8
9const Popover = PopoverPrimitive.Root;
10
11function PopoverTrigger({ className, children, ...props }: PopoverPrimitive.Trigger.Props) {
12 return (
13 <PopoverPrimitive.Trigger className={className} data-slot="popover-trigger" {...props}>
14 {children}
15 </PopoverPrimitive.Trigger>
16 );
17}
18
19function PopoverPopup({
20 children,
21 className,
22 positionerClassName,
23 viewportClassName,
24 side = "bottom",
25 align = "center",
26 sideOffset = 4,
27 alignOffset = 0,
28 collisionAvoidance,
29 tooltipStyle = false,
30 anchor,
31 ...props
32}: PopoverPrimitive.Popup.Props & {
33 positionerClassName?: string;
34 viewportClassName?: string;
35 side?: PopoverPrimitive.Positioner.Props["side"];
36 align?: PopoverPrimitive.Positioner.Props["align"];
37 sideOffset?: PopoverPrimitive.Positioner.Props["sideOffset"];
38 alignOffset?: PopoverPrimitive.Positioner.Props["alignOffset"];
39 collisionAvoidance?: PopoverPrimitive.Positioner.Props["collisionAvoidance"];
40 tooltipStyle?: boolean;
41 anchor?: PopoverPrimitive.Positioner.Props["anchor"];
42}) {
43 return (
44 <PopoverPrimitive.Portal>
45 <PopoverPrimitive.Positioner
46 align={align}
47 alignOffset={alignOffset}
48 anchor={anchor}
49 collisionAvoidance={collisionAvoidance}
50 className={cn(
51 "z-[130] h-(--positioner-height) w-(--positioner-width) max-w-(--available-width) transition-[top,left,right,bottom,transform] data-instant:transition-none",
52 positionerClassName,
53 )}
54 data-slot="popover-positioner"
55 side={side}
56 sideOffset={sideOffset}
57 >
58 <PopoverPrimitive.Popup
59 className={cn(
60 "dropdown-glass relative flex h-(--popup-height,auto) w-(--popup-width,auto) origin-(--transform-origin) rounded-lg text-popover-foreground outline-none transition-[width,height,scale,opacity] before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-lg)-1px)] before:shadow-[0_1px_--theme(--color-black/4%)] has-data-[slot=calendar]:rounded-xl has-data-[slot=calendar]:before:rounded-[calc(var(--radius-xl)-1px)] data-starting-style:scale-98 data-starting-style:opacity-0 dark:before:shadow-[0_-1px_--theme(--color-white/6%)]",
61 tooltipStyle &&
62 "w-fit text-balance rounded-md text-xs shadow-md/5 before:rounded-[calc(var(--radius-md)-1px)]",
63 !tooltipStyle &&
64 "shadow-[0_16px_40px_-18px_rgb(0_0_0/55%)] dark:shadow-[0_18px_44px_-18px_rgb(0_0_0/80%)]",
65 className,
66 )}
67 data-slot="popover-popup"
68 {...props}
69 >
70 <PopoverPrimitive.Viewport
71 className={cn(
72 "relative size-full max-h-(--available-height) overflow-clip px-(--viewport-inline-padding) py-4 [--viewport-inline-padding:--spacing(4)] has-data-[slot=calendar]:p-2 data-instant:transition-none **:data-current:data-ending-style:opacity-0 **:data-current:data-starting-style:opacity-0 **:data-previous:data-ending-style:opacity-0 **:data-previous:data-starting-style:opacity-0 **:data-current:w-[calc(var(--popup-width)-2*var(--viewport-inline-padding)-2px)] **:data-previous:w-[calc(var(--popup-width)-2*var(--viewport-inline-padding)-2px)] **:data-current:opacity-100 **:data-previous:opacity-100 **:data-current:transition-opacity **:data-previous:transition-opacity",
73 tooltipStyle
74 ? "py-1 [--viewport-inline-padding:--spacing(2)]"
75 : "not-data-transitioning:overflow-y-auto",
76 viewportClassName,
77 )}
78 data-slot="popover-viewport"
79 >
80 {children}
81 </PopoverPrimitive.Viewport>
82 </PopoverPrimitive.Popup>
83 </PopoverPrimitive.Positioner>
84 </PopoverPrimitive.Portal>
85 );
86}
87
88function PopoverClose({ ...props }: PopoverPrimitive.Close.Props) {
89 return <PopoverPrimitive.Close data-slot="popover-close" {...props} />;
90}
91
92function PopoverTitle({ className, ...props }: PopoverPrimitive.Title.Props) {
93 return (
94 <PopoverPrimitive.Title
95 className={cn("font-semibold text-lg leading-none", className)}
96 data-slot="popover-title"
97 {...props}
98 />
99 );
100}
101
102function PopoverDescription({ className, ...props }: PopoverPrimitive.Description.Props) {
103 return (
104 <PopoverPrimitive.Description
105 className={cn("text-muted-foreground text-sm", className)}
106 data-slot="popover-description"
107 {...props}
108 />
109 );
110}
111
112export {
113 PopoverCreateHandle,
114 Popover,
115 PopoverTrigger,
116 PopoverPopup,
117 PopoverPopup as PopoverContent,
118 PopoverTitle,
119 PopoverDescription,
120 PopoverClose,
121};