• Stars
    star
    123
  • Rank 288,467 (Top 6 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 5 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Very basic gallery grid based on gatsby-image

gatsby-image-gallery

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

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

Compatibility

Please check the table below to choose the version of this library to use depending on your version of Gatsby:

Gatsby Image Gallery Gatsby Gatsby Plugin Image Gatsby Image
v5 v2 Not supported v3
v6 v3 v1 Not supported
v7 v4-v5 v2-v3 Not supported
v8 v5 v3 Not supported

Only the latest major version of Gatsby Image Gallery is supported.

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

The images prop

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 accepts an object in the lightboxOptions prop, 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 accepts a function in the onClose prop, which will be called when react-image-lightbox is closed by the user.

Customise columns

To customise the number of columns and the space between the images, you have several props:

  • colWidth: percentage of total width to use on small screens (1/3 by default).
  • mdColWidth: percentage of total width to use on medium and large screens (1/4 by default).
  • gutter: margin around each image (0.25rem by default).
  • rowMargin: horizontal margin on each side of the gallery (-15px by default)

Customise image styles

You may also inject your own image styles by passing a component as customWrapper prop. The given component will be passed a few props that you should handle:

  • a GatbsyImage as children, this is the small image
  • a callback as onClick, opening the Lightbox when the small image is clicked

A minimal example may look like this, but you're free to bind the onClick to another element or render the image otherwise:

const CustomWrapper = ({ children, onClick }) => (
  <div className="my-custom-image-wraper" onClick={onClick}>
    {children}
  </div>
)

const MyPage = ({ data }) => {
  return (
    <Gallery
      //... Other props omited for clarity
      customWrapper={CustomWrapper} // example of use
    />
  )
}

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

More Repositories

1

django-codemod

A tool to automatically fix Django deprecations.
Python
175
star
2

deezer-python

Deezer client for python
Python
107
star
3

pypackage-template

A project template for Python package with heavy use of Github actions
Jinja
53
star
4

hello-lambda

Minimal project to get up and running on AWS lambda and pipenv
Makefile
29
star
5

pre-commit-autoupdate-action

Github action to run pre-commit autoupdate
25
star
6

cookiecutter-lambda-function

A cookiecutter template to create AWS Lambda function
Python
23
star
7

flake8-django-migrations

Flake8 plugin to lint for backwards incompatible database migrations
Python
8
star
8

read-nvmrc-action

Simple Github action to read value from .nvmrc file
8
star
9

deezer-oauth-cli

A small CLI to quickly obtain an API token for Deezer API.
Python
7
star
10

django-remake-migrations

A Django admin command to recreate all migrations in a project.
Python
7
star
11

django-tinymce4-widget

Widget for TinyMCE 4 without any static files
Python
5
star
12

cookiecutter-action-py

A cookiecutter template for generating GitHub actions running Python
Python
5
star
13

edubase-now

Convert the daily Edubase dump into an API in seconds.
Makefile
3
star
14

hacktoberfest-labeler-action

A Github Action to labels issues for Hacktoberfest.
Python
2
star
15

all-my-repos

My config to run all-repos
Python
2
star
16

github-actions

A collection of my own GitHub actions
2
star
17

browniebroke.com

Personal blog
TypeScript
2
star
18

carriere-web

Code for site
TypeScript
1
star
19

semaphoreci-notifier

A basic browser extension to send browser notifications on Semaphore CI
JavaScript
1
star
20

netlify-builds

A command line utility to check build usage across multiple Netlify accounts
Python
1
star
21

browniebroke-iac

Describe my infrastructure as code
HCL
1
star
22

festilist

Web application to create playlist based on a festival line up
Python
1
star
23

all-repos-envvar

An all-repos extension to read values from environment variables.
Python
1
star
24

semaphoreci-chrome-notifier

Chrome extension to send a desktop notification when Semaphore CI build terminates
JavaScript
1
star
25

stsmfa-cli

A small CLI to help with creating AWS profile for MFA protected sessions
Python
1
star
26

renovate-configs

My shareable Renovate configs
1
star