From 171da2d7fd0d61e7071df64fa1f29abf09b04029 Mon Sep 17 00:00:00 2001 From: sincerity developer <85999976+jisung24@users.noreply.github.com> Date: Tue, 31 Oct 2023 15:11:54 +0900 Subject: [PATCH] Feat/42 header component (#45) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 필요없는 import제거 * feat: Header컴포넌트 생성 * feat: Header스토리북 생성 * feat: HeaderType분리 & import * feat: 불필요한 import문 제거 * feat: header props명 title -> pageTitle로 변경 후 적용 * feat: pageTitle default parameter제공 * feat: header position fixed * feat: 불필요한 import제거 * feat: Header component 리뷰 반영 * feat: onClick props설정 * feat: 불필요한 주석 제거 * feat: Header 컴포넌트 design 수정 --------- Co-authored-by: Eugene Kim <67894159+eugene028@users.noreply.github.com> --- src/App.tsx | 1 + .../common/header/Header.stories.tsx | 57 +++++++++++++++++ src/components/common/header/Header.tsx | 62 +++++++++++++++++++ src/components/common/header/HeaderType.ts | 9 +++ 4 files changed, 129 insertions(+) create mode 100644 src/components/common/header/Header.stories.tsx create mode 100644 src/components/common/header/Header.tsx create mode 100644 src/components/common/header/HeaderType.ts diff --git a/src/App.tsx b/src/App.tsx index 9a708787..b2ef3339 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,3 +1,4 @@ +import './styles/index.css' import { RouterProvider } from 'react-router-dom' import { router } from './routes' import './styles/index.css' diff --git a/src/components/common/header/Header.stories.tsx b/src/components/common/header/Header.stories.tsx new file mode 100644 index 00000000..df5f1a01 --- /dev/null +++ b/src/components/common/header/Header.stories.tsx @@ -0,0 +1,57 @@ +import type { Meta, StoryObj } from '@storybook/react' +import Header from './Header' +const meta = { + title: 'Component/Header', + component: Header, + parameters: { + layout: 'centered' + }, + tags: ['autodocs'], + argTypes: { + headerType: { + control: 'select', + options: ['BackPush', 'Logo', 'Close', 'CloseWithTitle'] + }, + pageTitle: { + control: 'text' + }, + rightElement: { + control: 'text' + } + } +} satisfies Meta + +export default meta +type Story = StoryObj + +export const BackPushHeader: Story = { + args: { + headerType: 'BackPush' + } +} + +export const LogoHeader: Story = { + args: { + headerType: 'Logo', + pageTitle: 'pageName', + rightElement: ( + <> + {'👏'} + {'👏'} + + ) + } +} + +export const CloseHeader: Story = { + args: { + headerType: 'Close' + } +} + +export const CloseWithTitleHeader: Story = { + args: { + headerType: 'CloseWithTitle', + pageTitle: 'pageName' + } +} diff --git a/src/components/common/header/Header.tsx b/src/components/common/header/Header.tsx new file mode 100644 index 00000000..9f032459 --- /dev/null +++ b/src/components/common/header/Header.tsx @@ -0,0 +1,62 @@ +import type { HeaderProps } from './HeaderType' +import Icon from '../icon/Icon' + +const Header = ({ + headerType, + pageTitle = 'pageTitle', + onClick +}: HeaderProps) => { + return ( +
+
+ {headerType === 'BackPush' ? ( + alert('뒤로가기')}> + + + ) : headerType === 'Logo' ? ( + <> +
+ {'👍'} + + {pageTitle} + +
+
+
alert('알림보기!')}> + +
+ alert('사이드 바 열기')}> + + +
+ + ) : headerType === 'Close' ? ( + + + + ) : headerType === 'CloseWithTitle' ? ( +
+ + + + {pageTitle} +
+ ) : ( + '' + )} +
+
+ ) +} + +export default Header diff --git a/src/components/common/header/HeaderType.ts b/src/components/common/header/HeaderType.ts new file mode 100644 index 00000000..1554dece --- /dev/null +++ b/src/components/common/header/HeaderType.ts @@ -0,0 +1,9 @@ +import { ReactNode } from 'react' + +type HeaderType = 'BackPush' | 'Logo' | 'Close' | 'CloseWithTitle' +export interface HeaderProps { + headerType: HeaderType + pageTitle?: string + rightElement?: ReactNode + onClick?: () => void +}