-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopover.jsx
63 lines (60 loc) · 2.24 KB
/
popover.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import PropTypes from 'prop-types'
import {
Popover as AriaPopover,
composeRenderProps,
OverlayArrow,
PopoverContext,
useSlottedContext,
} from 'react-aria-components'
import { tv } from 'tailwind-variants'
const styles = tv({
base: 'rounded-xl border border-black/10 bg-white bg-clip-padding text-slate-700 shadow-2xl dark:border-white/[15%] dark:bg-zinc-900/70 dark:text-zinc-300 dark:backdrop-blur-2xl dark:backdrop-saturate-200 forced-colors:bg-[Canvas]',
variants: {
isEntering: {
true: 'duration-200 ease-out animate-in fade-in placement-left:slide-in-from-right-1 placement-right:slide-in-from-left-1 placement-top:slide-in-from-bottom-1 placement-bottom:slide-in-from-top-1',
},
isExiting: {
true: 'duration-150 ease-in animate-out fade-out placement-left:slide-out-to-right-1 placement-right:slide-out-to-left-1 placement-top:slide-out-to-bottom-1 placement-bottom:slide-out-to-top-1',
},
},
})
/**
* Renders a Popover component with the specified children, showArrow, className, and props.
*
* @param {object} props - The props for the Popover.
*/
export function Popover({ children, showArrow, className, ...props }) {
let popoverContext = useSlottedContext(PopoverContext)
let isSubmenu = popoverContext?.trigger === 'SubmenuTrigger'
let offset = showArrow ? 12 : 8
offset = isSubmenu ? offset - 6 : offset
return (
<AriaPopover
offset={offset}
{...props}
className={composeRenderProps(className, (className, renderProps) =>
styles({ ...renderProps, className })
)}
>
{showArrow && (
<OverlayArrow className="group">
<svg
width={12}
height={12}
viewBox="0 0 12 12"
className="block fill-white stroke-black/10 stroke-1 group-placement-left:-rotate-90 group-placement-right:rotate-90 group-placement-bottom:rotate-180 dark:fill-[#1f1f21] dark:stroke-zinc-600 forced-colors:fill-[Canvas] forced-colors:stroke-[ButtonBorder]"
>
<path d="M0 0 L6 6 L12 0" />
</svg>
</OverlayArrow>
)}
{children}
</AriaPopover>
)
}
Popover.propTypes = {
children: PropTypes.node,
showArrow: PropTypes.bool,
className: PropTypes.string,
placement: PropTypes.string,
}