Skip to content

Repository files navigation

@rc-component/image

Ant Design Part of the Ant Design ecosystem.

🖼️ Image display, fallback, and preview tooling for React.

NPM versionnpm downloadsbuild statusCodecovbundle sizedumi

English | 简体中文

Highlights

  • Supports placeholder, fallback, and preview.
  • Preview supports zoom, rotate, flip, drag, keyboard access, and custom actions.
  • Image.PreviewGroup supports grouped preview and custom preview items.
  • Ships compiled JavaScript, TypeScript definitions, and CSS assets.

Install

npm install @rc-component/image

Usage

importImagefrom'@rc-component/image';import'@rc-component/image/assets/index.css';exportdefaultfunctionApp(){return(<Imagesrc="https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png"/>);}

Preview Group

importImagefrom'@rc-component/image';import'@rc-component/image/assets/index.css';exportdefaultfunctionApp(){return(<Image.PreviewGroup><Imagesrc="https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png"/><Imagesrc="https://gw.alipayobjects.com/mdn/rms_08e378/afts/img/A*P0S-QIRUbsUAAAAAAAAAAABkARQnAQ"/></Image.PreviewGroup>);}

Examples

Run the local dumi site:

npm install
npm start

Then open http://localhost:8000.

API

Image

PropertyDescriptionTypeDefault
fallbackImage source used when loading failsstring-
placeholderPlaceholder before image loadsboolean | React.ReactElement-
prefixClsComponent class name prefixstringrc-image
previewWhether and how to show previewboolean | PreviewConfigtrue
previewPrefixClsPreview class name prefixstringrc-image-preview
srcImage sourcestring-
onErrorCallback when image loading fails(event: Event) => void-

Native image attributes are also supported.

PreviewConfig

PropertyDescriptionTypeDefault
actionsRenderCustom toolbar renderer(node: React.ReactElement, info: Omit<ToolbarRenderInfoType, 'current' | 'total'>) => React.ReactNode-
closeIconCustom close iconReact.ReactNode-
coverCustom preview coverReact.ReactNode | CoverConfig-
countRenderCustom count renderer(current: number, total: number) => React.ReactNode-
forceRenderForce render previewbooleanfalse
getContainerPreview containerstring | HTMLElement | () => HTMLElement | falsedocument.body
imageRenderCustom image renderer(node: React.ReactElement, info: { transform: TransformType; image: ImgInfo }) => React.ReactNode-
maskClosableWhether clicking mask closes previewbooleantrue
maxScaleMax scalenumber50
minScaleMin scalenumber1
movableEnable dragbooleantrue
openControlled preview open stateboolean-
scaleStepScale stepnumber0.5
srcCustom preview image sourcestring-
wheelEnable mouse wheel zoombooleantrue
onOpenChangeCallback when preview open state changes(open: boolean) => void-
onTransformCallback when transform changes(info: { transform: TransformType; action: TransformAction }) => void-

Image.PreviewGroup

PropertyDescriptionTypeDefault
childrenImage childrenReact.ReactNode-
classNamesSemantic preview popup class names{ popup?: Partial<Record<PreviewSemanticName, string>> }-
fallbackImage source used when loading failsstring-
iconsCustom preview operation iconsPreviewProps['icons']-
itemsPreview items(string | ImageElementProps)[]-
previewWhether and how to show preview groupboolean | GroupPreviewConfigtrue
previewPrefixClsPreview class name prefixstringrc-image-preview
stylesSemantic preview popup styles{ popup?: Partial<Record<PreviewSemanticName, React.CSSProperties>> }-

TransformType

typeTransformType={x: number;y: number;rotate: number;scale: number;flipX: boolean;flipY: boolean;};typeTransformAction=|'flipY'|'flipX'|'rotateLeft'|'rotateRight'|'zoomIn'|'zoomOut'|'close'|'prev'|'next'|'wheel'|'doubleClick'|'move'|'dragRebound';typeActions={onActive: (offset: number)=>void;onFlipY: ()=>void;onFlipX: ()=>void;onRotateLeft: ()=>void;onRotateRight: ()=>void;onZoomOut: ()=>void;onZoomIn: ()=>void;onClose: ()=>void;onReset: ()=>void;};typeToolbarRenderInfoType={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: Actions;transform: TransformType;current: number;total: number;image: ImgInfo;};

Development

npm install
npm start

The dumi site runs at http://localhost:8000 by default.

npm test
npm run tsc
npm run lint
npm run compile
npm run build

Release

npm run prepublishOnly

The release flow is handled by @rc-component/np through the rc-np command after the package build.

License

@rc-component/image is released under the MIT license.

About

🖼️ Image display, fallback, and preview tooling for React.

Topics

Resources

Stars

212 stars

Watchers

4 watching

Forks

Releases

Sponsor this project

Used by

Contributors

Languages