CardGrid
Responsive flex/@container wrapper that lays cards out in a wrapping row,
resizing its items at the ProductCard small/medium/full breakpoints via the
@container/card-grid query name.
Usage
import { calculateColumns, CARD_GRID, CARD_GRID_RESPONSIVE, CardGrid, CardGridItem, CardGridItemProps, CardGridProps, CardGridRowMetrics, CardGridRows, CardGridRowsProps, CardGridSkeletonItem, chunkIntoRows, getCardGridMetrics } from "@desk/ui/compositions/card-grid";Best practices
Render
CardGridItemchildren so each card carriesrole="listitem"under thisrole="list"container — wrapping arbitrary elements loses the list semantics.Keep this as the direct child of
CardGridso the list/listitem semantics stay intact; put the actual card inside it.Chunk items with
chunkIntoRows(usingcalculateColumns) before passingrows; provide a stablegetItemKey(andgetRowKeywhere rows reorder) so React reconciliation stays correct.Render one
CardGridSkeletonItemper expected card while data loads, inside the sameCardGrid— this keeps list semantics and column widths stable across the loading→loaded transition.
Props
CardGrid
| Prop | Type | Default | Description |
|---|---|---|---|
| ref | Ref<HTMLDivElement> | Allows getting a ref to the component instance.
Once the component unmounts, React will set |
CardGridItem
| Prop | Type | Default | Description |
|---|---|---|---|
| ref | Ref<HTMLDivElement> | Allows getting a ref to the component instance.
Once the component unmounts, React will set |
CardGridRows
| Prop | Type | Default | Description |
|---|---|---|---|
| getItemKey | (item: T) => string | ||
| getRowKey | (row: T[], rowIndex: number) => string | ||
| metrics | Omit<CardGridRowMetrics, "rowWidth"> | ||
| renderAfterRow | (props: { metrics: CardGridRowMetrics; row: T[]; rowIndex: number; }) => ReactNode | ||
| renderItem | (props: { index: number; item: T; row: T[]; rowIndex: number; }) => ReactNode | ||
| rows | T[][] |
CardGridSkeletonItem
| Prop | Type | Default | Description |
|---|---|---|---|
| className | string |
Also exports
- const
calculateColumns - const
CARD_GRID - const
CARD_GRID_RESPONSIVE - interface
CardGridItemProps - interface
CardGridProps - interface
CardGridRowMetrics - interface
CardGridRowsProps - const
chunkIntoRows - const
getCardGridMetrics
Composition
Builds on