import React from 'react' ; import * as ReactIs from 'react-is' ; import flatten from 'lodash/flatten' ; import ColumnGroup from '../ColumnGroup' ; /**
 * Get the columns ReactElement array.
 * - Handling the case where there is an array of <Column> in children.
 * - Filter empty items in children.
 */ function getTableColumns ( children ) { const childrenArray = Array . isArray ( children ) ? children : [ children ] ; const flattenColumns = flatten ( childrenArray ) . map ( ( column ) => { if ( column ?. type === ColumnGroup ) { const { header , children : groupChildren , align , fixed , verticalAlign , groupHeaderHeight } = column ?. props ; const childColumns = getTableColumns ( groupChildren ) ; return childColumns . map ( ( childColumn , index ) => { const groupCellProps = { ... childColumn ?. props , groupHeaderHeight , fixed , align : childColumn ?. props . align || align , verticalAlign : childColumn ?. props . verticalAlign || verticalAlign } ; field field field if ( index === 0 ) { groupCellProps . groupAlign = align ; groupCellProps . groupVerticalAlign = verticalAlign ; groupCellProps . groupCount = childColumns . length ; groupCellProps . groupHeader = header ; groupCellProps . resizable = false ; } return React . cloneElement ( childColumn , groupCellProps ) ; } ) ; } else if ( ReactIs . isFragment ( column ) ) { return getTableColumns ( column . props ?. children ) ; } return column ; } ) ; return flatten ( flattenColumns ) . filter ( Boolean ) ; } export default getTableColumns ;