Element: <oj-masonry-layout>

Oracle® JavaScript Extension Toolkit (JET)
7.1.0

F18183-01

Signature:

class ojMasonryLayout

QuickNav

Attributes

JET Custom Elements

JET components are implemented as custom HTML elements. In addition to the component attributes documented in this page, JET components also support standard HTML global attributes like id and aria-label.

The JET data binding syntax can be used to define both component and global attributes through the use of dynamically evaluated expressions. All attributes (component and global) support attribute-level binding by prefixing the attribute name with ":" (e.g. :id="[...]"). When using attribute-level binding, all expression values are treated as strings. Additionally, component attributes support property-level binding by using the attribute name directly with no ":" prefix. When using property-level binding, the expressions should evaluate to the types documented by the corresponding attributes. Property-level binding is strongly recommended over attribute-level binding for component attributes.

A detailed description of working with custom HTML elements can be found in: JET Custom Element Usage.



PREVIEW: This is a preview API. Preview APIs are production quality, but can be changed on a major version without a deprecation path.

Version:
  • 7.1.0
Since:
  • 1.1.0
Module:
  • ojmasonrylayout

Module usage

See JET Module Loading for an overview of module usage within JET.

Typescript Import Format
//To typecheck the element APIs, import as below.
import {ojMasonryLayout} from "ojs/ojmasonrylayout";

//For the transpiled javascript to load the element's module, import as below
import "ojs/ojmasonrylayout";

JET In Typescript

A detailed description of working with JET elements and classes in your typescript project can be found at: JET Typescript Usage.


JET MasonryLayout

Description: A grid of tiles.

A JET MasonryLayout can contain multiple direct child elements that can be sized and positioned.

Each direct child element must be styled using one of the predefined oj-masonrylayout-tile-CxR style classes to specify the size of that tile. A tile can span multiple columns and/or rows. The list of predefined size style classes can be found in styling section.

The number of columns in the layout is determined by the width of the element and the width of a 1x1 tile. The number of rows is determined by the number of columns and the number and sizes of tiles to be laid out. When the element is resized, relayout will occur and the number of columns and rows may change.

When performing layout, tiles are processed in the order in which they originally appeared in the DOM. Cells in the grid are processed in left-to-right, top-to-bottom order (or right-to-left, top-to-bottom order when the reading direction is right-to-left). A tile will be positioned in the first empty cell in which it fits. This can result in empty cells in the layout. Subsequent tiles may fill those earlier gaps if they fit.

Note for performance reasons, if the MasonryLayout has additional content that is expensive to render and is initially hidden, like on the back of a tile that can be flipped or in a collapsed tile that can be expanded, you should wrap the additional content in an oj-defer element (API doc oj.ojDefer) to defer the rendering of that content until it is shown.
See the Masonry Layout - Deferred Rendering demo for an example.


<oj-masonry-layout>
  <div class='oj-masonrylayout-tile-2x1'>Alpha</div>
  <div class='oj-masonrylayout-tile-1x2'>Beta</div>
  <div class='oj-masonrylayout-tile-1x1'>Gamma</div>
  <div class='oj-masonrylayout-tile-1x1'>Delta</div>
  <div class='oj-masonrylayout-tile-1x1'>Epsilon</div>
  <div class='oj-masonrylayout-tile-1x1'>Zeta</div>
</oj-masonry-layout>

Touch End User Information

MasonryLayout is for layout only and does not directly support touch interaction.

Keyboard End User Information

MasonryLayout is for layout only and does not directly support keyboard interaction.

Keyboard Application Developer Information

Providing keyboard support for the tiles in the masonry layout is the responsibility of the application developer, if the tiles do not already support keyboard interaction. This could be done, for example, by specifying tabindex on each tile to enable tab navigation. Alternatively, this could be done by adding a keyboard listener and responding to key events, like pressing the arrow keys.

Accessibility

MasonryLayout is for layout only. It is the responsibility of the application developer to make the tiles in the layout accessible. Sighted keyboard-only users need to be able to access the tiles in the layout just by using the keyboard. It is up to the child tiles of the MasonryLayout to support keyboard navigation. The MasonryLayout reorders the tile DOM elements to match the visual layout order so that tab order and screen reader reading order will match the visual layout order.

