Masonry
Grid layout with optimized available space for varying heights and widths
Use the Masonry
component to display content, like images or cards, in an organized, visually appealing manner. Unlike traditional grid layouts with fixed rows and columns, masonry layouts position elements in a way that optimizes available space, allowing for varying heights and widths of content blocks.
The Masonry
component expects an items
prop referencing an array of object. Each object in the array can have the following properties:
component
: Sets the item to a component.props
: Sets the props on the component.children
: Sets the children of the component.html
: Sets the item to a HTML string.
The children
property can be a number, a string, or reference another component object in the form of:
Child components cannot contain other child components. If you need further nesting, create a new component for the nested part and pass it to the top-level component
property of your item.
Columns
By default, the Masonry
component have three columns. This can be configured using the columns
property:
Custom Gaps and Element
The Masonry
component is rendered into a section
element. This can be customized along with the gap size using the element
and gap
props:
If you need to globally specify gaps for your Masonry
component, the preferred way is to override the following CSS variable:
This way, you won’t need to specify the gap
prop on each individual Masonry
component.
Sequential Order
The items of the masonry component are ordered from left to right, top to bottom. This ordering can be changed with the sequential
prop. Set sequential
to true
to order the items in sequential order, arranging them from top to bottom first:
API
Prop | Default | Purpose |
---|---|---|
items | [] | Sets the items of the masonry. |
items.component | - | Sets the item to a component. |
items.props | - | Sets the props on the component. |
items.children | - | Sets the children if the item is a component. |
items.children.component | - | Sets the children to a component. |
items.children.props | - | Sets props on the child component. |
items.children.children | - | Sets the children of the child component. |
items.html | - | Sets the item to a HTML string. |
element | section | Sets the HTML tag of the masonry. |
gap | 5px | Sets the gap between masonry items. |
columns | 3 | Sets the number of columns. |
sequential | false | Displays the masonry items in sequential order. |
className | - | Pass additional CSS classes for the masonry. |
Request improvement for this page