1.0.6 • Published 5 months ago

react-masonry-list v1.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

React Masonry List

npm License: MIT

A Masonry component implemented through css grid, fast and responsive. :star2: Each element first fills the column with the largest remaining space in the vertical direction, which will ensure that the height difference of each column is minimal.

npm.io

:point_right: demo page

Install

npm install react-masonry-list --save

Or use yarn yarn add react-masonry-list

Usage

import Layout from 'react-masonry-list';

const items = [
  //...
];

// If item contains img elements, don't forget set img's width. In order to get a better display effect, you can also set img's `object-fit` to `contain`.

const List = () => {
  return (
    <Layout
      minWidth={100}
      items={items.map((item) => (
        <div key={item.id}>...</div>
      ))}
    ></Layout>
  );
};

Use with NextJS

Because it's a client side only component, when using it with NextJS, you need to import it by dynamic API:

import dynamic from 'next/dynamic';

const Layout = dynamic(() => import('react-masonry-list'), {
  ssr: false,
});

const items = [
  //...
];

// If item contains img elements, don't forget set img's width. In order to get a better display effect, you can also set img's `object-fit` to `contain`.

const List = () => {
  return (
    <Layout
      minWidth={100}
      items={items.map((item) => (
        <div key={item.id}>...</div>
      ))}
    ></Layout>
  );
};

Props

nametyperequireddefaultdescription
itemsreact node arrayNo[]The items you want to render
colCountnumberNo3Column count
gapnumberNo10The size(px) of the gap between elements
minWidthnumberNo300The min width(px) of columns
classNamestringNo\ Custom class name of layout container

Browser compatibility

Refer to https://developer.mozilla.org/en-US/docs/Web/CSS/grid-template-columns#browser_compatibility

1.0.6

5 months ago

1.0.5

8 months ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.1.6

2 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago