Skip to content

Commit

Permalink
#85 feat: sideBar 수정 \n\n - 타입 및 컴포넌트 분리\n - 구조 수정\n - dummy 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
saejinpark committed Aug 14, 2023
1 parent 33942ba commit ad6fd2f
Show file tree
Hide file tree
Showing 10 changed files with 235 additions and 169 deletions.
157 changes: 0 additions & 157 deletions frontend/src/components/common/SideBar.tsx

This file was deleted.

99 changes: 99 additions & 0 deletions frontend/src/components/common/sideBar/Element.tsx
Original file line number Diff line number Diff line change
@@ -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<T extends ElementType>({
type,
props,
}: {
type: T;
props: ElementProps<T>;
}) {
switch (type) {
case ElementType.AddButton:
return (() => {
const { text } = props as ElementProps<ElementType.AddButton>;
return (
<AddButton>
<span>{text}</span>
<Icons.plus />
</AddButton>
);
})();
case ElementType.Assignee:
return (() => {
const { text, checked } = props as ElementProps<ElementType.Assignee>;
return (
<Assignee htmlFor={text}>
<Icons.userImageLarge />
<span>{text}</span>
<input type="checkbox" name={text} id={text} checked={checked} />
</Assignee>
);
})();
case ElementType.Label:
return (() => {
const { labelProps } = props as ElementProps<ElementType.Label>;
return <Label {...labelProps} />;
})();
case ElementType.milestone:
return (() => {
const { text, progress } = props as ElementProps<ElementType.milestone>;
return (
<Milestone>
<h4 className="blind">{text} 진행률</h4>
<progress id={text} value={progress} max="100">
{progress}%
</progress>
<br />
<label htmlFor={text}>{text}</label>
</Milestone>
);
})();
}
}

const AddButton = styled.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};
}
}
`;

const Assignee = styled.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%;
}
`;

const Milestone = styled.article`
& > progress {
width: 100%;
margin-bottom: 4px;
}
& > label {
${({ theme }) => theme.font.display.medium[12]};
color: ${({ theme }) => theme.color.neutral.text.strong};
}
`;
25 changes: 25 additions & 0 deletions frontend/src/components/common/sideBar/Elements.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import ElementType from '../../../constant/ElementType';
import ElementProps from '../../../types/ElementProps';
import Element from './Element';

const { Assignee, Label, milestone } = ElementType;

export default function Elements({
items,
}: {
items: (
| ElementProps<typeof Assignee>
| ElementProps<typeof Label>
| ElementProps<typeof milestone>
)[];
}) {
return (
<ul>
{items.map((props, index) => (
<li key={index}>
<Element type={props.type} props={props} />
</li>
))}
</ul>
);
}
51 changes: 51 additions & 0 deletions frontend/src/components/common/sideBar/SideBar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { styled } from 'styled-components';
import ElementType from '../../../constant/ElementType';
import ElementProps from '../../../types/ElementProps';
import Elements from './Elements';
import Element from './Element';

const { AddButton, Assignee, Label, milestone } = ElementType;

type SideBarProps = {
sideBarItems: [
ElementProps<typeof AddButton>,
(
| ElementProps<typeof Assignee>
| ElementProps<typeof Label>
| ElementProps<typeof milestone>
)[]
][];
};

export default function SideBar({ sideBarItems }: SideBarProps) {
return (
<Container>
<h2 className="blind">사이드바</h2>
<ul>
{sideBarItems.map(([props, items]) => (
<li key={props.text}>
<Element type={props.type} props={props} />
<Elements items={items} />
</li>
))}
</ul>
</Container>
);
}

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;
}
}
}
`;
7 changes: 2 additions & 5 deletions frontend/src/components/label/Label.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { styled } from 'styled-components';
import InformationTag from '../common/InformationTag';
import LabelProps from '../../types/LabelProps';

export default function Label({
textColor,
backgroundColor,
name,
}: {
textColor: string;
backgroundColor: string;
name: string;
}) {
}: LabelProps) {
return (
<Container $textColor={textColor} $backgroundColor={backgroundColor}>
<InformationTag size="small">{name}</InformationTag>
Expand Down
File renamed without changes.
8 changes: 8 additions & 0 deletions frontend/src/constant/ElementType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
enum ElementType {
AddButton,
Assignee,
Label,
milestone,
}

export default ElementType;
Loading

0 comments on commit ad6fd2f

Please sign in to comment.