Skip to content

Commit

Permalink
Modal animation
Browse files Browse the repository at this point in the history
  • Loading branch information
kichan05 committed Feb 14, 2024
1 parent cd38f99 commit 712277b
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 26 deletions.
25 changes: 25 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"react-dom": "^18.2.0",
"react-icons": "^5.0.1",
"react-scripts": "5.0.1",
"react-transition-group": "^4.4.5",
"styled-components": "^6.1.8",
"web-vitals": "^2.1.4"
},
Expand Down
51 changes: 30 additions & 21 deletions src/component/Modal.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import styled, {keyframes} from "styled-components";
import styled, {css, keyframes} from "styled-components";
import Button from "./Button";
import {UI_ACTION_TYPE, useUiDispatch} from "../context/UiReducer";
import {useEffect, useState} from "react";
import {CSSTransition} from "react-transition-group";

const fadeIn = keyframes`
0% {
Expand Down Expand Up @@ -59,9 +60,16 @@ const ModalStyle = styled.div`
top: 0;
left: 0;
animation-name: ${p => p.isShow ? fadeIn : fadeOut};
animation-duration: 250ms;
animation-duration: ${p=> p.timeout}ms;
animation-timing-function: ease-out;
${({state}) => css`
${state === "entering" && css`
animation-name: ${fadeIn};
`}
${state === "exiting" && css`
animation-name: ${fadeOut};
`}
`}
`

const ModalContent = styled.div`
Expand All @@ -72,23 +80,20 @@ const ModalContent = styled.div`
border-radius: 8px;
padding: 12px;
animation-name: ${p => p.isShow ? scaleUp : scaleDown};
animation-duration: 250ms;
animation-duration: ${p=> p.timeout}ms;
animation-timing-function: ease-out;
${({state}) => css`
${state === "entering" && css`
animation-name: ${scaleUp};
`}
${state === "exiting" && css`
animation-name: ${scaleDown};
`}
`}
`

const Modal = ({isShow}) => {
const uiDispatch = useUiDispatch()
const [isAnimation, setIsAnimation] = useState(false)

useEffect(() => {
if (!isShow) {
setIsAnimation(true)
setTimeout(() => {
setIsAnimation(false)
}, 240)
}
}, [isShow])

const closeModal = (e) => {
if(e.target !== e.currentTarget)
Expand All @@ -97,12 +102,16 @@ const Modal = ({isShow}) => {
uiDispatch({type: UI_ACTION_TYPE.modal_hide})
}

return (isShow || isAnimation) && (
<ModalStyle onClick={closeModal} isShow={isShow}>
<ModalContent isShow={isShow}>
<Button onClick={closeModal}>닫기</Button>
</ModalContent>
</ModalStyle>
return (
<CSSTransition in={isShow} timeout={250} unmountOnExit>
{state => (
<ModalStyle onClick={closeModal} state={state} timeout={250}>
<ModalContent>
<Button onClick={closeModal}>닫기</Button>
</ModalContent>
</ModalStyle>
)}
</CSSTransition>
)
}

Expand Down
14 changes: 9 additions & 5 deletions src/section/FirstSection.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import styled from "styled-components";
import {downUp, showLeft, animation, showRight} from "../style/animation";
import {GoChevronDown} from "react-icons/go";
import {UI_ACTION_TYPE, useUiDispatch} from "../context/UiReducer";

const FirstSectionStyle = styled.section`
width: 100%;
Expand Down Expand Up @@ -106,12 +107,15 @@ const FirstSectionStyle = styled.section`
`

export const FirstSection = () => {
const dispatch = useUiDispatch()

const scrollDown = () => {
window.scrollTo({
left: 0,
top: window.innerHeight,
behavior: "smooth"
})
dispatch({type: UI_ACTION_TYPE.modal_show})
// window.scrollTo({
// left: 0,
// top: window.innerHeight,
// behavior: "smooth"
// })
}

return (
Expand Down

0 comments on commit 712277b

Please sign in to comment.