Skip to content

Commit

Permalink
fix: support tables
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Sep 24, 2024
1 parent 1879a14 commit 142417a
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
53 changes: 53 additions & 0 deletions src/components/table/Table.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { type FC, type ReactNode } from "react"
import {
Table as MuiTable,
type TableProps as MuiTableProps,
TableBody,
type TableBodyProps,
TableCell,
type TableCellProps,
TableContainer,
type TableContainerProps,
TableHead,
type TableHeadProps,
TableRow,
type TableRowProps,
} from "@mui/material"

export interface TableProps extends MuiTableProps {
headers: ReactNode[]
children: ReactNode
containerProps?: TableContainerProps
headProps?: TableHeadProps
headCellProps?: TableCellProps
headRowProps?: TableRowProps
bodyProps?: TableBodyProps
}

const Table: FC<TableProps> = ({
headers,
children,
containerProps,
headProps,
headCellProps,
headRowProps,
bodyProps,
...tableProps
}) => (
<TableContainer {...containerProps}>
<MuiTable {...tableProps}>
<TableHead {...headProps}>
<TableRow {...headRowProps}>
{headers.map((header, index) => (
<TableCell {...headCellProps} key={`table-head-cell-${index}`}>
{header}
</TableCell>
))}
</TableRow>
</TableHead>
<TableBody {...bodyProps}>{children}</TableBody>
</MuiTable>
</TableContainer>
)

export default Table
8 changes: 8 additions & 0 deletions src/components/table/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export { default as Table } from "./Table"
export * from "./Table"
export {
TableCell as Cell,
type TableCellProps as CellProps,
TableRow as BodyRow,
type TableRowProps as BodyRowProps,
} from "@mui/material"
6 changes: 5 additions & 1 deletion src/theme/components/MuiTableHead.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { typographyClasses } from "@mui/material"
import { typographyClasses, tableCellClasses } from "@mui/material"

import { includesClassNames } from "../../utils/theme"
import type Components from "./_components"
Expand All @@ -12,7 +12,11 @@ const MuiTableHead: Components["MuiTableHead"] = {
}),
[`.${typographyClasses.root}`]: {
color: "white",
fontWeight: 600,
marginBottom: 0,
},
[`.${tableCellClasses.head}`]: {
color: "white",
fontWeight: 600,
},
}),
Expand Down

0 comments on commit 142417a

Please sign in to comment.