import React, { useRef } from "react"; import { useTheadContext } from "./thead"; interface IProps extends React.HTMLAttributes { colIndex?: number; // This prop is automatically injected by Thead via React.cloneElement width?: number; // Column width (default: 100) colSpan?: number; } const Th = ({ children, style, colIndex, width = 100, colSpan = 1, ...props }: IProps) => { // Ensure Th is used within Thead context - throws error if not wrapped const { columnCount, columnWidths } = useTheadContext(); // colIndex is injected by Thead component via React.cloneElement const effectiveColIndex = colIndex ?? 0; const ref = useRef(null); const showRightBorder = columnCount > 0 && effectiveColIndex + colSpan - 1 < columnCount - 1; // Calculate width based on colSpan const effectiveWidth = columnWidths .slice(effectiveColIndex, effectiveColIndex + colSpan) .reduce((sum, w) => sum + w, 0); return (
{children} {/* 👇 Invisible hit zone for right border hover detection */} {/* {showRightBorder && (
)} */}
); }; export default Th;