npm.io
1.0.9 • Published 1 year ago

react-draggable-masonry

Licence
MIT
Version
1.0.9
Deps
0
Size
29 kB
Vulns
0
Weekly
0

React-Draggable-Masonry

An open source library to provider a draggable masonry layout for your react projects, the layout is implmented by CSS and the lib is lightweight, only dependent on react.

Demo

Check here

Install

npm install --save react-draggable-masonry

Usage

Check the examples in demo folder

API

Wall

Prop Type Description
columnWidth number | string width of a brick
rowHeight number | string height of a brick
gap number | string space between brick
allowDragInSpace boolean allow brick to drag into this wall
dragMode "normal" | "adapt" the way to manage the brick size while drag and drop:
normal: keep the source size
adapt: resize to target size
swapMode "internal" | "external" the way to manage the bricker order:
internal: swap bricks with DOM operation
external: leave the DOM management to React
children reactNode any react component

Concrete

usually you don't need to use this component

Prop Type Description
id string unique id for the brick children
index number bricker order index in wall
children Brick Bricker component

Brick

Inherit all props from HTMLDIVElement and also have following props additional

Prop Type Description
draggable boolean enable/disable drag function on brick
width number how many cells in row will filled by this brick
height number how many cells in columns will filled by this brick
allowToSwap boolean set to false if you want a fixed brick, otherwise if a draggable birck move on this brick, it will swap the position with that one
children reactNode any react component

Mobile Support

Tested with drag-drop-touch and it able to work with mobile devices. check our demo code, you need install the package and import that to enable the mobile support.