2021-12-14 15:28:54 -08:00
|
|
|
import React, { forwardRef, useRef } from "react";
|
|
|
|
import { DismissButton, useOverlay } from "@react-aria/overlays";
|
2021-12-06 17:34:10 -08:00
|
|
|
import { FocusScope } from "@react-aria/focus";
|
|
|
|
import classNames from "classnames";
|
|
|
|
import styles from "./Popover.module.css";
|
2021-12-23 14:40:23 -08:00
|
|
|
import { useObjectRef } from "@react-aria/utils";
|
2021-12-06 17:34:10 -08:00
|
|
|
|
|
|
|
export const Popover = forwardRef(
|
|
|
|
({ isOpen = true, onClose, className, children, ...rest }, ref) => {
|
2021-12-23 14:40:23 -08:00
|
|
|
const popoverRef = useObjectRef(ref);
|
2021-12-14 15:28:54 -08:00
|
|
|
|
2021-12-06 17:34:10 -08:00
|
|
|
const { overlayProps } = useOverlay(
|
|
|
|
{
|
|
|
|
isOpen,
|
|
|
|
onClose,
|
|
|
|
shouldCloseOnBlur: true,
|
|
|
|
isDismissable: true,
|
|
|
|
},
|
2021-12-14 15:28:54 -08:00
|
|
|
popoverRef
|
2021-12-06 17:34:10 -08:00
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
2021-12-14 15:28:54 -08:00
|
|
|
<FocusScope restoreFocus>
|
|
|
|
<div
|
|
|
|
{...overlayProps}
|
|
|
|
{...rest}
|
|
|
|
className={classNames(styles.popover, className)}
|
|
|
|
ref={popoverRef}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
<DismissButton onDismiss={onClose} />
|
|
|
|
</div>
|
|
|
|
</FocusScope>
|
2021-12-06 17:34:10 -08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|