diff --git a/app/ui/view/molecule/grid/grid-root.tsx b/app/ui/view/molecule/grid/grid-root.tsx index 5012e7f8..c2dd079a 100644 --- a/app/ui/view/molecule/grid/grid-root.tsx +++ b/app/ui/view/molecule/grid/grid-root.tsx @@ -1,10 +1,13 @@ import { cva } from 'class-variance-authority'; import { ReactNode } from 'react'; +export type ColType = 3 | 4 | 5 | 6; + type GridRootProps = { children: ReactNode; - cols: 3 | 4 | 5 | 6; + cols: ColType; }; + export const GridVariants = cva('grid', { variants: { cols: { diff --git a/app/ui/view/molecule/list/list-root.tsx b/app/ui/view/molecule/list/list-root.tsx index b8f33e93..438d6876 100644 --- a/app/ui/view/molecule/list/list-root.tsx +++ b/app/ui/view/molecule/list/list-root.tsx @@ -1,9 +1,10 @@ import { ReactNode } from 'react'; -type ListRootProps = { - children: ReactNode; +type ListRootProps = { + data: T[]; + render: (item: T) => ReactNode; }; -export function ListRoot({ children }: ListRootProps) { - return
{children}
; +export function ListRoot({ data, render }: ListRootProps) { + return
{data.map((item) => render(item))}
; } diff --git a/app/ui/view/molecule/table/table-header.tsx b/app/ui/view/molecule/table/table-header.tsx index 8bdd0273..d1ee513f 100644 --- a/app/ui/view/molecule/table/table-header.tsx +++ b/app/ui/view/molecule/table/table-header.tsx @@ -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 ( -
{children}
+
+ + {headerinfo.map((info) => ( + {info} + ))} + +
); } diff --git a/app/ui/view/molecule/table/table-root.tsx b/app/ui/view/molecule/table/table-root.tsx index b8c1f7dd..9a87fe31 100644 --- a/app/ui/view/molecule/table/table-root.tsx +++ b/app/ui/view/molecule/table/table-root.tsx @@ -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
{children}
; +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 ( + + + {item.map((info) => ( + {info} + ))} + {actionButton ? {actionButton} : null} + + + ); + }; + + return ( +
+ + +
+ ); } diff --git a/app/ui/view/molecule/table/table.stories.tsx b/app/ui/view/molecule/table/table.stories.tsx index 6f917c37..6a8652dc 100644 --- a/app/ui/view/molecule/table/table.stories.tsx +++ b/app/ui/view/molecule/table/table.stories.tsx @@ -20,28 +20,10 @@ export const TakenLectureTable: StoryObj = { ['HEC01208', '데이터구조와알고리즘1', '3'], ['HEC01208', '데이터구조와알고리즘1', '3'], ]; + return (
- - - - {headerInfo.map((info) => ( - {info} - ))} - - - - {lectures.map((lecture, index) => ( - - - {lecture.map((info) => ( - {info} - ))} - - - ))} - -
+ ); }, @@ -55,31 +37,10 @@ export const ButtonLectureTable: StoryObj = { ['2022', '2학기', 'HEC01208', '데이터구조와알고리즘1', '3'], ['2022', '2학기', 'HEC01208', '데이터구조와알고리즘1', '3'], ]; + const actionButton =
- - - {headerInfo.map((info) => ( - {info} - ))} - - - - {lectures.map((lecture, index) => ( - - - {lecture.map((info) => ( - {info} - ))} - -
+ ); },