72 lines
1.9 KiB
TypeScript
72 lines
1.9 KiB
TypeScript
import { TableHead, TableRow } from "@common/components/ui";
|
|
|
|
interface TableUpperProps {
|
|
id: string;
|
|
title: string;
|
|
upName?: string;
|
|
upSequnce?: number;
|
|
row? : number;
|
|
rowSpan?: number;
|
|
colSpan?: number;
|
|
visible?:boolean;
|
|
widthPercent?: number;
|
|
}
|
|
|
|
const HeadMakeColSpan = ({ upHeadList }: { upHeadList: TableUpperProps[] }) => {
|
|
const maxRow = upHeadList?.reduce((max, head) => Math.max(max, head.row || 0), 0);
|
|
//upHeadList.forEach((item) => item.visible ?item.visible:true)
|
|
|
|
if(maxRow == 0){
|
|
return (
|
|
<>
|
|
<TableRow className="bg-gray-50">
|
|
{upHeadList
|
|
.filter((item) => item.visible != false)
|
|
.map((head: TableUpperProps) => {
|
|
return (
|
|
<TableHead
|
|
key={head.id}
|
|
colSpan={head.colSpan || 1}
|
|
rowSpan={head.rowSpan || 1}
|
|
style={{ whiteSpace: 'pre-line' }}
|
|
className="bg-gray-50"
|
|
>
|
|
{head.title}
|
|
</TableHead>
|
|
);
|
|
})}
|
|
</TableRow>
|
|
</>
|
|
);
|
|
}else{
|
|
return (
|
|
<>
|
|
{Array.from({ length: maxRow + 1 }, (_, rowIndex) => (
|
|
<TableRow key={rowIndex+ " headerRow"} className="bg-gray-50">
|
|
{upHeadList
|
|
.filter((item) => item.visible != false)
|
|
.map((head: TableUpperProps, idx) => {
|
|
if (head.row === rowIndex) {
|
|
return (
|
|
<TableHead
|
|
key={head.id?head.id:rowIndex+"_"+idx}
|
|
colSpan={head.colSpan || 1}
|
|
rowSpan={head.rowSpan || 1}
|
|
style={{ whiteSpace: 'pre-line' }}
|
|
className="bg-gray-50"
|
|
>
|
|
{head.title}
|
|
</TableHead>
|
|
);
|
|
}
|
|
})}
|
|
</TableRow>
|
|
))}
|
|
</>
|
|
);
|
|
}
|
|
|
|
}
|
|
|
|
export { HeadMakeColSpan };
|