diff --git a/src/components/Table/Table.tsx b/src/components/Table/Table.tsx index 88280df69..965639dc6 100644 --- a/src/components/Table/Table.tsx +++ b/src/components/Table/Table.tsx @@ -1,6 +1,6 @@ 'use client'; -import type { ComponentProps, FC } from 'react'; +import { forwardRef, type ComponentPropsWithRef } from 'react'; import { twMerge } from 'tailwind-merge'; import { mergeDeep } from '../../helpers/merge-deep'; import { getTheme } from '../../theme-store'; @@ -25,40 +25,30 @@ export interface FlowbiteTableRootTheme { wrapper: string; } -export interface TableProps extends ComponentProps<'table'> { +export interface TableProps extends ComponentPropsWithRef<'table'> { striped?: boolean; hoverable?: boolean; theme?: DeepPartial; } -const TableComponent: FC = ({ - children, - className, - striped, - hoverable, - theme: customTheme = {}, - ...props -}) => { - const theme = mergeDeep(getTheme().table, customTheme); - - return ( -
- -
- - {children} -
-
-
- ); -}; +const TableComponent = forwardRef( + ({ children, className, striped, hoverable, theme: customTheme = {}, ...props }, ref) => { + const theme = mergeDeep(getTheme().table, customTheme); + + return ( +
+ +
+ + {children} +
+
+
+ ); + }, +); TableComponent.displayName = 'Table'; -TableHead.displayName = 'Table.Head'; -TableBody.displayName = 'Table.Body'; -TableRow.displayName = 'Table.Row'; -TableCell.displayName = 'Table.Cell'; -TableHeadCell.displayName = 'Table.HeadCell'; export const Table = Object.assign(TableComponent, { Head: TableHead, diff --git a/src/components/Table/TableBody.tsx b/src/components/Table/TableBody.tsx index 8bd4108a0..e95dab06c 100644 --- a/src/components/Table/TableBody.tsx +++ b/src/components/Table/TableBody.tsx @@ -1,6 +1,6 @@ 'use client'; -import type { ComponentProps, FC } from 'react'; +import { forwardRef, type ComponentPropsWithRef } from 'react'; import { twMerge } from 'tailwind-merge'; import { mergeDeep } from '../../helpers/merge-deep'; import type { DeepPartial } from '../../types'; @@ -13,20 +13,23 @@ export interface FlowbiteTableBodyTheme { cell: FlowbiteTableCellTheme; } -export interface TableBodyProps extends ComponentProps<'tbody'> { +export interface TableBodyProps extends ComponentPropsWithRef<'tbody'> { theme?: DeepPartial; } -export const TableBody: FC = ({ children, className, theme: customTheme = {}, ...props }) => { - const { theme: rootTheme } = useTableContext(); +export const TableBody = forwardRef( + ({ children, className, theme: customTheme = {}, ...props }, ref) => { + const { theme: rootTheme } = useTableContext(); - const theme = mergeDeep(rootTheme.body, customTheme); + const theme = mergeDeep(rootTheme.body, customTheme); - return ( - - - {children} - - - ); -}; + return ( + + + {children} + + + ); + }, +); +TableBody.displayName = 'Table.Body'; diff --git a/src/components/Table/TableCell.tsx b/src/components/Table/TableCell.tsx index e3920ad7d..c1c0683c9 100644 --- a/src/components/Table/TableCell.tsx +++ b/src/components/Table/TableCell.tsx @@ -1,6 +1,6 @@ 'use client'; -import type { ComponentProps, FC } from 'react'; +import { forwardRef, type ComponentPropsWithRef } from 'react'; import { twMerge } from 'tailwind-merge'; import { mergeDeep } from '../../helpers/merge-deep'; import type { DeepPartial } from '../../types'; @@ -10,18 +10,21 @@ export interface FlowbiteTableCellTheme { base: string; } -export interface TableCellProps extends ComponentProps<'td'> { +export interface TableCellProps extends ComponentPropsWithRef<'td'> { theme?: DeepPartial; } -export const TableCell: FC = ({ children, className, theme: customTheme = {}, ...props }) => { - const { theme: bodyTheme } = useTableBodyContext(); +export const TableCell = forwardRef( + ({ children, className, theme: customTheme = {}, ...props }, ref) => { + const { theme: bodyTheme } = useTableBodyContext(); - const theme = mergeDeep(bodyTheme.cell, customTheme); + const theme = mergeDeep(bodyTheme.cell, customTheme); - return ( - - {children} - - ); -}; + return ( + + {children} + + ); + }, +); +TableCell.displayName = 'Table.Cell'; diff --git a/src/components/Table/TableHead.tsx b/src/components/Table/TableHead.tsx index 0379c93b6..65cd6a73c 100644 --- a/src/components/Table/TableHead.tsx +++ b/src/components/Table/TableHead.tsx @@ -1,6 +1,6 @@ 'use client'; -import type { ComponentProps, FC } from 'react'; +import { forwardRef, type ComponentPropsWithRef } from 'react'; import { twMerge } from 'tailwind-merge'; import { mergeDeep } from '../../helpers/merge-deep'; import type { DeepPartial } from '../../types'; @@ -13,20 +13,23 @@ export interface FlowbiteTableHeadTheme { cell: FlowbiteTableHeadCellTheme; } -export interface TableHeadProps extends ComponentProps<'thead'> { +export interface TableHeadProps extends ComponentPropsWithRef<'thead'> { theme?: DeepPartial; } -export const TableHead: FC = ({ children, className, theme: customTheme = {}, ...props }) => { - const { theme: rootTheme } = useTableContext(); +export const TableHead = forwardRef( + ({ children, className, theme: customTheme = {}, ...props }, ref) => { + const { theme: rootTheme } = useTableContext(); - const theme = mergeDeep(rootTheme.head, customTheme); + const theme = mergeDeep(rootTheme.head, customTheme); - return ( - - - {children} - - - ); -}; + return ( + + + {children} + + + ); + }, +); +TableHead.displayName = 'Table.Head'; diff --git a/src/components/Table/TableHeadCell.tsx b/src/components/Table/TableHeadCell.tsx index bf69bc5ad..2f4366cab 100644 --- a/src/components/Table/TableHeadCell.tsx +++ b/src/components/Table/TableHeadCell.tsx @@ -1,6 +1,6 @@ 'use client'; -import type { ComponentProps, FC } from 'react'; +import { forwardRef, type ComponentPropsWithRef } from 'react'; import { twMerge } from 'tailwind-merge'; import { mergeDeep } from '../../helpers/merge-deep'; import type { DeepPartial } from '../../types'; @@ -10,18 +10,21 @@ export interface FlowbiteTableHeadCellTheme { base: string; } -export interface TableHeadCellProps extends ComponentProps<'th'> { +export interface TableHeadCellProps extends ComponentPropsWithRef<'th'> { theme?: DeepPartial; } -export const TableHeadCell: FC = ({ children, className, theme: customTheme = {}, ...props }) => { - const { theme: headTheme } = useTableHeadContext(); +export const TableHeadCell = forwardRef( + ({ children, className, theme: customTheme = {}, ...props }, ref) => { + const { theme: headTheme } = useTableHeadContext(); - const theme = mergeDeep(headTheme.cell, customTheme); + const theme = mergeDeep(headTheme.cell, customTheme); - return ( - - {children} - - ); -}; + return ( + + {children} + + ); + }, +); +TableHeadCell.displayName = 'Table.HeadCell'; diff --git a/src/components/Table/TableRow.tsx b/src/components/Table/TableRow.tsx index 6c5baa5bb..05a36b544 100644 --- a/src/components/Table/TableRow.tsx +++ b/src/components/Table/TableRow.tsx @@ -1,6 +1,6 @@ 'use client'; -import type { ComponentProps, FC } from 'react'; +import { forwardRef, type ComponentPropsWithRef } from 'react'; import { twMerge } from 'tailwind-merge'; import { mergeDeep } from '../../helpers/merge-deep'; import type { DeepPartial } from '../../types'; @@ -12,22 +12,26 @@ export interface FlowbiteTableRowTheme { striped: string; } -export interface TableRowProps extends ComponentProps<'tr'> { +export interface TableRowProps extends ComponentPropsWithRef<'tr'> { theme?: DeepPartial; } -export const TableRow: FC = ({ children, className, theme: customTheme = {}, ...props }) => { - const { theme: rootTheme, hoverable, striped } = useTableContext(); +export const TableRow = forwardRef( + ({ children, className, theme: customTheme = {}, ...props }, ref) => { + const { theme: rootTheme, hoverable, striped } = useTableContext(); - const theme = mergeDeep(rootTheme.row, customTheme); + const theme = mergeDeep(rootTheme.row, customTheme); - return ( - - {children} - - ); -}; + return ( + + {children} + + ); + }, +); +TableRow.displayName = 'Table.Row';