Raw
1 import { Popover as RadixPopover } from "radix-ui"
2 import * as React from "react"
3
4 import { clx } from "@/utils/clx"
5
6 /**
7 * This component is based on the [Radix UI Popover](https://www.radix-ui.com/primitives/docs/components/popover) primitves.
8 */
9 const Root = (
10 props: React.ComponentPropsWithoutRef<typeof RadixPopover.Root>
11 ) => {
12 return <RadixPopover.Root {...props} />
13 }
14 Root.displayName = "Popover"
15
16 const Trigger = React.forwardRef<
17 React.ElementRef<typeof RadixPopover.Trigger>,
18 React.ComponentPropsWithoutRef<typeof RadixPopover.Trigger>
19 >((props, ref) => {
20 return <RadixPopover.Trigger ref={ref} {...props} />
21 })
22 Trigger.displayName = "Popover.Trigger"
23
24 const Anchor = React.forwardRef<
25 React.ElementRef<typeof RadixPopover.Anchor>,
26 React.ComponentPropsWithoutRef<typeof RadixPopover.Anchor>
27 >((props, ref) => {
28 return <RadixPopover.Anchor ref={ref} {...props} />
29 })
30 Anchor.displayName = "Popover.Anchor"
31
32 const Close = React.forwardRef<
33 React.ElementRef<typeof RadixPopover.Close>,
34 React.ComponentPropsWithoutRef<typeof RadixPopover.Close>
35 >((props, ref) => {
36 return <RadixPopover.Close ref={ref} {...props} />
37 })
38 Close.displayName = "Popover.Close"
39
40 interface ContentProps
41 extends React.ComponentPropsWithoutRef<typeof RadixPopover.Content> {}
42
43 /**
44 * @excludeExternal
45 */
46 const Content = React.forwardRef<
47 React.ElementRef<typeof RadixPopover.Content>,
48 ContentProps
49 >(
50 (
51 {
52 className,
53 /**
54 * The distance in pixels from the anchor.
55 */
56 sideOffset = 8,
57 /**
58 * The preferred side of the anchor to render against when open.
59 * Will be reversed when collisions occur and `avoidCollisions` is enabled.
60 */
61 side = "bottom",
62 /**
63 * The preferred alignment against the anchor. May change when collisions occur.
64 */
65 align = "start",
66 collisionPadding,
67 ...props
68 }: ContentProps,
69 ref
70 ) => {
71 return (
72 <RadixPopover.Portal>
73 <RadixPopover.Content
74 ref={ref}
75 sideOffset={sideOffset}
76 side={side}
77 align={align}
78 collisionPadding={collisionPadding}
79 className={clx(
80 "bg-ui-bg-base text-ui-fg-base shadow-elevation-flyout max-h-[var(--radix-popper-available-height)] min-w-[220px] overflow-hidden rounded-lg p-1",
81 "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",
82 className
83 )}
84 {...props}
85 />
86 </RadixPopover.Portal>
87 )
88 }
89 )
90 Content.displayName = "Popover.Content"
91
92 const Seperator = React.forwardRef<
93 HTMLDivElement,
94 React.ComponentPropsWithoutRef<"div">
95 >(({ className, ...props }, ref) => {
96 return (
97 <div
98 ref={ref}
99 className={clx("bg-ui-border-base -mx-1 my-1 h-px", className)}
100 {...props}
101 />
102 )
103 })
104 Seperator.displayName = "Popover.Seperator"
105
106 const Popover = Object.assign(Root, {
107 Trigger,
108 Anchor,
109 Close,
110 Content,
111 Seperator,
112 })
113
114 export { Popover }