JSPM

  • Created
  • Published
  • Downloads 1521
  • Score
    100M100P100Q113100F
  • License MIT

Simple & featured native masonry layout implementation for React JS

Package Exports

  • react-xmasonry

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-xmasonry) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

react-xmasonry

Dependencies License

Simple, minimalistic and featured native masonry layout for React JS.

General Features

  • React JS native masonry layout implementation with no dependencies.
  • Minimalistic design and simple use case.
  • Ability to control blocks width (in columns) and column width.
  • Responsive, mobile-friendly approach (so there is no "fixed block width" option).
  • Fully customizable: use CSS animations and transitions you wish (use .xmasonry and .xblock selectors).

Visit the demo page for more details.

Installation

npm install react-xmasonry --save

Example of Usage

Import XMasonry and XBlock components:

import { XMasonry, XBlock } from "react-xmasonry";

The simplest layout using JSX and a little styling looks as following:

<XMasonry>
    <XBlock>
        <div className="card">
            <h1>Card One</h1>
            <p>Any text</p>
        </div>
    </XBlock>
    <XBlock width="2">
        <div className="card">
            <h1>Card Two</h1>
            <p>Any text</p>
        </div>
    </XBlock>
</XMasonry>

There is no more JavaScript than positioning and sizing! Use any CSS to make animations and transitions you like (.xmasonry and .xblock selectors), for example:

@keyframes comeIn {
    0% { transform: scale(0) }
    75% { transform: scale(1.03) }
    100% { transform: scale(1) }
}

.xmasonry .xblock {
    animation: comeIn ease 0.5s;
    animation-iteration-count: 1;
}

.card {
    margin: 10px;
    padding: 5px;
    border-radius: 10px;
    box-shadow: 0 1px 3px darkgray;
}

See the example page sources.

Using Components

There are several properties you can assign to XMasonry and XBlock components.

<XMasonry> Component Properties

Property Default Description
center true A boolean value determining whether nested <XBlock>s should be centered if there are empty columns left
responsive true A boolean value determining whether the layout should be responsive to window size changes
targetBlockWidth 300 A number which determines the "target" width in pixels of the nested <XBlock>s. The layout takes all available space, and determines the number of columns using this value. For example, if container has 600 px of available width and we specify targetBlockWidth={200}, we will get exactly 3 columns of 200 px width. And it will still be 3 columns if there is 660 pixels available, this time with each column taking 220 px.

<XBlock> Component Properties

Property Default Description
width 1 A number which determines nested block width in columns. If the number of columns available is less than the specified width, nested block will shrink to fit available space.