Socket
Socket
Sign inDemoInstall

react-photo-gallery

Package Overview
Dependencies
9
Maintainers
1
Versions
97
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-photo-gallery

Responsive Justified React Image Gallery Component


Version published
Maintainers
1
Install size
892 kB
Created

Readme

Source

Join the chat at https://gitter.im/react-photo-gallery/Lobby npm version 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 style layout
  • Uses actual image elements, optionally pass in srcSet and sizes attributes
  • Supports row or column direction layout
  • Supports passing in a custom image component for implementation of things like image selection, favorites, captions, or whatever your little heart desires!
  • SSR app compatible

Preview

Installation

To install:

yarn add react-photo-gallery

Documentation and Examples

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

To build some examples locally, run:

yarn install
yarn start

Then open localhost:8000 in a browser.

Use


import Gallery from 'react-photo-gallery';

export default class Sample extends React.Component {
    render() {
	return (
	    <Gallery photos={PHOTO_SET} />
	);
    }
}
const PHOTO_SET = [
  {
    src: 'http://example.com/example/img1.jpg',
    width: 4,
    height: 3
  },
  {
    src: 'http://example.com/example/img2.jpg',
    width: 1,
    height: 1
  }
];

PropertyTypeDefaultDescription
photosarrayundefinedrequired; array of objects
columnsnumber or functionundefinedoptional; number of photos per row or a function which receives the container width and should return the desired number of photos per row; defaults to Gallery's breakpoint choosing
onClickfunctionundefinedoptional; do something when the user clicks a photo; receives arguments event and an object containing the index, photo obj originally sent and the next and previous photos in the gallery if they exist
marginnumber2optional; number of margin pixels around each entire image
directionstring'row'optional; column or row based layout
ImageComponentfunctiondefault componentoptional; use a different image component than the default provided to display your photo

Photos array item properties (passed into Gallery's photos property)

PropertyTypeDefaultDescription
srcstringundefinedrequired; the img src attribute value of the image
srcSetarray or stringundefinedoptional; srcSet attribute of the image
sizesarray or stringundefinedoptional; sizes attribute of the image
widthnumberundefinedrequired; original width of the gallery image (only used for calculating aspect ratio)
heightnumberundefinedrequired; original height of the gallery image (only used for calculating aspect ratio)
altstringundefinedoptional; alt text of the gallery image
keystringsrcoptional; key to be used on component

ImageComponent props

If you're passing a function component to ImageComponent you will receive back these props:

PropertyTypeValue
marginstringoptional; margin prop optionally passed into Gallery by user
indexnumberrequired; the index of the photo within the Gallery
photoobjectrequired; the individual object passed into Gallery's photos array prop, with all the same props except recalculated height and width
directionstringoptional; direction passed into Gallery
topnumberrequired if direction is 'column'; top position of this image, only passed if direction prop was 'column'
leftnumberrequired if direction is 'column'; left position of this image, only passed if direction prop was 'column'
onClickfunctionoptional; the onClick function optionally passsed into Gallery by user

Keywords

FAQs

Last updated on 31 Dec 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc