From 27405ec9cb8be1c1a1121f8af9a6915e01b43074 Mon Sep 17 00:00:00 2001 From: Cat Hanbit Date: Mon, 14 Aug 2023 16:35:33 +0900 Subject: [PATCH 1/2] =?UTF-8?q?#85=20feat:=20sideBar=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 타입 및 컴포넌트 분리 - 구조 수정 - dummy 제거 --- frontend/src/components/common/SideBar.tsx | 157 ------------------ .../src/components/common/sideBar/Element.tsx | 99 +++++++++++ .../components/common/sideBar/Elements.tsx | 25 +++ .../src/components/common/sideBar/SideBar.tsx | 51 ++++++ frontend/src/components/label/Label.tsx | 7 +- .../constant/{CheckBox.tsx => CheckBox.ts} | 0 frontend/src/constant/ElementType.ts | 8 + frontend/src/pages/Components.tsx | 34 +++- frontend/src/types/ElementProps.ts | 16 ++ frontend/src/types/LabelProps.ts | 7 + 10 files changed, 235 insertions(+), 169 deletions(-) delete mode 100644 frontend/src/components/common/SideBar.tsx create mode 100644 frontend/src/components/common/sideBar/Element.tsx create mode 100644 frontend/src/components/common/sideBar/Elements.tsx create mode 100644 frontend/src/components/common/sideBar/SideBar.tsx rename frontend/src/constant/{CheckBox.tsx => CheckBox.ts} (100%) create mode 100644 frontend/src/constant/ElementType.ts create mode 100644 frontend/src/types/ElementProps.ts create mode 100644 frontend/src/types/LabelProps.ts diff --git a/frontend/src/components/common/SideBar.tsx b/frontend/src/components/common/SideBar.tsx deleted file mode 100644 index c69344a47..000000000 --- a/frontend/src/components/common/SideBar.tsx +++ /dev/null @@ -1,157 +0,0 @@ -import { styled } from 'styled-components'; -import Icons from '../../design/Icons'; - -enum ElementType { - AddButton, - Assignee, - Label, - milestone, -} - -const { AddButton, Assignee, Label, milestone } = ElementType; - -type ElementProps = { - type: T; -} & (T extends typeof AddButton - ? { text: string } - : T extends typeof Assignee - ? { text: string; checked: boolean } - : T extends typeof Label - ? { text: string } - : { text: string; progress: number }); - -const dummy: ElementProps< - typeof AddButton | typeof Assignee | typeof Label | typeof milestone ->[] = [ - { type: AddButton, text: 'label1' }, - { type: Assignee, text: 'label2', checked: false }, - { type: Label, text: 'label3' }, - { type: milestone, text: 'label4', progress: 30 }, -]; - -export default function SideBar() { - return ( - -

사이드바

-
    - {dummy.map((props) => ( -
  • - -
  • - ))} -
-
- ); -} - -const Container = styled.aside` - width: 288px; - border: 1px solid ${({ theme }) => theme.color.neutral.border.default}; - overflow: hidden; - border-radius: ${({ theme }) => theme.objectStyles.radius.large}; - & > ul { - & > li { - padding: 32px; - border-bottom: 1px solid - ${({ theme }) => theme.color.neutral.border.default}; - &:last-child { - border: 0; - } - & > button { - width: 100%; - border: 0; - background-color: transparent; - display: inline-flex; - align-items: center; - justify-content: space-between; - color: ${({ theme }) => theme.color.neutral.text.default}; - ${({ theme }) => theme.font.available.medium[16]}; - & > svg { - & > path { - stroke: ${({ theme }) => theme.color.neutral.text.default}; - } - } - } - - & > label { - width: 100%; - display: inline-flex; - gap: 8px; - align-items: center; - ${({ theme }) => theme.font.display.medium[12]}; - & > input { - display: none; - } - & > span { - display: inline-block; - color: ${({ theme }) => theme.color.neutral.text.strong}; - width: 100%; - } - } - & > span { - border: 1px solid ${({ theme }) => theme.color.neutral.border.default}; - ${({ theme }) => theme.font.display.medium[12]}; - border-radius: ${({ theme }) => theme.objectStyles.radius.large}; - color: ${({ theme }) => theme.color.neutral.text.weak}; - height: 24px; - display: inline-flex; - align-items: center; - padding: 0 8px; - } - & > article { - & > progress { - width: 100%; - margin-bottom: 4px; - } - & > label { - ${({ theme }) => theme.font.display.medium[12]}; - color: ${({ theme }) => theme.color.neutral.text.strong}; - } - } - } - } -`; - -function Element({ - type, - props, -}: { - type: T; - props: ElementProps; -}) { - const { - text, - checked, - progress, - }: { text: string; checked?: boolean; progress?: number } = props; - switch (type) { - case AddButton: - return ( - - ); - case Assignee: - return ( - - ); - case Label: - return {text}; - case milestone: - return ( -
-

{text} 진행률

- - {progress}% - -
- -
- ); - } -} diff --git a/frontend/src/components/common/sideBar/Element.tsx b/frontend/src/components/common/sideBar/Element.tsx new file mode 100644 index 000000000..9600be0d2 --- /dev/null +++ b/frontend/src/components/common/sideBar/Element.tsx @@ -0,0 +1,99 @@ +import { styled } from 'styled-components'; +import ElementType from '../../../constant/ElementType'; +import Icons from '../../../design/Icons'; +import ElementProps from '../../../types/ElementProps'; +import Label from '../../label/Label'; + +export default function Element({ + type, + props, +}: { + type: T; + props: ElementProps; +}) { + switch (type) { + case ElementType.AddButton: + return (() => { + const { text } = props as ElementProps; + return ( + + {text} + + + ); + })(); + case ElementType.Assignee: + return (() => { + const { text, checked } = props as ElementProps; + return ( + + + {text} + + + ); + })(); + case ElementType.Label: + return (() => { + const { labelProps } = props as ElementProps; + return