|
| 1 | +'use client'; |
| 2 | + |
| 3 | +import type { Meta, StoryObj } from '@storybook/react'; |
| 4 | +import { useState } from 'react'; |
| 5 | +import { Tab, TabInfo, TabProps } from './Tab'; |
| 6 | + |
| 7 | +// Tab 타입 정의 |
| 8 | +type TabType = 'comment' | 'photo' | 'link'; |
| 9 | + |
| 10 | +const defaultTabInfo: TabInfo<TabType> = [ |
| 11 | + { tabType: 'comment', label: '댓글' }, |
| 12 | + { tabType: 'photo', label: '사진', count: 0 }, |
| 13 | + { tabType: 'link', label: '링크', count: 0 }, |
| 14 | +]; |
| 15 | + |
| 16 | +const meta: Meta<typeof Tab> = { |
| 17 | + title: 'components/Tab', |
| 18 | + component: Tab, |
| 19 | + argTypes: { |
| 20 | + selectedTab: { control: 'text' }, |
| 21 | + onClick: { action: 'clicked' }, |
| 22 | + }, |
| 23 | +}; |
| 24 | +export default meta; |
| 25 | + |
| 26 | +type Story = StoryObj<TabProps<TabType>>; |
| 27 | + |
| 28 | +// 기본 Tab UI |
| 29 | +export const Default: Story = { |
| 30 | + render: (args) => { |
| 31 | + const [selectedTab, setSelectedTab] = useState<TabType>('comment'); |
| 32 | + |
| 33 | + return <Tab {...args} selectedTab={selectedTab} onClick={setSelectedTab} />; |
| 34 | + }, |
| 35 | + args: { |
| 36 | + tabInfo: defaultTabInfo, |
| 37 | + }, |
| 38 | +}; |
| 39 | + |
| 40 | +// count가 있는 Tab |
| 41 | +export const WithCounts: Story = { |
| 42 | + render: (args) => { |
| 43 | + const [selectedTab, setSelectedTab] = useState<TabType>('comment'); |
| 44 | + |
| 45 | + return ( |
| 46 | + <Tab |
| 47 | + {...args} |
| 48 | + tabInfo={[ |
| 49 | + { tabType: 'comment', label: '댓글' }, |
| 50 | + { tabType: 'photo', label: '사진', count: 9 }, |
| 51 | + { tabType: 'link', label: '링크', count: 5 }, |
| 52 | + ]} |
| 53 | + selectedTab={selectedTab} |
| 54 | + onClick={setSelectedTab} |
| 55 | + /> |
| 56 | + ); |
| 57 | + }, |
| 58 | +}; |
0 commit comments