anvil/striker-ui/components/Grid.tsx

38 lines
901 B
TypeScript
Raw Normal View History

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,
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;
return itemGridProps ? (
2022-11-12 01:45:47 +00:00
<MUIGrid
{...calculateItemBreakpoints(index, key)}
key={key}
item
{...itemGridProps}
/>
) : undefined;
2022-11-12 01:45:47 +00:00
});
}, [calculateItemBreakpoints, layout]);
return (
// 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;