Virtual Card Grid

View as Markdown

Thousands of cards in a scrolling grid that draws only the ones in view, with as many columns as fit.

4,800 photos
IMG_02041.heicLisbon · 1 Jan 2026
IMG_02042.heicKyoto · 2 Jan 2026
IMG_02043.heicOaxaca · 3 Jan 2026
IMG_02044.heicTromsø · 4 Jan 2026
IMG_02045.heicCape Town · 5 Jan 2026
IMG_02046.heicHobart · 6 Jan 2026
IMG_02047.heicReykjavík · 7 Jan 2026
IMG_02048.heicValparaíso · 8 Jan 2026
IMG_02049.heicLisbon · 9 Jan 2026
IMG_02050.heicKyoto · 10 Jan 2026
IMG_02051.heicOaxaca · 11 Jan 2026
IMG_02052.heicTromsø · 12 Jan 2026

When to use

Thousands of cards in a scrolling grid that draws only the ones in view, with as many columns as fit. Use Gallery instead when there are at most a few hundred cards.

Usage

import { VirtualCardGrid } from "./ui/uicontext/components/VirtualCardGrid.ts"
const Message = UiSchema.TaggedEnum({ Resized: { width: Schema.Number } })export const Products = (h: Html.H<typeof Message.Type>, width: number, names: ReadonlyArray<string>) =>	VirtualCardGrid(h, { label: "Products", count: names.length, width, onResize: (w) => Message.Resized({ width: w }), item: (i) => h.div.children(names[i] ?? "") })

Examples

A company directory

Short rows with rowHeight: 76; columns at least minWidth wide fill the space.

Ada OkaforEngineering · Lisbon
Priya OkaforDesign · Berlin
Kenji OkaforSales · Toronto
Tomás OkaforSupport · Singapore
Amara OkaforFinance · Lisbon
Lena OkaforMarketing · Berlin
Omar OkaforData · Toronto
Sofia OkaforLegal · Singapore
Wei OkaforEngineering · Lisbon
Noah OkaforDesign · Berlin
Ines OkaforSales · Toronto
Ravi OkaforSupport · Singapore

API reference

Options

VirtualCardGrid options
NameTypeDefaultDescription
keystring—Names the instance among others in the same view; needed for more than one.
labelrequiredstring—What the cards are: "Photos".
countrequirednumber——
widthrequirednumber—The grid's measured width; 0 before it's measured, which draws for fallbackWidth.
onResizerequired(width: number) => Message——
itemrequired(index: number) => View.Content—Draws the card at an index.
minWidthnumber200The narrowest a column gets, in pixels; 200 by default.
rowHeightnumber240A row's height, card and gap together, in pixels; 240 by default.
heightstring"480px"The scrolling box's height; "480px" by default.
fallbackWidthnumber960The width to lay out for before the first measure; 960 by default.
scrollToIndexnumber—Scrolls to the row holding this card.
styleStyle——

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/virtual-card-grid

Source