-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: 컴포넌트, 스타일 import * feat(ui-kit): 테이블 컴포넌트 추가 * chore: 린트 픽스
- Loading branch information
Showing
9 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,4 @@ | |
@import './ProgressBar'; | ||
@import './Tag'; | ||
@import './Modal'; | ||
@import './Table'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |