# react-simple-masonry

> A simple, standalone react component for responsive masonry layouts.

Latest version **1.0.6** (published 2022-05-31) · ISC license · 0 weekly downloads

## Install

```sh
npm install react-simple-masonry
pnpm add react-simple-masonry
yarn add react-simple-masonry
bun add react-simple-masonry
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2022-05-31 |
| First published | 2022-05-31 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | theabdullahalam |
| Keywords | react, simple, masonry, masonry layout, responsive masonry, simple masonry, react masonry, masonry component |

## Links

- npm: https://www.npmjs.com/package/react-simple-masonry
- Homepage: https://github.com/theabdullahalam/react-simple-masonry
- Issues: https://github.com/theabdullahalam/react-simple-masonry/issues
- npm.io page: https://npm.io/package/react-simple-masonry

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.6 (latest) — 2022-05-31
- 1.0.5 — 2022-05-31
- 1.0.4 — 2022-05-31
- 1.0.3 — 2022-05-31
- 1.0.2 — 2022-05-31
- 1.0.1 — 2022-05-31
- 1.0.0 — 2022-05-31

## README

# React Simple Masonry
Simple standalone wrapper component for rendering responsive masonry layouts.

## Installation
```shell
npm i react-simple-masonry
```

## Usage
### With HTML Elements
#### Straightforward
Simply wrap your elements with the `<Masonry>` component, and you should get a three-column masonry layout, with a gap of ```1rem``` between the columns.
```jsx
<Masonry>
  {
    images.map((url, i) => <img src={url} key={i} />)
  }
</Masonry>
```

#### Number of columns

To change the number of columns, pass in a `columnCounts` object with a default value - 
```jsx
<Masonry columnCounts={{ default: 4 }}>
  {
    images.map((url, i) => <img src={url} key={i} />)
  }
</Masonry>
```

#### Different columns for different screen sizes

To specify the number of columns to show up till particular breakpoints, pass in a `columnCounts` object with the breakpoints you need, and a default value. The breakpoints are equivalent to `max-width` media queries -

```jsx
<Masonry 
  columnCounts={
    { 
      600: 1, 
      800: 2, 
      1000: 3, 
      default: 4 
    }
  }
>
  {
    images.map((url, i) => <img src={url} key={i} />)
  }
</Masonry>
```

#### Gap between columns

To specify the size of the gap between columns - 

```jsx
<Masonry 
  columnCounts={
    { 
      600: 1, 
      800: 2, 
      1000: 3, 
      default: 4 
    }
  }
  columnGap="2rem"
>
  {
    images.map((url, i) => <img src={url} key={i} />)
  }
</Masonry>
```

### With Custom Components
Rendering custom components is similar to how one would render regular elements, except that the component must add the style passed in by the `Masonry` component.

For example, if your implementation looks like this:

```jsx
<Masonry 
  columnCounts={
    { 
      600: 1, 
      800: 2, 
      default: 3
    }
  }
  columnGap="1rem"
>
  {
    images.map((url, i) => <MyComponent url={url} key={i} />)
  }
</Masonry>
```

then your `MyComponent` component must do this:
```jsx
// accept masonry_item_style among other props...
export function MyComponent({masonry_item_style}){
  // ...your code
  return (
    // you can add your own styles after masonry_item_style like so
    // style={{
    //      ...masonry_item_style, 
    //      background: "wheat", 
    //      ...etc 
    //   }}
    <div style={{...masonry_item_style}}>
      // ...rest of the component
    </div>
  )
}
```

---
_Source: https://npm.io/package/react-simple-masonry · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
