All Projects → paulcollett → React Masonry Css

paulcollett / React Masonry Css

Licence: mit
React Masonry layout component powered by CSS, dependancy free

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Masonry Css

Cucumber Js
Cucumber for JavaScript
Stars: ✭ 4,383 (+871.84%)
Mutual labels:  hacktoberfest
Github Readme Stats
⚡ Dynamically generated stats for your github readmes
Stars: ✭ 34,955 (+7650.55%)
Mutual labels:  hacktoberfest
Libmesh
libMesh github repository
Stars: ✭ 450 (-0.22%)
Mutual labels:  hacktoberfest
Electron Forge
A complete tool for creating, publishing, and installing modern Electron applications
Stars: ✭ 4,714 (+945.23%)
Mutual labels:  hacktoberfest
Cockroach
CockroachDB - the open source, cloud-native distributed SQL database.
Stars: ✭ 22,700 (+4933.26%)
Mutual labels:  hacktoberfest
Dynamoid
Ruby ORM for Amazon's DynamoDB.
Stars: ✭ 449 (-0.44%)
Mutual labels:  hacktoberfest
Goa
Design-based APIs and microservices in Go
Stars: ✭ 4,493 (+896.23%)
Mutual labels:  hacktoberfest
Csi Digitalocean
A Container Storage Interface (CSI) Driver for DigitalOcean Block Storage
Stars: ✭ 452 (+0.22%)
Mutual labels:  hacktoberfest
React Native Elements
Cross-Platform React Native UI Toolkit
Stars: ✭ 21,758 (+4724.39%)
Mutual labels:  hacktoberfest
Telegram
✈️ Telegram Notifications Channel for Laravel
Stars: ✭ 450 (-0.22%)
Mutual labels:  hacktoberfest
Swagger Ui
Swagger UI is a collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.
Stars: ✭ 21,279 (+4618.18%)
Mutual labels:  hacktoberfest
Mattermost Server
Mattermost is an open source platform for secure collaboration across the entire software development lifecycle.
Stars: ✭ 21,623 (+4694.46%)
Mutual labels:  hacktoberfest
Nudein
An easy-to-use attributed text view for iOS Apps,use like masonry
Stars: ✭ 450 (-0.22%)
Mutual labels:  masonry
Bubbletea
A powerful little TUI framework 🏗
Stars: ✭ 7,886 (+1648.56%)
Mutual labels:  hacktoberfest
Kubectl Neat
Clean up Kuberntes yaml and json output to make it readable
Stars: ✭ 451 (+0%)
Mutual labels:  hacktoberfest
Btcd
An alternative full node bitcoin implementation written in Go (golang)
Stars: ✭ 4,588 (+917.29%)
Mutual labels:  hacktoberfest
Graphql Engine
Blazing fast, instant realtime GraphQL APIs on your DB with fine grained access control, also trigger webhooks on database events.
Stars: ✭ 24,845 (+5408.87%)
Mutual labels:  hacktoberfest
Zek
Generate a Go struct from XML.
Stars: ✭ 451 (+0%)
Mutual labels:  hacktoberfest
Justtryharder
JustTryHarder, a cheat sheet which will aid you through the PWK course & the OSCP Exam. (Inspired by PayloadAllTheThings)
Stars: ✭ 450 (-0.22%)
Mutual labels:  hacktoberfest
Superjson
Safely serialize JavaScript expressions to a superset of JSON, which includes Dates, BigInts, and more.
Stars: ✭ 446 (-1.11%)
Mutual labels:  hacktoberfest

A new masonry component powered by CSS to be fast loading and free of jQuery or other dependencies. Built specifically for React projects.

image

😎 Why?

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.

😄 What does this do

  • Responsive! ..always
  • IE 10+
  • No Dependencies - Which means no need for jQuery!
  • Works with existing CSS animations on your elements, like fading in on first load
  • CSS powered (Faster to render)
  • Allows for Gaps (Gutters) between elements

🏳️ What doesn't this do

  • Works with elements with different widths
  • Sorting based on height - This kills performance, so if you don't need it we're here for you

😲 Simple Usage

Add react-masonry-css to your project:

npm install react-masonry-css

In your React Component...

import Masonry from 'react-masonry-css'

//...

<Masonry
  breakpointCols={3}
  className="my-masonry-grid"
  columnClassName="my-masonry-grid_column">
  {/* array of JSX items */}
</Masonry>

And, CSS:

.my-masonry-grid {
  display: -webkit-box; /* Not needed if autoprefixing */
  display: -ms-flexbox; /* Not needed if autoprefixing */
  display: flex;
  margin-left: -30px; /* gutter size offset */
  width: auto;
}
.my-masonry-grid_column {
  padding-left: 30px; /* gutter size */
  background-clip: padding-box;
}

/* Style your items */
.my-masonry-grid_column > div { /* change div to reference your elements you put in <Masonry> */
  background: grey;
  margin-bottom: 30px;
}

Responsive Breakpoints

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.

const breakpointColumnsObj = {
  default: 4,
  1100: 3,
  700: 2,
  500: 1
};

//...

<Masonry
  breakpointCols={breakpointColumnsObj}
  className="my-masonry-grid"
  columnClassName="my-masonry-grid_column"
>
  <div>My Element</div>
  <div>My Element</div>
  <div>My Element</div>
  <div>My Element</div>
</Masonry>

Configuration Props

  • breakpointCols={{default: 4, 800: 2}} optional (defaults to 2 columns)
  • className for the container
  • columnClassName class name added to each generated column

Example Demo

https://paulcollett.github.io/react-masonry-css/demo/

Common usage

outputting an array of items:

var items = [
  {id: 1, name: 'My First Item'},
  {id: 2, name: 'Another item'},
  {id: 3, name: 'Third Item'},
  {id: 4, name: 'Here is the Fourth'},
  {id: 5, name: 'High Five'}
];

// Convert array to JSX items
items = items.map(function(item) {
  return <div key={item.id}>{item.name}</div>
});

<Masonry
  breakpointCols={myBreakpointsAndCols}
  className="my-masonry-grid"
  columnClassName="my-masonry-grid_column"
>
  {items}
</Masonry>

Optional, Responsive gutters

We can add the following to the above CSS to further adjust the layout between screen sizes.

/* Optional, different gutter size on mobile */
@media (max-width: 800px) {
  .my-masonry-grid {
    margin-left: -15px; /* gutter size offset */
  }
  .my-masonry-grid_column {
    padding-left: 15px; /* gutter size offset */
  }
  .my-masonry-grid_column > div {
    margin-bottom: 15px; /* space between items */
  }
}

Use with Preact

Currently you can use react-masonry-css with Preact (https://github.com/developit/preact) via the shim (https://github.com/developit/preact-compat)

DummyJS

Improve your frontend builds with dynamic placeholder images and dummy text from DummyJs.com. https://www.npmjs.com/package/dummyjs

Suggestions & Issues

https://github.com/paulcollett/react-masonry-css/issues/

Contact me direct:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].