The masonry is a container component which allows to lay out items in a masonry grid.

Layout Types

fixed-spread

All items have the same fixed width. The remaining space is equally distributed between the container and items. If the first row is not filled, then the items are left aligned.

Lorem ipsum dolor sit amet, corpora postulant ocurreret in mel. His illum augue causae ut, vim ne magna prodesset, est ad nemore quodsi alienum. Eos ne case mazim nominavi, ea est malorum sapientem. Ei noluisse expetenda qui. Mei in iusto convenire torquatos. At vix iusto corpora indoctum, nam choro apeirian eu. Et summo volumus sed, sea sale maiorum dignissim te.
Show Markup

                

fixed-centered

All items have the same fixed width. They are centered in the middle of the container with the defined spacing between each other.

Lorem ipsum dolor sit amet, corpora postulant ocurreret in mel. His illum augue causae ut, vim ne magna prodesset, est ad nemore quodsi alienum. Eos ne case mazim nominavi, ea est malorum sapientem. Ei noluisse expetenda qui. Mei in iusto convenire torquatos. At vix iusto corpora indoctum, nam choro apeirian eu. Et summo volumus sed, sea sale maiorum dignissim te.
Show Markup

                

variable

The columnwidth defines the minimum width for the item. If there is remaining space, then it is distributed equally between all items.

Lorem ipsum dolor sit amet, corpora postulant ocurreret in mel. His illum augue causae ut, vim ne magna prodesset, est ad nemore quodsi alienum. Eos ne case mazim nominavi, ea est malorum sapientem. Ei noluisse expetenda qui. Mei in iusto convenire torquatos. At vix iusto corpora indoctum, nam choro apeirian eu. Et summo volumus sed, sea sale maiorum dignissim te.
Show Markup

                

dashboard

Similar to the variable layout; however, remaining vertical space will be filled by expanding items.

Lorem ipsum dolor sit amet, corpora postulant ocurreret in mel. His illum augue causae ut, vim ne magna prodesset, est ad nemore quodsi alienum. Eos ne case mazim nominavi, ea est malorum sapientem. Ei noluisse expetenda qui. Mei in iusto convenire torquatos. At vix iusto corpora indoctum, nam choro apeirian eu. Et summo volumus sed, sea sale maiorum dignissim te.
Show Markup

              

Orderable

Lorem ipsum dolor sit amet, corpora postulant ocurreret in mel. His illum augue causae ut, vim ne magna prodesset, est ad nemore quodsi alienum. Ei noluisse expetenda qui. Mei in iusto convenire torquatos.
Show Markup

                      

Multi-column Items

Lorem ipsum dolor sit amet, corpora postulant ocurreret in mel. His illum augue causae ut, vim ne magna prodesset, est ad nemore quodsi alienum. Ei noluisse expetenda qui. Mei in iusto convenire torquatos. Et summo volumus sed, sea sale maiorum dignissim te.
Show Markup

            

Filtering Items

The following example shows how items can be filtered with JavaScript.
Lorem ipsum dolor sit amet, corpora postulant ocurreret in mel. His illum augue causae ut, vim ne magna prodesset, est ad nemore quodsi alienum. Ei noluisse expetenda qui. Mei in iusto convenire torquatos.
Show Markup

                      
                        
                        

Selecting Items

The following example shows one possibility how selection can be implemented.

Click on items to select/unselect them:

Lorem ipsum dolor sit amet, corpora postulant ocurreret in mel. His illum augue causae ut, vim ne magna prodesset, est ad nemore quodsi alienum. Ei noluisse expetenda qui. Mei in iusto convenire torquatos.
Show Markup

                      
                        

Coral.Masonry API

Constructor

JavaScript:

new Coral.Masonry() or document.createElement('coral-masonry')

HTML Tag:

<coral-masonry>

Extends

Sub-components

Instance Properties

instance.items {Coral.Collection}

Readonly
Coral.Collection which allows to interact with the masonry items.

instance.layout {String}

Reflected
The layout name for this masonry. Must be one of Coral.Masonry.layouts. The following layout types are available by default:
  • fixed-centered: Layout with fixed width centered items
  • fixed-spread: Layout with fixed width and evenly spread items
  • variable: Layout with variable width items
  • dashboard: Layout with variable width items which are expanded in their height to fill gaps
HTML Attribute:
  • layout

instance.selectedItem {Coral.Masonry.Item}

Readonly
The first selected item or null if no item is selected.

instance.selectedItems {Array.<Coral.Masonry.Item>}

Readonly
An array of all selected items.

instance.spacing {Number}

The spacing between the items and the masonry container in pixel. If this property is not set, then it falls back to the CSS padding of the masonry and margin of the items.
Default Value:
  • null
HTML Attribute:
  • spacing

Methods

Coral.Masonry.registerLayout

Registers a layout with the given name. The name can then be set at Coral.Masonry.layout to render a masonry with the this registered layout.
Parameters:
Name Type Description
name String the lower case name of the layout
Layout Layout class which extends Layout

instance.deselectAll

Deselects all items.
See:
  • #selectAll

instance.get

Get the value of a property.
Parameters:
Name Type Description
property String The name of the property to fetch the value of.
Returns:
Property value. {*}
Inherited From:

