import React, { ReactNode, CSSProperties, useRef, useEffect } from 'react'; // components import Button from '../Button'; import Typography from '../Typography'; import CircularProgress from '../CircularProgress'; // cross-icon import Cross from '../../../assets/images/modal-icons/cross' import NewCancel from '../../../assets/images/modal-icons/new-cancel' // styles import './styles.scss'; interface DialogProps { icon?: ReactNode; customStyles?: CSSProperties; open: boolean; handleClose: () => void; loading?: boolean; title?: string | ReactNode; subHeading?: string; description?: string; onSubmit?: () => void; onCancel?: () => void; cancelText?: string; submitText?: string; children?: ReactNode; isGallery?: boolean; currentTheme?: string | null | undefined; } const buttonStyles: CSSProperties = { color: '#fff', backgroundColor: 'var(--primary-color)', maxWidth: '100px', minHeight: '40px', border: '0.5px solid var(--border-color)', fontSize: '14px', }; const heading: CSSProperties = { color: 'var(--primary-color)', fontWeight: '600', textAlign: 'center', }; const subHeadingStyle: CSSProperties = { fontSize: '16px', color: 'var(--text-color)', fontWeight: '600', textAlign: 'center', }; const progressStyles: CSSProperties = { width: '20px', height: '20px', border: '2px solid #fff', }; const Dialog: React.FC = ({ icon = null, customStyles = {}, open, handleClose, loading = false, title = "", subHeading = "", description = "", onSubmit, onCancel, cancelText = "", submitText = "", children = [], isGallery = false, currentTheme = "default" }) => { const contentAdjust = submitText.length > 6 ? "fit-content" : "100px"; const modalRef = useRef(null); const handleClickOutside = (event: MouseEvent) => { if (modalRef.current && !modalRef.current.contains(event.target as Node)) { handleClose(); } }; const handleKeyDown = (event: KeyboardEvent) => { if (event.key === 'Escape' && !loading) { handleClose(); } } useEffect(() => { if (open) { // document.addEventListener('mousedown', handleClickOutside); document.addEventListener('keydown', handleKeyDown); } else { // document.removeEventListener('mousedown', handleClickOutside); document.removeEventListener('keydown', handleKeyDown); } return () => { // document.removeEventListener('mousedown', handleClickOutside); document.removeEventListener('keydown', handleKeyDown); }; }, [open]); useEffect(() => { const handleCopy = (event: KeyboardEvent) => { if ((event.metaKey || event.ctrlKey) && event.key === 'c') { event.stopPropagation(); } }; document.addEventListener('keydown', handleCopy, true); return () => { document.removeEventListener('keydown', handleCopy, true); }; }, []); return (
{icon &&
{icon}
} {title} {subHeading && ( {subHeading} )} {description && ( {description} )} {children}
{!isGallery && <> }
); }; export default Dialog;