- add a reusable modal component and export it from the shared ui barrel - gate all delete and remove flows behind explicit confirmation dialogs - use a solid modal surface color token with fallback to avoid transparent body
42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
import { useEffect } from 'react';
|
|
import styles from './Modal.module.css';
|
|
|
|
export interface ModalProps {
|
|
open: boolean;
|
|
title: string;
|
|
children?: React.ReactNode;
|
|
onClose: () => void;
|
|
footer?: React.ReactNode;
|
|
}
|
|
|
|
export function Modal({ open, title, children, onClose, footer }: ModalProps) {
|
|
useEffect(() => {
|
|
if (!open) return;
|
|
const onKeyDown = (event: KeyboardEvent) => {
|
|
if (event.key === 'Escape') onClose();
|
|
};
|
|
window.addEventListener('keydown', onKeyDown);
|
|
return () => window.removeEventListener('keydown', onKeyDown);
|
|
}, [open, onClose]);
|
|
|
|
if (!open) return null;
|
|
|
|
return (
|
|
<div className={styles.overlay} role="presentation" onClick={onClose}>
|
|
<div
|
|
className={styles.dialog}
|
|
role="dialog"
|
|
aria-modal="true"
|
|
aria-label={title}
|
|
onClick={(event) => event.stopPropagation()}
|
|
>
|
|
<div className={styles.header}>
|
|
<h3 className={styles.title}>{title}</h3>
|
|
</div>
|
|
<div className={styles.body}>{children}</div>
|
|
{footer && <div className={styles.footer}>{footer}</div>}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|