-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'Feature/#119_모달_공통_컴포넌트_구현' of https://github.com/boost…
…campwm-2024/web33-Nocta into Feature/#127_탭_브라우징_피드백_반영
- Loading branch information
Showing
7 changed files
with
214 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { cva, cx } from "@styled-system/css"; | ||
import { glassContainer } from "@styled-system/recipes"; | ||
|
||
export const textButtonContainer = ({ variant }: { variant: "primary" | "secondary" }) => { | ||
return cx(glassContainer({ border: "lg" }), textButton({ variant })); | ||
}; | ||
|
||
const textButton = cva({ | ||
base: { | ||
borderRadius: "md", | ||
width: "150px", | ||
height: "40px", | ||
cursor: "pointer", | ||
}, | ||
variants: { | ||
variant: { | ||
primary: { | ||
background: "white/35", | ||
_hover: { | ||
background: "white/40", | ||
}, | ||
}, | ||
secondary: { | ||
background: "transparent", | ||
_hover: { | ||
background: "white/10", | ||
}, | ||
}, | ||
}, | ||
}, | ||
defaultVariants: { | ||
variant: "primary", | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { textButtonContainer } from "./textButton.style"; | ||
|
||
interface TextButtonProps { | ||
variant?: "primary" | "secondary"; | ||
children: React.ReactNode; | ||
onClick?: () => void; | ||
} | ||
|
||
export const TextButton = ({ variant = "primary", children, onClick }: TextButtonProps) => { | ||
return ( | ||
<button className={textButtonContainer({ variant })} onClick={onClick}> | ||
{children} | ||
</button> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
export const overlayAnimation = { | ||
initial: { | ||
opacity: 0, | ||
}, | ||
animate: { | ||
opacity: 1, | ||
}, | ||
exit: { | ||
opacity: 0, | ||
}, | ||
}; | ||
|
||
export const modalContainerAnimation = { | ||
initial: { | ||
scale: 0.7, | ||
opacity: 0, | ||
top: "50%", | ||
left: "50%", | ||
transform: "translate(-50%, -50%)", | ||
}, | ||
animate: { | ||
scale: 1, | ||
opacity: 1, | ||
}, | ||
exit: { | ||
scale: 0.7, | ||
opacity: 0, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { css, cx } from "@styled-system/css"; | ||
import { glassContainer } from "@styled-system/recipes"; | ||
|
||
export const container = css({ | ||
display: "flex", | ||
zIndex: 10000, | ||
position: "fixed", | ||
inset: 0, | ||
justifyContent: "center", | ||
alignItems: "center", | ||
width: "100vw", | ||
height: "100vh", | ||
}); | ||
|
||
export const overlayBox = css({ | ||
position: "absolute", | ||
inset: 0, | ||
width: "100%", | ||
height: "100%", | ||
background: "gray.500/30", | ||
backdropFilter: "blur(5px)", | ||
}); | ||
|
||
export const modalContainer = cx( | ||
glassContainer({ border: "lg" }), | ||
css({ | ||
display: "flex", | ||
zIndex: 10001, | ||
position: "absolute", | ||
top: "50%", | ||
left: "50%", | ||
transform: "translate(-50%, -50%)", | ||
flexDirection: "column", | ||
width: "400px", | ||
height: "200px", | ||
padding: "md", | ||
boxShadow: "md", | ||
}), | ||
); | ||
export const modalContent = css({ | ||
display: "flex", | ||
justifyContent: "center", | ||
alignItems: "center", | ||
width: "100%", | ||
height: "100%", | ||
textAlign: "center", | ||
}); | ||
|
||
export const buttonContainer = css({ | ||
display: "flex", | ||
gap: "md", | ||
justifyContent: "center", | ||
alignItems: "center", | ||
width: "100%", | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { motion, AnimatePresence } from "framer-motion"; | ||
import { createPortal } from "react-dom"; | ||
import { TextButton } from "../button/textButton"; | ||
import { modalContainerAnimation, overlayAnimation } from "./modal.animation"; | ||
import { | ||
buttonContainer, | ||
container, | ||
modalContainer, | ||
modalContent, | ||
overlayBox, | ||
} from "./modal.style"; | ||
|
||
interface ModalProps { | ||
isOpen: boolean; | ||
children: React.ReactNode; | ||
primaryButtonLabel: string; | ||
primaryButtonOnClick: () => void; | ||
secondaryButtonLabel?: string; | ||
secondaryButtonOnClick?: () => void; | ||
} | ||
|
||
export const Modal = ({ | ||
isOpen, | ||
children, | ||
primaryButtonLabel, | ||
primaryButtonOnClick, | ||
secondaryButtonLabel, | ||
secondaryButtonOnClick, | ||
}: ModalProps) => { | ||
const portal = document.getElementById("modal") as HTMLElement; | ||
|
||
return createPortal( | ||
<AnimatePresence> | ||
{isOpen && ( | ||
<div className={container}> | ||
<motion.div | ||
initial={overlayAnimation.initial} | ||
animate={overlayAnimation.animate} | ||
exit={overlayAnimation.exit} | ||
className={overlayBox} | ||
/> | ||
|
||
<motion.div | ||
initial={modalContainerAnimation.initial} | ||
animate={modalContainerAnimation.animate} | ||
exit={modalContainerAnimation.exit} | ||
className={modalContainer} | ||
> | ||
<div className={modalContent}>{children}</div> | ||
<div className={buttonContainer}> | ||
{secondaryButtonLabel && ( | ||
<TextButton onClick={secondaryButtonOnClick} variant="secondary"> | ||
{secondaryButtonLabel} | ||
</TextButton> | ||
)} | ||
<TextButton onClick={primaryButtonOnClick}>{primaryButtonLabel}</TextButton> | ||
</div> | ||
</motion.div> | ||
</div> | ||
)} | ||
</AnimatePresence>, | ||
portal, | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { useState } from "react"; | ||
|
||
export const useModal = () => { | ||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
const openModal = () => setIsOpen(true); | ||
const closeModal = () => setIsOpen(false); | ||
|
||
return { | ||
isOpen, | ||
openModal, | ||
closeModal, | ||
}; | ||
}; |