Giter Site home page Giter Site logo

thedemodev / react-photo-gallery Goto Github PK

View Code? Open in Web Editor NEW

This project forked from neptunian/react-photo-gallery

0.0 0.0 0.0 10.6 MB

React Photo Gallery

Home Page: http://neptunian.github.io/react-photo-gallery/

License: Other

JavaScript 100.00%

react-photo-gallery's Introduction

React Photo Gallery

Join the chat at https://gitter.im/react-photo-gallery/Lobby npm version npm downloads Build Status Coverage Status Dependency Status

  • 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

Installation

yarn add react-photo-gallery

API Documentation

http://neptunian.github.io/react-photo-gallery/

CodeSandbox Demos with Example Use Cases

To build some examples locally, git clone and run:

yarn install
yarn start

Then open localhost:8000 in a browser.

Minimal Setup Example

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 and this Google Photos blog article (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 for writing about this interesting algorithm and whos code served as a starting off point.

react-photo-gallery's People

Contributors

brianrc avatar dmr avatar fusillicode avatar gitter-badger avatar hedleysmith avatar imerica avatar infacq avatar jorrit avatar levibuzolic avatar lotharschulz avatar neptunian avatar timiscoding avatar vadistic avatar

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.