import { type ReactNode } from 'react'; import { Dialog as MuiDialog, DialogTitle, DialogContent, DialogActions, type DialogProps, IconButton, Typography } from '@mui/material'; import { Close as CloseIcon } from '@mui/icons-material'; import clsx from 'clsx'; import './rds-modal.scss'; export interface RdsModalProps extends Omit { title?: string; visibility?: 'open' | 'closed'; onClose: () => void; actions?: ReactNode; headerChrome?: 'closeable' | 'plain'; icon?: ReactNode; media?: 'none' | 'icon' | 'image' | 'both'; imageSrc?: string; body?: 'visible' | 'hidden'; [key: string]: unknown; } const RdsModal= ({ title, visibility, onClose, actions, headerChrome, icon, media, body, imageSrc, children, ...props }: RdsModalProps) => { const legacyIsOpen = typeof props['isOpen'] === 'boolean' ? (props['isOpen'] as boolean) : undefined; const legacyShowCloseButton = typeof props['showCloseButton'] === 'boolean' ? (props['showCloseButton'] as boolean) : undefined; const legacyShowIcon = typeof props['showIcon'] === 'boolean' ? (props['showIcon'] as boolean) : undefined; const legacyShowDescription = typeof props['showDescription'] === 'boolean' ? (props['showDescription'] as boolean) : undefined; const resolvedIsOpen = visibility === 'open' ? true : visibility === 'closed' ? false : (legacyIsOpen ?? true); const resolvedShowCloseButton = headerChrome === 'closeable' ? true : headerChrome === 'plain' ? false : (legacyShowCloseButton ?? true); const resolvedShowDescription = body === 'visible' ? true : body === 'hidden' ? false : (legacyShowDescription ?? true); const resolvedShowIcon = media === 'none' ? false : media === 'icon' || media === 'both' ? true : (legacyShowIcon ?? true); const resolvedImageSrc = typeof imageSrc === 'string' && imageSrc.trim() ? imageSrc : undefined; const showImage = media === 'none' || media === 'icon' ? false : media === 'image' || media === 'both' ? true : Boolean(resolvedImageSrc); const hasImageHeader = Boolean(resolvedImageSrc && showImage); const closeButton = resolvedShowCloseButton ? ( ) : null; return ( {(title || icon || resolvedImageSrc) && ( {hasImageHeader && closeButton && (
{closeButton}
)}
{(icon && resolvedShowIcon) || (resolvedImageSrc && showImage) ? (
{icon && resolvedShowIcon && ( {icon} )} {resolvedImageSrc && showImage && ( Modal )}
) : null}
{title} {!hasImageHeader && closeButton}
)} {resolvedShowDescription && children} {actions && ( {actions} )}
); }; RdsModal.displayName = 'RdsModal'; export default RdsModal;