import React, { TableHTMLAttributes } from 'react' import { ColumnWithLooseAccessor, HeaderGroup } from 'react-table' import { concat } from '../utils' import Colgroup from './Colgroup' import { useHorizontalScroll } from './providers/HorizontalScrollProvider' import { useTable } from './providers/TableProvider' export type Props = { columns: Array> headerGroups: Array> tableHtmlProps?: TableHTMLAttributes cellClassName?: string } export default function THead(props: Props) { const { columns, headerGroups, tableHtmlProps, cellClassName } = props const { prefix, fixHead } = useTable() const { registerHeadDom } = useHorizontalScroll() const headerPrefix = concat(prefix, 'header') function renderHeadRow() { return headerGroups.map(headerGroup => ( // eslint-disable-next-line react/jsx-key {headerGroup.headers.map((column, idx) => column.render('Header', { isLast: idx === headerGroup.headers.length - 1, key: column.id, index: idx, className: cellClassName }))} )) } if (fixHead) { return (
{renderHeadRow()}
) } return ( {renderHeadRow()} ) }