import React, { Children, cloneElement, isValidElement } from "react";
import TableRowProps from "./TableRow.types";
import { TableCell } from "../index";
export const TableRow = ({
id,
children,
classes,
firstCellIsHeader,
...attributes
}: TableRowProps) => {
const arrayChildren: any = Children.toArray(children);
return (
<>
{Children.map(arrayChildren, (child: any, index) => {
if (isValidElement(child) && child.type === TableCell) {
if (firstCellIsHeader && index === 0) {
return (
<>
{cloneElement(child as React.ReactElement, { isHeader: true, scope: "row" })}
>
);
}
return <>{cloneElement(child as React.ReactElement, {})}>;
}
})}
>
);
};
export default TableRow;