Skip to content

Commit

Permalink
Feat/table re (#56)
Browse files Browse the repository at this point in the history
* chore: 컴포넌트, 스타일 import

* feat(ui-kit): 테이블 컴포넌트 추가

* chore: 린트 픽스
  • Loading branch information
Junkim93 authored Mar 10, 2021
1 parent 468653f commit b057271
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ui-kit/src/components/Table/TableBody.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';
import classnames from 'classnames';
import { TableProps } from './index';

const TableBody = ({ children }: TableProps) => {
return (
<tbody className={classnames('lubycon-table__body', 'lubycon-font-weight--regular')}>
{children}
</tbody>
);
};

export default TableBody;
22 changes: 22 additions & 0 deletions ui-kit/src/components/Table/TableCell.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';
import classnames from 'classnames';
import { TableProps } from './index';
import { useTableHeadContext } from './TableHead';

interface TableCellProps extends TableProps {
as?: 'th' | 'td';
}

const TableCell = ({ children, align = 'left', as }: TableCellProps) => {
const { variant } = useTableHeadContext();
const isHeadCell = variant === 'head' ? 'th' : 'td';
const Component = as ?? isHeadCell;

return (
<Component className={classnames("lubycon-table__cell", `lubycon-table--align-${align}`)}>
{children}
</Component>
);
};

export default TableCell;
21 changes: 21 additions & 0 deletions ui-kit/src/components/Table/TableHead.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React, { createContext } from 'react';
import { useContext } from 'react';
import { TableProps } from './index';

const TableHeadContext = createContext({ variant: '' });

const TableHead = ({ children }: TableProps) => {
return (
<TableHeadContext.Provider value={{ variant: 'head' }}>
<thead className="lubycon-table__head">
{children}
</thead>
</TableHeadContext.Provider>
);
};

export function useTableHeadContext() {
return useContext(TableHeadContext);
}

export default TableHead;
13 changes: 13 additions & 0 deletions ui-kit/src/components/Table/TableRow.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';
import classnames from 'classnames';
import { TableProps } from './index';

const TableRow = ({ children }: TableProps) => {
return (
<tr className={classnames('lubycon-table__row')}>
{children}
</tr>
);
};

export default TableRow;
16 changes: 16 additions & 0 deletions ui-kit/src/components/Table/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React, { HTMLAttributes } from 'react';
import classnames from 'classnames';

export interface TableProps extends Omit<HTMLAttributes<HTMLTableElement>, 'align' | 'bgcolor'> {
align?: 'left' | 'center' | 'right';
}

const Table = ({ children }: TableProps) => {
return <table className={classnames('lubycon-table', 'lubycon-shadow--2')}>{children}</table>;
};

export default Table;
export { default as TableHead } from './TableHead';
export { default as TableBody } from './TableBody';
export { default as TableRow } from './TableRow';
export { default as TableCell } from './TableCell';
1 change: 1 addition & 0 deletions ui-kit/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export { default as ProgressBar } from './components/ProgressBar';
export { default as Accordion } from './components/Accordion';
export { default as Tag } from './components/Tag';
export { default as Modal, ModalHeader, ModalContent, ModalFooter } from './components/Modal';
export { default as Table, TableHead, TableBody, TableRow, TableCell } from './components/Table';
export { Portal } from './contexts/Portal';
export { useToast } from './contexts/Toast';
export { useSnackbar } from './contexts/Snackbar';
Expand Down
30 changes: 30 additions & 0 deletions ui-kit/src/sass/components/_Table.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.lubycon-table {
word-break: break-all;
border-collapse: collapse;
color: get-color('gray100');

&__head {
background-color: get-color('gray20');
}
&__body {
background-color: get-color('gray10');
.lubycon-table__row:not(:last-child) {
border-bottom: 1px solid get-color('gray20');
}
}
&__cell {
padding: 8px 20px;
}

&--align {
&-left {
text-align: left;
}
&-center {
text-align: center;
}
&-right {
text-align: right;
}
}
}
1 change: 1 addition & 0 deletions ui-kit/src/sass/components/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
@import './ProgressBar';
@import './Tag';
@import './Modal';
@import './Table';
34 changes: 34 additions & 0 deletions ui-kit/src/stories/Table.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from 'react';
import { Meta } from '@storybook/react/types-6-0';
import { Table, TableHead, TableBody, TableRow, TableCell } from 'src';

export default {
title: 'Lubycon UI Kit/Table',
} as Meta;

const header = ['제목', '제목', '제목', '제목', '제목'];
const contents = ['내용', '내용을 입력하세요', '내용', '내용을 입력하세요', '내용'];
const iterator = [undefined, undefined, undefined, undefined, undefined, undefined];

export const Default = () => {
return (
<Table>
<TableHead>
<TableRow>
{header.map((name, i) => (
<TableCell key={`th-${i}`}>{name}</TableCell>
))}
</TableRow>
</TableHead>
<TableBody>
{iterator.map((v, rowIdx) => (
<TableRow key={`tbody-row-${rowIdx}`}>
{contents.map((content, contentIdx) => (
<TableCell key={`td-${contentIdx}`}>{content}</TableCell>
))}
</TableRow>
))}
</TableBody>
</Table>
);
};

0 comments on commit b057271

Please sign in to comment.