import { Close } from '@mui/icons-material' import { Box, Divider, IconButton, Modal, Sheet, Typography } from '@mui/joy' import useMediaQuery from '@mui/material/useMediaQuery' import { forwardRef, useId } from 'react' const WIDTH_BY_SIZE = { sm: 400, md: 520, lg: 680, xl: 840, } /** * The app's modal primitive. It owns modal layout, spacing, accessibility, * responsive presentation, and motion so feature components only own content. */ const AppModal = forwardRef( ( { open, onClose, children, title, description, footer, size = 'md', fullWidth = true, isMobile: isMobileProp, keepMounted = false, mobilePresentation = 'sheet', role = 'dialog', showCloseButton = true, showHandle = false, closeOnBackdrop = true, closeOnEscape = true, backdropBlur = true, maxHeight = '90dvh', contentSx, footerSx, sx, unmountDelay = 180, ...modalProps }, ref, ) => { const generatedId = useId() const detectedMobile = useMediaQuery('(max-width:768px)') const isMobile = isMobileProp ?? detectedMobile const titleId = title ? `${generatedId}-title` : undefined const descriptionId = description ? `${generatedId}-description` : undefined const isSheet = isMobile && mobilePresentation === 'sheet' const isFullscreen = isMobile && mobilePresentation === 'fullscreen' const handleClose = (event, reason) => { if (reason === 'backdropClick' && !closeOnBackdrop) return if (reason === 'escapeKeyDown' && !closeOnEscape) return onClose?.(event, reason) } return ( {isSheet && showHandle && ( ) }, ) AppModal.displayName = 'AppModal' export default AppModal