# react-photo-gallery

> Responsive Justified React Image Gallery Component

Latest version **8.0.0** (published 2019-07-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-photo-gallery
pnpm add react-photo-gallery
yarn add react-photo-gallery
bun add react-photo-gallery
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 8.0.0 |
| Published | 2019-07-01 |
| First published | 2015-12-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 55.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2014 |
| Author | Sandra Gonzales |
| Maintainers | neptunian |
| Keywords | react, react component, react-component, justified image gallery, photo gallery, responsive, image gallery, images, react-image-gallery, react-masonry-gallery, react-photo-gallery, image-gallery, react-gallery, react image gallery, react gallery, masonry, react masonry, react-masonry, masonry layout, grid, layout |

## Links

- npm: https://www.npmjs.com/package/react-photo-gallery
- Repository: https://github.com/neptunian/react-photo-gallery
- Issues: https://github.com/neptunian/react-photo-gallery/issues
- npm.io page: https://npm.io/package/react-photo-gallery

## Dependencies (2)

- [prop-types](https://npm.io/package/prop-types.md) ~15.7.2
- [resize-observer-polyfill](https://npm.io/package/resize-observer-polyfill.md) ^1.5.0

## Alternatives

- [@lexical/table](https://npm.io/package/@lexical/table.md) — 3.0M weekly downloads
- [mantine-datatable](https://npm.io/package/mantine-datatable.md) — 98.2K weekly downloads
- [react-native-collapsible-tab-view](https://npm.io/package/react-native-collapsible-tab-view.md) — 70.6K weekly downloads
- [@handsontable/vue3](https://npm.io/package/@handsontable/vue3.md) — 16.1K weekly downloads
- [vuewordcloud](https://npm.io/package/vuewordcloud.md) — 7.2K weekly downloads

## Recent versions

- 8.0.0 (latest) — 2019-07-01
- 7.0.2 — 2019-04-20
- 7.0.1 — 2019-04-20
- 7.0.0 — 2019-04-20
- 6.3.4 — 2019-04-13
- 6.3.3 — 2019-04-13
- 6.3.2-test3 — 2019-04-13
- 6.3.2 — 2019-02-25
- 6.3.1 — 2019-01-30
- 6.3.0 — 2018-12-31
- 6.2.2 — 2018-11-23
- 6.2.1 — 2018-09-05
- 6.2.0 — 2018-08-14
- 6.1.7 — 2018-08-14
- 6.1.6 — 2018-08-13
- … 82 more at https://npm.io/package/react-photo-gallery/versions

## README

# React Photo Gallery

[![Join the chat at https://gitter.im/react-photo-gallery/Lobby](https://badges.gitter.im/react-photo-gallery/Lobby.svg)](https://gitter.im/react-photo-gallery/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![npm version](https://badge.fury.io/js/react-photo-gallery.svg)](https://badge.fury.io/js/react-photo-gallery)
![npm downloads](https://img.shields.io/npm/dt/react-photo-gallery.svg)
[![Build Status](https://travis-ci.org/neptunian/react-photo-gallery.svg?branch=master)](https://travis-ci.org/neptunian/react-photo-gallery)
[![Coverage Status](https://coveralls.io/repos/github/neptunian/react-photo-gallery/badge.svg?branch=master)](https://coveralls.io/github/neptunian/react-photo-gallery?branch=master)
[![Dependency Status](https://david-dm.org/neptunian/react-photo-gallery.svg)](https://david-dm.org/neptunian/react-photo-gallery)

* Responsive, accessible, composable, and customizable image gallery component 
* Maintains the original aspect ratio of your photos
* Creates a masonry or justified grid 
* Supports row or column direction layout
* Provides an image renderer for custom implementation of things like image selection, favorites, captions, etc.
* SSR app compatible

## Preview

| Row       | Column           |
| ------------- |:-------------:|
| <img src="https://live.staticflickr.com/65535/40680327133_6f6218bfa3.jpg" /> | <img src="https://live.staticflickr.com/65535/47594180212_0dc2694eda.jpg"> |


## Installation

```
yarn add react-photo-gallery
```

## API Documentation

[http://neptunian.github.io/react-photo-gallery/](http://neptunian.github.io/react-photo-gallery/)

## CodeSandbox Demos with Example Use Cases

* [Basic Row Layout](https://codesandbox.io/s/9yx911wl9y)
* [Basic Column Layout](https://codesandbox.io/s/r09k1xj614)
* [With Lightbox](https://codesandbox.io/s/5vn3lvz2n4)
* [Dynamic Columns Using columns prop](https://codesandbox.io/s/ll7ym48027)
* [Selection using custom renderImage](https://codesandbox.io/s/o7o241q09)
* [Sortable with drag and drop](https://codesandbox.io/s/8y7n1r9y5j)

To build some examples locally, git clone and run:

```
yarn install
yarn start
```

Then open [`localhost:8000`](http://localhost:8000) in a browser.


## Minimal Setup Example

```jsx

const photos = [
  {
    src: 'http://example.com/example/img1.jpg',
    width: 4,
    height: 3
  },
  {
    src: 'http://example.com/example/img2.jpg',
    width: 1,
    height: 1
  }
];

<Gallery photos={photos} />;

```

## How It Works

### Row Layout
This layout uses an algorithm adapted from the Knuth and Plass line breaking algorithm.  It uses a graph to calculate the single best layout where each photo to break on is represented by a node and each edge is represented by a row. The cost of the edge is determined by the user provided `targetRowHeight` vs the row height calculated if it were to break on this node/photo. What you end up with is a layout with rows that are similar in height and photos that are not being stretched or shrunken abnormally as is what happens in a naive implementation. This solves the issue of panoramas shrinking rows or having stragglers or stretched images at the last row, instead creating a justified grid.  To make sure it's speedy the graph is being built as the shortest path is being calculated so the entire adjacency list is not calculated ahead of time. You can control how many neighboring nodes that Dijkstra's algorithm will search when it's visiting a node by adjusting the `limitNodeSearch` property, but it's recommended you use the default algorithm. See documentation for recommendations.

Inspired by [this blog article](http://blog.vjeux.com/2014/image/google-plus-layout-find-best-breaks.html) and this [Google Photos blog article](https://medium.com/google-design/google-photos-45b714dfbed1) (under 2. Justified Gallery).

### Column Layout
Goes through each column looking for the best place to insert the next photo by finding the shortest column. Not recommended for panorama aspect ratios.

## Thanks

Special thanks to [Christopher Chedeau](https://blog.vjeux.com/) for [writing about this interesting algorithm](http://blog.vjeux.com/2014/image/google-plus-layout-find-best-breaks.html) and whos code served as a starting off point.

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