Masonry

View as Markdown

Photos or cards of different heights, packed into columns in their own order.

  • Dawn over Lofoten
    Dawn over LofotenInes Duarte
  • Harbour, low tide
    Harbour, low tideKenji Mori
  • Salt flats
    Salt flatsAda Okafor
  • Lavender rows, Valensole
    Lavender rows, ValensolePriya Raman
  • Rice terraces at noon
    Rice terraces at noonTomas Berg
  • Fog in the pines
    Fog in the pinesJo Lovelace
  • Dune ridge
    Dune ridgeRafael Costa
  • Glacier lagoon
    Glacier lagoonBen Okafor
  • Orchard in bloom
    Orchard in bloomMira Haas
  • Night market lanterns
    Night market lanternsLin Zhao
  • Cliff path, Algarve
    Cliff path, AlgarveInes Duarte
  • Tide pools
    Tide poolsKenji Mori

When to use

Photos or cards of different heights, packed into columns in their own order. Use Gallery instead when the cards are records with fields to show.

Usage

import { Masonry } from "./ui/uicontext/components/Masonry.ts"
interface Photo {	readonly id: string	readonly url: string	readonly alt: string	readonly width: number	readonly height: number}export const Photos = <M>(h: Html.H<M>, photos: ReadonlyArray<Photo>) =>	Masonry(h, {		label: "Photos",		items: photos.map((p) => ({ key: p.id, ratio: p.height / p.width })),		item: (_, i) => h.img.attrs({ src: photos[i]!.url, alt: photos[i]!.alt }),	})

Examples

Cards, at most three across

extra is the card's fixed part under its picture. maxColumns caps the columns for wider cards.

API reference

Options

Masonry options
NameTypeDefaultDescription
labelrequiredstring—What the wall holds, for screen readers: "Moodboard".
itemsrequiredMasonryItem[]——
itemrequired(item: MasonryItem, index: number) => View.Content—Draws an item; it fills its box.
maxColumns1 | 2 | 3 | 444 by default; fewer for wide cards.
styleStyle——

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/masonry

Source