Styling

The following css classes can be used to specify the size of a masonry tile.

Class Description
oj-masonrylayout-tile-1x1 A tile that spans 1 column and 1 row.
oj-masonrylayout-tile-1x2 A tile that spans 1 column and 2 rows.
oj-masonrylayout-tile-1x3 A tile that spans 1 column and 3 rows.
oj-masonrylayout-tile-2x1 A tile that spans 2 columns and 1 row.
oj-masonrylayout-tile-2x2 A tile that spans 2 columns and 2 rows.
oj-masonrylayout-tile-2x3 A tile that spans 2 columns and 3 rows.
oj-masonrylayout-tile-3x1 A tile that spans 3 columns and 1 row.
oj-masonrylayout-tile-3x2 A tile that spans 3 columns and 2 rows.

Reading direction

As with any JET element, in the unusual case that the directionality (LTR or RTL) changes post-init, the MasonryLayout must be refresh()ed.

Context Menu

Masonry Layout supports context menu for performing cut and paste operations on tiles as an accessible alternative to drag and drop reordering. When defining a context menu, masonry layout will provide built-in behavior for "cut" and "paste" if the following format for menu <oj-option> items is used:

  • <oj-option data-oj-command="oj-masonrylayout-['commandname']" ></oj-option>
The available translated text will be applied to menu items defined this way.

The supported commands:

Default Function data-oj-command value
Cut oj-masonrylayout-cut
Paste Before oj-masonrylayout-paste-before
Paste After oj-masonrylayout-paste-after

Note: Application logic should not interact with the component's properties or invoke its methods until the BusyContext indicates that the component is ready for interaction.

Slots

JET components that allow child content support slots. Please see the slots section of the JET component overview doc for more information on allowed slot content and slot types.

Default

<oj-masonry-layout> accepts arbitrary direct child elements that can be sized and positioned, which it will lay out as a grid of tiles. Each direct child element must be styled using one of the predefined oj-masonrylayout-tile-CxR style classes to specify the size of that tile. A tile can span multiple columns and/or rows.

contextMenu

The contextMenu slot is set on the oj-menu within this element. This is used to designate the JET Menu that this component should launch as a context menu on right-click, Shift-F10, Press & Hold, or component-specific gesture. If specified, the browser's native context menu will be replaced by the JET Menu specified in this slot.

The application can register a listener for the Menu's ojBeforeOpen event. The listener can cancel the launch via event.preventDefault(), or it can customize the menu contents by editing the menu DOM directly, and then calling refresh() on the Menu.

To help determine whether it's appropriate to cancel the launch or customize the menu, the ojBeforeOpen listener can use component API's to determine which table cell, chart item, etc., is the target of the context menu. See the JSDoc of the individual components for details.

Keep in mind that any such logic must work whether the context menu was launched via right-click, Shift-F10, Press & Hold, or component-specific touch gesture.

Attributes

(nullable) reorder-handle :string

Specify the selector of the descendant DOM element in a oj-masonry-layout child that can be used to reorder the child by drag-and-drop.

This attribute value is null by default, meaning that oj-masonry-layout children cannot be reordered. If each child that can be reordered has an element with style class 'my-reorder-handle', then the reorder-handle attribute would be specified as '.my-reorder-handle'.

When specifying a reorder-handle, the application should also specify a context menu with actions to cut and paste tiles as an accessible alternative to drag-and-drop reordering.

To specify a context menu, see the documentation of oj-menu.

Default Value:
  • null
Names
Item Name
Property reorderHandle
Property change event reorderHandleChanged
Property change listener attribute (must be of type function) on-reorder-handle-changed

translations :object|null

A collection of translated resources from the translation bundle, or null if this component has no resources. Resources may be accessed and overridden individually or collectively, as seen in the examples.

If the component does not contain any translatable resource, the default value of this attribute will be null. If not, an object containing all resources relevant to the component.

If this component has translations, their documentation immediately follows this doc entry.

