Skip to content
Open
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
36 changes: 33 additions & 3 deletions apps/docs/src/stories/Tab.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,45 @@ const meta = {
title: 'Components/Tab',
component: Tab,
tags: ['autodocs'],
parameters: {
docs: {
description: {
component: '동일한 위계의 요소를 그룹화하여 화면이동 없이 빠르게 탐색합니다.',
},
},
},
args: {
tabItems: ['Tab1', 'Tab2', 'Tab3'],
selectedInitial: 'Tab1',
translator: { Tab1: '탭1', Tab2: '탭2', Tab3: '탭3' },
},
argTypes: {
style: { control: 'radio', options: ['primary', 'secondary'] },
size: { control: 'radio', options: ['sm', 'md', 'lg'] },
selectedInitial: { control: 'select', options: ['Tab1', 'Tab2', 'Tab3'] },
tabItems: {
description: '여러 Tab 항목을 전달합니다.',
table: { type: { summary: 'T[]' } },
Copy link

Choose a reason for hiding this comment

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

story는 구체적인 타입이나 예시를 넣는것이 문서를 읽는데 더 좋은 방향인 것 같아요 제네릭 타입보단 string[] 을 사용해보는건 어떤가요?

},
selectedInitial: {
control: 'select',
options: ['Tab1', 'Tab2', 'Tab3'],
description: 'Tab의 초기 선택 값을 설정합니다.',
table: { type: { summary: 'T (optional)' } },
},
translator: {
description: 'Tab 항목의 텍스트를 원하는 컴포넌트로 변경합니다.',
Copy link

Choose a reason for hiding this comment

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

Tab 항목의 텍스트를 ReactNode로 매핑합니다. (아이콘, 강조 텍스트 등 가능)

와 같이 ReactNode 사용을 명시해줘도 좋을 것 같아요!

table: { type: { summary: 'Record<T, ReactNode>' } },
},
style: {
control: 'inline-radio',
options: ['primary', 'secondary'],
description: 'Tab의 스타일을 설정합니다.',
table: { type: { summary: 'primary | secondary' } },
},
size: {
control: 'inline-radio',
options: ['sm', 'md', 'lg'],
description: 'Tab의 크기를 설정합니다.',
table: { type: { summary: 'sm | md | lg' } },
},
Comment on lines +41 to +46
Copy link

Choose a reason for hiding this comment

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

해당 문서에 defaultValue가 빠진 것 같아요! 이부분 추가해주세요!

},
} as Meta<typeof Tab>;

Expand Down
15 changes: 10 additions & 5 deletions packages/ui/Tab/Tab.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ReactNode} from 'react';
import type { ReactNode } from 'react';
import { useState } from 'react';
import * as S from './style.css';
import { createTabItemVariant, createTabVariant } from './utils';
Expand Down Expand Up @@ -30,21 +30,24 @@ function Tab<T extends string>(props: TabProps<T>) {
};

return (
<div className={`${S.tab} ${tabVariant} ${className}`}>
<div className={`${S.tab} ${tabVariant} ${className}`} role='tablist'>
{tabItems.map((item) => {
const isSelected = selected === item ? 'selected' : '';
const isSelected = selected === item;
return (
<div className={S.tabItemWrap} key={item}>
<button
className={`${S.tabItem} ${tabItemVariant} ${isSelected} ${S.fontStyles[size]}`}
aria-selected={isSelected}
className={`${S.tabItem} ${tabItemVariant} ${isSelected ? 'selected' : ''} ${S.fontStyles[size]}`}
onClick={() => {
handleClickTabItem(item);
}}
role='tab'
tabIndex={isSelected ? 0 : -1}
type='button'
>
{translator ? translator[item] : item}
</button>
<div className={`${S.tabItemUnderline} ${isSelected}`} />
<div className={`${S.tabItemUnderline} ${isSelected ? 'selected' : ''}`} />
Copy link

Choose a reason for hiding this comment

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

selected className이 어떤 용도로 활용되는건가요??
이부분도 중보되고 있어서 상단에 변수로 선언해두면 좋을 것 같아요

 const selectedClassName= isSelected ? 'selected' : ''

Copy link
Member

Choose a reason for hiding this comment

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

수정하신 isSelected 문제 없어보이네요.
그리고 클래스네임은 빈 문자열보다는 null (없음)은 어떠신지

위 재훈님이 말씀하신 것도 동의합니다

</div>
);
})}
Expand All @@ -53,3 +56,5 @@ function Tab<T extends string>(props: TabProps<T>) {
}

export default Tab;

Tab.displayName = 'Tab';