AVIS / frontend /src /components /common /Modal.jsx
X2-0's picture
HF Clean Deploy
1c0c94d
Raw
History Blame Contribute Delete
767 Bytes
import { useEffect } from 'react'
export default function Modal({ title, icon, onClose, children }) {
useEffect(() => {
const onKey = (e) => e.key === 'Escape' && onClose()
window.addEventListener('keydown', onKey)
return () => window.removeEventListener('keydown', onKey)
}, [onClose])
return (
<div className="modal-overlay" onClick={onClose}>
<div className="modal" onClick={(e) => e.stopPropagation()}>
<div className="modal-head">
{icon && <span style={{ fontSize: 24 }}>{icon}</span>}
<b>{title}</b>
<button className="x" onClick={onClose} aria-label="close">
×
</button>
</div>
<div className="modal-body">{children}</div>
</div>
</div>
)
}