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 viewportClassName,
23 side = "bottom",
24 align = "center",
25 sideOffset = 4,
26 alignOffset = 0,
27 tooltipStyle = false,
28 anchor,
29 ...props
30}: PopoverPrimitive.Popup.Props & {
31 viewportClassName?: string;
32 side?: PopoverPrimitive.Positioner.Props["side"];
33 align?: PopoverPrimitive.Positioner.Props["align"];
34 sideOffset?: PopoverPrimitive.Positioner.Props["sideOffset"];
35 alignOffset?: PopoverPrimitive.Positioner.Props["alignOffset"];
36 tooltipStyle?: boolean;
37 anchor?: PopoverPrimitive.Positioner.Props["anchor"];
38}) {
39 return (
40 <PopoverPrimitive.Portal>
41 <PopoverPrimitive.Positioner
42 align={align}
43 alignOffset={alignOffset}
44 anchor={anchor}
45 className="z-[130] h-(--positioner-height) w-(--positioner-width) max-w-(--available-width) transition-transform data-instant:transition-none"
46 data-slot="popover-positioner"
47 side={side}
48 sideOffset={sideOffset}
49 >
50 <PopoverPrimitive.Popup
51 className={cn(
52 "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%)]",
53 tooltipStyle &&
54 "w-fit text-balance rounded-md text-xs shadow-md/5 before:rounded-[calc(var(--radius-md)-1px)]",
55 !tooltipStyle &&
56 "shadow-[0_16px_40px_-18px_rgb(0_0_0/55%)] dark:shadow-[0_18px_44px_-18px_rgb(0_0_0/80%)]",
57 className,
58 )}
59 data-slot="popover-popup"
60 {...props}
61 >
62 <PopoverPrimitive.Viewport
63 className={cn(
64 "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",
65 tooltipStyle
66 ? "py-1 [--viewport-inline-padding:--spacing(2)]"
67 : "not-data-transitioning:overflow-y-auto",
68 viewportClassName,
69 )}
70 data-slot="popover-viewport"
71 >
72 {children}
73 </PopoverPrimitive.Viewport>
74 </PopoverPrimitive.Popup>
75 </PopoverPrimitive.Positioner>
76 </PopoverPrimitive.Portal>
77 );
78}
79
80function PopoverClose({ ...props }: PopoverPrimitive.Close.Props) {
81 return <PopoverPrimitive.Close data-slot="popover-close" {...props} />;
82}
83
84function PopoverTitle({ className, ...props }: PopoverPrimitive.Title.Props) {
85 return (
86 <PopoverPrimitive.Title
87 className={cn("font-semibold text-lg leading-none", className)}
88 data-slot="popover-title"
89 {...props}
90 />
91 );
92}
93
94function PopoverDescription({ className, ...props }: PopoverPrimitive.Description.Props) {
95 return (
96 <PopoverPrimitive.Description
97 className={cn("text-muted-foreground text-sm", className)}
98 data-slot="popover-description"
99 {...props}
100 />
101 );
102}
103
104export {
105 PopoverCreateHandle,
106 Popover,
107 PopoverTrigger,
108 PopoverPopup,
109 PopoverPopup as PopoverContent,
110 PopoverTitle,
111 PopoverDescription,
112 PopoverClose,
113};