import React from 'react'; import { DialogContent, IconButton, SvgIcon } from '@mui/material'; import { ModalActions, ModalContainer, ModalPaper, ModalRoot, ModalRootBackdrop, ModalTitle, ModalTitleCaption } from './style'; type SizeProp = 'xxl' | 'xl' | 'l' | 'm' | 's' | 'xs' | 'xxs' | string | number; type Size = { min?: SizeProp, max?: SizeProp, set?: SizeProp, } type ScrollProp = 'hidden' | 'x' | 'y' | 'auto'; interface DialogProps { className?: string; unclosable?: boolean, open: boolean; caption: string; width?: Size, height?: Size, padding?: string | number, scroll?: ScrollProp, actions?: JSX.Element; onClose?: () => void; children?: React.ReactNode | React.ReactNode[] | any } export const Dialog: React.FC = ({ className, unclosable, open, width, height, scroll, padding, caption, children, actions, onClose }) => { const handleClose = () => { if (onClose) { onClose(); } } const scrollToCSS = (scroll?: ScrollProp) => { switch (scroll) { case 'x': return { overflowX: 'auto' as any, overflowY: 'hidden' as any } case 'y': return { overflowX: 'hidden' as any, overflowY: 'auto' as any } case 'auto': return { overflowX: 'auto' as any, overflowY: 'auto' as any } default: return { overflowX: 'hidden' as any, overflowY: 'hidden' as any } } } const sizeToCSS = (size?: SizeProp) => { return size ? size === 'xxl' ? '2048px' : size === 'xl' ? '1536px' : size === 'l' ? '1024px' : size === 'm' ? '800px' : size === 's' ? '600px' : size === 'xs' ? '400px' : size === 'xxs' ? '200px' : size : 'unset' } const getPaperStyle = (width?: Size, height?: Size, scroll?: ScrollProp) => { return { width: width ? sizeToCSS(width.set) : 'unset', minWidth: width ? sizeToCSS(width.min) : 'unset', maxWidth: width ? sizeToCSS(width.max) : 'unset', height: height ? sizeToCSS(height.set) : 'unset', minHeight: height ? sizeToCSS(height.min) : 'unset', maxHeight: height ? sizeToCSS(height.max) : 'unset', overflow: 'hidden' } } return ( <> { open && {caption} { !unclosable && } {children} { !!actions && {actions} } } ); } const CloseIcon = () => ( )