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 ๐Ÿ™

ยฉ 2026 โ€“ย Pkg Stats / Ryan Hefner

react-perfect-gallery

v1.0.3

Published

๐Ÿ–ผ๏ธ Modern React image gallery component with touch gestures, infinite scrolling, zoom, and beautiful UI. Mobile-first design with TypeScript support.

Readme

๐Ÿ–ผ๏ธ React Perfect Gallery

A modern, lightweight, and beautiful image gallery React component with mobile-first gestures, infinite scrolling, zoom, and accessibility features. Built with TypeScript and optimized for performance.

โœจ Features

  • ๐Ÿ“ฑ Mobile-First Design - Optimized for touch devices with swipe gestures
  • ๐ŸŽฏ Infinite Scrolling - Optional infinite loop through images
  • ๐Ÿ” Zoom Functionality - Mouse wheel zoom and pan support
  • โŒจ๏ธ Keyboard Navigation - Arrow keys, Escape, and Tab support
  • ๐ŸŽจ Highly Customizable - Custom styles, classes, IDs, and components
  • ๐Ÿ“ Responsive Design - Works perfectly on all screen sizes
  • ๐ŸŽช Thumbnail Navigation - Interactive thumbnail strip with auto-scroll
  • ๐ŸŽญ Loading States - Beautiful loading spinners for images
  • โ™ฟ Accessibility - ARIA labels, focus trapping, and screen reader support
  • โšก Performance - Image preloading and lazy loading optimization

๐Ÿ“ฆ Installation

npm install react-perfect-gallery

๏ฟฝ Screenshots

Desktop View

Mobile View

import React, { useState } from 'react';
import { Gallery, GalleryImage } from 'react-perfect-gallery';

// if you use types use it, if not you can remove it
const images: GalleryImage[] = [
  {
    src: 'https://example.com/image1.jpg',
    alt: 'Beautiful landscape',
    thumbnail: 'https://example.com/thumb1.jpg'
  },
  // ... more images
];

function App() {
  const [isOpen, setIsOpen] = useState(false);
  const [currentIndex, setCurrentIndex] = useState(0);

  const openGallery = (index: number) => {
    setCurrentIndex(index);
    setIsOpen(true);
  };

  const closeGallery = () => {
    setIsOpen(false);
  };

  return (
    <div>
      <div className="thumbnail-grid">
        {images.map((image, index) => (
          <div
            key={index}
            className="thumbnail-item"
            onClick={() => openGallery(index)}
          >
            <img
              src={image.thumbnail}
              alt={image.alt}
              className="thumbnail-image"
            />
            <div className="thumbnail-overlay">
              <span className="view-icon">๐Ÿ”</span>
            </div>
          </div>
        ))}
      </div>
      
      <Gallery
        images={images}
        isOpen={isOpen}
        initialIndex={currentIndex}
        onClose={closeGallery}
        enableZoom={true}
        enableSwipe={true}
        infiniteScroll={true}
        showThumbnails={true}
      />
    </div>
  );
}

export default App;

๐Ÿ“‹ Props

Basic Props

| Prop | Type | Default | Description | |------|------|---------|-------------| | images | GalleryImage[] | Required | Array of image objects | | isOpen | boolean | Required | Controls gallery visibility | | onClose | () => void | Required | Called when gallery closes | | initialIndex | number | 0 | Starting image index | | className | string | '' | Additional CSS classes |

Feature Props

| Prop | Type | Default | Description | |------|------|---------|-------------| | showThumbnails | boolean | true | Show/hide thumbnail strip | | enableZoom | boolean | true | Enable mouse wheel zoom | | enableSwipe | boolean | true | Enable touch swipe gestures | | infiniteScroll | boolean | true | Loop infinitely through images | | centerNavigation | boolean | true | Center navigation arrows |

Customization Props

| Prop | Type | Default | Description | |------|------|---------|-------------| | customClasses | GalleryCustomClasses | {} | Override CSS classes | | customIds | GalleryCustomIds | {} | Set custom element IDs | | customStyles | GalleryCustomStyles | {} | Inline style overrides | | customCloseButton | ReactNode | undefined | Custom close button | | customPrevButton | ReactNode | undefined | Custom previous button | | customNextButton | ReactNode | undefined | Custom next button | | customCounter | (current, total) => ReactNode | undefined | Custom counter component | | customThumbnail | (image, index, isActive) => ReactNode | undefined | Custom thumbnail component |

๐ŸŽจ Customization Examples

Custom Classes and IDs

const customClasses = {
  modal: 'my-custom-modal',
  backdrop: 'my-dark-backdrop',
  content: 'my-rounded-content',
  close: 'my-red-close-btn',
  nav: 'my-blue-nav-btns'
};

const customIds = {
  modal: 'myImageGallery',
  close: 'closeGalleryBtn',
  image: 'mainGalleryImage'
};

<Gallery
  images={images}
  isOpen={isOpen}
  onClose={handleClose}
  customClasses={customClasses}
  customIds={customIds}
