0.2.0 • Published 3 years ago

react-slim-image-viewer v0.2.0

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

React Slim Image Viewer

Display images in a full-screen modal, with left and right navigation to switch between several images. Supports keyboard navigation and mouse scroll. Tiny library with zero dependencies (except React).

This React component is heavily inspired by (aka copied from) react-simple-image-viewer by specter256, thanks for your work Alexander!

screenshot showing react-slim-image-viewer

The screenshot above shows what this component looks like with default styling. The "prev" navigation arrow is highlighted because my mouse cursor is hovering it. You can change the name of the CSS classes used to disable the default styles if you want to provider your own. Or you can pass in a styles prop to customize the styles. Your choice.

You can see a usage example here: https://github.com/Tobbe/react-slim-image-viewer/blob/main/src/App.tsx

Installation

npm install react-slim-image-viewer

or

yarn add react-slim-image-viewer

API

PropertyTypeDescription
srcstring[]Array of image URLs
currentIndexnumberIndex of image in src property which will be shown first when viewer is opened
onClosefunctionCallback which will be called when viewer will closed
stylesRsivStylesCustom styles for all html elements of the modal window
baseClassNamestringChange the base part of the css class name. This will disable built-in styles

Shortcuts

ShortcutDescription
EscapeClose the viewer
Right Arrow / lNext image
Left Arrow / hPrevious image
Mouse wheelScrolling previous / next image

Contributing

PRs and issue reports are welcome!

Testing pre-release version

  1. npm run build:lib
  2. Copy the built files to where you want to use them. Example (standing in a project that you want to test the new version in): cp -r ../react-slim-image-viewer/lib/* node_modules/react-slim-image-viewer/