npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

njgallery

v1.1.11

Published

NextJS Justified Gallery with Lightbox.

Downloads

3

Readme

NextJS Justified Gallery (njGallery)


About

njGallery (Next.JS Justified Gallery) was designed to maintain image aspect ratio without cropping. It takes as input an array of image URLs and sizes the images to fill the width of the container they've been placed in.

Images always maintain their original aspect ratios. This applies to the gallery, lightbox, and fullscreen mode. When the browser window is resized, the calculation re-runs in order to maintain justification.

Live demo: http://business.jerradjohnson.com/gallery

Examples:

Gallery

img.png

Lightbox

img_1.png

Fullscreen Mode

img_3.png

Features

The lightbox offers autoplay, shuffle, a dark background mode, and optional tooltip display.

Autoplay or shuffle continue if enabled when fullscreen mode is chosen.

Keypresses (right and left arrows, escape) will change to the next or previous image, or close the lightbox or fullscreen mode.

Usage

Import

Import njGallery, and import the CSS (or create your own styles), e.g.

import {NjGallery} from 'njGallery'
import "njgallery/styles/lightbox.css";

Setup

Set remote image access in next.js.config, e.g.

module.exports = {
  reactStrictMode: true,
    images: {
        domains: ['raw.githubusercontent.com'],
    },
}

Sample Gallery input and call

const photoArray = [
    {
        blurSrc: "https://raw.githubusercontent.com/Jerrad-Johnson/njgallery-with-lightbox/main/shared_images/tiny/Shared.jpg",
        src: "https://raw.githubusercontent.com/Jerrad-Johnson/njgallery-with-lightbox/main/shared_images/sm/Shared.jpg",
        lg_img_url: "https://raw.githubusercontent.com/Jerrad-Johnson/njgallery-with-lightbox/main/shared_images/lg/Shared.jpg",
        height: 450,
        width: 300,
        alt: "Parrot",
        tooltip_left: tooltips_left[0],
        tooltip_right: tooltips_right[0],
    },
];
    

const galleryInputs = {
    images: photoArray,
}
<NjGallery
   { ...galleryInputs }
/>

Requirements

Every image must include src (url), height, width, and alt. Height and width must be provided as whole numbers representing pixel measurements, e.g. 300.

If you're dynamically generating a list, pass an empty array of images [] until the data is loaded. Example: const galleryInputs = { images: [] }

blurSrc is not required, but highly recommended.


Options

Default values will be used if you set none of these values. You may skip this section.

List

Unless otherwise stated, any number examples must be a whole number, e.g. 20 and will be interpreted as a pixel value.

containerWidth Defines the width of your gallery's container. The value can be any valid CSS. Example: 200px, 50%. Default: 100%

containerPadding Defines the padding of your gallery's container, and more padding leaves less room for images. Default: 10.

imagePadding Defines the padding between images. You can set horizontal, vertical, or both. Default: {vertical: 10, horizontal: 10}.

targetRowHeight Although image height will vary, the algorithm will attempt to keep them at or close to this value. Default: 300.

showIncompleteRows Determines whether images will be hidden if they do not complete a row. For example, if you have six images, and four fit on a single row, and the last two cannot be sized to fill the next row, then they will be omitted entirely. Must be boolean. Default: true.

targetRowHeightTolerance Decimals are allowed, and the range is from 0 to 1. At 0, as long as the container is large enough, no vertical resizing will occur. All images will be at their target height, and no justification will occur. This value will often distort images, and is not recommended. Default: .2

maxRows Limits the number of rows of images your gallery will display; beyond this, images will be hidden. Example: 3. Default: Number.POSITIVE_INFINITY.

Lightbox tooltips can be added to your images, and any valid JSX should render. Example:

const tooltips_left = [
    (
        <ul>
            <li>Title: Reptile Gardens Parrot</li>
        </ul>
    ),
];
const tooltips_right = [
    (
        <ul>
            <li>Camera Model</li>
            <li>Lens Model</li>
        </ul>
    ),
];

const photoArray = [
    {
        blurSrc: "https://raw.githubusercontent.com/Jerrad-Johnson/njgallery-with-lightbox/main/shared_images/tiny/Shared.jpg",
        src: "https://raw.githubusercontent.com/Jerrad-Johnson/njgallery-with-lightbox/main/shared_images/sm/Shared.jpg",
        lg_img_url: "https://raw.githubusercontent.com/Jerrad-Johnson/njgallery-with-lightbox/main/shared_images/lg/Shared.jpg",
        height: 450,
        width: 300,
        alt: "Parrot",
        tooltip_left: tooltips_left[0],
        tooltip_right: tooltips_right[0],
    },
]

You may apply a custom style to the MUI buttons. Example:

const lightboxMuiButtonsTheme = {
    palette: {
        primary: {
            main: '#555555',
            contrastText: '#000',
        },
        secondary: {
            main: '#dddddd',
            contrastText: '#fff',
        },
    },
};

const lightboxFullscreenMuiCloseButtonTheme = {
    palette: {
        primary: {
            main: '#dddddd',
            contrastText: '#fff',
        },
    }
}

const galleryInputs = {
    images: photoArray,
    lightboxMuiButtonTheme: lightboxMuiButtonsTheme,
    lightboxFullscreenMuiCloseButtonTheme: lightboxFullscreenMuiCloseButtonTheme,
}

Sample with options, and custom MUI theming:

const galleryInputs = {
    images: photoArray, 
    containerWidth: "100%",
    containerPadding: 10,
    imagePadding: {vertical: 10, horizontal: 10},
    targetRowHeight: 300,
    showIncompleteRows: false,
    targetRowHeightTolerance: .2,
    maxRows: 1,
    lightboxMuiButtonTheme: lightboxMuiButtonsTheme,
    lightboxFullscreenMuiCloseButtonTheme: lightboxFullscreenMuiCloseButtonTheme,
}

Known Bugs

Minor

Scrollbars appear upon window resize if in fullscreen mode. This slightly hides the close button.

Notes

Project required npx @next/codemod next-image-to-legacy-image

Credits

NextJS Justified Gallery uses a slightly modified justified-layout script by SmugMug.

Their license is included credits/LICENSE