computer-scienceangular-roadmapbackend-roadmapblockchain-roadmapdba-roadmapdeveloper-roadmapdevops-roadmapfrontend-roadmapgo-roadmaphactoberfestjava-roadmapjavascript-roadmapnodejs-roadmappython-roadmapqa-roadmapreact-roadmaproadmapstudy-planvue-roadmapweb3-roadmap
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.1 KiB
47 lines
1.1 KiB
1 year ago
|
import { type ReactNode, useRef } from 'react';
|
||
|
import { useOutsideClick } from '../hooks/use-outside-click';
|
||
|
import { useKeydown } from '../hooks/use-keydown';
|
||
|
import { cn } from '../lib/classname';
|
||
|
|
||
|
type ModalProps = {
|
||
|
onClose: () => void;
|
||
|
children: ReactNode;
|
||
|
bodyClassName?: string;
|
||
|
wrapperClassName?: string;
|
||
|
};
|
||
|
|
||
|
export function Modal(props: ModalProps) {
|
||
|
const { onClose, children, bodyClassName, wrapperClassName } = props;
|
||
|
|
||
|
const popupBodyEl = useRef<HTMLDivElement>(null);
|
||
|
|
||
|
useKeydown('Escape', () => {
|
||
|
onClose();
|
||
|
});
|
||
|
|
||
|
useOutsideClick(popupBodyEl, () => {
|
||
|
onClose();
|
||
|
});
|
||
|
|
||
|
return (
|
||
|
<div className="popup fixed left-0 right-0 top-0 z-[99] flex h-full items-center justify-center overflow-y-auto overflow-x-hidden bg-black/50">
|
||
|
<div
|
||
|
className={cn(
|
||
|
'relative h-full w-full max-w-md p-4 md:h-auto',
|
||
|
wrapperClassName
|
||
|
)}
|
||
|
>
|
||
|
<div
|
||
|
ref={popupBodyEl}
|
||
|
className={cn(
|
||
|
'popup-body relative h-full rounded-lg bg-white shadow',
|
||
|
bodyClassName
|
||
|
)}
|
||
|
>
|
||
|
{children}
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
);
|
||
|
}
|