mirror of
https://github.com/duckietm/Nitro-V3.git
synced 2026-06-19 23:16:21 +00:00
29 lines
1004 B
TypeScript
29 lines
1004 B
TypeScript
import { CSSProperties, FC, useMemo } from 'react';
|
|
import { Grid, GridProps } from './Grid';
|
|
|
|
export interface AutoGridProps extends GridProps
|
|
{
|
|
columnMinWidth?: number;
|
|
columnMinHeight?: number;
|
|
}
|
|
|
|
export const AutoGrid: FC<AutoGridProps> = props =>
|
|
{
|
|
const { columnMinWidth = 40, columnMinHeight = 40, columnCount = 0, fullHeight = false, maxContent = true, overflow = 'auto', style = {}, ...rest } = props;
|
|
|
|
const getStyle = useMemo(() =>
|
|
{
|
|
let newStyle: CSSProperties = {};
|
|
|
|
newStyle['--nitro-grid-column-min-height'] = (columnMinHeight + 'px');
|
|
|
|
if(columnCount > 1) newStyle.gridTemplateColumns = `repeat(auto-fill, minmax(${ columnMinWidth }px, 1fr))`;
|
|
|
|
if(Object.keys(style).length) newStyle = { ...newStyle, ...style };
|
|
|
|
return newStyle;
|
|
}, [ columnMinWidth, columnMinHeight, columnCount, style ]);
|
|
|
|
return <Grid columnCount={ columnCount } fullHeight={ fullHeight } overflow={ overflow } style={ getStyle } { ...rest } />;
|
|
};
|