From 8cd89c92b5520d36dd2e7182ad783857356c8b22 Mon Sep 17 00:00:00 2001 From: MERx88 Date: Sun, 29 Dec 2024 22:53:27 +0900 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20change=20tabs=20s?= =?UTF-8?q?tructure=20to=20pass=20component=20by=20props?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 37 +++++++++++++++++++++++------ src/components/Tabs/index.tsx | 44 +++++++++++------------------------ 2 files changed, 44 insertions(+), 37 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 9cdbe62..8c875b2 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -49,16 +49,16 @@ const TABS = [ const CHIPS = [ { - index: 0, - name: "고정멤버", + label: "고정멤버", + value: "고정멤버", }, { - index: 1, - name: "아카데미", + label: "아카데미", + value: "아카데미", }, { - index: 2, - name: "이세돌", + label: "이세돌", + value: "이세돌", }, ] @@ -255,7 +255,30 @@ const App = () => { TABS={TABS} selectedTabIndex={selectedTabIndex} setSelectedTabIndex={setSelectedTabIndex} - CHIPS={CHIPS} + topButtonComponent={ + alert(`filter 의 options 이 선택되었습니다 "${value}"`)} + /> + } + bottomButtonComponent={ + alert("Button Click!")}> + Button Fill small gray + + } + chipComponents={CHIPS.map((CHIP, index) => ( + { + alert(`${value} selected`) + }} + /> + ))} /> {selectedTabIndex === 0 && ( diff --git a/src/components/Tabs/index.tsx b/src/components/Tabs/index.tsx index 55c1b50..447783c 100644 --- a/src/components/Tabs/index.tsx +++ b/src/components/Tabs/index.tsx @@ -7,16 +7,20 @@ interface IItem { title: string } -interface IChip { - index: number - name: string -} - -const Tabs = ({ TABS, CHIPS, selectedTabIndex, setSelectedTabIndex }: { +const Tabs = ({ + TABS, + selectedTabIndex, + setSelectedTabIndex, + topButtonComponent, + bottomButtonComponent, + chipComponents, +}: { TABS: IItem[] - CHIPS: IChip[] selectedTabIndex: Number setSelectedTabIndex: React.Dispatch> + topButtonComponent?: React.ReactElement // top Button (e.g. filter) + bottomButtonComponent?: React.ReactElement // bottom Button(e.g. memberfilter) + chipComponents?: React.ReactElement[] // render chips }) => { return ( @@ -36,21 +40,11 @@ const Tabs = ({ TABS, CHIPS, selectedTabIndex, setSelectedTabIndex }: { ) })} - - {/* TODO : IMPORT FILTER COMPONENT */} - - + {topButtonComponent} - - {CHIPS.map(CHIP => { - return # {CHIP.name} - })} - - - {/* TODO : IMPORT MEMBER FILTER COMPONENT */} - - + {chipComponents} + {bottomButtonComponent} ) @@ -92,15 +86,5 @@ const ChipWrapper = styled.div` align-items: center; gap: 10px; ` -// TODO : ERASE CHIP CSS -const FakeChip = styled.span` - width: fit-content; - height: fit-content; - border-radius: 5px; - background-color: gray; - padding: 8px 12px; - font-size: 14px; - color: white; -` export default Tabs