Masonry
Description
The Masonry component arranges its child components in a dynamic, grid-like layout where items are organized into columns of equal width. It is part of the Collections group and is ideal for displaying cards or items with variable height, much like a Pinterest-style layout. Use this component when you need a responsive, masonry-style grid that automatically lays out items in multiple columns with a configurable gutter.
Usage
Instantiate the Masonry component using the static helper methods provided by the Tesserae.UI class. Specify the number of columns and optional gutter space (in pixels) between items. The component automatically wraps each child in a container with styling adjustments.
Below is a minimal example demonstrating how to create a Masonry layout with several card components:
API reference
public class Masonry : IContainer<Masonry, IComponent>, IHasBackgroundColor, IHasMarginPadding, ISpecialCaseStylingA masonry (Pinterest-style) layout that flows items of varying heights into columns of equal width.
- Namespace
- Tesserae
- Implements
- IContainer<Masonry, IComponent>, IHasBackgroundColor, IHasMarginPadding, ISpecialCaseStyling
Constructors
| Name | Description |
|---|---|
| Masonry | Initializes a new instance of this class. |
Properties
| Name | Description |
|---|---|
| Background | Gets or sets the CSS background of the component. |
| Margin | Gets or sets the CSS margin of the component. |
| Padding | Gets or sets the CSS padding of the component. |
| StylingContainer | Gets or sets the styling container. |
| PropagateToStackItemParent | Gets or sets the propagate to stack item parent. |
public string Background { get ; set ; }Gets or sets the CSS background of the component.
public string Margin { get ; set ; }Gets or sets the CSS margin of the component.
public string Padding { get ; set ; }Gets or sets the CSS padding of the component.
public HTMLElement StylingContainerGets or sets the styling container.
Methods
| Name | Description |
|---|---|
| Add | Adds the given item to the component. |
| Clear | Clears the component's current state. |
| Replace | Replaces an existing item with a new one. |
| Remove | Removes the given item from the component. |
| Render | Renders the component's root HTML element. |
public void Replace(IComponent newComponent, IComponent oldComponent)Replaces an existing item with a new one.
public void Remove(IComponent component)Removes the given item from the component.
Samples
Masonry Layout with Dynamic Cards
In this sample, a Masonry layout is created with 4 columns. Cards with varying heights are dynamically generated and added to the layout.