parent
e3ebbac07e
commit
fa3fc07d85
2 changed files with 50 additions and 0 deletions
@ -0,0 +1,33 @@ |
||||
import { Grid as MUIGrid } from '@mui/material'; |
||||
import { FC, useMemo } from 'react'; |
||||
|
||||
const Grid: FC<GridProps> = ({ |
||||
calculateItemBreakpoints = () => ({ xs: 1 }), |
||||
layout, |
||||
...restGridProps |
||||
}) => { |
||||
const itemElements = useMemo(() => { |
||||
const items = Object.entries(layout); |
||||
|
||||
return items.map(([itemId, itemGridProps], index) => { |
||||
const key = itemId; |
||||
|
||||
return ( |
||||
<MUIGrid |
||||
{...calculateItemBreakpoints(index, key)} |
||||
key={key} |
||||
item |
||||
{...itemGridProps} |
||||
/> |
||||
); |
||||
}); |
||||
}, [calculateItemBreakpoints, layout]); |
||||
|
||||
return ( |
||||
<MUIGrid container {...restGridProps}> |
||||
{itemElements} |
||||
</MUIGrid> |
||||
); |
||||
}; |
||||
|
||||
export default Grid; |
@ -0,0 +1,17 @@ |
||||
type GridLayout = { |
||||
[id: string]: import('@mui/material').GridProps; |
||||
}; |
||||
|
||||
type GridOptionalProps = { |
||||
calculateItemBreakpoints?: ( |
||||
index: number, |
||||
key: string, |
||||
) => Partial< |
||||
Pick<import('@mui/material').GridProps, 'xs' | 'sm' | 'md' | 'lg' | 'xl'> |
||||
>; |
||||
}; |
||||
|
||||
type GridProps = import('@mui/material').GridProps & |
||||
GridOptionalProps & { |
||||
layout: GridLayout; |
||||
}; |
Loading…
Reference in new issue