Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Dony] Table 컴포넌트 구현 #7

Merged
merged 18 commits into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/playground-react/constants/icons.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export const SortingIcon = () => (
<svg
xmlns="http://www.w3.org/2000/svg"
width="17"
height="14"
viewBox="0 0 17 14"
>
<path
id="다각형_3"
data-name="다각형 3"
d="M7.645,1.408a1,1,0,0,1,1.71,0l6.723,11.073A1,1,0,0,1,15.223,14H1.777a1,1,0,0,1-.855-1.519Z"
transform="translate(17 14) rotate(180)"
fill="#007aff"
/>
</svg>
);
30 changes: 30 additions & 0 deletions packages/playground-react/constants/mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export const noticeList = [
{
id: 1,
title: '스터디 가입전 해당 공지사항을 숙지해주세요.',
writer: '파크',
date: 1669750385300,
view: 101,
},
{
id: 2,
title: '스터디 전체 공지 드립니다.',
writer: '도니',
date: 1662476400000,
view: 110,
},
{
id: 3,
title: '스터디 전체 공지 드립니다.',
writer: '햄디',
date: 1662476400000,
view: 9,
},
{
id: 4,
title: '스터디 전체 공지 드립니다.',
writer: '제이미',
date: 1668750300553,
view: 9,
},
];
44 changes: 44 additions & 0 deletions packages/playground-react/pages/table/basic-table.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { BasicTable, Text } from '@cos-ui/react';

import { noticeList } from '@constants/mock';

const getDateForm = (date: number) => {
const dateArray = [
new Date(date).getFullYear(),
new Date(date).getMonth() + 1,
new Date(date).getDate(),
];

return dateArray
.map((number) => (number < 10 ? `0${number}` : number))
.join('.');
};
Copy link
Member

Choose a reason for hiding this comment

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

다른 곳에서도 쓰일 것 같아서 분리해도 좋을 것 같네요~

Copy link
Contributor Author

@jindonyy jindonyy Dec 1, 2022

Choose a reason for hiding this comment

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

playground 는 예시를 만들어놓는 패키지라 utils 폴더가 좀 고민되네요..!
단지 예시로 만든 데이터에 쓸 함수인데 util로 빼는게 적절할까요??

Copy link
Member

Choose a reason for hiding this comment

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

helpers 정도로 빼도 좋을 것 같아요

Copy link
Contributor Author

@jindonyy jindonyy Dec 1, 2022

Choose a reason for hiding this comment

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

분리를 해야하나 말아야하나가 고민이였던건데 분리를 해야한다면 용도로는 util이 맞는거 같아요! 다른 플젝에도 쓸 수 있는 함수니까요.
-> 그럼 helpers 안에 컴포넌트 이름 별로 폴더를 만들어서 컴포넌트에 필요한 함수들을 빼는걸로 할께요!

Copy link
Contributor

Choose a reason for hiding this comment

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

@healtheloper 혹시 utils가 아니라 helpers로 분리하는 이유가 뭔지 여쭤봐도 될까요? 나쁘지는 않은 것 같은데 정확히 어떤 차이 때문에 helpers로 구분하는지 궁금해서요!

Copy link
Member

Choose a reason for hiding this comment

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

@hemudi 관점의 차이이긴 할텐데 utils 라고 하면 "YYYY.MM.DD" 뿐만 아니라 다양한 것도 적용할 수 있어야 할 것 같다고 생각했어요, 예를들어 다른 프로젝트에서 "YYYY:MM:DD:SS" 로 쓰고싶은데? 한다면 살을 덧붙여 추가해내는 법도 있긴 하겠지만 당장에는 해당 프로젝트에서 필요로하는 포맷으로 바꾸는 용도이기 때문에 좀 더 프로젝트의 성격이 들어간 느낌이라 helpers 가 좋지않을까 생각했었습니다


const BasicTablePage = () => (
<BasicTable caption="test" columnsWidth={['10rem', '*', '12rem', '10rem']}>
{noticeList.map(({ id, title, writer, date, view }) => (
<BasicTable.Row key={id}>
<BasicTable.BodyCell>
<Text sx={{ textAlign: 'center' }} ellipsis>
{writer}
</Text>
</BasicTable.BodyCell>
<BasicTable.BodyCell>
<Text ellipsis>{title}</Text>
</BasicTable.BodyCell>
<BasicTable.BodyCell>
<Text sx={{ textAlign: 'center' }} ellipsis>
{getDateForm(date)}
</Text>
</BasicTable.BodyCell>
<BasicTable.BodyCell>
<Text sx={{ textAlign: 'center' }} ellipsis>
{view}
</Text>
</BasicTable.BodyCell>
</BasicTable.Row>
))}
</BasicTable>
);

