Back to Ant Design

Masonry

components/masonry/index.en-US.md

6.3.72.7 KB
Original Source

A masonry layout component for displaying content with different heights.

When To Use

  • When displaying images or cards with irregular heights
  • When content needs to be evenly distributed in columns
  • When column count needs to be responsive

Examples

<!-- prettier-ignore -->

<code src="./demo/basic.tsx">Basic</code> <code src="./demo/responsive.tsx">Responsive</code> <code src="./demo/image.tsx">Image</code> <code src="./demo/dynamic.tsx">Dynamic</code> <code src="./demo/style-class.tsx">Custom semantic dom styling</code> <code src="./demo/fresh.tsx" debug>Fresh</code>

API

Common props ref:Common props

Masonry

PropertyDescriptionTypeDefaultVersion
classNamesCustomize class for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string>-
columnsNumber of columns, can be a fixed value or a responsive configurationnumber | { xs?: number; sm?: number; md?: number }3
freshWhether to continuously monitor the size changes of child itemsbooleanfalse
gutterSpacing, can be a fixed value, responsive configuration, or a configuration for horizontal and vertical spacingGap | [Gap, Gap]0
itemsMasonry itemsMasonryItem[]-
itemRenderCustom item rendering function(item: MasonryItem) => React.ReactNode-
stylesCustomize inline style for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties>-
onLayoutChangeCallback for column sorting changes({ key: React.Key; column: number }[]) => void-

MasonryItem

PropertyDescriptionTypeDefault Value
childrenCustom display content, takes precedence over itemRenderReact.ReactNode-
columnSpecifies the column to which the item belongsnumber-
dataCustom data storageT-
heightHeight of the itemnumber-
keyUnique identifier for the itemstring | number-

Gap

Gap represents the spacing between items. It can either be a fixed value or a responsive configuration.

ts
type Gap = undefined | number | Partial<Record<'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl', number>>;

Semantic DOM

<code src="./demo/_semantic.tsx" simplify="true"></code>

Design Token

<ComponentTokenTable component="Masonry"></ComponentTokenTable>