Skip to content

Commit

Permalink
feat: create TableHeadRow component
Browse files Browse the repository at this point in the history
  • Loading branch information
raky291 committed Aug 16, 2024
1 parent 210cb9e commit 487b3e8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/ui/src/components/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { TableCell } from "./TableCell";
import { TableContext } from "./TableContext";
import { TableHead, type FlowbiteTableHeadTheme } from "./TableHead";
import { TableHeadCell } from "./TableHeadCell";
import { TableHeadRow } from "./TableHeadRow";
import { TableRow, type FlowbiteTableRowTheme } from "./TableRow";

export interface FlowbiteTableTheme {
Expand Down Expand Up @@ -52,6 +53,7 @@ TableComponent.displayName = "Table";

export const Table = Object.assign(TableComponent, {
Head: TableHead,
HeadRow: TableHeadRow,
Body: TableBody,
Row: TableRow,
Cell: TableCell,
Expand Down
3 changes: 2 additions & 1 deletion packages/ui/src/components/Table/TableHead.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { TableHeadContext } from "./TableHeadContext";

export interface FlowbiteTableHeadTheme {
base: string;
row: string;
cell: FlowbiteTableHeadCellTheme;
}

Expand All @@ -26,7 +27,7 @@ export const TableHead = forwardRef<HTMLTableSectionElement, TableHeadProps>(
return (
<TableHeadContext.Provider value={{ theme }}>
<thead className={twMerge(theme.base, className)} ref={ref} {...props}>
<tr>{children}</tr>
{children}
</thead>
</TableHeadContext.Provider>
);
Expand Down
28 changes: 28 additions & 0 deletions packages/ui/src/components/Table/TableHeadRow.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"use client";

import { forwardRef, type ComponentPropsWithRef } from "react";
import { twMerge } from "tailwind-merge";
import { mergeDeep } from "../../helpers/merge-deep";
import type { DeepPartial } from "../../types";
import { useTableContext } from "./TableContext";
import type { FlowbiteTableHeadTheme } from "./TableHead";

export interface TableHeadRowProps extends ComponentPropsWithRef<"tr"> {
theme?: DeepPartial<FlowbiteTableHeadTheme>;
}

export const TableHeadRow = forwardRef<HTMLTableRowElement, TableHeadRowProps>(
({ children, className, theme: customTheme = {}, ...props }, ref) => {
const { theme: rootTheme } = useTableContext();

const theme = mergeDeep(rootTheme.head, customTheme);

return (
<tr className={twMerge(theme.row, className)} ref={ref} {...props}>
{children}
</tr>
);
},
);

TableHeadRow.displayName = "Table.HeadRow";

0 comments on commit 487b3e8

Please sign in to comment.