'use client'; import { PolymorphicComponentProps } from '@kalink-ui/dibbly'; import { assignInlineVars } from '@vanilla-extract/dynamic'; import { ElementType } from 'react'; import { defaultOrder, resolveResponsive } from '../../styles/responsive'; import { gridVars, GridVariants } from './grid.css'; import { gridResponsive } from './grid.responsive'; import type { Responsive } from '../../styles/responsive'; interface GridVariantResponsive { spacing?: Responsive>; columnSpacing?: Responsive>; rowSpacing?: Responsive>; columns?: Responsive>; autoLayout?: Responsive>; justifyItems?: Responsive>; alignItems?: Responsive>; justifyContent?: Responsive>; alignContent?: Responsive>; } export type GridProps = PolymorphicComponentProps & GridVariantResponsive & { /** * The minimum size of a grid cell */ minSize?: string; }; /** * The Grid layout provides a flexible, responsive grid system. It can also * arranges elements in a structured, multi-column format, automatically * adjusting the number of columns based on the available space and * predefined constraints. * * https://every-layout.dev/layouts/grid/ */ export function Grid(props: GridProps) { const { use: Comp = 'div', minSize, className, spacing, columnSpacing, rowSpacing, columns = { xs: 4, md: 8, lg: 12 }, autoLayout, justifyItems, alignItems, justifyContent, alignContent, ...rest } = props; const autoLayoutMap = resolveResponsive(autoLayout, defaultOrder); const columnsMap = resolveResponsive(columns, defaultOrder); const columnsEntries = Object.entries(columnsMap).filter( ([breakpoint]) => !autoLayoutMap[breakpoint as keyof typeof autoLayoutMap], ); const columnsForLayout = columnsEntries.length ? (Object.fromEntries(columnsEntries) as Responsive< NonNullable >) : undefined; return ( )} /> ); }