Security News
The Risks of Misguided Research in Supply Chain Security
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
react-image-gallery
Advanced tools
React carousel image gallery component with thumbnail and mobile support
react-image-gallery is a flexible and customizable image gallery component for React applications. It allows developers to create responsive and interactive image galleries with features like slide shows, thumbnails, and full-screen mode.
Basic Image Gallery
This code sample demonstrates how to create a basic image gallery using react-image-gallery. The gallery displays a series of images with corresponding thumbnails.
import React from 'react';
import ImageGallery from 'react-image-gallery';
const images = [
{
original: 'https://example.com/image1.jpg',
thumbnail: 'https://example.com/thumb1.jpg',
},
{
original: 'https://example.com/image2.jpg',
thumbnail: 'https://example.com/thumb2.jpg',
},
{
original: 'https://example.com/image3.jpg',
thumbnail: 'https://example.com/thumb3.jpg',
},
];
const MyGallery = () => (
<ImageGallery items={images} />
);
export default MyGallery;
Auto Play Slide Show
This code sample shows how to enable the auto-play feature in the image gallery. The gallery will automatically cycle through the images.
import React from 'react';
import ImageGallery from 'react-image-gallery';
const images = [
{
original: 'https://example.com/image1.jpg',
thumbnail: 'https://example.com/thumb1.jpg',
},
{
original: 'https://example.com/image2.jpg',
thumbnail: 'https://example.com/thumb2.jpg',
},
{
original: 'https://example.com/image3.jpg',
thumbnail: 'https://example.com/thumb3.jpg',
},
];
const MyGallery = () => (
<ImageGallery items={images} autoPlay={true} />
);
export default MyGallery;
Full-Screen Mode
This code sample demonstrates how to enable the full-screen mode in the image gallery. Users can view images in full-screen by clicking the full-screen button.
import React from 'react';
import ImageGallery from 'react-image-gallery';
const images = [
{
original: 'https://example.com/image1.jpg',
thumbnail: 'https://example.com/thumb1.jpg',
},
{
original: 'https://example.com/image2.jpg',
thumbnail: 'https://example.com/thumb2.jpg',
},
{
original: 'https://example.com/image3.jpg',
thumbnail: 'https://example.com/thumb3.jpg',
},
];
const MyGallery = () => (
<ImageGallery items={images} showFullscreenButton={true} />
);
export default MyGallery;
react-photo-gallery is a React component for creating responsive image galleries. It offers a more grid-based layout compared to react-image-gallery and is optimized for performance with features like lazy loading.
react-images is a lightbox component for displaying images in a modal. It focuses on providing a simple and customizable lightbox experience, whereas react-image-gallery offers a more comprehensive gallery solution.
react-slick is a carousel component for React. It is highly customizable and supports various types of content, not just images. It is more versatile in terms of content types compared to react-image-gallery.
Live demo: linxtion.com/demo/react-image-gallery
React image gallery is a React component for building image galleries and carousels
Features of react-image-gallery
npm install react-image-gallery
# SCSS
@import "node_modules/react-image-gallery/styles/scss/image-gallery.scss";
# CSS
@import "node_modules/react-image-gallery/styles/css/image-gallery.css";
# Webpack
import "react-image-gallery/styles/css/image-gallery.css";
# Stylesheet with no icons
node_modules/react-image-gallery/styles/scss/image-gallery-no-icon.scss
node_modules/react-image-gallery/styles/css/image-gallery-no-icon.css
Need more example? See example/app.js
import ImageGallery from 'react-image-gallery';
class MyComponent extends React.Component {
render() {
const images = [
{
original: 'http://lorempixel.com/1000/600/nature/1/',
thumbnail: 'http://lorempixel.com/250/150/nature/1/',
},
{
original: 'http://lorempixel.com/1000/600/nature/2/',
thumbnail: 'http://lorempixel.com/250/150/nature/2/'
},
{
original: 'http://lorempixel.com/1000/600/nature/3/',
thumbnail: 'http://lorempixel.com/250/150/nature/3/'
}
]
return (
<ImageGallery items={images} />
);
}
}
items
: (required) Array of objects, see example above,
original
- image src urlthumbnail
- image thumbnail src urloriginalClass
- custom image classthumbnailClass
- custom thumbnail classrenderItem
- Function for custom renderer (see renderItem below)renderThumbInner
- Function for custom thumbnail renderer (see renderThumbInner below)originalAlt
- image altthumbnailAlt
- thumbnail image altoriginalTitle
- image titlethumbnailTitle
- thumbnail image titlethumbnailLabel
- label for thumbnaildescription
- description for imageimageSet
- array of <source>
using <picture>
element (see app.js
for example)srcSet
- image srcset (html5 attribute)sizes
- image sizes (html5 attribute)bulletClass
- extra class for the bullet of the itembulletOnClick
- callback({item, itemIndex, currentIndex})
infinite
: Boolean, default true
lazyLoad
: Boolean, default false
showNav
: Boolean, default true
showThumbnails
: Boolean, default true
thumbnailPosition
: String, default bottom
top, right, bottom, left
showFullscreenButton
: Boolean, default true
useBrowserFullscreen
: Boolean, default true
useTranslate3D
: Boolean, default true
translate
instead of translate3d
css property to transition slidesshowPlayButton
: Boolean, default true
isRTL
: Boolean, default false
showBullets
: Boolean, default false
showIndex
: Boolean, default false
autoPlay
: Boolean, default false
disableThumbnailScroll
: Boolean, default false
disableArrowKeys
: Boolean, default false
disableSwipe
: Boolean, default false
defaultImage
: String, default undefined
indexSeparator
: String, default ' / '
, ignored if showIndex
is false
slideDuration
: Number, default 450
swipingTransitionDuration
: Number, default 0
slideInterval
: Number, default 3000
flickThreshold
: Number (float), default 0.4
swipeThreshold
: Number, default 30
stopPropagation
: Boolean, default false
preventDefaultTouchmoveEvent
: Boolean, default false
startIndex
: Number, default 0
onImageError
: Function, callback(event)
onThumbnailError
: Function, callback(event)
onThumbnailClick
: Function, callback(event, index)
onImageLoad
: Function, callback(event)
onSlide
: Function, callback(currentIndex)
onScreenChange
: Function, callback(fullscreenElement)
onPause
: Function, callback(currentIndex)
onPlay
: Function, callback(currentIndex)
onClick
: Function, callback(event)
onTouchMove
: Function, callback(event) on gallery slide
onTouchEnd
: Function, callback(event) on gallery slide
onTouchStart
: Function, callback(event) on gallery slide
onMouseOver
: Function, callback(event) on gallery slide
onMouseLeave
: Function, callback(event) on gallery slide
additionalClass
: String,
renderCustomControls
: Function, custom controls rendering
_renderCustomControls() {
return <a href='' className='image-gallery-custom-action' onClick={this._customAction.bind(this)}/>
}
renderItem
: Function, custom item rendering
[{thumbnail: '...', renderItem: this.myRenderItem}]
orImageGallery
to completely override _renderItem
, see source for referencerenderThumbInner
: Function, custom thumbnail rendering
[{thumbnail: '...', renderThumbInner: this.myRenderThumbInner}]
orImageGallery
to completely override _renderThumbInner
, see source for referencerenderLeftNav
: Function, custom left nav component
onClick
callback that will slide to the previous item and disabled
argument for when to disable the nav renderLeftNav(onClick, disabled) {
return (
<button
className='image-gallery-custom-left-nav'
disabled={disabled}
onClick={onClick}/>
)
}
renderRightNav
: Function, custom right nav component
onClick
callback that will slide to the next item and disabled
argument for when to disable the nav renderRightNav(onClick, disabled) {
return (
<button
className='image-gallery-custom-right-nav'
disabled={disabled}
onClick={onClick}/>
)
}
renderPlayPauseButton
: Function, play pause button component
onClick
callback that will toggle play/pause and isPlaying
argument for when gallery is playing renderPlayPauseButton: (onClick, isPlaying) => {
return (
<button
type='button'
className={
`image-gallery-play-button${isPlaying ? ' active' : ''}`}
onClick={onClick}
/>
);
}
renderFullscreenButton
: Function, custom fullscreen button component
onClick
callback that will toggle fullscreen and isFullscreen
argument for when fullscreen is active renderFullscreenButton: (onClick, isFullscreen) => {
return (
<button
type='button'
className={
`image-gallery-fullscreen-button${isFullscreen ? ' active' : ''}`}
onClick={onClick}
/>
);
},
play()
: plays the slidespause()
: pauses the slidesfullScreen()
: activates full screenexitFullScreen()
: deactivates full screenslideToIndex(index)
: slides to a specific indexgetCurrentIndex()
: returns the current indexgit clone https://github.com/xiaolin/react-image-gallery.git
cd react-image-gallery
npm install
npm start
Then open localhost:8001
in a browser.
MIT
FAQs
React carousel image gallery component with thumbnail and mobile support
The npm package react-image-gallery receives a total of 110,835 weekly downloads. As such, react-image-gallery popularity was classified as popular.
We found that react-image-gallery demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.