mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-01-15 21:53:36 +01:00
56 lines
1.2 KiB
TypeScript
56 lines
1.2 KiB
TypeScript
import classNames from 'classnames';
|
|
import FocusTrap from 'focus-trap-react';
|
|
import { motion } from 'framer-motion';
|
|
import type { ReactNode } from 'react';
|
|
import { Portal } from './Portal';
|
|
|
|
interface Props {
|
|
children: ReactNode;
|
|
portalName: string;
|
|
open: boolean;
|
|
onClose?: () => void;
|
|
zIndex?: keyof typeof zIndexes;
|
|
variant?: 'default' | 'transparent';
|
|
}
|
|
|
|
const zIndexes: Record<number, string> = {
|
|
10: 'z-10',
|
|
20: 'z-20',
|
|
30: 'z-30',
|
|
40: 'z-40',
|
|
50: 'z-50',
|
|
};
|
|
|
|
export function Overlay({
|
|
variant = 'default',
|
|
zIndex = 30,
|
|
open,
|
|
onClose,
|
|
portalName,
|
|
children,
|
|
}: Props) {
|
|
return (
|
|
<Portal name={portalName}>
|
|
{open && (
|
|
<FocusTrap>
|
|
<motion.div
|
|
className={classNames('fixed inset-0', zIndexes[zIndex])}
|
|
initial={{ opacity: 0 }}
|
|
animate={{ opacity: 1 }}
|
|
>
|
|
<div
|
|
aria-hidden
|
|
onClick={onClose}
|
|
className={classNames(
|
|
'absolute inset-0',
|
|
variant === 'default' && 'bg-gray-600/30 dark:bg-black/30 backdrop-blur-sm',
|
|
)}
|
|
/>
|
|
<div className="bg-red-100">{children}</div>
|
|
</motion.div>
|
|
</FocusTrap>
|
|
)}
|
|
</Portal>
|
|
);
|
|
}
|