Giter VIP home page Giter VIP logo

othergallery's Introduction

gatsby-image-gallery

CI status Current npm package version. Released under the MIT license. Total alerts

Very basic gallery grid based on gatsby-plugin-image and react-image-lightbox, styling powered by styled-components.

Install

npm install --save @browniebroke/gatsby-image-gallery

Note: this library is compatible with Gatbsy v3 and gatsby-plugin-image as of version 6. If you want to use it with Gastby v2 and the gatsby-image plugin, please stick to version 5 or earlier.

Usage

This library provides a Gallery component, rendering as a grid of images that can be clicked to open in full size inside a lightbox. See below for a minimal example:

import { graphql } from 'gatsby'
import React from 'react'

import Gallery from '@browniebroke/gatsby-image-gallery'

const MyPage = ({ data }) => {
  const images = data.allFile.edges.map(({ node }) => node.childImageSharp)
  // `images` is an array of objects with `thumb` and `full`
  return <Gallery images={images} />
}

export const pageQuery = graphql`
  query ImagesForGallery {
    allFile {
      edges {
        node {
          childImageSharp {
            thumb: gatsbyImageData(
              width: 270
              height: 270
              placeholder: BLURRED
            )
            full: gatsbyImageData(layout: FULL_WIDTH)
          }
        }
      }
    }
  }
`

export default MyPage

Details

The images prop is an array of objects with 2 required properties: thumb and full that should each be a GatsbyImage compatible object.

In addition, images may have the following properties:

  • thumbAlt: (string) used to set the alt attribute on the thumbnail image
  • title: (node) passed to the Lightbox component as imageTitle.
  • caption: (node) passed to the Lightbox component as imageCaption.

Passing options to Lightbox

The <Gallery> component also accepts an object in the lightboxOptions props, which will be passed down directly to react-image-lightbox.

You can see the full list of options in their documentation.

Passing onClose callback to Lightbox

The <Gallery> component also accepts a function in the onClose prop, which will be called when react-image-lightbox is closed by the user.

Example

For a full working example, there is one in the example folder which is deployed to Netlify.

Development

Releases

Releases are automated using semantic release. This library parses the commit log to detect which version number should be bumped.

License

MIT © browniebroke

othergallery's People

Contributors

xarxaoberta avatar

Watchers

 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.