Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Modals to be centered using flex instead of translation #200

Merged
merged 3 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions src/components/Modal/Modal.styled.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import styled from "@emotion/styled"
import { Box as BoxMui, Paper as PaperMui, useTheme } from "@mui/material"
import {
Box as BoxMui,
Modal as MuiModal,
Paper as PaperMui,
useTheme,
} from "@mui/material"
import { ModalProps } from "./Modal.types"

const Modal = styled(MuiModal)({
display: "flex",
alignItems: "center",
justifyContent: "center",
})

const ModalContainer = styled(PaperMui)((props: Pick<ModalProps, "size">) => {
const theme = useTheme()
let size = "900px"
Expand All @@ -12,10 +23,6 @@ const ModalContainer = styled(PaperMui)((props: Pick<ModalProps, "size">) => {
}

return {
position: "absolute" as const,
top: "50%",
left: "50%",
transform: "translate(-50%, -50%)",
width: size,
borderRadius: "12px",
overflow: "hidden",
Expand All @@ -26,9 +33,6 @@ const ModalContainer = styled(PaperMui)((props: Pick<ModalProps, "size">) => {
borderRadius: "0px",
margin: "0",
padding: "0",
top: "0",
left: "0",
transform: "translate(0, 0)",
},
}
})
Expand All @@ -55,6 +59,7 @@ const ModalActionsContainer = styled(BoxMui)({
})

export {
Modal,
ModalContainer,
ModalTitleContainer,
ModalContentContainer,
Expand Down
7 changes: 4 additions & 3 deletions src/components/Modal/Modal.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React from "react"
import ArrowBackIosNewRoundedIcon from "@mui/icons-material/ArrowBackIosNewRounded"
import CancelRoundedIcon from "@mui/icons-material/CancelRounded"
import { IconButton, Modal as MuiModal, Typography } from "@mui/material"
import { IconButton, Typography } from "@mui/material"
import { ModalProps } from "./Modal.types"
import {
Modal as BaseModal,
ModalActionsContainer,
ModalContainer,
ModalContentContainer,
Expand Down Expand Up @@ -66,11 +67,11 @@ const ModalContent = React.memo(
const Modal = React.memo((props: ModalProps) => {
const { open, onClose, children, ...modalContentProps } = props
return (
<MuiModal open={open} onClose={onClose}>
<BaseModal open={open} onClose={onClose}>
<ModalContent {...modalContentProps} onClose={onClose}>
{children}
</ModalContent>
</MuiModal>
</BaseModal>
)
})

Expand Down
Loading