export default BasicTablePage;
84 changes: 24 additions & 60 deletions packages/playground-react/pages/table/column-table.tsx
Original file line number Diff line number Diff line change
@@ -1,97 +1,61 @@
import { ColumnTable, Text, FlexBox } from '@cos-ui/react';

const noticeList = [
{
id: 1,
title: '스터디 가입전 해당 공지사항을 숙지해주세요.',
writer: '파크',
date: '2022.10.22',
view: 101,
},
{
id: 2,
title: '스터디 전체 공지 드립니다.',
writer: '도니',
date: '2022.09.20',
view: 110,
},
{
id: 3,
title: '스터디 전체 공지 드립니다.',
writer: '햄디',
date: '2022.09.20',
view: 9,
},
{
id: 4,
title: '스터디 전체 공지 드립니다.',
writer: '제이미',
date: '2022.09.22',
view: 9,
},
];
import { SortingIcon } from '@constants/icons';
import { noticeList } from '@constants/mock';

const sortValues = {
const sortingValues = {
writer: noticeList.map(({ writer }) => writer),
date: noticeList.map(({ date }) => {
const numberDate = Number(date.split('.').join(''));
return numberDate.toString().length < 8 ? numberDate * 10 : numberDate;
}),
date: noticeList.map(({ date }) => date),
view: noticeList.map(({ view }) => Number(view)),
Copy link
Member

Choose a reason for hiding this comment

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

그냥 써도 Number type 일 것 같아요~

};

const SortIcon = () => (
<svg
xmlns="http://www.w3.org/2000/svg"
width="17"
height="14"
viewBox="0 0 17 14"
>
<path
id="다각형_3"
data-name="다각형 3"
d="M7.645,1.408a1,1,0,0,1,1.71,0l6.723,11.073A1,1,0,0,1,15.223,14H1.777a1,1,0,0,1-.855-1.519Z"
transform="translate(17 14) rotate(180)"
fill="#007aff"
/>
</svg>
);
const getDateForm = (date: number) => {
const dateArray = [
new Date(date).getFullYear(),
new Date(date).getMonth() + 1,
new Date(date).getDate(),
];

return dateArray
.map((number) => (number < 10 ? `0${number}` : number))
.join('.');
};

const ColumnTablePage = () => (
<ColumnTable
caption="공지사항"
columnsWidth={['85px', '*', '120px', '120px', '120px']}
sortValues={sortValues}
columnsWidth={['8.5rem', '*', '12rem', '12rem', '12rem']}
sortingValues={sortingValues}
>
<ColumnTable.Row>
<ColumnTable.HeadCell>번호</ColumnTable.HeadCell>
<ColumnTable.HeadCell>
<Text as="div" sx={{ textAlign: 'center' }}>
번호
<Text as="div" sx={{ textAlign: 'left' }}>
제목
</Text>
</ColumnTable.HeadCell>
<ColumnTable.HeadCell>제목</ColumnTable.HeadCell>
<ColumnTable.HeadCell name="writer">
<FlexBox
sx={{ justifyContent: 'center', alignItems: 'center', gap: '1rem' }}
>
작성자
<SortIcon />
<SortingIcon />
</FlexBox>
</ColumnTable.HeadCell>
<ColumnTable.HeadCell name="date">
<FlexBox
sx={{ justifyContent: 'center', alignItems: 'center', gap: '1rem' }}
>
날짜
<SortIcon />
<SortingIcon />
</FlexBox>
</ColumnTable.HeadCell>
<ColumnTable.HeadCell name="view">
<FlexBox
sx={{ justifyContent: 'center', alignItems: 'center', gap: '1rem' }}
>
조회수
<SortIcon />
<SortingIcon />
</FlexBox>
</ColumnTable.HeadCell>
</ColumnTable.Row>
Expand All @@ -112,7 +76,7 @@ const ColumnTablePage = () => (
</ColumnTable.BodyCell>
<ColumnTable.BodyCell>
<Text sx={{ textAlign: 'center' }} ellipsis>
{date}
{getDateForm(date)}
</Text>
</ColumnTable.BodyCell>
<ColumnTable.BodyCell>
Expand Down
94 changes: 94 additions & 0 deletions packages/playground-react/pages/table/row-table.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { RowTable, Text, FlexBox } from '@cos-ui/react';

import { SortingIcon } from '@constants/icons';
import { noticeList } from '@constants/mock';

const sortingValues = {
writer: noticeList.map(({ writer }) => writer),
date: noticeList.map(({ date }) => date),
view: noticeList.map(({ view }) => Number(view)),
};

const getDateForm = (date: number) => {
const dateArray = [
new Date(date).getFullYear(),
new Date(date).getMonth() + 1,
new Date(date).getDate(),
];

return dateArray
.map((number) => (number < 10 ? `0${number}` : number))
.join('.');
};

const RowTablePage = () => (
<RowTable
caption="공지사항"
columnsWidth={['12rem', '25%', '25%', '25%', '25%']}
sortingValues={sortingValues}
>
<RowTable.Row>
<RowTable.HeadCell>번호</RowTable.HeadCell>
{noticeList.map(({ id }) => (
<RowTable.BodyCell key={id}>
<Text ellipsis>{id}</Text>
</RowTable.BodyCell>
))}
</RowTable.Row>
<RowTable.Row>
<RowTable.HeadCell>제목</RowTable.HeadCell>
{noticeList.map(({ id, title }) => (
<RowTable.BodyCell key={id}>
<Text ellipsis>{title}</Text>
</RowTable.BodyCell>
))}
</RowTable.Row>
<RowTable.Row>
<RowTable.HeadCell name="writer">
<FlexBox
sx={{ justifyContent: 'center', alignItems: 'center', gap: '1rem' }}
>
작성자
<SortingIcon />
</FlexBox>
</RowTable.HeadCell>
{noticeList.map(({ id, writer }) => (
<RowTable.BodyCell key={id}>
<Text ellipsis>{writer}</Text>
</RowTable.BodyCell>
))}
</RowTable.Row>
<RowTable.Row>
<RowTable.HeadCell name="date">
<FlexBox
sx={{ justifyContent: 'center', alignItems: 'center', gap: '1rem' }}
>
날짜
<SortingIcon />
</FlexBox>
</RowTable.HeadCell>
{noticeList.map(({ id, date }) => (
<RowTable.BodyCell key={id}>
<Text ellipsis>{getDateForm(date)}</Text>
</RowTable.BodyCell>
))}
</RowTable.Row>
<RowTable.Row>
<RowTable.HeadCell name="view">
<FlexBox
sx={{ justifyContent: 'center', alignItems: 'center', gap: '1rem' }}
>
조회수
<SortingIcon />
</FlexBox>
</RowTable.HeadCell>
{noticeList.map(({ id, view }) => (
<RowTable.BodyCell key={id}>
<Text ellipsis>{view}</Text>
</RowTable.BodyCell>
))}
</RowTable.Row>
</RowTable>
);

export default RowTablePage;
17 changes: 5 additions & 12 deletions packages/playground-react/tsconfig.path.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,11 @@
"compilerOptions": {
"baseUrl": "./",
"paths": {
"@components/*": [
"components/*"
],
"@pages/*": [
"pages/*"
],
"@styles/*": [
"styles/*"
],
"@utils/*": [
"utils/*"
]
"@components/*": ["components/*"],
"@pages/*": ["pages/*"],
"@styles/*": ["styles/*"],
"@utils/*": ["utils/*"],
"@constants/*": ["constants/*"]
}
}
}
15 changes: 10 additions & 5 deletions packages/primitives/src/components/Table/BasicTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@ const BasicTable = ({
<caption css={offscreen}>{caption}</caption>
{columnsWidth && (
<colgroup>
{columnsWidth.map((width, index) => (
// 유동적으로 변하지 않는 리스트
// eslint-disable-next-line react/no-array-index-key
<col key={index} width={width} />
))}
{columnsWidth.map((width, index) => {
const pxWidth = /[0-9.]+rem/.test(width)
? `${parseFloat(width) * 10}px`
: width;
Comment on lines +21 to +24
Copy link
Member

Choose a reason for hiding this comment

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

추후 '%, em 등의 단위도 쓸 수 있게 해주세요' 라는 요구사항이 있을 수도 있다고 생각해요
그러면 삼항연산자가 변경에 대응하기가 좋을까? 라는 생각이 들었어요

Copy link
Contributor Author

Choose a reason for hiding this comment

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

%는 사용가능합니다! em은 부모 박스의 css에 따라 상대적으로 정해지는거라 모든 부모들의 font-size를 계산해야하고 em을 width에 잘쓰지 않아서 고려해도 되지 않다고 생각했어요!
width에 자주 쓰는 px, %, rem 3가지가 가능하니 괜찮지않을까 싶습니다!

return (
// 유동적으로 변하지 않는 리스트
// eslint-disable-next-line react/no-array-index-key
<col key={index} width={pxWidth} />
);
})}
</colgroup>
)}
<tbody>{children}</tbody>
Expand Down