/>

Custom Styles

const customStyles = {
  modal: {
    background: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)'
  },
  content: {
    backgroundColor: 'rgba(255, 255, 255, 0.1)',
    borderRadius: '20px',
    border: '2px solid rgba(255, 255, 255, 0.2)'
  },
  close: {
    backgroundColor: '#ff4757',
    color: 'white',
    borderRadius: '50%'
  }
};

<Gallery
  images={images}
  isOpen={isOpen}
  onClose={handleClose}
  customStyles={customStyles}
/>

Custom Components

const customCloseButton = (
  <button className="my-custom-close" onClick={handleClose}>
    Close Gallery โœ•
  </button>
);

const customCounter = (current: number, total: number) => (
  <div className="my-counter">
    Image {current} of {total}
  </div>
);

const customThumbnail = (image: GalleryImage, index: number, isActive: boolean) => (
  <div className={`my-thumbnail ${isActive ? 'active' : ''}`}>
    <img src={image.thumbnail} alt={image.alt} />
    <span>{index + 1}</span>
  </div>
);

<Gallery
  images={images}
  isOpen={isOpen}
  onClose={handleClose}
  customCloseButton={customCloseButton}
  customCounter={customCounter}
  customThumbnail={customThumbnail}
/>

๐ŸŽ›๏ธ Navigation Options

Infinite vs Bounded Scrolling

// Infinite scrolling (loops forever)
<Gallery infiniteScroll={true} />

// Bounded scrolling (stops at boundaries)
<Gallery infiniteScroll={false} />

Navigation Positioning

// Centered navigation (arrows in middle)
<Gallery centerNavigation={true} />

// Edge navigation (arrows on sides)
<Gallery centerNavigation={false} />

๐Ÿ“ฑ Mobile Usage

The gallery is optimized for mobile devices:

  • Swipe Gestures: Swipe left/right to navigate, swipe down to close
  • Touch Optimized: Large touch targets and smooth animations
  • Responsive Design: Adapts to all screen sizes
  • Performance: Optimized for mobile browsers

โŒจ๏ธ Keyboard Navigation

  • Escape: Close gallery
  • Arrow Left: Previous image
  • Arrow Right: Next image
  • Tab: Navigate through interactive elements
  • Shift + Tab: Navigate backwards

๐ŸŽฏ TypeScript Support

Full TypeScript support with comprehensive type definitions:

import { GalleryImage, GalleryProps, GalleryCustomClasses } from 'react-images-gallery';

const images: GalleryImage[] = [
  {
    src: 'https://example.com/image.jpg',
    alt: 'Description',
    thumbnail: 'https://example.com/thumb.jpg'
  }
];

๐ŸŽจ CSS Classes

Override default styles using these CSS classes:

.gallery-modal /* Main modal container */
.gallery-backdrop /* Background overlay */
.gallery-content /* Content container */
.gallery-close /* Close button */
.gallery-nav /* Navigation buttons */
.gallery-nav-prev /* Previous button */
.gallery-nav-next /* Next button */
.gallery-image-container /* Image container */
.gallery-image /* Main image */
.gallery-counter /* Image counter */
.gallery-thumbnails /* Thumbnail strip */
.gallery-thumbnail /* Individual thumbnail */
.gallery-thumbnail.active /* Active thumbnail */

๐Ÿ”ง Advanced Usage

Disable Features

<Gallery
  images={images}
  isOpen={isOpen}
  onClose={handleClose}
  showThumbnails={false}      // Hide thumbnails
  enableZoom={false}          // Disable zoom
  enableSwipe={false}         // Disable swipe
  infiniteScroll={false}      // Bounded scrolling
  centerNavigation={false}    // Edge navigation
/>

Performance Tips

  • Use optimized image sizes and formats
  • Enable lazy loading for large galleries
  • Consider disabling thumbnails for very large collections
  • Use the thumbnail prop for faster loading

๐ŸŒŸ Examples

Basic Gallery

<Gallery
  images={images}
  isOpen={isOpen}
  onClose={handleClose}
/>

Full Customization

<Gallery
    images={images}
    isOpen={isOpen}
    onClose={handleClose}
    infiniteScroll={true}
    centerNavigation={true}
    showThumbnails={true}
    enableZoom={true}
    enableSwipe={true}
    customStyles={{
        modal: { background: 'rgba(0, 0, 0, 0.95)' },
        content: { borderRadius: '20px' }
    }}
    customCounter={(current, total) => (
        <span style={{ color: 'white' }}>
      ๐Ÿ“ธ {current} / {total}
    </span>
    )}
/>

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

GitHub: https://github.com/razan-aboushi/React-image-gallery

๐Ÿ“„ License

MIT ยฉ Razan Aboushi

MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • Built with React and TypeScript
  • Inspired by modern gallery designs
  • Optimized for performance and accessibility

React Perfect Gallery - Modern, beautiful, and highly customizable image galleries for React applications.