| 1 |
import { Fragment } from 'react'; |
| 2 |
import { IRow, IRowData, IExtraData, IHeaderRow } from '../../../components'; |
| 3 |
import { mapOpenedRows } from '../../../components'; |
| 4 |
import { Tbody } from '../../../components'; |
| 5 |
|
| 6 |
export interface BodyWrapperProps { |
| 7 |
children?: React.ReactNode; |
| 8 |
mappedRows?: IRow[]; |
| 9 |
rows?: IRow[]; |
| 10 |
onCollapse?: ( |
| 11 |
event: React.MouseEvent, |
| 12 |
rowIndex: number, |
| 13 |
isOpen: boolean, |
| 14 |
rowData: IRowData, |
| 15 |
extraData: IExtraData |
| 16 |
) => undefined; |
| 17 |
tbodyRef?: React.Ref<any> | Function; |
| 18 |
headerRows?: IHeaderRow[]; |
| 19 |
} |
| 20 |
|
| 21 |
export const BodyWrapper: React.FunctionComponent<BodyWrapperProps> = ({ |
| 22 |
mappedRows, |
| 23 |
tbodyRef, |
| 24 |
/* eslint-disable @typescript-eslint/no-unused-vars */ |
| 25 |
rows = [] as IRow[], |
| 26 |
onCollapse, |
| 27 |
headerRows, |
| 28 |
/* eslint-enable @typescript-eslint/no-unused-vars */ |
| 29 |
...props |
| 30 |
}: BodyWrapperProps) => { |
| 31 |
if (mappedRows && mappedRows.some((row) => row.hasOwnProperty('parent'))) { |
| 32 |
return ( |
| 33 |
<Fragment> |
| 34 |
{mapOpenedRows(mappedRows, props.children).map((oneRow, key) => ( |
| 35 |
<Tbody {...props} isExpanded={oneRow.isOpen} key={`tbody-${key}`} ref={tbodyRef as React.Ref<any>}> |
| 36 |
{oneRow.rows} |
| 37 |
</Tbody> |
| 38 |
))} |
| 39 |
</Fragment> |
| 40 |
); |
| 41 |
} |
| 42 |
return <Tbody {...props} ref={tbodyRef as React.Ref<any>} />; |
| 43 |
}; |
| 44 |
BodyWrapper.displayName = 'BodyWrapper'; |