rc-image
React easy to use image component
Last updated a year ago by zombiej .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install rc-image 
SYNC missed versions from official npm registry.

rc-image

React Image.

NPM version npm download build status Codecov bundle size dumi

Feature

  • [x] Placeholder
  • [x] Preview
  • [x] Rotate
  • [x] Zoom
  • [x] Flip
  • [x] Fallback
  • [x] 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

Name Type Default Description
preview boolean | PreviewType true Whether to show preview
prefixCls string rc-image Classname prefix
placeholder boolean | ReactElement - if true will set default placeholder or use ReactElement set customize placeholder
fallback string - Load failed src
previewPrefixCls string rc-image-preview Preview classname prefix
onError (event: Event) => void - Load failed callback

PreviewType

Name Type Default Description
visible boolean - Whether the preview is open or not
closeIcon React.ReactNode - Custom close icon
src string - Customize preview src
movable boolean true Enable drag
scaleStep number 0.5 The number to which the scale is increased or decreased
minScale number 1 Min scale
maxScale number 50 Max scale
forceRender boolean - Force render preview
getContainer string | HTMLElement | (() => HTMLElement) | false document.body Return the mount node for preview
imageRender (originalNode: React.ReactElement, info: { transform: TransformType }) => React.ReactNode - Customize image
toolbarRender (originalNode: React.ReactElement, 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

Name Type Default Description
preview boolean | PreviewGroupType true Whether to show preview,
current: If Preview the show img index, default 0
previewPrefixCls string rc-image-preview Preview classname prefix
icons { [iconKey]?: ReactNode } - Icons in the top operation bar, iconKey: 'rotateLeft' | 'rotateRight' | 'zoomIn' | 'zoomOut' | 'close' | 'left' | 'right'
fallback string - Load failed src
items (string | { src: string, alt: string, crossOrigin: string, ... })[] - preview group

PreviewGroupType

Name Type Default Description
visible boolean - Whether the preview is open or not
movable boolean true Enable drag
current number - Current index
closeIcon React.ReactNode - Custom close icon
scaleStep number 0.5 The number to which the scale is increased or decreased
minScale number 1 Min scale
maxScale number 50 Max scale
forceRender boolean - Force render preview
getContainer string | HTMLElement | (() => HTMLElement) | false document.body Return the mount node for preview
countRender (current: number, total: number) => ReactNode - Customize count
imageRender (originalNode: React.ReactElement, info: { transform: TransformType, current: number }) => React.ReactNode - Customize image
toolbarRender (originalNode: React.ReactElement, 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: {
    prevIcon?: React.ReactNode;
    nextIcon?: React.ReactNode;
    flipYIcon: React.ReactNode;
    flipXIcon: React.ReactNode;
    rotateLeftIcon: React.ReactNode;
    rotateRightIcon: React.ReactNode;
    zoomOutIcon: React.ReactNode;
    zoomInIcon: React.ReactNode;
  };
  actions: {
    onActive?: (offset: number) => void;
    onFlipY: () => void;
    onFlipX: () => void;
    onRotateLeft: () => void;
    onRotateRight: () => void;
    onZoomOut: () => void;
    onZoomIn: () => void;
    onClose: () => void;
    onReset: () => 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.

Current Tags

  • 7.12.0                                ...           latest (a year ago)

94 Versions

  • 7.12.0                                ...           a year ago
  • 7.11.1                                ...           a year ago
  • 7.11.0                                ...           2 years ago
  • 7.10.0                                ...           2 years ago
  • 7.9.0                                ...           2 years ago
  • 7.8.1                                ...           2 years ago
  • 7.8.0                                ...           2 years ago
  • 7.7.1                                ...           2 years ago
  • 7.7.0                                ...           2 years ago
  • 7.6.0                                ...           2 years ago
  • 7.5.1                                ...           2 years ago
  • 7.5.0                                ...           2 years ago
  • 7.4.0                                ...           2 years ago
  • 7.3.2                                ...           2 years ago
  • 7.3.1                                ...           3 years ago
  • 7.3.0                                ...           3 years ago
  • 7.2.0                                ...           3 years ago
  • 7.1.3                                ...           3 years ago
  • 7.1.2                                ...           3 years ago
  • 7.1.1                                ...           3 years ago
  • 7.1.0                                ...           3 years ago
  • 7.0.0                                ...           3 years ago
  • 7.0.0-2                                ...           3 years ago
  • 7.0.0-0                                ...           3 years ago
  • 6.1.0                                ...           3 years ago
  • 6.0.0                                ...           3 years ago
  • 5.18.1                                ...           3 years ago
  • 5.18.0                                ...           3 years ago
  • 5.17.1                                ...           3 years ago
  • 5.16.0                                ...           3 years ago
  • 5.15.2                                ...           3 years ago
  • 5.15.1                                ...           3 years ago
  • 5.14.0                                ...           3 years ago
  • 5.13.0                                ...           3 years ago
  • 5.12.2                                ...           3 years ago
  • 5.12.1                                ...           3 years ago
  • 5.12.0                                ...           3 years ago
  • 5.11.0                                ...           3 years ago
  • 5.10.2                                ...           3 years ago
  • 5.10.1                                ...           3 years ago
  • 5.10.0                                ...           3 years ago
  • 5.9.0                                ...           4 years ago
  • 5.8.0                                ...           4 years ago
  • 5.7.1                                ...           4 years ago
  • 5.6.4                                ...           4 years ago
  • 5.6.3                                ...           4 years ago
  • 5.7.0                                ...           4 years ago
  • 5.6.2                                ...           4 years ago
  • 5.6.1                                ...           4 years ago
  • 5.6.0                                ...           4 years ago
  • 5.5.0                                ...           4 years ago
  • 5.4.0                                ...           4 years ago
  • 5.3.0                                ...           4 years ago
  • 5.2.5                                ...           5 years ago
  • 5.2.4                                ...           5 years ago
  • 5.2.3                                ...           5 years ago
  • 5.2.2                                ...           5 years ago
  • 5.2.1                                ...           5 years ago
  • 5.2.0                                ...           5 years ago
  • 5.1.4                                ...           5 years ago
  • 5.1.3                                ...           5 years ago
  • 5.1.2                                ...           5 years ago
  • 5.1.1                                ...           5 years ago
  • 5.0.2                                ...           5 years ago
  • 5.0.1                                ...           5 years ago
  • 5.1.0                                ...           5 years ago
  • 5.0.0                                ...           5 years ago
  • 5.0.0-beta.3                                ...           5 years ago
  • 5.0.0-beta.2                                ...           5 years ago
  • 5.0.0-beta.1                                ...           5 years ago
  • 4.6.0                                ...           5 years ago
  • 4.5.0                                ...           5 years ago
  • 4.4.0                                ...           5 years ago
  • 4.3.2                                ...           5 years ago
  • 4.3.1                                ...           5 years ago
  • 4.3.0                                ...           5 years ago
  • 4.2.0                                ...           5 years ago
  • 4.1.1                                ...           5 years ago
  • 4.1.0                                ...           5 years ago
  • 4.0.1                                ...           5 years ago
  • 4.0.0                                ...           5 years ago
  • 3.3.0 [deprecated]           ...           5 years ago
  • 3.2.2                                ...           6 years ago
  • 3.2.1                                ...           6 years ago
  • 3.2.0                                ...           6 years ago
  • 3.1.0                                ...           6 years ago
  • 3.0.6                                ...           6 years ago
  • 3.0.5                                ...           6 years ago
  • 3.0.4                                ...           6 years ago
  • 3.0.3                                ...           6 years ago
  • 3.0.2                                ...           6 years ago
  • 3.0.1                                ...           6 years ago
  • 3.0.0                                ...           6 years ago
  • 2.0.0                                ...           8 years ago
Downloads
Today 0
This Week 49
This Month 73
Last Day 4
Last Week 24
Last Month 2
Dependencies (6)
Dev Dependencies (20)
Dependents (2)

Copyright 2013 - present © cnpmjs.org | Home |