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

Masonry 瀑布流

排列高度不一的卡片与图片。

基本用法

灵感 1

不同高度的卡片

灵感 2

不同高度的卡片

灵感 3

不同高度的卡片

灵感 4

不同高度的卡片

灵感 5

不同高度的卡片

灵感 6

不同高度的卡片
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={`灵感 ${index + 1}`}>
          <div style={{ height }}>不同高度的卡片</div>
        </Card>
      ))}
    </Masonry>
  );
}

更多用法

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={`风景 ${index}`}
          width="100%"
          height={index === 2 ? 220 : 150}
        />
      ))}
    </Masonry>
  );
}

使用说明

按列从上到下排列;按行阅读或固定焦点顺序的内容建议使用 Grid。

类型

组装数据、定义回调和使用 ref 时,可以导入这些类型。

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

MasonryProps API

属性类型默认值说明
columnsnumber | Partial<Record<'xs' | 'sm' | 'md' | 'lg' | 'xl', number>>{ xs: 1, sm: 2, lg: 3 }列数;较大断点继承较小断点
gapnumber | string16间距;数组为 [纵向, 横向]