For AI agents: the complete documentation index is available at https://ifhover.github.io/leaf-ui/en/llms.txt, the full documentation bundle is available at https://ifhover.github.io/leaf-ui/en/llms-full.txt, and this page is available as Markdown at https://ifhover.github.io/leaf-ui/en/components/masonry.md.

Masonry

Arrange cards and images of varying heights.

Basic usage

Idea 1

Cards of different heights

Idea 2

Cards of different heights

Idea 3

Cards of different heights

Idea 4

Cards of different heights

Idea 5

Cards of different heights

Idea 6

Cards of different heights
basic.tsx
import { Card, Masonry } from '@ifhover/leaf-ui';

export function MasonryBasic() {
  return (
    <Masonry columns={{ xs: 1, sm: 2, lg: 3 }} gap={16}>
      {[100, 160, 120, 180, 110, 140].map((height, index) => (
        <Card key={height} title={`Idea ${index + 1}`}>
          <div style={{ height }}>Cards of different heights</div>
        </Card>
      ))}
    </Masonry>
  );
}

More examples

advanced.tsx
import { Image, Masonry } from '@ifhover/leaf-ui';

import { withBase } from '@rspress/core/runtime';

export function MasonryImages() {
  return (
    <Masonry columns={{ xs: 1, sm: 2 }}>
      {[1, 2, 3].map((index) => (
        <Image
          key={index}
          src={withBase(`/media/landscape-${index}.svg`)}
          alt={`Landscape ${index}`}
          width="100%"
          height={index === 2 ? 220 : 150}
        />
      ))}
    </Masonry>
  );
}

Usage

Flows down each column. Use Grid when row order matters for reading or focus.

Types

Import these types for data, callbacks and refs.

import type { MasonryProps } from '@ifhover/leaf-ui';

MasonryProps API

PropertyTypeDefaultDescription
columnsnumber | Partial<Record<'xs' | 'sm' | 'md' | 'lg' | 'xl', number>>{ xs: 1, sm: 2, lg: 3 }Columns; unspecified breakpoints inherit smaller ones
gapnumber | string16Gap; tuples use [vertical, horizontal]