Bariyard / react-masonry

React layout library inspired by Masonry.

Home Page:https://bogdanpetru.github.io/react-masonry/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

react masonry

ReactJs layout library inspired by Masonry.

It places elements in optimal positions by stacking them from left to right and from top to bottom.

See Demo.

This component is in development, any help is welcome :).

Usage

Place any elements inside the Masonry component. They will be cloned, measured and positioned.

Elements rendered inside Masonry must be DOM elements.

import Mansonry, { Brick } from 'react-masonry'

return <Masonry>
  <img src="helloWolrd.jpg" />
  <div className="box">some text</div>
  <img src="foo.png" />
</Masonry>

Install

Clone project.

run yarn install or npm install

run yarn start or npm start - will open in browser the demo (localhost:3000).

Api:

  • gutter: number|{top, left, right, bottom} - default: 0

Space around stones. Specify a number for all 4 directions or specify for desired directions with an object.

  • transition: fade|fadeMove|false - fade - if different than false, each item will appear one after another with an interval of transitionStep in between.

Whether place stones one after another using an animation.

  • transitionStep: number - 50 - in ms, time in between each stone placement, this is relevant if transition prop is not false.

  • transitionDuration: number - 300

Transition duration in ms.

Speed with which stones are placed when enterOneAfterAnother=true

  • updateOnWindowResize: bool - true

Whether to calculate again positions when Windows changes size.

  • Customize specific stones in different way

These props can be also added on div element like so:

data-masonry-settings={{ gutter: 20, offset: { bottom: 20 } }}

TODO

  • simplify and remove img logic
  • add tests for covered cases validate stones
  • fix edge case where an item is bigger than the container
  • add prettier
  • update stone positions on props change that influence positioning

About

React layout library inspired by Masonry.

https://bogdanpetru.github.io/react-masonry/


Languages

Language:JavaScript 91.6%Language:HTML 5.8%Language:CSS 2.6%