Skip to content

Commit 4d70f4f

Browse files
authored
Merge pull request #49 from Wedvice/f/list-tab-component/suji_chae
[feat] ListTab 컴포넌트 구현
2 parents 39ceff3 + 22ddf40 commit 4d70f4f

5 files changed

Lines changed: 148 additions & 0 deletions

File tree

.github/workflows/git-push.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: git push into another repo to deploy to vercel
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
container: pandoc/latex
11+
steps:
12+
- uses: actions/checkout@v2
13+
- name: Install mustache (to update the date)
14+
run: apk add ruby && gem install mustache
15+
- name: creates output
16+
run: sh ./build.sh
17+
- name: Pushes to another repository
18+
id: push_directory
19+
uses: cpina/github-action-push-to-another-repository@main
20+
env:
21+
API_TOKEN_GITHUB: ${{ secrets.VECEL_TOKEN }}
22+
with:
23+
source-directory: 'output'
24+
destination-github-username: jungjunhyung99
25+
destination-repository-name: Wedvice_FE
26+
user-email: ${{ secrets.GITHUB_EMAIL }}
27+
commit-message: ${{ github.event.commits[0].message }}
28+
target-branch: main
29+
- name: Test get variable exported by push-to-another-repository
30+
run: echo $DESTINATION_CLONED_DIRECTORY

build.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
cd ../
3+
mkdir output
4+
cp -R ./Wedvice_FE/* ./output
5+
cp -R ./output ./Wedvice_FE/
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
'use client';
2+
3+
import type { Meta, StoryObj } from '@storybook/react';
4+
import { useState } from 'react';
5+
import { ListTab, ListTabProps } from './ListTab';
6+
import { TabInfo } from '../tab/Tab';
7+
8+
// ListTab 타입 정의
9+
type ListTabType = 'all' | 'inProgress' | 'completed';
10+
11+
const defaultListTabInfo: TabInfo<ListTabType> = [
12+
{ tabType: 'all', label: '전체', count: 7 },
13+
{ tabType: 'inProgress', label: '진행 중', count: 5 },
14+
{ tabType: 'completed', label: '진행 완료' },
15+
];
16+
17+
const meta: Meta<typeof ListTab> = {
18+
title: 'components/ListTab',
19+
component: ListTab,
20+
argTypes: {
21+
selectedTab: { control: 'text' },
22+
onClick: { action: 'clicked' },
23+
},
24+
};
25+
export default meta;
26+
27+
type Story = StoryObj<ListTabProps<ListTabType>>;
28+
29+
// 기본 ListTab UI
30+
export const Default: Story = {
31+
render: (args) => {
32+
const [selectedTab, setSelectedTab] = useState<ListTabType>('all');
33+
34+
return (
35+
<ListTab {...args} selectedTab={selectedTab} onClick={setSelectedTab} />
36+
);
37+
},
38+
args: {
39+
tabInfo: defaultListTabInfo,
40+
},
41+
};
42+
43+
// count가 있는 ListTab
44+
export const WithCounts: Story = {
45+
render: (args) => {
46+
const [selectedTab, setSelectedTab] = useState<ListTabType>('all');
47+
48+
return (
49+
<ListTab
50+
{...args}
51+
tabInfo={[
52+
{ tabType: 'all', label: '전체', count: 7 },
53+
{ tabType: 'inProgress', label: '진행 중', count: 5 },
54+
{ tabType: 'completed', label: '진행 완료', count: 2 },
55+
]}
56+
selectedTab={selectedTab}
57+
onClick={setSelectedTab}
58+
/>
59+
);
60+
},
61+
};
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
'use client';
2+
3+
import { Dispatch, forwardRef, SetStateAction } from 'react';
4+
import { TabInfo } from '../tab/Tab';
5+
6+
export interface ListTabProps<T> {
7+
tabInfo: TabInfo<T>;
8+
selectedTab: T;
9+
className?: string;
10+
onClick: Dispatch<SetStateAction<T>>;
11+
}
12+
13+
const ListTabComponent = <T,>(
14+
{ className, tabInfo, selectedTab, onClick, ...props }: ListTabProps<T>,
15+
ref: React.Ref<HTMLDivElement>,
16+
) => {
17+
return (
18+
<div
19+
ref={ref}
20+
className={`${className} flex h-[70px] w-full items-center rounded-2xl bg-gray-100 p-1 text-center`}
21+
{...props}
22+
>
23+
{tabInfo.map(({ tabType, label, count }) => {
24+
const isSelected = selectedTab === tabType;
25+
26+
return (
27+
<button
28+
key={String(tabType)}
29+
className={`flex h-full w-full select-none flex-col justify-center gap-1 rounded-2xl ${
30+
isSelected ? 'bg-gray-200 text-white' : 'text-gray-500'
31+
}`}
32+
onClick={() => onClick(tabType)}
33+
>
34+
{count !== undefined && count > 0 && (
35+
<span
36+
className={`text-xl font-semibold ${isSelected ? 'text-primary-400' : 'text-gray-500'}`}
37+
>
38+
{count}
39+
</span>
40+
)}
41+
<span className='text-xs font-medium'>{label}</span>
42+
</button>
43+
);
44+
})}
45+
</div>
46+
);
47+
};
48+
49+
export const ListTab = forwardRef(ListTabComponent) as <T>(
50+
props: ListTabProps<T> & { ref?: React.Ref<HTMLDivElement> },
51+
) => JSX.Element;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { ListTab } from './ListTab';

0 commit comments

Comments
 (0)