Git Product home page Git Product logo

johnsonjo4531 / react-fast-masonry Goto Github PK

View Code? Open in Web Editor NEW
5.0 3.0 0.0 4.05 MB

A fast masonry infinite-scrolling component using the intersection api

Home Page: https://johnsonjo4531.github.io/react-fast-masonry/

License: MIT License

JavaScript 6.63% HTML 1.44% CSS 0.26% Shell 0.10% TypeScript 91.56%
infinite-scroll masonry masonry-layout react reactjs intersection-observer mit-license

react-fast-masonry's Introduction

react-fast-masonry

A react masonry library featuring infinite-scrolling capabilities using bricks.js and react-intersection list. It's based off react-masonry-infinite, but uses react-intersection-list instead of react-infinite-scroll for faster infinite scrolling.

Since it's based on bricks.js you will need to set all of your items within the masonry container to be the same width. What makes this different then bricks.js is it allows container-queries on it's sizing options rather than media queries. It also allows you to set custom widths at those container query breakpoints.

Installing

npm i --save react-fast-masonry

Usage

First import the library react-fast-masonry

import MasonryLayout from "react-fast-masonry";

Then use it like so.

<MasonryLayout
  // This is a required prop this defines how wide your gutters and columns are (required) and optionally provides a way to  define your column-width (columnWidth) and container-queries (cq)
  sizes={[
    { columns: 1, gutter: 0, columnWidth: "100%" },
    { cq: 768, columns: 2, gutter: 20, columnWidth: 300 },
    { cq: 1024, columns: 3, gutter: 20, columnWidth: 400 }
  ]}
  items={this.state.items}
  // The columnWidth here comes from the sizes prop up above
  renderItem={({ columnWidth }, index: number, key: any) => (
    <div
      style={{
        width: columnWidth
      }}
      key={key}
    >
      {index}
    </div>
  )}
  loadMore={this.loadMore}
  awaitMore={true}
  pageSize={20}
  className="masonry"
/>

A full fledged example of the above might is given as the Simple masonry layout in the storybook.

react-fast-masonry's People

Contributors

johnsonjo4531 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

react-fast-masonry's Issues

Examples

Is it possible to view the source code of the storybook examples? Or some other example source code?

Prepending items / scrolling backwards

How does this behave if items are added to the beginning of the list?

Currently trying to find a way to achieve an infinite scrolling masonry layout that allows the user to click a button to "load previous", and then enable infinite scrolling behaviour in the upward direction.

Is this something I could possibly tweak this component to do, or is it at odds with how bricks.js is designed?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.