Names
Item Name
Property translations
Property change event translationsChanged
Property change listener attribute (must be of type function) on-translations-changed

(nullable) translations.label-cut :string

Context menu text used for cutting a tile.

See the translations attribute for usage examples.

Default Value:
  • "Cut"
Since:
  • 1.1.0
Names
Item Name
Property translations.labelCut

(nullable) translations.label-paste-after :string

Context menu text used for pasting a tile after another tile.

See the translations attribute for usage examples.

Default Value:
  • "Paste After"
Since:
  • 1.1.0
Names
Item Name
Property translations.labelPasteAfter

(nullable) translations.label-paste-before :string

Context menu text used for pasting a tile before another tile.

See the translations attribute for usage examples.

Default Value:
  • "Paste Before"
Since:
  • 1.1.0
Names
Item Name
Property translations.labelPasteBefore

Events

ojAnimateEnd

Triggered when a default animation has ended.
Properties:

All of the event payloads listed below can be found under event.detail.

Name Type Description
action string The action that triggers the animation. Supported values are:
  • "insert" - when a tile is inserted
  • "move" - when a tile is moved
  • "remove" - when a tile is removed
  • "resize" - when a tile is resized
  • "reorder" - when a tile is reordered
element Element The element being animated.

ojAnimateStart

Triggered when a default animation is about to start on the element.

The default animation can be cancelled by calling event.preventDefault(), followed by a call to event.detail.endCallback(). event.detail.endCallback() should be called immediately after event.preventDefault() if the application merely wants to cancel animation, or it should be called when the custom animation ends if the application is invoking another animation function. Failure to call event.detail.endCallback() may prevent the element from working properly.

For more information on customizing animations, see the documentation of oj.AnimationUtils.

The default animations are controlled via the theme (SCSS) :

$masonryLayoutInsertAnimation: ((effect: "zoomIn", duration: $masonryLayoutAnimationDuration, timingFunction: "ease-in-out"), "fadeIn") !default;
$masonryLayoutRemoveAnimation: ((effect: "zoomOut", duration: $masonryLayoutAnimationDuration, timingFunction: "ease-in-out"), "fadeOut") !default;
$masonryLayoutMoveAnimation: (effect: "addTransition", duration: $masonryLayoutAnimationDuration, timingFunction: "ease-in-out", transitionProperties: ('top', 'left', 'right')) !default;
$masonryLayoutResizeAnimation: (effect: "addTransition", duration: $masonryLayoutAnimationDuration, timingFunction: "ease-in-out", transitionProperties: ('width', 'height', 'top', 'left', 'right')) !default;
$masonryLayoutReorderAnimation: (effect: "addTransition", duration: $masonryLayoutAnimationDurationFast, timingFunction: "ease-in-out", transitionProperties: ('width', 'height', 'top', 'left', 'right')) !default;
Properties:

All of the event payloads listed below can be found under event.detail.

Name Type Description
action string The action that triggers the animation. Supported values are:
  • "insert" - when a tile is inserted
  • "move" - when a tile is moved
  • "remove" - when a tile is removed
  • "resize" - when a tile is resized
  • "reorder" - when a tile is reordered

Note that some animation effects may not look appropriate for a given action.
element Element The element being animated.
endCallback function():void If the event listener calls event.preventDefault to cancel the default animation, it must call the endCallback function after it finishes its own animation handling and any custom animation has ended.

ojBeforeInsert

Triggered immediately before a tile is inserted. This event can be cancelled by calling event.preventDefault().
Properties:

All of the event payloads listed below can be found under event.detail.

Name Type Description
tile Element The tile that is about to be inserted.
index number The 0-based index into the set of rendered oj-masonry-layout children where the tile will be inserted.

ojBeforeRemove

Triggered immediately before a tile is removed. This event can be cancelled by calling event.preventDefault().
Properties:

All of the event payloads listed below can be found under event.detail.

Name Type Description
tile Element The tile that will be removed.

ojBeforeReorder

Triggered immediately before a tile is reordered. This event can be cancelled by calling event.preventDefault().
Properties:

