Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: create TableHeadRow component #1470

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/stupid-guests-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"flowbite-react": minor
---

Added a new TableHeadRow component for enhanced customization of table header rows.
6 changes: 6 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ git push -u origin fix/accordion-alwaysopen

9. Fill out the Pull Request template, which will be available automatically

10. At the end you need to create a new changeset, use the following command and answers the provided questions.

```bash
bunx changeset
```

#### What Happens Next?

If you have followed the steps above, your Pull Request will be reviewed by a maintainer soon. If it passes review, it will be merged into the `main` branch and will be included in the next release. If not, you will receive feedback about what needs to be improved until it is ready to be merged.
Expand Down
16 changes: 9 additions & 7 deletions packages/ui/src/components/Table/Table.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ describe("Components / Table", () => {
const TestTable: FC<TableProps> = (props) => (
<Table {...props}>
<Table.Head>
<Table.HeadCell>Product name</Table.HeadCell>
<Table.HeadCell>Color</Table.HeadCell>
<Table.HeadCell>Category</Table.HeadCell>
<Table.HeadCell>Price</Table.HeadCell>
<Table.HeadCell>
<span className="sr-only">Edit</span>
</Table.HeadCell>
<Table.HeadRow>
<Table.HeadCell>Product name</Table.HeadCell>
<Table.HeadCell>Color</Table.HeadCell>
<Table.HeadCell>Category</Table.HeadCell>
<Table.HeadCell>Price</Table.HeadCell>
<Table.HeadCell>
<span className="sr-only">Edit</span>
</Table.HeadCell>
</Table.HeadRow>
</Table.Head>
<Table.Body className="divide-y">
<Table.Row className="bg-white dark:border-gray-700 dark:bg-gray-800">
Expand Down
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
4 changes: 3 additions & 1 deletion packages/ui/src/components/Table/TableHead.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import type { DeepPartial } from "../../types";
import { useTableContext } from "./TableContext";
import type { FlowbiteTableHeadCellTheme } from "./TableHeadCell";
import { TableHeadContext } from "./TableHeadContext";
import { FlowbiteTableHeadRowTheme } from "./TableHeadRow";

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

Expand All @@ -26,7 +28,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
31 changes: 31 additions & 0 deletions packages/ui/src/components/Table/TableHeadRow.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"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 { useTableHeadContext } from "./TableHeadContext";

export interface FlowbiteTableHeadRowTheme {
base: string;
}

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

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

const theme = mergeDeep(headTheme.row, customTheme);

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

TableHeadRow.displayName = "Table.HeadRow";
3 changes: 3 additions & 0 deletions packages/ui/src/components/Table/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export const tableTheme: FlowbiteTableTheme = createTheme({
},
head: {
base: "group/head text-xs uppercase text-gray-700 dark:text-gray-400",
row: {
base: "group/row",
},
cell: {
base: "bg-gray-50 px-6 py-3 group-first/head:first:rounded-tl-lg group-first/head:last:rounded-tr-lg dark:bg-gray-700",
},
Expand Down
Loading