1- <div align =" center " >
2-
31# React Image Gallery
42
53** A responsive, customizable image gallery component for React**
64
5+ <br />
6+
77[ ![ npm version] ( https://badge.fury.io/js/react-image-gallery.svg )] ( https://badge.fury.io/js/react-image-gallery )
88[ ![ Download Count] ( http://img.shields.io/npm/dm/react-image-gallery.svg?style=flat )] ( https://www.npmjs.com/package/react-image-gallery )
99[ ![ Bundle size] ( https://badgen.net/bundlephobia/minzip/react-image-gallery )] ( https://bundlephobia.com/package/react-image-gallery )
1010[ ![ CI] ( https://github.com/xiaolin/react-image-gallery/actions/workflows/ci.yml/badge.svg )] ( https://github.com/xiaolin/react-image-gallery/actions/workflows/ci.yml )
1111[ ![ TypeScript] ( https://img.shields.io/badge/TypeScript-Ready-blue.svg )] ( https://www.typescriptlang.org/ )
1212[ ![ License: MIT] ( https://img.shields.io/badge/License-MIT-yellow.svg )] ( https://opensource.org/licenses/MIT )
1313
14- [ ![ Live Demo] ( https://img.shields.io/badge/🚀_Live_Demo-Visit_Site-blue?style=for-the-badge )] ( http://linxtion.com/demo/react-image-gallery )
14+ <br />
15+
16+ ** [ 🚀 View Live Demo] ( http://linxtion.com/demo/react-image-gallery ) **
17+
18+ <br />
1519
1620![ React Image Gallery Demo] ( https://github.com/xiaolin/react-image-gallery/raw/master/static/ig-demo.gif )
1721
18- </ div >
22+ <br / >
1923
2024---
2125
3236| ↕️ ** Vertical Mode** | Slide vertically instead of horizontally |
3337| 🎬 ** Custom Slides** | Render videos, iframes, or any custom content |
3438
35- ---
39+ < br />
3640
37- ## 🚀 Getting started
41+ ---
3842
39- React Image Gallery requires ** React 16.0.0 or later. **
43+ ## 🚀 Getting Started
4044
4145```
4246npm install react-image-gallery
4347```
4448
45- ### Zero-config (Recommended)
46-
47- Styles are automatically injected when you import the component. No separate CSS import required!
48-
49- ``` js
50- import ImageGallery from " react-image-gallery" ;
51-
52- // That's it! Styles are automatically injected.
53- ```
54-
55- ### Manual style import (Optional)
56-
57- If you prefer to manage styles yourself (for customization, bundling optimization, or to prevent auto-injection):
58-
59- ``` css
60- /* CSS @import */
61- @import " ~react-image-gallery/styles/image-gallery.css" ;
62- ```
63-
64- ``` js
65- // JS import (using webpack or similar bundler)
66- import " react-image-gallery/styles/image-gallery.css" ;
67- ```
68-
69- Note: If you import the CSS manually, it will be detected and auto-injection will be skipped.
70-
71- ### 🎨 Theming with CSS Custom Properties
72-
73- Customize the gallery appearance by overriding CSS custom properties:
74-
75- ``` css
76- /* In your CSS or styled component */
77- .image-gallery {
78- --ig-primary-color : #ff6b6b ; /* Primary/accent color */
79- --ig-white : #ffffff ; /* Icon and text color */
80- --ig-black : #000000 ; /* Background color in fullscreen */
81- --ig-background-overlay : rgba (0 , 0 , 0 , 0.5 ); /* Overlay background */
82- --ig-thumbnail-size : 120px ; /* Thumbnail dimensions */
83- --ig-thumbnail-border-width : 3px ; /* Thumbnail border width */
84- }
85- ```
86-
87- Or apply globally:
88-
89- ``` css
90- :root {
91- --ig-primary-color : #e91e63 ;
92- }
93- ```
94-
95- ### 📖 Example
96-
97- Need more examples? See [ ` example/App.jsx ` ] ( https://github.com/xiaolin/react-image-gallery/blob/master/example/App.jsx )
98-
99- ``` js
49+ ``` jsx
10050import ImageGallery from " react-image-gallery" ;
10151
10252const images = [
@@ -108,102 +58,81 @@ const images = [
10858 original: " https://picsum.photos/id/1015/1000/600/" ,
10959 thumbnail: " https://picsum.photos/id/1015/250/150/" ,
11060 },
111- {
112- original: " https://picsum.photos/id/1019/1000/600/" ,
113- thumbnail: " https://picsum.photos/id/1019/250/150/" ,
114- },
11561];
11662
11763function MyGallery () {
11864 return < ImageGallery items= {images} / > ;
11965}
12066```
12167
68+ For more examples, see [ ` example/App.jsx ` ] ( https://github.com/xiaolin/react-image-gallery/blob/master/example/App.jsx )
69+
70+ <br />
71+
12272---
12373
12474## ⚙️ Props
12575
126- - ` items ` : (required) Array of objects, see example above,
127- - Available Properties
128- - ` original ` - image src url
129- - ` thumbnail ` - image thumbnail src url
130- - ` fullscreen ` - image for fullscreen (defaults to original)
131- - ` originalHeight ` - image height (html5 attribute)
132- - ` originalWidth ` - image width (html5 attribute)
133- - ` loading ` - image loading. Either "lazy" or "eager" (html5 attribute)
134- - ` thumbnailHeight ` - image height (html5 attribute)
135- - ` thumbnailWidth ` - image width (html5 attribute)
136- - ` thumbnailLoading ` - image loading. Either "lazy" or "eager" (html5 attribute)
137- - ` originalClass ` - custom image class
138- - ` thumbnailClass ` - custom thumbnail class
139- - ` renderItem ` - Function for custom rendering a specific slide (see renderItem below)
140- - ` renderThumbInner ` - Function for custom thumbnail renderer (see renderThumbInner below)
141- - ` originalAlt ` - image alt
142- - ` thumbnailAlt ` - thumbnail image alt
143- - ` originalTitle ` - image title
144- - ` thumbnailTitle ` - thumbnail image title
145- - ` thumbnailLabel ` - label for thumbnail
146- - ` description ` - description for image
147- - ` srcSet ` - image srcset (html5 attribute)
148- - ` sizes ` - image sizes (html5 attribute)
149- - ` bulletClass ` - extra class for the bullet of the item
150- - ` infinite ` : Boolean, default ` true `
151- - infinite sliding
76+ - ` items ` : (required) Array of objects. Available properties:
77+ - ` original ` - image source URL
78+ - ` thumbnail ` - thumbnail source URL
79+ - ` fullscreen ` - fullscreen image URL (defaults to original)
80+ - ` originalHeight ` - image height (html5 attribute)
81+ - ` originalWidth ` - image width (html5 attribute)
82+ - ` loading ` - "lazy" or "eager" (HTML5 attribute)
83+ - ` thumbnailHeight ` - image height (html5 attribute)
84+ - ` thumbnailWidth ` - image width (html5 attribute)
85+ - ` thumbnailLoading ` - "lazy" or "eager" (HTML5 attribute)
86+ - ` originalClass ` - custom image class
87+ - ` thumbnailClass ` - custom thumbnail class
88+ - ` renderItem ` - Function for custom rendering a specific slide (see renderItem below)
89+ - ` renderThumbInner ` - Function for custom thumbnail renderer (see renderThumbInner below)
90+ - ` originalAlt ` - image alt
91+ - ` thumbnailAlt ` - thumbnail image alt
92+ - ` originalTitle ` - image title
93+ - ` thumbnailTitle ` - thumbnail image title
94+ - ` thumbnailLabel ` - label for thumbnail
95+ - ` description ` - description for image
96+ - ` srcSet ` - image srcset (html5 attribute)
97+ - ` sizes ` - image sizes (html5 attribute)
98+ - ` bulletClass ` - extra class for the bullet of the item
99+ - ` infinite ` : Boolean, default ` true ` - loop infinitely
152100- ` lazyLoad ` : Boolean, default ` false `
153101- ` showNav ` : Boolean, default ` true `
154102- ` showThumbnails ` : Boolean, default ` true `
155- - ` thumbnailPosition ` : String, default ` bottom `
156- - available positions: ` top, right, bottom, left `
103+ - ` thumbnailPosition ` : String, default ` bottom ` - options: ` top ` , ` right ` , ` bottom ` , ` left `
157104- ` showFullscreenButton ` : Boolean, default ` true `
158- - ` useBrowserFullscreen ` : Boolean, default ` true `
159- - if false, fullscreen will be done via css within the browser
160- - ` useTranslate3D ` : Boolean, default ` true `
161- - if false, will use ` translate ` instead of ` translate3d ` css property to transition slides
105+ - ` useBrowserFullscreen ` : Boolean, default ` true ` - if false, uses CSS-based fullscreen
106+ - ` useTranslate3D ` : Boolean, default ` true ` - if false, uses ` translate ` instead of ` translate3d `
162107- ` showPlayButton ` : Boolean, default ` true `
163- - ` isRTL ` : Boolean, default ` false `
164- - if true, gallery's direction will be from right-to-left (to support right-to-left languages)
108+ - ` isRTL ` : Boolean, default ` false ` - right-to-left mode
165109- ` showBullets ` : Boolean, default ` false `
166- - ` maxBullets ` : Number, default ` undefined `
167- - Maximum number of bullets to show at once. Active bullet stays centered while bullets slide. Minimum value is 3.
110+ - ` maxBullets ` : Number, default ` undefined ` - max bullets shown (minimum 3, active bullet stays centered)
168111- ` showIndex ` : Boolean, default ` false `
169112- ` autoPlay ` : Boolean, default ` false `
170- - ` disableThumbnailScroll ` : Boolean, default ` false `
171- - disables the thumbnail container from adjusting
172- - ` disableKeyDown ` : Boolean, default ` false `
173- - disables keydown listener for keyboard shortcuts (left arrow, right arrow, esc key)
113+ - ` disableThumbnailScroll ` : Boolean, default ` false ` - disable thumbnail auto-scroll
114+ - ` disableKeyDown ` : Boolean, default ` false ` - disable keyboard navigation
174115- ` disableSwipe ` : Boolean, default ` false `
175116- ` disableThumbnailSwipe ` : Boolean, default ` false `
176- - ` onErrorImageURL ` : String, default ` undefined `
177- - an image src pointing to your default image if an image fails to load
178- - handles both slide image, and thumbnail image
117+ - ` onErrorImageURL ` : String, default ` undefined ` - fallback image URL for failed loads
179118- ` indexSeparator ` : String, default ` ' / ' ` , ignored if ` showIndex ` is false
180- - ` slideDuration ` : Number, default ` 550 `
181- - transition duration during image slide in milliseconds
182- - ` swipingTransitionDuration ` : Number, default ` 0 `
183- - transition duration while swiping in milliseconds
119+ - ` slideDuration ` : Number, default ` 550 ` - slide transition duration (ms)
120+ - ` swipingTransitionDuration ` : Number, default ` 0 ` - transition duration while swiping (ms)
184121- ` slideInterval ` : Number, default ` 3000 `
185122- ` slideOnThumbnailOver ` : Boolean, default ` false `
186- - ` slideVertically ` : Boolean, default ` false `
187- - if true, slides will transition vertically instead of horizontally
188- - ` flickThreshold ` : Number (float), default ` 0.4 `
189- - Determines the max velocity of a swipe before it's considered a flick (lower = more sensitive)
190- - ` swipeThreshold ` : Number, default ` 30 `
191- - A percentage of how far the offset of the current slide is swiped to trigger a slide event.
192- e.g. If the current slide is swiped less than 30% to the left or right, it will not trigger a slide event.
193- - ` stopPropagation ` : Boolean, default ` false `
194- - Automatically calls stopPropagation on all 'swipe' events.
123+ - ` slideVertically ` : Boolean, default ` false ` - slide vertically instead of horizontally
124+ - ` flickThreshold ` : Number, default ` 0.4 ` - swipe velocity threshold (lower = more sensitive)
125+ - ` swipeThreshold ` : Number, default ` 30 ` - percentage of slide width needed to trigger navigation
126+ - ` stopPropagation ` : Boolean, default ` false ` - call stopPropagation on swipe events
195127- ` startIndex ` : Number, default ` 0 `
196- - ` onImageError ` : Function, ` callback(event) `
197- - overrides onErrorImage
198- - ` onThumbnailError ` : Function, ` callback(event) `
199- - overrides onErrorImage
128+ - ` onImageError ` : Function, ` callback(event) ` - overrides ` onErrorImageURL `
129+ - ` onThumbnailError ` : Function, ` callback(event) ` - overrides ` onErrorImageURL `
200130- ` onThumbnailClick ` : Function, ` callback(event, index) `
201131- ` onBulletClick ` : Function, ` callback(event, index) `
202132- ` onImageLoad ` : Function, ` callback(event) `
203133- ` onSlide ` : Function, ` callback(currentIndex) `
204134- ` onBeforeSlide ` : Function, ` callback(nextIndex) `
205- - ` onScreenChange ` : Function, ` callback(boolean) `
206- - When fullscreen is toggled a boolean is passed to the callback
135+ - ` onScreenChange ` : Function, ` callback(isFullscreen) `
207136- ` onPause ` : Function, ` callback(currentIndex) `
208137- ` onPlay ` : Function, ` callback(currentIndex) `
209138- ` onClick ` : Function, ` callback(event) `
@@ -212,93 +141,19 @@ function MyGallery() {
212141- ` onTouchStart ` : Function, ` callback(event) on gallery slide `
213142- ` onMouseOver ` : Function, ` callback(event) on gallery slide `
214143- ` onMouseLeave ` : Function, ` callback(event) on gallery slide `
215- - ` additionalClass ` : String,
216- - Additional class that will be added to the root node of the component.
217- - ` renderCustomControls ` : Function, custom controls rendering
218- - Use this to render custom controls or other elements on the currently displayed image (like the fullscreen button)
219- ``` javascript
220- _renderCustomControls () {
221- return < a href= ' ' className= ' image-gallery-custom-action' onClick= {this ._customAction .bind (this )}/ >
222- }
223- ```
224- - ` renderItem ` : Function, custom item rendering
225- - NOTE: Highly suggest looking into a render cache such as React.memo if you plan to override renderItem
226- - On a specific item ` [{thumbnail: '...', renderItem: this.myRenderItem}] `
227- - As a prop passed into ` ImageGallery ` to completely override ` renderItem ` , see source for renderItem implementation
144+ - ` additionalClass ` : String, additional class for the root node
145+ - ` renderCustomControls ` : Function, render custom controls on the current slide
146+ - ` renderItem ` : Function, custom slide rendering
228147- ` renderThumbInner ` : Function, custom thumbnail rendering
229-
230- - On a specific item ` [{thumbnail: '...', renderThumbInner: this.myRenderThumbInner}] `
231- - As a prop passed into ` ImageGallery ` to completely override ` _renderThumbInner ` , see source for reference
232-
233148- ` renderLeftNav ` : Function, custom left nav component
234- - See [ ` <LeftNav /> ` ] ( https://github.com/xiaolin/react-image-gallery/blob/master/src/components/controls/LeftNav.jsx )
235- - Use this to render a custom left nav control
236- - Args:
237- - ` onClick ` callback that will slide to the previous item
238- - ` disabled ` boolean for when the nav is disabled
239- ``` javascript
240- renderLeftNav : (onClick , disabled ) => (
241- < LeftNav onClick= {onClick} disabled= {disabled} / >
242- );
243- ```
244149- ` renderRightNav ` : Function, custom right nav component
245- - See [ ` <RightNav /> ` ] ( https://github.com/xiaolin/react-image-gallery/blob/master/src/components/controls/RightNav.jsx )
246- - Use this to render a custom right nav control
247- - Args:
248- - ` onClick ` callback that will slide to the next item
249- - ` disabled ` boolean for when the nav is disabled
250- ``` javascript
251- renderRightNav : (onClick , disabled ) => (
252- < RightNav onClick= {onClick} disabled= {disabled} / >
253- );
254- ```
255- - ` renderTopNav ` : Function, custom top nav component (for vertical sliding)
256- - See [ ` <TopNav /> ` ] ( https://github.com/xiaolin/react-image-gallery/blob/master/src/components/controls/TopNav.jsx )
257- - Use this to render a custom top nav control when ` slideVertically ` is true
258- - Args:
259- - ` onClick ` callback that will slide to the previous item
260- - ` disabled ` boolean for when the nav is disabled
261- ``` javascript
262- renderTopNav : (onClick , disabled ) => (
263- < TopNav onClick= {onClick} disabled= {disabled} / >
264- );
265- ```
266- - ` renderBottomNav ` : Function, custom bottom nav component (for vertical sliding)
267- - See [ ` <BottomNav /> ` ] ( https://github.com/xiaolin/react-image-gallery/blob/master/src/components/controls/BottomNav.jsx )
268- - Use this to render a custom bottom nav control when ` slideVertically ` is true
269- - Args:
270- - ` onClick ` callback that will slide to the next item
271- - ` disabled ` boolean for when the nav is disabled
272- ``` javascript
273- renderBottomNav : (onClick , disabled ) => (
274- < BottomNav onClick= {onClick} disabled= {disabled} / >
275- );
276- ```
277- - ` renderPlayPauseButton ` : Function, play pause button component
278- - See [ ` <PlayPause /> ` ] ( https://github.com/xiaolin/react-image-gallery/blob/master/src/components/controls/PlayPause.jsx )
279- - Use this to render a custom play pause button
280- - Args:
281- - ` onClick ` callback that will toggle play/pause
282- - ` isPlaying ` boolean for when gallery is playing
283- ``` javascript
284- renderPlayPauseButton : (onClick , isPlaying ) => (
285- < PlayPause onClick= {onClick} isPlaying= {isPlaying} / >
286- );
287- ```
288- - ` renderFullscreenButton ` : Function, custom fullscreen button component
289- - See [ ` <Fullscreen /> ` ] ( https://github.com/xiaolin/react-image-gallery/blob/master/src/components/controls/Fullscreen.jsx )
290- - Use this to render a custom fullscreen button
291- - Args:
292- - ` onClick ` callback that will toggle fullscreen
293- - ` isFullscreen ` argument for when fullscreen is active
294- ``` javascript
295- renderFullscreenButton : (onClick , isFullscreen ) => (
296- < Fullscreen onClick= {onClick} isFullscreen= {isFullscreen} / >
297- ),
298- ```
299- - ` useWindowKeyDown ` : Boolean, default ` true `
300- - If ` true ` , listens to keydown events on window (window.addEventListener)
301- - If ` false ` , listens to keydown events on image gallery element (imageGalleryElement.addEventListener)
150+ - ` renderTopNav ` : Function, custom top nav component (vertical mode)
151+ - ` renderBottomNav ` : Function, custom bottom nav component (vertical mode)
152+ - ` renderPlayPauseButton ` : Function, custom play/pause button
153+ - ` renderFullscreenButton ` : Function, custom fullscreen button
154+ - ` useWindowKeyDown ` : Boolean, default ` true ` - use window or element for key events
155+
156+ <br />
302157
303158---
304159
@@ -312,15 +167,18 @@ The following functions can be accessed using [refs](https://reactjs.org/docs/re
312167- ` slideToIndex(index) ` : slides to a specific index
313168- ` getCurrentIndex() ` : returns the current index
314169
170+ <br />
171+
315172---
316173
317174## 🤝 Contributing
318175
319- Each pull request (PR) should be specific and isolated to the issue you're trying to fix. Please do not stack features, chores, refactors, or enhancements in one PR. Describe your feature/implementation in the PR. If you're unsure whether it's useful or if it involves a major change , please open an issue first and seek feedback .
176+ Pull requests should be focused on a single issue. If you're unsure whether a change is useful or involves a major modification , please open an issue first.
320177
321- - Follow eslint provided
178+ - Follow the eslint config
322179- Comment your code
323- - Write [ clean] ( https://github.com/ryanmcdermott/clean-code-javascript ) code
180+
181+ <br />
324182
325183---
326184
@@ -337,6 +195,8 @@ npm start
337195
338196Then open [ ` localhost:8001 ` ] ( http://localhost:8001 ) in a browser.
339197
198+ <br />
199+
340200---
341201
342202## 📄 License
0 commit comments