All of the event payloads listed below can be found under event.detail.

Name Type Description
tile Element The tile that will be reordered.
fromIndex number The 0-based index into the set of rendered oj-masonry-layout children from which the tile will be reordered.

ojBeforeResize

Triggered immediately before a tile is resized. This event can be cancelled by calling event.preventDefault().
Properties:

All of the event payloads listed below can be found under event.detail.

Name Type Description
tile Element The tile that will be resized.
previousSizeStyleClass string The previous size style class applied to the tile.
sizeStyleClass string The new size style class that will be applied to the tile.

ojInsert

Triggered immediately after a tile is inserted.
Properties:

All of the event payloads listed below can be found under event.detail.

Name Type Description
tile Element The tile that was inserted.
index number The 0-based index into the set of rendered oj-masonry-layout children where the tile was inserted.

ojRemove

Triggered immediately after a tile is removed.
Properties:

All of the event payloads listed below can be found under event.detail.

Name Type Description
tile Element The tile that was removed.

ojReorder

Triggered immediately after a tile is reordered.
Properties:

All of the event payloads listed below can be found under event.detail.

Name Type Description
tile Element The tile that was reordered.
fromIndex number The 0-based index into the set of rendered oj-masonry-layout children from which the tile was reordered.
toIndex number The 0-based index into the set of rendered oj-masonry-layout children to which the tile was reordered.

ojResize

Triggered immediately after a tile is resized.
Properties:

All of the event payloads listed below can be found under event.detail.

Name Type Description
tile Element The tile that was resized.
previousSizeStyleClass string The previous size style class applied to the tile.
sizeStyleClass string The new size style class applied to to the tile.

Methods

getProperty(property) → {any}

Retrieves the value of a property or a subproperty. The return type will be the same as the type of the property as specified in this API document. If the method is invoked with an incorrect property/subproperty name, it returns undefined.
Parameters:
Name Type Description
property string The property name to get. Supports dot notation for subproperty access.
Since:
  • 4.0.0
Returns:
Type
any
Example

Get a single subproperty of a complex property:

let subpropValue = myComponent.getProperty('complexProperty.subProperty1.subProperty2');

insertTile(selector, index) → {void}

Insert a tile into the masonryLayout.
Parameters:
Name Type Description
selector string Selector identifying the tile to insert. The tile does not need to be a child of the oj-masonry-layout when this method is called. This method will reparent the tile to the oj-masonry-layout.
index number The 0-based index into the set of rendered oj-masonry-layout children where the tile will be inserted.
Returns:
Type
void

refresh() → {void}

Refreshes the visual state of the masonryLayout. JET elements require a refresh() after the DOM is programmatically changed underneath the element.

This method does not accept any arguments.

Returns:
Type
void

removeTile(selector) → {void}

Remove a tile from the masonryLayout.
Parameters:
Name Type Description
selector string Selector identifying the tile to remove.
Returns:
Type
void

resizeTile(selector, sizeStyleClass) → {void}

Resize a tile in the masonryLayout.
Parameters:
Name Type Description
selector string Selector identifying the tile to resize.
sizeStyleClass string New size style class to apply to the tile.
Returns:
Type
void

setProperties(properties) → {void}

Performs a batch set of properties. The type of value for each property being set must match the type of the property as specified in this API document.
Parameters:
Name Type Description
properties Object An object containing the property and value pairs to set.
Since:
  • 4.0.0
Returns:
Type
void
Example

Set a batch of properties:

myComponent.setProperties({"prop1": "value1", "prop2.subprop": "value2", "prop3": "value3"});

setProperty(property, value) → {void}

Sets a property or a subproperty (of a complex property) and notifies the component of the change, triggering a [property]Changed event. The value should be of the same type as the type of the attribute mentioned in this API document.
Parameters:
Name Type Description
property string The property name to set. Supports dot notation for subproperty access.
value any The new value to set the property to.
Since:
  • 4.0.0
Returns:
Type
void
Example

Set a single subproperty of a complex property:

myComponent.setProperty('complexProperty.subProperty1.subProperty2', "someValue");