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-50 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 "relative flex h-(--popup-height,auto) w-(--popup-width,auto) origin-(--transform-origin) rounded-lg border bg-popover not-dark:bg-clip-padding text-popover-foreground shadow-lg/5 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 className,
64 )}
65 data-slot="popover-popup"
66 {...props}
67 >
68 <PopoverPrimitive.Viewport
69 className={cn(
70 "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",
71 tooltipStyle
72 ? "py-1 [--viewport-inline-padding:--spacing(2)]"
73 : "not-data-transitioning:overflow-y-auto",
74 viewportClassName,
75 )}
76 data-slot="popover-viewport"
77 >
78 {children}
79 </PopoverPrimitive.Viewport>
80 </PopoverPrimitive.Popup>
81 </PopoverPrimitive.Positioner>
82 </PopoverPrimitive.Portal>
83 );
84}
85
86function PopoverClose({ ...props }: PopoverPrimitive.Close.Props) {
87 return <PopoverPrimitive.Close data-slot="popover-close" {...props} />;
88}
89
90function PopoverTitle({ className, ...props }: PopoverPrimitive.Title.Props) {
91 return (
92 <PopoverPrimitive.Title
93 className={cn("font-semibold text-lg leading-none", className)}
94 data-slot="popover-title"
95 {...props}
96 />
97 );
98}
99
100function PopoverDescription({ className, ...props }: PopoverPrimitive.Description.Props) {
101 return (
102 <PopoverPrimitive.Description
103 className={cn("text-muted-foreground text-sm", className)}
104 data-slot="popover-description"
105 {...props}
106 />
107 );
108}
109
110export {
111 PopoverCreateHandle,
112 Popover,
113 PopoverTrigger,
114 PopoverPopup,
115 PopoverPopup as PopoverContent,
116 PopoverTitle,
117 PopoverDescription,
118 PopoverClose,
119};