fix(striker-ui): add custom Grid

main
Tsu-ba-me 2 years ago
parent e3ebbac07e
commit fa3fc07d85
  1. 33
      striker-ui/components/Grid.tsx
  2. 17
      striker-ui/types/Grid.d.ts

@ -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…
Cancel
Save