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

레이아웃 컴포넌트 구현 #87

Merged
merged 2 commits into from
Jul 20, 2023
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
6 changes: 6 additions & 0 deletions frontend/src/components/common/Dashboard/style.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { styled } from 'styled-components';

import { theme } from '@styles/theme';

export const Container = styled.div`
display: flex;
flex-direction: column;
Expand All @@ -9,6 +11,10 @@ export const Container = styled.div`
height: 100vh;
padding: 20px;
border-right: 2px solid var(--gray);

@media (min-width: ${theme.breakpoint.sm}) {
height: 100%;
}
`;

export const ContentContainer = styled.div`
Expand Down
86 changes: 86 additions & 0 deletions frontend/src/components/common/Layout/Layout.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import type { Meta, StoryObj } from '@storybook/react';

import { Category } from '@type/category';
import type { User } from '@type/user';

import Skeleton from '../Skeleton';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

예전에 스켈레톤 UI 구현 pr 에서 코멘트로 남겼던 사항인데, 지속시간이 짧은 맥박 효과 애니메이션을 사용하신 이유가 궁금해요~~~

Copy link
Collaborator Author

@Gilpop8663 Gilpop8663 Jul 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

블로그 참고한 곳이 웨이브 효과인줄 알았으나 맥박이였네요! 이슈를 생성해서 따로 수정해보겠습니다~ 맥박 효과를 사용한 이유는 없어요! 😱

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이슈 생성했습니다~

#91

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋아요~~~


import Layout from '.';

const meta: Meta<typeof Layout> = {
component: Layout,
};

export default meta;
type Story = StoryObj<typeof Layout>;

const MOCK_USER_INFO: User = {
nickname: '우아한 코끼리',
postCount: 4,
voteCount: 128,
userPoint: 200,
};

const MOCK_FAVORITE_CATEGORIES: Category[] = [
{ id: 12312, name: '음식', isFavorite: false },
{ id: 12, name: '연애', isFavorite: true },
{ id: 13, name: '패션', isFavorite: true },
{ id: 14, name: '금융', isFavorite: false },
{ id: 12312, name: '음식', isFavorite: false },
{ id: 12, name: '연애', isFavorite: true },
{ id: 13, name: '패션', isFavorite: true },
{ id: 14, name: '금융', isFavorite: false },
{ id: 12312, name: '음식', isFavorite: false },
{ id: 12, name: '연애', isFavorite: true },
{ id: 13, name: '패션', isFavorite: true },
{ id: 14, name: '금융', isFavorite: false },
{ id: 12312, name: '음식', isFavorite: false },
{ id: 12, name: '연애', isFavorite: true },
{ id: 13, name: '패션', isFavorite: true },
{ id: 14, name: '금융', isFavorite: false },
];

export const VisibleCategory: Story = {
render: () => (
<Layout
isSidebarVisible={true}
userInfo={MOCK_USER_INFO}
categoryList={MOCK_FAVORITE_CATEGORIES}
handleFavoriteClick={() => {}}
handleLogoutClick={() => {}}
>
<Skeleton />
<Skeleton />
<Skeleton />
<Skeleton />
<Skeleton />
<Skeleton />
<Skeleton />
<Skeleton />
<Skeleton />
<Skeleton />
</Layout>
),
};

export const HiddenCategory: Story = {
render: () => (
<Layout
isSidebarVisible={false}
categoryList={MOCK_FAVORITE_CATEGORIES}
handleFavoriteClick={() => {}}
handleLogoutClick={() => {}}
>
<Skeleton />
<Skeleton />
<Skeleton />
<Skeleton />
<Skeleton />
<Skeleton />
<Skeleton />
<Skeleton />
<Skeleton />
<Skeleton />
</Layout>
),
};
52 changes: 52 additions & 0 deletions frontend/src/components/common/Layout/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React, { PropsWithChildren } from 'react';

import type { Category } from '@type/category';
import type { User } from '@type/user';

import Dashboard from '@components/common/Dashboard';
import WideHeader from '@components/common/WideHeader';

import * as S from './style';

interface LayoutProps extends PropsWithChildren {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍👍

userInfo?: User;
categoryList: Category[];
selectedCategory?: string;
isSidebarVisible: boolean;
handleFavoriteClick: (categoryId: number) => void;
handleLogoutClick: () => void;
}

export default function Layout({
userInfo,
categoryList,
selectedCategory,
isSidebarVisible,
handleFavoriteClick,
handleLogoutClick,
children,
}: LayoutProps) {
return (
<S.Container>
<S.WideHeaderWrapper>
<WideHeader />
</S.WideHeaderWrapper>
<S.ContentContainer>
{isSidebarVisible && (
<S.DashboardWrapper>
<Dashboard
userInfo={userInfo}
categoryList={categoryList}
selectedCategory={selectedCategory}
handleFavoriteClick={handleFavoriteClick}
handleLogoutClick={handleLogoutClick}
/>
</S.DashboardWrapper>
)}
<S.MainContainer $isSidebarVisible={isSidebarVisible}>
<S.ChildrenWrapper $isSidebarVisible={isSidebarVisible}>{children}</S.ChildrenWrapper>
</S.MainContainer>
</S.ContentContainer>
</S.Container>
);
}
55 changes: 55 additions & 0 deletions frontend/src/components/common/Layout/style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { styled } from 'styled-components';

import { theme } from '@styles/theme';

export const Container = styled.div`
height: 100vh;
`;

export const ContentContainer = styled.div`
display: flex;
justify-content: space-between;

@media (min-width: ${theme.breakpoint.sm}) {
padding-top: 70px;
}
`;

export const WideHeaderWrapper = styled.div`
width: 100%;

position: fixed;
top: 0;

@media (max-width: ${theme.breakpoint.sm}) {
display: none;
visibility: hidden;
}
`;

export const DashboardWrapper = styled.aside`
height: 90vh;

position: fixed;
left: 0;

@media (max-width: ${theme.breakpoint.sm}) {
display: none;
visibility: hidden;
}
`;

export const MainContainer = styled.main<{ $isSidebarVisible: boolean }>`
display: flex;
justify-content: center;

width: 100%;
@media (min-width: ${theme.breakpoint.sm}) {
padding-left: ${({ $isSidebarVisible }) => $isSidebarVisible && '225px'};
}
`;

export const ChildrenWrapper = styled.div<{ $isSidebarVisible: boolean }>`
width: 100%;
max-width: ${({ $isSidebarVisible }) => $isSidebarVisible && '500px'};
`;