-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Refactor table component and add new props
- Loading branch information
1 parent
b0be474
commit 14cf989
Showing
5 changed files
with
63 additions
and
56 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
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 |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import { ReactNode } from 'react'; | ||
|
||
type ListRootProps = { | ||
children: ReactNode; | ||
type ListRootProps<T> = { | ||
data: T[]; | ||
render: (item: T) => ReactNode; | ||
}; | ||
|
||
export function ListRoot({ children }: ListRootProps) { | ||
return <div className="rounded-2xl border-[1px] border-black-2 w-full">{children}</div>; | ||
export function ListRoot<T>({ data, render }: ListRootProps<T>) { | ||
return <div className="rounded-2xl border-[1px] border-black-2 w-full">{data.map((item) => render(item))}</div>; | ||
} |
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 |
---|---|---|
@@ -1,10 +1,19 @@ | ||
import { ReactNode } from 'react'; | ||
import Grid from '../grid'; | ||
import { ColType } from '../grid/grid-root'; | ||
|
||
type TableHeaderProps = { | ||
children: ReactNode; | ||
headerinfo: string[]; | ||
cols: ColType; | ||
}; | ||
export function TableHeader({ children }: TableHeaderProps) { | ||
|
||
export function TableHeader({ cols, headerinfo }: TableHeaderProps) { | ||
return ( | ||
<div className="text-light-blue-6 leading-4 text-lg font-bold bg-light-blue-1 py-5 rounded-[100px]">{children}</div> | ||
<div className="text-light-blue-6 leading-4 text-lg font-bold bg-light-blue-1 py-5 rounded-[100px]"> | ||
<Grid cols={cols}> | ||
{headerinfo.map((info) => ( | ||
<Grid.Column key={info}>{info}</Grid.Column> | ||
))} | ||
</Grid> | ||
</div> | ||
); | ||
} |
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 |
---|---|---|
@@ -1,9 +1,42 @@ | ||
import { ReactNode } from 'react'; | ||
import { TableHeader } from './table-header'; | ||
import { ColType } from '../grid/grid-root'; | ||
import List from '../list'; | ||
import Grid from '../grid'; | ||
|
||
type TableRootProps = { | ||
children: ReactNode; | ||
headerinfo: string[]; | ||
// cols: ColType; | ||
data: string[][]; | ||
actionButton?: JSX.Element; | ||
}; | ||
|
||
export function TableRoot({ children }: TableRootProps) { | ||
return <div className="flex flex-col gap-2.5 w-[800px]">{children}</div>; | ||
function isCol(cols: number): cols is ColType { | ||
if (cols === 3 || cols === 4 || cols === 5 || cols === 6) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
export function TableRoot({ data, headerinfo, actionButton }: TableRootProps) { | ||
const cols = actionButton ? headerinfo.length + 1 : headerinfo.length; | ||
|
||
const render = (item: string[]) => { | ||
return ( | ||
<List.Row> | ||
<Grid cols={isCol(cols) ? cols : 6}> | ||
{item.map((info) => ( | ||
<Grid.Column key={info}>{info}</Grid.Column> | ||
))} | ||
{actionButton ? <Grid.Column>{actionButton}</Grid.Column> : null} | ||
</Grid> | ||
</List.Row> | ||
); | ||
}; | ||
|
||
return ( | ||
<div className="flex flex-col gap-2.5 w-[800px]"> | ||
<TableHeader headerinfo={headerinfo} cols={isCol(cols) ? cols : 6} /> | ||
<List data={data} render={render}></List> | ||
</div> | ||
); | ||
} |
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