import React, { ReactNode, CSSProperties, useRef, useEffect } from 'react'; // components import Typography from '../../Typography'; import CircularProgress from '../../CircularProgress'; // @ts-ignore import CloseNew from '../../../../assets/images/modal-icons/close-new.svg' // 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; isQRCode?: boolean; } const buttonStyles: CSSProperties = { color: '#fff', backgroundColor: 'var(--primary-color)', maxWidth: '100%', minHeight: '50px', border: '0.5px solid var(--border-color)', fontSize: '14px', borderRadius: '8px' }; const heading: CSSProperties = { color: '#000', fontWeight: '600', textAlign: 'center', margin: '0', }; const subHeadingStyle: CSSProperties = { fontSize: '16px', color: '#656565', fontWeight: '400', textAlign: 'center', width: '100%', maxWidth: '400px', margin: '0', fontFamily: 'var(--font-family)', lineHeight: '20px', }; const progressStyles: CSSProperties = { width: '20px', height: '20px', border: '2px solid #fff', }; const DialogV2: React.FC = ({ icon = null, customStyles = {}, open, handleClose, loading = false, title = "", subHeading = "", description = "", onSubmit, onCancel, cancelText = "", submitText = "", children = [], isGallery = false, currentTheme = "default", isQRCode = false }) => { 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 ( <> { isGallery || isQRCode ? (
{title} close
{icon &&
{icon}
} {subHeading && ( {subHeading} )} {description && ( {description} )} {children}
{(!isGallery || isQRCode) && <> }
) : (
{icon &&
{icon}
} {title} close
{subHeading && ( {subHeading} )} {description && ( {description} )} {children}
{!isGallery && <> }
) } ); }; export default DialogV2;