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

Feat/42 header component #45

Merged
merged 14 commits into from
Oct 31, 2023
1 change: 1 addition & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import './styles/index.css'
import { RouterProvider } from 'react-router-dom'
import { router } from './routes'
import './styles/index.css'
Expand Down
57 changes: 57 additions & 0 deletions src/components/common/header/Header.stories.tsx
Original file line number Diff line number Diff line change
@@ -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<typeof Header>

export default meta
type Story = StoryObj<typeof meta>

export const BackPushHeader: Story = {
args: {
headerType: 'BackPush'
}
}

export const LogoHeader: Story = {
args: {
headerType: 'Logo',
pageTitle: 'pageName',
rightElement: (
<>
<span className={'mx-[6px]'}>{'👏'}</span>
<span>{'👏'}</span>
</>
)
}
}

export const CloseHeader: Story = {
args: {
headerType: 'Close'
}
}

export const CloseWithTitleHeader: Story = {
args: {
headerType: 'CloseWithTitle',
pageTitle: 'pageName'
}
}
62 changes: 62 additions & 0 deletions src/components/common/header/Header.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import type { HeaderProps } from './HeaderType'
import Icon from '../icon/Icon'

const Header = ({
headerType,
pageTitle = 'pageTitle',
onClick
}: HeaderProps) => {
return (
<header
className={`fixed left-[50%] top-0 translate-x-[-50%] w-[390px] h-[80px] bg-white-0 text-black-900 px-[22px] border-b-[1px] border-gray-100`}
>
<div
className={`w-full h-full ${
headerType === 'BackPush' ||
headerType === 'Close' ||
headerType === 'CloseWithTitle'
? 'flex items-center justify-start'
: 'flex items-center justify-between'
}`}
>
{headerType === 'BackPush' ? (
<span onClick={() => alert('뒤로가기')}>
<Icon icon={'BackPush'} classStyle={'cursor-pointer'} />
</span>
) : headerType === 'Logo' ? (
<>
<div>
<span>{'👍'}</span>
<span className={'mx-[20px] font-nsk subHead-18'}>
{pageTitle}
</span>
</div>
<div className={'flex items-center justify-between'}>
<div className={'mx-[7px]'} onClick={() => alert('알림보기!')}>
<Icon icon={'Alarm'} classStyle={'cursor-pointer'} />
</div>
<span onClick={() => alert('사이드 바 열기')}>
<Icon icon={'SideBar'} classStyle={'cursor-pointer'} />
</span>
</div>
</>
) : headerType === 'Close' ? (
eugene028 marked this conversation as resolved.
Show resolved Hide resolved
<span onClick={onClick}>
<Icon icon={'Close'} classStyle={'cursor-pointer'} />
</span>
) : headerType === 'CloseWithTitle' ? (
<div className={'flex cursor-pointer items-center'}>
<span onClick={onClick}>
<Icon icon={'Close'} classStyle={'cursor-pointer'} />
</span>
<span className={'mx-[20px] font-nsk subHead-18'}>{pageTitle}</span>
</div>
) : (
''
)}
</div>
</header>
)
}

export default Header
9 changes: 9 additions & 0 deletions src/components/common/header/HeaderType.ts
Original file line number Diff line number Diff line change
@@ -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
}