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-[60] 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 className,
56 )}
57 data-slot="popover-popup"
58 {...props}
59 >
60 <PopoverPrimitive.Viewport
61 className={cn(
62 "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",
63 tooltipStyle
64 ? "py-1 [--viewport-inline-padding:--spacing(2)]"
65 : "not-data-transitioning:overflow-y-auto",
66 viewportClassName,
67 )}
68 data-slot="popover-viewport"
69 >
70 {children}
71 </PopoverPrimitive.Viewport>
72 </PopoverPrimitive.Popup>
73 </PopoverPrimitive.Positioner>
74 </PopoverPrimitive.Portal>
75 );
76}
77
78function PopoverClose({ ...props }: PopoverPrimitive.Close.Props) {
79 return <PopoverPrimitive.Close data-slot="popover-close" {...props} />;
80}
81
82function PopoverTitle({ className, ...props }: PopoverPrimitive.Title.Props) {
83 return (
84 <PopoverPrimitive.Title
85 className={cn("font-semibold text-lg leading-none", className)}
86 data-slot="popover-title"
87 {...props}
88 />
89 );
90}
91
92function PopoverDescription({ className, ...props }: PopoverPrimitive.Description.Props) {
93 return (
94 <PopoverPrimitive.Description
95 className={cn("text-muted-foreground text-sm", className)}
96 data-slot="popover-description"
97 {...props}
98 />
99 );
100}
101
102export {
103 PopoverCreateHandle,
104 Popover,
105 PopoverTrigger,
106 PopoverPopup,
107 PopoverPopup as PopoverContent,
108 PopoverTitle,
109 PopoverDescription,
110 PopoverClose,
111};