2 Star 0 Fork 0

react-component/image

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

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-component/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
open 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
actionsRender (originalNode: React.ReactElement, info: Omit<ToolbarRenderInfoType, 'current' | 'total'>) => React.ReactNode - Customize toolbar
onOpenChange (open: boolean, prevVisible: boolean) => void - Callback when open is changed
onTransform { transform: TransformType, action: TransformAction } - Callback when transform is changed

Image.PreviewGroup

preview the merged src

import Image from '@rc-component/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
open 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
actionsRender (originalNode: React.ReactElement, info: ToolbarRenderInfoType) => React.ReactNode - Customize toolbar
onOpenChange (open: boolean, prevVisible: boolean, current: number) => void - Callback when open 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.

🤝 Contributing

Contribution Leaderboard
MIT LICENSE Copyright (c) 2015-present Alipay.com, https://www.alipay.com/ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

🖼 React Image Component 展开 收起
README
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_react-component/image.git
git@gitee.com:mirrors_react-component/image.git
mirrors_react-component
image
image
master

搜索帮助