2022-11-14 23:22:01 +00:00
|
|
|
import { Box as MUIBox, Grid as MUIGrid } from '@mui/material';
|
2022-11-12 01:45:47 +00:00
|
|
|
import { FC, useMemo } from 'react';
|
|
|
|
|
|
|
|
const Grid: FC<GridProps> = ({
|
|
|
|
calculateItemBreakpoints = () => ({ xs: 1 }),
|
|
|
|
layout,
|
2022-11-14 23:22:01 +00:00
|
|
|
wrapperBoxProps,
|
2022-11-12 01:45:47 +00:00
|
|
|
...restGridProps
|
|
|
|
}) => {
|
|
|
|
const itemElements = useMemo(() => {
|
|
|
|
const items = Object.entries(layout);
|
|
|
|
|
|
|
|
return items.map(([itemId, itemGridProps], index) => {
|
|
|
|
const key = itemId;
|
|
|
|
|
2022-11-15 01:36:49 +00:00
|
|
|
return itemGridProps ? (
|
2022-11-12 01:45:47 +00:00
|
|
|
<MUIGrid
|
|
|
|
{...calculateItemBreakpoints(index, key)}
|
|
|
|
key={key}
|
|
|
|
item
|
|
|
|
{...itemGridProps}
|
|
|
|
/>
|
2022-11-15 01:36:49 +00:00
|
|
|
) : undefined;
|
2022-11-12 01:45:47 +00:00
|
|
|
});
|
|
|
|
}, [calculateItemBreakpoints, layout]);
|
|
|
|
|
|
|
|
return (
|
2022-11-14 23:22:01 +00:00
|
|
|
// Make Grid compatible with FlexBox by adding an extra empty wrapper.
|
|
|
|
<MUIBox {...wrapperBoxProps}>
|
|
|
|
<MUIGrid container {...restGridProps}>
|
|
|
|
{itemElements}
|
|
|
|
</MUIGrid>
|
|
|
|
</MUIBox>
|
2022-11-12 01:45:47 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Grid;
|