import React, { forwardRef, memo, type ReactNode, type CSSProperties } from "react"; import { assert } from "tsafe/assert"; import type { Equals } from "tsafe"; import { fr } from "./fr"; import { cx } from "./tools/cx"; import { symToStr } from "tsafe/symToStr"; import type { FrClassName } from "./fr/generatedFromCss/classNames"; import { useAnalyticsId } from "./tools/useAnalyticsId"; export type TableProps = { id?: string; data: ReactNode[][]; className?: string; caption?: ReactNode; headers?: ReactNode[]; /** Default: false */ fixed?: boolean; /** Default: false */ noScroll?: boolean; /** Default: false */ bordered?: boolean; /** Default: false */ noCaption?: boolean; /** Default: false */ bottomCaption?: boolean; style?: CSSProperties; colorVariant?: TableProps.ColorVariant; }; export namespace TableProps { type ExtractColorVariant = FrClassName extends `fr-table--${infer AccentColor}` ? Exclude< AccentColor, "no-scroll" | "no-caption" | "caption-bottom" | "layout-fixed" | "bordered" > : never; export type ColorVariant = ExtractColorVariant; } /** @see */ export const Table = memo( forwardRef((props, ref) => { const { id: id_props, data, headers, caption, bordered = false, noScroll = false, fixed = false, noCaption = false, bottomCaption = false, colorVariant, className, style, ...rest } = props; assert>(); const id = useAnalyticsId({ "defaultIdPrefix": "fr-table", "explicitlyProvidedId": id_props }); return (
{caption !== undefined && } {headers !== undefined && ( {headers.map((header, i) => ( ))} )} {data.map((row, i) => ( {row.map((col, j) => ( ))} ))}
{caption}
{header}
{col}
); }) ); Table.displayName = symToStr({ Table }); export default Table;