You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
901 B
37 lines
901 B
import { Box as MUIBox, Grid as MUIGrid } from '@mui/material'; |
|
import { FC, useMemo } from 'react'; |
|
|
|
const Grid: FC<GridProps> = ({ |
|
calculateItemBreakpoints = () => ({ xs: 1 }), |
|
layout, |
|
wrapperBoxProps, |
|
...restGridProps |
|
}) => { |
|
const itemElements = useMemo(() => { |
|
const items = Object.entries(layout); |
|
|
|
return items.map(([itemId, itemGridProps], index) => { |
|
const key = itemId; |
|
|
|
return itemGridProps ? ( |
|
<MUIGrid |
|
{...calculateItemBreakpoints(index, key)} |
|
key={key} |
|
item |
|
{...itemGridProps} |
|
/> |
|
) : undefined; |
|
}); |
|
}, [calculateItemBreakpoints, layout]); |
|
|
|
return ( |
|
// Make Grid compatible with FlexBox by adding an extra empty wrapper. |
|
<MUIBox {...wrapperBoxProps}> |
|
<MUIGrid container {...restGridProps}> |
|
{itemElements} |
|
</MUIGrid> |
|
</MUIBox> |
|
); |
|
}; |
|
|
|
export default Grid;
|
|
|