diff --git a/src/frontend/components/UI/Dialog/components/Dialog.tsx b/src/frontend/components/UI/Dialog/components/Dialog.tsx index 10076db8e7..345872b89b 100644 --- a/src/frontend/components/UI/Dialog/components/Dialog.tsx +++ b/src/frontend/components/UI/Dialog/components/Dialog.tsx @@ -1,16 +1,20 @@ -import { faXmark } from '@fortawesome/free-solid-svg-icons' -import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' -import ContextProvider from 'frontend/state/ContextProvider' import React, { - KeyboardEvent, ReactNode, - SyntheticEvent, useCallback, useContext, useEffect, - useRef, useState } from 'react' +import { + Dialog as MuiDialog, + DialogContent, + IconButton, + Paper, + styled +} from '@mui/material' +import CloseIcon from '@mui/icons-material/Close' + +import ContextProvider from 'frontend/state/ContextProvider' interface DialogProps { className?: string @@ -19,15 +23,22 @@ interface DialogProps { onClose: () => void } +const StyledPaper = styled(Paper)(() => ({ + backgroundColor: 'var(--modal-background)', + color: 'var(--text-default)', + maxWidth: '100%', + '&:has(.settingsDialogContent)': { + height: '80%' + } +})) + export const Dialog: React.FC = ({ children, className, showCloseButton = false, onClose }) => { - const dialogRef = useRef(null) - const onCloseRef = useRef(onClose) - onCloseRef.current = onClose + const [open, setOpen] = useState(true) const [focusOnClose, setFocusOnClose] = useState(null) const { disableDialogBackdropClose } = useContext(ContextProvider) @@ -35,84 +46,49 @@ export const Dialog: React.FC = ({ setFocusOnClose(document.querySelector('*:focus')) }, []) - const close = () => { - onCloseRef.current() + const close = useCallback(() => { + setOpen(false) + onClose() if (focusOnClose) { setTimeout(() => focusOnClose.focus(), 200) } - } - - useEffect(() => { - const dialog = dialogRef.current - if (dialog) { - const cancel = () => { - close() - } - dialog.addEventListener('cancel', cancel) - - if (disableDialogBackdropClose) { - dialog['showPopover']() - - return () => { - dialog.removeEventListener('cancel', cancel) - dialog['hidePopover']() - } - } else { - dialog.showModal() - - return () => { - dialog.removeEventListener('cancel', cancel) - dialog.close() - } - } - } - return - }, [dialogRef.current, disableDialogBackdropClose]) - - const onDialogClick = useCallback( - (e: SyntheticEvent) => { - if (e.target === dialogRef.current) { - const ev = e.nativeEvent as MouseEvent - const tg = e.target as HTMLElement - if ( - ev.offsetX < 0 || - ev.offsetX > tg.offsetWidth || - ev.offsetY < 0 || - ev.offsetY > tg.offsetHeight - ) { - close() - } - } - }, - [onClose] - ) - - const closeIfEsc = (event: KeyboardEvent) => { - if (event.key === 'Escape') { - close() - } - } + }, [onClose, focusOnClose]) return ( -
- + + <> {showCloseButton && ( -
- -
+ + + )} - {children} -
-
+ {children} + + ) } diff --git a/src/frontend/screens/Settings/components/SettingsModal/index.scss b/src/frontend/screens/Settings/components/SettingsModal/index.scss index 59fd6ba37a..1af39519d6 100644 --- a/src/frontend/screens/Settings/components/SettingsModal/index.scss +++ b/src/frontend/screens/Settings/components/SettingsModal/index.scss @@ -10,17 +10,3 @@ width: 100%; } } - -.InstallModal__dialog:has(.settingsDialogContent) { - margin-top: max(2rem, 13vh); - @media screen and (max-height: 800px) { - margin-top: max(2rem, 8vh); - .settingsDialogContent { - min-height: 70vh; - } - } - - @media screen and (max-height: 700px) { - margin-top: max(2rem, 6vh); - } -}