import React from 'react'; import { Box, HStack, VStack } from '../../primitives'; import type { ISimpleGridProps } from './types'; // const isDebug = process.env.NODE_ENV !== 'production'; import { useThemeProps } from '../../../hooks/useThemeProps'; const DEBUG_STYLES = false ? { rows: { border: '1px solid black', }, cols: { border: '1px solid red', }, } : { rows: {}, cols: {}, }; const SimpleGrid = (props: ISimpleGridProps, ref?: any): JSX.Element => { const { columns, space, spacingX, spacingY, minChildWidth, children, ...remainingProps } = useThemeProps('SimpleGrid', props); let cellSpacing = space ?? 0; let cellSpacingX = spacingX ?? cellSpacing; let cellSpacingY = spacingY ?? cellSpacing; const childrenArray = React.Children.toArray(children); if (columns) { let rowSlices = []; for (let i = 0; i < childrenArray.length; i = i + columns) { rowSlices.push(childrenArray.slice(i, i + columns)); } return ( {rowSlices.map((row, rowIndex) => { return ( {row.map((col: any) => { return ( {col} ); })} ); })} ); } // Needs more work for empty spacing i.e. auto-fit. Current workaround is to use wrap and let the columns be created dynamically // https://css-tricks.com/auto-sizing-columns-css-grid-auto-fill-vs-auto-fit/ else if (minChildWidth) { return ( {childrenArray.map((col: any) => { return ( {col} ); })} ); } return <>; }; export default React.memo(React.forwardRef(SimpleGrid));