import { Table, Caption, Thead, Tbody, Tr } from './table-elements' import { ComponentProps } from '../../types' import React from 'react' export interface TableProps extends ComponentProps { tblHead: React.ReactNode tblBody: React.ReactNode tblCaption?: React.ReactNode } export type dataType = { id: number; items: string[] }[] /** * Render the `thead` by passing an array of names */ export const RenderHead = (data: []) => { const head = data.map((item, index) => { return {item} }) return {head} } /** * Render the table body `tr`, `td` with the data provided */ export const RenderBody = (data: Record[]) => { const rec = data.map((item, index) => { return ( {/* {item?.id} {item?.items} */} ) }) return {rec} } /** * Render the table placing `caption`, `thead` and `tbody` in the correct order * caption is optional */ export const RenderTable = ({ tblBody, tblCaption, tblHead }: TableProps) => { return ( {tblCaption && } {tblHead}{tblBody}
{tblCaption}
) } RenderTable.displayName = 'TBL' RenderBody.displayName = 'renderBody' RenderHead.displayName = 'renderHead'