instance.hide

Hide this component.
Returns:
this, chainable {Coral.Component}
Inherited From:

instance.off

Remove an event listener.
Parameters:
Name Type Optional Description
eventName String No
The event name to stop listening for.
selector String Yes
The selector that was used for event delegation.
func function No
The function that was passed to on().
useCapture Boolean Yes
Only remove listeners with useCapture set to the value passed in.
Returns:
this, chainable. {Coral.Component}
Inherited From:

instance.on

Add an event listener.
Parameters:
Name Type Optional Default Description
eventName String No
The event name to listen for.
selector String Yes
The selector to use for event delegation.
func function No
The function that will be called when the event is triggered.
useCapture Boolean Yes
false Whether or not to listen during the capturing or bubbling phase.
Returns:
this, chainable. {Coral.Component}
Inherited From:

instance.remove

Non-destructively remove this element. It can be re-added by simply appending it to the document again. It will be garbage collected if there are no more references to it. This is different from using jQuery's remove(), which is destructive in that it removes data and listeners.
Inherited From:

instance.selectAll

Selects all items.
See:
  • #deselectAll

instance.show

Show this component.
Returns:
this, chainable {Coral.Component}
Inherited From:

instance.trigger

Trigger an event.
Parameters:
Name Type Optional Default Description
eventName String No
The event name to trigger.
props Object Yes
Additional properties to make available to handlers as event.detail.
bubbles Boolean Yes
true Set to false to prevent the event from bubbling.
cancelable Boolean Yes
true Set to false to prevent the event from being cancelable.
Returns:
CustomEvent object {CustomEvent}
Inherited From:

Events

coral-component:attached

Triggered when the component is attached to the DOM.
Callback Parameters:
Name Type Description
event Object Event object.
Inherited From:

coral-component:detached

Triggered when the component is detached to the DOM.
Callback Parameters:
Name Type Description
event Object Event object.
Inherited From:

coral-component:ready

Triggerred when the component has been upgraded and is ready for use.
Callback Parameters:
Name Type Description
event Object Event object.
Inherited From:

coral-masonry:order

Triggered when an item is reordered.
Callback Parameters:
Name Type Description
event Object

Event object

Name Type Optional Description
event.detail.item Coral.Masonry.Item No
The reordered item
event.detail.oldBefore Coral.Masonry.Item No
<nullable>
The previous item before the reordering.
event.detail.before Coral.Masonry.Item No
<nullable>
The previous item after the reordering.

Coral.Masonry.Item API

Constructor

JavaScript:

new Coral.Masonry.Item() or document.createElement('coral-masonry-item')

HTML Tag:

<coral-masonry-item>

Extends

Instance Properties

instance.orderable {Boolean}

Whether or not it is possible to order items with drag & drop.
Default Value:
  • false
HTML Attribute:
  • orderable

instance.selected {Boolean}

Reflected
Whether the item is selected.
Default Value:
  • false
HTML Attribute:
  • selected

Methods

instance.get

Get the value of a property.
Parameters:
Name Type Description
property String The name of the property to fetch the value of.
Returns:
Property value. {*}
Inherited From:

instance.hide

Hide this component.
Returns:
this, chainable {Coral.Component}
Inherited From:

instance.off

Remove an event listener.
Parameters:
Name Type Optional Description
eventName String No
The event name to stop listening for.
selector String Yes
The selector that was used for event delegation.
func function No
The function that was passed to on().
useCapture Boolean Yes
Only remove listeners with useCapture set to the value passed in.
Returns:
this, chainable. {Coral.Component}
Inherited From:

instance.on

Add an event listener.
Parameters:
Name Type Optional Default Description
eventName String No
The event name to listen for.
selector String Yes
The selector to use for event delegation.
func function No
The function that will be called when the event is triggered.
useCapture Boolean Yes
false Whether or not to listen during the capturing or bubbling phase.
Returns:
this, chainable. {Coral.Component}
Inherited From:

instance.remove

Non-destructively remove this element. It can be re-added by simply appending it to the document again. It will be garbage collected if there are no more references to it. This is different from using jQuery's remove(), which is destructive in that it removes data and listeners.
Inherited From:

instance.show

Show this component.
Returns:
this, chainable {Coral.Component}
Inherited From:

instance.trigger

Trigger an event.
Parameters:
Name Type Optional Default Description
eventName String No
The event name to trigger.
props Object Yes
Additional properties to make available to handlers as event.detail.
bubbles Boolean Yes
true Set to false to prevent the event from bubbling.
cancelable Boolean Yes
true Set to false to prevent the event from being cancelable.
Returns:
CustomEvent object {CustomEvent}
Inherited From:

Events

coral-component:attached

Triggered when the component is attached to the DOM.
Callback Parameters:
Name Type Description
event Object Event object.
Inherited From:

coral-component:detached

Triggered when the component is detached to the DOM.
Callback Parameters:
Name Type Description
event Object Event object.
Inherited From:

coral-component:ready

Triggerred when the component has been upgraded and is ready for use.
Callback Parameters:
Name Type Description
event Object Event object.
Inherited From: