What is rc-image?
The rc-image npm package is a React component library for displaying images in a more versatile and enhanced manner. It provides features such as modal viewing, image rotation, zooming, and dragging, making it a powerful tool for implementing image galleries or for enhancing the image viewing experience in web applications.
What are rc-image's main functionalities?
Modal Image Viewing
This feature allows images to be viewed in a modal (popup) when clicked, providing a closer look. The code sample demonstrates how to enable modal viewing with visibility control.
{"import React from 'react';\nimport Image from 'rc-image';\n\nexport default () => (\n <Image\n preview={{\n visible: true,\n onVisibleChange: (vis) => console.log('visible:', vis),\n }}\n src='path/to/image.jpg'\n />\n);"}
Image Rotation
Enables the rotation of images. This example shows how to rotate an image by 90 degrees using inline styles.
{"import React from 'react';\nimport Image from 'rc-image';\n\nexport default () => (\n <Image\n style={{ transform: 'rotate(90deg)' }}\n src='path/to/image.jpg'\n />\n);"}
Zoom and Drag
This feature allows users to zoom in/out on images and drag them around for better viewing. The code sample demonstrates enabling zoom and drag capabilities in the preview modal.
{"import React from 'react';\nimport Image from 'rc-image';\n\nexport default () => (\n <Image\n preview={{\n zoomable: true,\n draggable: true,\n }}\n src='path/to/image.jpg'\n />\n);"}
Other packages similar to rc-image
react-image-lightbox
A flexible and responsive lightbox component for displaying images and videos in React. It offers similar modal viewing capabilities but is more focused on lightbox functionalities and does not support image rotation or dragging out of the box.
react-image-gallery
This package is designed for creating image galleries in React applications. It supports thumbnail navigation, fullscreen mode, and custom renderers but lacks the advanced image manipulation features like rotation and dragging found in rc-image.
react-photo-view
Offers a rich set of features for image viewing in React, including pinch to zoom, slide to close, and rotation. It is similar to rc-image in terms of providing an enhanced image viewing experience but focuses more on touch interactions.
rc-image
React Image
Feature
Keyboard
install
Usage
npm install
npm start
const Image = require('rc-image');
ReactDOM.render(
<Image src="https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png" />
), document.getElementById('root'));
API
Name | Type | Default | Description |
---|
preview | boolean | true | Whether to show preview |
prefixCls | string | rc-image | Classname prefix |
placeholder | ReactNode | - | Loading placeholder |
fallback | string | - | Load failed src |
onPreviewClose | function(e) | - | Preview close callback |
Example
http://localhost:8003/examples/
Test Case
npm test
Coverage
npm run coverage
License
rc-image is released under the MIT license.