CardGrid
Responsive @container list that lays cards out in rows. The default
wrap layout is a wrapping flex row whose items resize at the ProductCard
small/medium/full breakpoints via the @container/card-grid query name;
layout="fill" is a grid whose columns stretch to fill each row.
Usage
Best practices
Render
CardGridItemchildren so each card is a list item under this<ul>- wrapping arbitrary elements loses the list semantics.Use
layout="fill"wherever the grid's width changes with the page (a docked panel, a collapsing sidebar): fixed widths leave a ragged gap at the right edge, fill columns don't. KeepCardGridRowson the default, as its row widths come from the fixed metrics.Give the loading grid the same
layoutandminItemSizeas the loaded one, so skeletons and cards share columns and nothing reflows when data lands.Keep this as the direct child of
CardGridso the list 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
CardGridItem
CardGridRows
CardGridSkeletonItem
Also exports
- const
calculateColumns - const
CARD_GRID - const
CARD_GRID_FILL_MIN_WIDTH - const
CARD_GRID_RESPONSIVE - const
cardGridFillColumns - interface
CardGridItemProps - type
CardGridItemSize - type
CardGridProps - interface
CardGridRowMetrics - interface
CardGridRowsProps - const
chunkIntoRows - const
getCardGridMetrics
Composition
Builds on