-
Notifications
You must be signed in to change notification settings - Fork 9
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
Menu 컴포넌트 CSS 수정 #127
Menu 컴포넌트 CSS 수정 #127
Changes from all commits
1cff61a
200f4c2
8485558
07e0b49
9a6dd0f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
/** @jsx jsx */ | ||
/** @jsxRuntime classic */ | ||
import { jsx, css } from '@emotion/react'; | ||
import styled from '@emotion/styled'; | ||
import { useRecoilState } from 'recoil'; | ||
import { animated, useSpring, useTransition } from 'react-spring'; | ||
|
||
import { HeaderButton } from '@components/atoms'; | ||
import { ReactComponent as HamburgerMenu } from '@assets/hamburgerMenu.svg'; | ||
import { ReactComponent as DoubleChevronRight } from '@assets/doubleChevronRight.svg'; | ||
import { hoveredMenuToggleState, staticMenuToggleState } from '@/stores'; | ||
import { Menu } from '@molecules/index'; | ||
|
||
const wrapperCss = () => css` | ||
const wrapperCss = css` | ||
position: relative; | ||
display: flex; | ||
align-items: center; | ||
|
@@ -21,20 +23,25 @@ const wrapperCss = () => css` | |
margin-right: 8px; | ||
min-width: 0; | ||
`; | ||
const hoverAreaCss = () => css` | ||
const hoverAreaCss = css` | ||
position: absolute; | ||
display: inline-block; | ||
top: 45px; | ||
left: 0; | ||
width: 100%; | ||
height: 100vh; | ||
`; | ||
const menuCss = (staticMenuToggle: boolean) => css` | ||
const AnimatedMenu = styled(animated.div)` | ||
position: absolute; | ||
display: inline-block; | ||
top: ${staticMenuToggle ? 0 : 50}px; | ||
left: 0; | ||
margin-top: ${staticMenuToggle ? 0 : 10}px; | ||
`; | ||
const buttonWrapper = css` | ||
position: relative; | ||
width: 16px; | ||
height: 16px; | ||
`; | ||
const AnimatedButton = styled(animated.div)` | ||
position: absolute; | ||
`; | ||
|
||
function HeaderMenu(): JSX.Element { | ||
|
@@ -44,23 +51,41 @@ function HeaderMenu(): JSX.Element { | |
const [hoveredMenuToggle, setHoveredMenuToggle] = useRecoilState( | ||
hoveredMenuToggleState, | ||
); | ||
const menuStyleProps = useSpring({ | ||
top: staticMenuToggle ? 0 : 50, | ||
left: hoveredMenuToggle || staticMenuToggle ? 0 : -240, | ||
opacity: hoveredMenuToggle || staticMenuToggle ? 1 : 0, | ||
marginTop: staticMenuToggle ? 0 : 10, | ||
}); | ||
const hamburgerMenuStyleProps = useSpring({ | ||
opacity: hoveredMenuToggle ? 0 : 1, | ||
}); | ||
const doubleChevronRightStyleProps = useSpring({ | ||
opacity: hoveredMenuToggle ? 1 : 0, | ||
}); | ||
|
||
return ( | ||
<div | ||
css={wrapperCss()} | ||
css={wrapperCss} | ||
onMouseEnter={() => setHoveredMenuToggle(true)} | ||
onMouseLeave={() => setHoveredMenuToggle(false)} | ||
> | ||
<HeaderButton clickHandler={() => setStaticMenuToggle(!staticMenuToggle)}> | ||
{staticMenuToggle || | ||
(!hoveredMenuToggle ? <HamburgerMenu /> : <DoubleChevronRight />)} | ||
{staticMenuToggle || ( | ||
<div css={buttonWrapper}> | ||
<AnimatedButton style={hamburgerMenuStyleProps}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 참고해서 BlockHandler에 fadein-out 효과를 넣어보도록 하겠습니다. |
||
<HamburgerMenu /> | ||
</AnimatedButton> | ||
<AnimatedButton style={doubleChevronRightStyleProps}> | ||
<DoubleChevronRight /> | ||
</AnimatedButton> | ||
</div> | ||
)} | ||
</HeaderButton> | ||
<div css={hoverAreaCss()} /> | ||
{(staticMenuToggle || hoveredMenuToggle) && ( | ||
<div css={menuCss(staticMenuToggle)}> | ||
<Menu /> | ||
</div> | ||
)} | ||
<div css={hoverAreaCss} /> | ||
<AnimatedMenu style={menuStyleProps}> | ||
<Menu /> | ||
</AnimatedMenu> | ||
</div> | ||
); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,29 +7,28 @@ import { HeaderMenu } from '@components/organisms'; | |
import { useRecoilValue, useSetRecoilState } from 'recoil'; | ||
import { blockMapState, pageState, staticMenuToggleState } from '@/stores'; | ||
import { createBlock } from '@/utils'; | ||
import styled from '@emotion/styled'; | ||
import { animated, useSpring } from 'react-spring'; | ||
|
||
const staticMenuAreaCss = () => css` | ||
const staticMenuAreaCss = css` | ||
position: fixed; | ||
z-index: 2; | ||
`; | ||
const staticHeaderAreaCss = (staticMenuToggle: boolean) => css` | ||
const AnimatedStaticHeaderArea = styled(animated.div)` | ||
position: fixed; | ||
right: 0; | ||
left: ${staticMenuToggle ? 240 : 0}px; | ||
width: calc(100% - ${staticMenuToggle ? 240 : 0}px); | ||
background-color: #ffffff; | ||
z-index: 1; | ||
`; | ||
const staticScrollAreaCss = (staticMenuToggle: boolean) => css` | ||
const AnimatedStaticScrollArea = styled(animated.div)` | ||
position: fixed; | ||
top: 45px; | ||
right: 0; | ||
left: ${staticMenuToggle ? 240 : 0}px; | ||
width: calc(100% - ${staticMenuToggle ? 240 : 0}px); | ||
background-color: #ffffff; | ||
height: calc(100% - 45px); | ||
overflow: auto; | ||
`; | ||
const bottomMarginCss = () => css` | ||
const bottomMarginCss = css` | ||
display: inline-block; | ||
width: 100%; | ||
height: calc(100% - 200px); | ||
|
@@ -40,6 +39,10 @@ function PageComponent(): JSX.Element { | |
const staticMenuToggle = useRecoilValue(staticMenuToggleState); | ||
const page = useRecoilValue(pageState); | ||
const setBlockMap = useSetRecoilState(blockMapState); | ||
const staticAreaStyleProps = useSpring({ | ||
left: staticMenuToggle ? 240 : 0, | ||
width: `calc(100% - ${staticMenuToggle ? 240 : 0}px)`, | ||
}); | ||
|
||
const createBlockHandler = async () => { | ||
const { parent, block } = await createBlock({ parentBlockId: page.rootId }); | ||
|
@@ -53,21 +56,21 @@ function PageComponent(): JSX.Element { | |
|
||
return ( | ||
<div> | ||
<div css={staticMenuAreaCss()}> | ||
<div css={staticMenuAreaCss}> | ||
<HeaderMenu /> | ||
</div> | ||
<div css={staticHeaderAreaCss(staticMenuToggle)}> | ||
<AnimatedStaticHeaderArea style={staticAreaStyleProps}> | ||
<Header /> | ||
</div> | ||
<div css={staticScrollAreaCss(staticMenuToggle)}> | ||
</AnimatedStaticHeaderArea> | ||
<AnimatedStaticScrollArea style={staticAreaStyleProps}> | ||
Comment on lines
-59
to
+65
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 애니메이션 넘 부드러워용 😌 |
||
<Title /> | ||
<Editor /> | ||
<div | ||
css={bottomMarginCss()} | ||
css={bottomMarginCss} | ||
onClick={createBlockHandler} | ||
onKeyUp={createBlockHandler} | ||
/> | ||
</div> | ||
</AnimatedStaticScrollArea> | ||
</div> | ||
); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
react도 애니메이션 적용이 가능하네요.
커스텀 애니메이션 만들 걱정을 하고있었는데 좋은 참고가 되었습니다. :)
block handler도 애니메이션을 적용했으면 좋겠네요.