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

Menu 컴포넌트 CSS 수정 #127

Merged
merged 5 commits into from
Dec 16, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
9 changes: 9 additions & 0 deletions frontend/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 frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"react-app-rewired": "^2.1.6",
"react-dom": "^17.0.1",
"react-scripts": "^4.0.1",
"react-spring": "^8.0.27",
"recoil": "^0.1.2",
"typescript": "^4.1.2",
"web-vitals": "^0.2.4"
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/components/atoms/HeaderButton/HeaderButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ const buttonCss = (): SerializedStyles => css`
user-select: none;
cursor: pointer;
color: inherit;
minwidth: 0px;
min-width: 0px;
padding: 6px;
margin: auto;
white-space: nowrap;
border-radius: 3px;
font-size: inherit;
border: 0;
outline: 0;
&:hover {
background-color: #cccccc;
}
Expand Down
16 changes: 11 additions & 5 deletions frontend/src/components/molecules/Menu/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ const plusCss = (staticMenuToggle: boolean) => css`
border: 1px solid rgba(55, 53, 47, 0.16);
border-radius: 3px;
`;
const menuListCss = () => css`
overflow-y: auto;
height: calc(100% - 44px);
`;

function Menu(): JSX.Element {
const [pages, setPages] = useRecoilState(pagesState);
Expand Down Expand Up @@ -93,11 +97,13 @@ function Menu(): JSX.Element {
</div>
)}
<div css={workspaceCss()}>WORKSPACE</div>
<Suspense fallback={<div>Loading...</div>}>
{pages.map((page) => (
<MenuItem key={page.id} page={page} />
))}
</Suspense>
<div css={menuListCss()}>
<Suspense fallback={<div>Loading...</div>}>
{pages.map((page) => (
<MenuItem key={page.id} page={page} />
))}
</Suspense>
</div>
</div>
);
}
Expand Down
29 changes: 16 additions & 13 deletions frontend/src/components/organisms/HeaderMenu/HeaderMenu.tsx
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;
Expand All @@ -21,20 +23,17 @@ 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;
`;

function HeaderMenu(): JSX.Element {
Expand All @@ -44,23 +43,27 @@ 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,
});

return (
<div
css={wrapperCss()}
css={wrapperCss}
onMouseEnter={() => setHoveredMenuToggle(true)}
onMouseLeave={() => setHoveredMenuToggle(false)}
>
<HeaderButton clickHandler={() => setStaticMenuToggle(!staticMenuToggle)}>
{staticMenuToggle ||
(!hoveredMenuToggle ? <HamburgerMenu /> : <DoubleChevronRight />)}
</HeaderButton>
<div css={hoverAreaCss()} />
{(staticMenuToggle || hoveredMenuToggle) && (
<div css={menuCss(staticMenuToggle)}>
<Menu />
</div>
)}
<div css={hoverAreaCss} />
<AnimatedMenu style={menuStyleProps}>
<Menu />
</AnimatedMenu>
</div>
);
}
Expand Down
31 changes: 17 additions & 14 deletions frontend/src/components/pages/PageComponent/PageComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 });
Expand All @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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>
);
}
Expand Down