Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

📷 A flexible image gallery lightbox with native-feeling touch gestures and buttery smooth animations, built with react-spring.

License

NotificationsYou must be signed in to change notification settings

tim-soft/react-spring-lightbox

Repository files navigation

npmNPMnpm bundle sizePRs WelcomeTravis (.org)

React-spring-lightbox is a flexible image gallery lightbox with native-feeling touch gestures and buttery smooth animations.


Docs    Codesandbox

✨ Features

  • ☝️    Mousewheel, swipe or click+drag to page photos
  • ⌨️  Keyboard controlsEsc
  • 🐁  Ctrl +Mousewheel orTrackpad Pinch to zoom
  • 🔎  Double/Single-tap or double/single-click to zoom in/out
  • 👌    Pinch to zoom
  • 👈  Panning on zoomed-in images
  • 🏁  Highly performant spring based animations viareact-spring
  • No external CSS
  • Implement your own UI
  • Supports IE 11, Edge, Safari, Chrome, Firefox and Opera
  • Full typescript support
  • Supports any<img /> attribute includingloading (lazy loading),srcset andaria-*

Install

yarn add react-spring-lightbox

Usage

Theimages prop now accepts a list of objects whose properties can bealmost any valid React<img /> prop includingsrcset,loading (lazy loading) andaria-* attributes.

If you use typescript, the exact type can be imported fromimport { ImagesListType } from 'react-spring-lightbox';

importReact,{useState}from'react';importLightbox,{ImagesListType}from'react-spring-lightbox';constimages:ImagesListType=[{src:'https://timellenberger.com/static/blog-content/dark-mode/win10-dark-mode.jpg',loading:'lazy',alt:'Windows 10 Dark Mode Setting',},{src:'https://timellenberger.com/static/blog-content/dark-mode/macos-dark-mode.png',loading:'lazy',alt:'macOS Mojave Dark Mode Setting',},{src:'https://timellenberger.com/static/blog-content/dark-mode/android-9-dark-mode.jpg',loading:'lazy',alt:'Android 9.0 Dark Mode Setting',},];constCoolLightbox=()=>{const[currentImageIndex,setCurrentIndex]=useState(0);constgotoPrevious=()=>currentImageIndex>0&&setCurrentIndex(currentImageIndex-1);constgotoNext=()=>currentImageIndex+1<images.length&&setCurrentIndex(currentImageIndex+1);return(<LightboxisOpen={true}onPrev={gotoPrevious}onNext={gotoNext}images={images}currentIndex={currentImageIndex}/* Add your own UI */// renderHeader={() => (<CustomHeader />)}// renderFooter={() => (<CustomFooter />)}// renderPrevButton={() => (<CustomLeftArrowButton />)}// renderNextButton={() => (<CustomRightArrowButton />)}// renderImageOverlay={() => (<ImageOverlayComponent >)}/* Add styling */// className="cool-class"// style={{ background: "grey" }}/* Handle closing */// onClose={handleClose}/* Use single or double click to zoom */// singleClickToZoom/* react-spring config for open/close animation */// pageTransitionConfig={{//   from: { transform: "scale(0.75)", opacity: 0 },//   enter: { transform: "scale(1)", opacity: 1 },//   leave: { transform: "scale(0.75)", opacity: 0 },//   config: { mass: 1, tension: 320, friction: 32 }// }}/>);};exportdefaultCoolLightbox;

Props

PropDescription
isOpenFlag that dictates if the lightbox is open or closed
onCloseFunction that closes the Lightbox
onPrevFunction that changes currentIndex to previous image in images
onNextFunction that changes currentIndex to next image in images
currentIndexIndex of image in images array that is currently shown
renderHeaderA React component that renders above the image pager
renderFooterA React component that renders below the image pager
renderPrevButtonA React component that is used for previous button in image pager
renderNextButtonA React component that is used for next button in image pager
renderImageOverlayA React component that renders within the image stage, useful for creating UI overlays on top of the current image
singleClickToZoomOverrides the default behavior of double clicking causing an image zoom to a single click
imagesArray of image objects to be shown in Lightbox
classNameClasses are applied to the root lightbox component
styleInline styles are applied to the root lightbox component
pageTransitionConfigReact-Spring useTransition config for page open/close animation

Local Development

Clone the repo

git clone https://github.com/tim-soft/react-spring-lightbox.git react-spring-lightboxcd react-spring-lightbox

Setup symlinks

yarn linkcd exampleyarn link react-spring-lightbox

Run the library in development mode

yarn start

Run the example app in development mode

cd exampleyarn dev

Changes to the library code should hot reload in the demo app

License

MIT ©Tim Ellenberger

About

📷 A flexible image gallery lightbox with native-feeling touch gestures and buttery smooth animations, built with react-spring.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors4

  •  
  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp