Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
react-image-turntable
Advanced tools
Display a set of images as a draggable 360 degree turntable.
npm i react-image-turntable
# Or
yarn add react-image-turntable
# Or
pnpm i react-image-turntable
import { ReactImageTurntable, useReactImageTurntable } 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 App = () => {
const turntableProps = useReactImageTurntable({ images });
return <ReactImageTurntable {...turntableProps} />;
};
See the example code for full demo.
useReactImageTurntable
PropsThe useReactImageTurntable
hook accepts the following properties.
Props | Type | Required | Default Value | Description |
---|---|---|---|---|
autoRotate.enabled | boolean | false | Whether to automatically rotate the turntable. | |
autoRotate.interval | number | 200 | The interval between autorotations in ms. | |
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. | |
onIndexChange | (index: number) => void | undefined | Callback to trigger whenever the active index changes. |
The useReactImageTurntable
hook returns the following properties.
Props | Type | Description |
---|---|---|
activeImageIndex | number | The index of the image currently being shown. |
setActiveImageIndex | (index: number) => void | Function to set the active index. |
images | string[] | The images passed into the hook. |
ref | RefObject<HTMLDivElement> | The ref of the root turntable element. |
Note that there is no need for a setImages
function. images
is not stored in state. If you want
to change the images simply change the images
prop passed into the hook.
import { ReactImageTurntable, useReactImageTurntable } 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 App = () => {
const turntableProps = useReactImageTurntable({
autoRotate: { disabled: true, interval: 75 },
images,
initialImageIndex: 1, // Start on the second image.
movementSensitivity: 50, // Increase the amount of drag needed to change images.
onIndexChange: (index) => console.log(`Active image index changed to ${index}`),
});
const handleSelectFirstImage = () => {
turntableProps.setActiveIndex(0);
};
return (
<>
<button type="button" onClick={handleSelectFirstImage}>
Select first image
</button>
<ReactImageTurntable {...turntableProps} />
</>
);
};
The library uses the first image in images[]
to intrinsically size the component, it also exports
the following className
s allowing you to apply custom styles.
className | Purpose |
---|---|
CLASS_NAME_IMG | Base class for all images. |
CLASS_NAME_IMG_PRIMARY | Class of first image in images[] (sets the size of the main component). |
CLASS_NAME_IMG_SECONDARY | Class of subsequent images. |
See the contributing guide to get started.
The library is built for ES2021
.
FAQs
Display a set of images as a draggable 360 degree turntable.
The npm package react-image-turntable receives a total of 2,946 weekly downloads. As such, react-image-turntable popularity was classified as popular.
We found that react-image-turntable demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.