mirror of
https://github.com/router-for-me/Cli-Proxy-API-Management-Center.git
synced 2026-02-03 03:10:50 +08:00
36 lines
1.0 KiB
TypeScript
36 lines
1.0 KiB
TypeScript
import type { PropsWithChildren, ReactNode } from 'react';
|
|
import { IconX } from './icons';
|
|
|
|
interface ModalProps {
|
|
open: boolean;
|
|
title?: ReactNode;
|
|
onClose: () => void;
|
|
footer?: ReactNode;
|
|
width?: number | string;
|
|
}
|
|
|
|
export function Modal({ open, title, onClose, footer, width = 520, children }: PropsWithChildren<ModalProps>) {
|
|
if (!open) return null;
|
|
|
|
const handleMaskClick = (event: React.MouseEvent<HTMLDivElement>) => {
|
|
if (event.target === event.currentTarget) {
|
|
onClose();
|
|
}
|
|
};
|
|
|
|
return (
|
|
<div className="modal-overlay" onClick={handleMaskClick}>
|
|
<div className="modal" style={{ width }} role="dialog" aria-modal="true">
|
|
<div className="modal-header">
|
|
<div className="modal-title">{title}</div>
|
|
<button className="modal-close" onClick={onClose} aria-label="Close">
|
|
<IconX size={18} />
|
|
</button>
|
|
</div>
|
|
<div className="modal-body">{children}</div>
|
|
{footer && <div className="modal-footer">{footer}</div>}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|