diff --git a/docs/examples/basic.tsx b/docs/examples/basic.tsx index adb78dd9..bc0c6393 100644 --- a/docs/examples/basic.tsx +++ b/docs/examples/basic.tsx @@ -35,6 +35,10 @@ export default function Base() { style={{ marginRight: 24, }} + preview={{ + dragRebound: false, + mask: 'close drag rebound' + }} /> = ({ maskClassName, icons, scaleStep, + dragRebound, ...dialogProps }: ImagePreviewType = typeof preview === 'object' ? preview : {}; const src = previewSrc ?? imgSrc; @@ -288,6 +289,7 @@ const ImageInternal: CompoundedComponent = ({ mousePosition={mousePosition} src={mergedSrc} alt={alt} + dragRebound={dragRebound} getContainer={getPreviewContainer} icons={icons} scaleStep={scaleStep} diff --git a/src/Operations.tsx b/src/Operations.tsx index 606db304..f5faba6f 100644 --- a/src/Operations.tsx +++ b/src/Operations.tsx @@ -24,6 +24,7 @@ interface OperationsProps scale: number; onSwitchLeft: React.MouseEventHandler; onSwitchRight: React.MouseEventHandler; + onRefresh: ()=> void; onZoomIn: () => void; onZoomOut: () => void; onRotateRight: () => void; @@ -49,6 +50,7 @@ const Operations: React.FC = (props) => { onSwitchLeft, onSwitchRight, onClose, + onRefresh, onZoomIn, onZoomOut, onRotateRight, @@ -56,7 +58,7 @@ const Operations: React.FC = (props) => { onFlipX, onFlipY } = props; - const { rotateLeft, rotateRight, zoomIn, zoomOut, close, left, right, flipX, flipY } = icons; + const { rotateLeft, rotateRight, refresh, zoomIn, zoomOut, close, left, right, flipX, flipY } = icons; const toolClassName = `${prefixCls}-operations-operation`; const iconClassName = `${prefixCls}-operations-icon`; const tools = [ @@ -65,6 +67,11 @@ const Operations: React.FC = (props) => { onClick: onClose, type: 'close', }, + { + icon: refresh, + onClick: onRefresh, + type: 'refresh', + }, { icon: zoomIn, onClick: onZoomIn, diff --git a/src/Preview.tsx b/src/Preview.tsx index ccd74dcb..955ad3fd 100644 --- a/src/Preview.tsx +++ b/src/Preview.tsx @@ -21,6 +21,7 @@ export interface PreviewProps extends Omit { rotateRight?: React.ReactNode; zoomIn?: React.ReactNode; zoomOut?: React.ReactNode; + refresh?: React.ReactNode; close?: React.ReactNode; left?: React.ReactNode; right?: React.ReactNode; @@ -76,6 +77,16 @@ const Preview: React.FC = (props) => { resetTransform(); }; + const onRefresh = ()=> { + console.log('refresh'); + updateTransform({ + rotate: 0, + x: 0, + y: 0, + scale: 1, + }) + } + const onZoomIn = () => { dispatchZoomChange(BASE_SCALE_RATIO + scaleStep); }; @@ -304,6 +315,7 @@ const Preview: React.FC = (props) => { onRotateLeft={onRotateLeft} onFlipX={onFlipX} onFlipY={onFlipY} + onRefresh={onRefresh} onClose={onClose} />