Socket
Socket
Sign inDemoInstall

rc-image

Package Overview
Dependencies
13
Maintainers
5
Versions
88
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    rc-image

React easy to use image component


Version published
Weekly downloads
1.2M
increased by2.1%
Maintainers
5
Install size
898 kB
Created
Weekly downloads
 

Package description

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

Readme

Source

rc-image

React Image.

NPM version npm download build status Codecov bundle size dumi

Feature

  • Placeholder
  • Preview
  • Rotate
  • Zoom
  • Flip
  • Fallback
  • Multiple Preview

install

rc-image

Usage

npm install
npm start
import Image from 'rc-image';

export default () => (
  <Image src="https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png" />
);

API

NameTypeDefaultDescription
previewboolean | PreviewTypetrueWhether to show preview
prefixClsstringrc-imageClassname prefix
placeholderboolean | ReactElement-if true will set default placeholder or use ReactElement set customize placeholder
fallbackstring-Load failed src
previewPrefixClsstringrc-image-previewPreview classname prefix
onError(event: Event) => void-Load failed callback

PreviewType

NameTypeDefaultDescription
visibleboolean-Whether the preview is open or not
closeIconReact.ReactNode-Custom close icon
srcstring-Customize preview src
scaleStepnumber0.5The number to which the scale is increased or decreased
minScalenumber1Min scale
maxScalenumber50Max scale
forceRenderboolean-Force render preview
getContainerstring | HTMLElement | (() => HTMLElement) | falsedocument.bodyReturn the mount node for preview
imageRender(originalNode: React.ReactNode, info: { transform: TransformType }) => React.ReactNode-Customize image
toolbarRender(originalNode: React.ReactNode, info: Omit<ToolbarRenderInfoType, 'current' | 'total'>) => React.ReactNode-Customize toolbar
onVisibleChange(visible: boolean, prevVisible: boolean) => void-Callback when visible is changed
onTransform{ transform: TransformType, action: TransformAction }-Callback when transform is changed

Image.PreviewGroup

preview the merged src

import Image from 'rc-image';

export default () => (
  <Image.PreviewGroup>
    <Image src="https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png" />
    <Image src="https://gw.alipayobjects.com/mdn/rms_08e378/afts/img/A*P0S-QIRUbsUAAAAAAAAAAABkARQnAQ" />
  </Image.PreviewGroup>
);

API

NameTypeDefaultDescription
previewboolean | PreviewGroupTypetrueWhether to show preview,
current: If Preview the show img index, default 0
previewPrefixClsstringrc-image-previewPreview classname prefix
icons{ [iconKey]?: ReactNode }-Icons in the top operation bar, iconKey: 'rotateLeft' | 'rotateRight' | 'zoomIn' | 'zoomOut' | 'close' | 'left' | 'right'
fallbackstring-Load failed src
items(string | { src: string, alt: string, crossOrigin: string, ... })[]-preview group

PreviewGroupType

NameTypeDefaultDescription
visibleboolean-Whether the preview is open or not
currentnumber-Current index
closeIconReact.ReactNode-Custom close icon
scaleStepnumber0.5The number to which the scale is increased or decreased
minScalenumber1Min scale
maxScalenumber50Max scale
forceRenderboolean-Force render preview
getContainerstring | HTMLElement | (() => HTMLElement) | falsedocument.bodyReturn the mount node for preview
countRender(current: number, total: number) => ReactNode-Customize count
imageRender(originalNode: React.ReactNode, info: { transform: TransformType, current: number }) => React.ReactNode-Customize image
toolbarRender(originalNode: React.ReactNode, info: ToolbarRenderInfoType) => React.ReactNode-Customize toolbar
onVisibleChange(visible: boolean, prevVisible: boolean, current: number) => void-Callback when visible is changed
onTransform{ transform: TransformType, action: TransformAction }-Callback when transform is changed

TransformType

{
  x: number;
  y: number;
  rotate: number;
  scale: number;
  flipX: boolean;
  flipY: boolean;
}

TransformAction

type TransformAction =
  | 'flipY'
  | 'flipX'
  | 'rotateLeft'
  | 'rotateRight'
  | 'zoomIn'
  | 'zoomOut'
  | 'close'
  | 'prev'
  | 'next'
  | 'wheel'
  | 'doubleClick'
  | 'move'
  | 'dragRebound';

ToolbarRenderInfoType

{
  icons: {
    flipYIcon: React.ReactNode;
    flipXIcon: React.ReactNode;
    rotateLeftIcon: React.ReactNode;
    rotateRightIcon: React.ReactNode;
    zoomOutIcon: React.ReactNode;
    zoomInIcon: React.ReactNode;
  };
  actions: {
    onFlipY: () => void;
    onFlipX: () => void;
    onRotateLeft: () => void;
    onRotateRight: () => void;
    onZoomOut: () => void;
    onZoomIn: () => void;
  };
  transform: {
    x: number;
    y: number;
    rotate: number;
    scale: number;
    flipX: boolean;
    flipY: boolean;
  },
  current: number;
  total: number;
}

Example

http://localhost:8003/examples/

Test Case

npm test

Coverage

npm run coverage

License

rc-image is released under the MIT license.

Keywords

FAQs

Last updated on 14 Jul 2023

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc