react-masonry-component

WebJar for react-masonry-component

License

License

MIT
Categories

Categories

React User Interface Web Frameworks
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

react-masonry-component
Last Version

Last Version

4.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

react-masonry-component
WebJar for react-masonry-component
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/eiriklv/react-masonry-component

Download react-masonry-component

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/react-masonry-component/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>react-masonry-component</artifactId>
    <version>4.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/react-masonry-component/
implementation 'org.webjars.npm:react-masonry-component:4.1.0'
// https://jarcasting.com/artifacts/org.webjars.npm/react-masonry-component/
implementation ("org.webjars.npm:react-masonry-component:4.1.0")
'org.webjars.npm:react-masonry-component:jar:4.1.0'
<dependency org="org.webjars.npm" name="react-masonry-component" rev="4.1.0">
  <artifact name="react-masonry-component" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='react-masonry-component', version='4.1.0')
)
libraryDependencies += "org.webjars.npm" % "react-masonry-component" % "4.1.0"
[org.webjars.npm/react-masonry-component "4.1.0"]

Dependencies

compile (4)

Group / Artifact Type Version
org.webjars.npm : imagesloaded jar [4.0.0,5)
org.webjars.npm : lodash.assign jar [4.0.9,5)
org.webjars.npm : lodash.debounce jar [4.0.6,5)
org.webjars.npm : masonry-layout jar [4.0.0,5)

Project Modules

There are no modules declared in this project.

React Masonry Component

npm version Build Status

IE8 support

if you wish to have IE8 support, v2 with React 0.14 is the highest version available.

Table of contents

  1. Usage
  2. Basic usage
  3. Custom props
  4. Accessing Masonry instance
  5. Images Loaded Options
  6. Events

Introduction:

A React.js Masonry component. (Also available as a mixin if needed)

Live demo:

hearsay.me

Usage:

  • The component is bundled with Masonry, so no additional dependencies needed!

  • You can optionally include Masonry as a script tag if there should be any reason for doing so <script src='//cdnjs.cloudflare.com/ajax/libs/masonry/3.1.5/masonry.pkgd.min.js' />

  • To use the component just require the module.

Basic usage

npm install --save react-masonry-component

import * as React from 'react';
import Masonry from 'react-masonry-component';

const masonryOptions = {
    transitionDuration: 0
};

const imagesLoadedOptions = { background: '.my-bg-image-el' }

class Gallery extends React.Component {
    render() {
        const childElements = this.props.elements.map(function(element){
           return (
                <li className="image-element-class">
                    <img src={element.src} />
                </li>
            );
        });
    
        return (
            <Masonry
                className={'my-gallery-class'} // default ''
                elementType={'ul'} // default 'div'
                options={masonryOptions} // default {}
                disableImagesLoaded={false} // default false
                updateOnEachImageLoad={false} // default false and works only if disableImagesLoaded is false
                imagesLoadedOptions={imagesLoadedOptions} // default {}
            >
                {childElements}
            </Masonry>
        );
    }
}

export default Gallery;

ES6-style modules are also supported, just use:

import Masonry from 'react-masonry-component';
Custom props

You can also include your own custom props - EG: inline-style and event handlers.

import * as React from 'react';
import Masonry from 'react-masonry-component';

const masonryOptions = {
    transitionDuration: 0
};

const style = {
    backgroundColor: 'tomato'
};

class Gallery extends React.Component {
    handleClick() {}
    render() {
        return (
            <Masonry
                className={'my-gallery-class'}
                style={style}
                onClick={this.handleClick}
            >
                {...}
            </Masonry>
        );
    }
}

export default Gallery;
Accessing Masonry instance

Should you need to access the instance of Masonry (for example to listen to masonry events) you can do so by using refs.

import * as React from 'react';
import Masonry from 'react-masonry-component';

class Gallery extends React.Component {
    handleLayoutComplete() { },

    componentDidMount() {
        this.masonry.on('layoutComplete', this.handleLayoutComplete);
    },

    componentWillUnmount() {
        this.masonry.off('layoutComplete', this.handleLayoutComplete);
    },

     render() {
         return (
             <Masonry
                 ref={function(c) {this.masonry = this.masonry || c.masonry;}.bind(this)}
             >
                 {...}
             </Masonry>
         );
     }
}

export default Gallery;
Images Loaded Options

React Masonry Component uses Desandro's imagesloaded library to detect when images have loaded. Should you want to pass options down to it then you need to populate the imagesLoadedOptions property on React Masonry Component.

This will most commonly be used when the elements in your gallery have CSS background images and you want to capture their load event. More info availabe on the imagesloaded website.

eg:

import * as React from 'react';
import Masonry from 'react-masonry-component';

class Gallery extends React.Component {
  render() {
    const imagesLoadedOptions = { background: '.my-bg-image-el' }
    
    return (
        <Masonry
            className={'my-gallery-class'}
            elementType={'ul'}
            options={masonryOptions}
            imagesLoadedOptions={imagesLoadedOptions}
        >
            <div className="my-bg-image-el"></div>
        </Masonry>
    );
  }
}

export default Gallery;
Events
  • onImagesLoaded - triggered when all images are loaded or after each image is loaded when updateOnEachImageLoad is set to true
  • onLayoutComplete - triggered after a layout and all positioning transitions have completed.
  • onRemoveComplete - triggered after an item element has been removed
class Gallery extends React.Component {
    componentDidMount() {
        this.hide();
    },
    handleImagesLoaded(imagesLoadedInstance) {
        this.show();
    },
    render() {
        return (
            <Masonry
                onImagesLoaded={this.handleImagesLoaded}
                onLayoutComplete={laidOutItems => this.handleLayoutComplete(laidOutItems)}
                onRemoveComplete={removedItems => this.handleRemoveComplete(removedItems)}
            >
                {...}
            </Masonry>
        )
    }
}

Versions

Version
4.1.0