✨(react) add a popover component
A design system needs a popover mecanism. In the select component, this logic is handled by downshift. We introduce a new component, responsible to open an element in a popin and close it when the user click outside of it.
This commit is contained in:
committed by
aleb_the_flash
parent
f967775fb6
commit
1d1cf81cf6
28
packages/react/src/components/Popover/index.tsx
Normal file
28
packages/react/src/components/Popover/index.tsx
Normal file
@@ -0,0 +1,28 @@
|
||||
import React, { PropsWithChildren, RefObject } from "react";
|
||||
import classNames from "classnames";
|
||||
import { useHandleClickOutside } from ":/hooks/useHandleClickOutside";
|
||||
|
||||
type PopoverProps = PropsWithChildren & {
|
||||
parentRef: RefObject<HTMLDivElement>;
|
||||
onClickOutside: () => void;
|
||||
borderless?: boolean;
|
||||
};
|
||||
|
||||
export const Popover = ({
|
||||
parentRef,
|
||||
children,
|
||||
onClickOutside,
|
||||
borderless = false,
|
||||
}: PopoverProps) => {
|
||||
useHandleClickOutside(parentRef, onClickOutside);
|
||||
|
||||
return (
|
||||
<div
|
||||
className={classNames("c__popover", {
|
||||
"c__popover--borderless": borderless,
|
||||
})}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user