Gathering detailed insights and metrics for react-masonry-css
Gathering detailed insights and metrics for react-masonry-css
Gathering detailed insights and metrics for react-masonry-css
Gathering detailed insights and metrics for react-masonry-css
React Masonry layout component powered by CSS, dependancy free
npm install react-masonry-css
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
961 Stars
101 Commits
66 Forks
3 Watching
1 Branches
9 Contributors
Updated on 28 Nov 2024
Minified
Minified + Gzipped
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-6.9%
15,307
Compared to previous day
Last week
-2%
82,245
Compared to previous week
Last month
10.4%
355,573
Compared to previous month
Last year
4.5%
4,181,376
Compared to previous year
A Masonry component leveraging CSS and native React rendering, for fast, responsive masonry layouts
Existing solutions like React wrapped DeSandro Masonry, while popular, don't actually leverage React's highly optimized Virtual DOM renderer and in DeSandro Masonry's case, actually renders elements twice before showing the layout. All of this is ok but we found it to lead to a slow, "laggy" user experience that would occasionally miss-render our layout.
Our need for a simple Masonry layout that was fast, used React's Virtual DOM without needing jQuery or other dependencies led us to explore what we could do with the latest techniques using just CSS within a React Component.
Between flexbox, css columns, css grid we settled on plain ol' div's and a dab of flexbox that allows for "fluid" responsive layouts by default but most importantly is true to Reacts rendering lifecycle.
react-masonry-css
Is a React Component with a simple interface to order items into the desired columns at specified breakpoints. With minimal CSS this leads to a quick, reliable solution that also has great browser support along with rendering performance.
Add react-masonry-css
to your project:
1npm install react-masonry-css
In your React Component...
1import Masonry from 'react-masonry-css' 2 3//... 4 5<Masonry 6 breakpointCols={3} 7 className="my-masonry-grid" 8 columnClassName="my-masonry-grid_column"> 9 {/* array of JSX items */} 10</Masonry>
And, CSS:
1.my-masonry-grid { 2 display: -webkit-box; /* Not needed if autoprefixing */ 3 display: -ms-flexbox; /* Not needed if autoprefixing */ 4 display: flex; 5 margin-left: -30px; /* gutter size offset */ 6 width: auto; 7} 8.my-masonry-grid_column { 9 padding-left: 30px; /* gutter size */ 10 background-clip: padding-box; 11} 12 13/* Style your items */ 14.my-masonry-grid_column > div { /* change div to reference your elements you put in <Masonry> */ 15 background: grey; 16 margin-bottom: 30px; 17}
Different columns can be specified by passing an object containing key's of the window widths and their value as the number of columns. To have a fallback value, use the default
key.
1 2const breakpointColumnsObj = { 3 default: 4, 4 1100: 3, 5 700: 2, 6 500: 1 7}; 8 9//... 10 11<Masonry 12 breakpointCols={breakpointColumnsObj} 13 className="my-masonry-grid" 14 columnClassName="my-masonry-grid_column" 15> 16 <div>My Element</div> 17 <div>My Element</div> 18 <div>My Element</div> 19 <div>My Element</div> 20</Masonry>
breakpointCols={{default: 4, 800: 2}}
optional (defaults to 2 columns)className
for the containercolumnClassName
class name added to each generated columnhttps://paulcollett.github.io/react-masonry-css/demo/
outputting an array of items:
1var items = [ 2 {id: 1, name: 'My First Item'}, 3 {id: 2, name: 'Another item'}, 4 {id: 3, name: 'Third Item'}, 5 {id: 4, name: 'Here is the Fourth'}, 6 {id: 5, name: 'High Five'} 7]; 8 9// Convert array to JSX items 10items = items.map(function(item) { 11 return <div key={item.id}>{item.name}</div> 12}); 13 14<Masonry 15 breakpointCols={myBreakpointsAndCols} 16 className="my-masonry-grid" 17 columnClassName="my-masonry-grid_column" 18> 19 {items} 20</Masonry>
We can add the following to the above CSS to further adjust the layout between screen sizes.
1/* Optional, different gutter size on mobile */ 2@media (max-width: 800px) { 3 .my-masonry-grid { 4 margin-left: -15px; /* gutter size offset */ 5 } 6 .my-masonry-grid_column { 7 padding-left: 15px; /* gutter size offset */ 8 } 9 .my-masonry-grid_column > div { 10 margin-bottom: 15px; /* space between items */ 11 } 12}
You can use react-masonry-css
with Preact when using preact/compat
Improve your frontend builds with dynamic placeholder images and dummy text from DummyJs.com. https://www.npmjs.com/package/dummyjs
https://github.com/paulcollett/react-masonry-css/issues/
Contact me direct:
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
Found 6/21 approved changesets -- score normalized to 2
Reason
0 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More