nerdyman / react-image-turntable

Display a set of images as a draggable 360 degree turntable.
https://githubbox.com/nerdyman/react-image-turntable/tree/main/example
MIT License
21 stars 1 forks source link
360 component hacktoberfest image react rotator slider turntable
# React Image Turntable Display a set of images as a draggable 360 degree turntable. [![React Image Turntable with rotating car](https://raw.githubusercontent.com/nerdyman/stuff/main/libs/react-image-turntable/capture.gif)](https://codesandbox.io/s/github/nerdyman/react-image-turntable/tree/main/example?file=/src/App.tsx:5537-5598) ### [👉   Try the demo  ðŸ‘ˆ](https://codesandbox.io/s/github/nerdyman/react-image-turntable/tree/main/example?file=/src/App.tsx:5537-5598)
NPM package License MIT GitHub CI status

Features

Install

npm i react-image-turntable
# Or
yarn add react-image-turntable
# Or
pnpm i react-image-turntable

Usage

Props

Props Type Required Default Value Description
images string[] ✓ undefined List of image src attributes.
initialImageIndex number 0 Index of image to show first.
movementSensitivity number 20 The amount a "drag" has to move before an image changes to next or previous.

Example

import React from 'react';
import { ReactImageTurntable } from 'react-image-turntable';

const images = [
  'https://via.placeholder.com/1200x800?text=1',
  'https://via.placeholder.com/1200x800?text=2',
  'https://via.placeholder.com/1200x800?text=3',
];

export const Turntable = () => <ReactImageTurntable images={images} />;

Also see the example code in the repo.

Custom Styling

The library uses the first image passed to intrinsically size the component, it also exports following classNames to apply custom styles when needed.

className Purpose
CLASS_NAME_IMG Base class for images.
CLASS_NAME_IMG_PRIMARY Class of first rendered image (sets the size of the main component).
CLASS_NAME_IMG_SECONDARY Class of subsequent images.

Contributing

See the contributing guide to get started.


Browser Support

The library is built for ES2021.

Notes