@canlooks/can-ui 0.0.17 → 0.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,19 @@
1
+ import { Ref, ReactNode } from 'react';
1
2
  import { ModalProps } from '../modal';
2
- import { ReactZoomPanPinchProps } from 'react-zoom-pan-pinch';
3
+ import { ReactZoomPanPinchContentRef, ReactZoomPanPinchProps } from 'react-zoom-pan-pinch';
3
4
  export interface ImagePreviewProps extends ModalProps {
4
5
  src?: string | string[];
5
6
  defaultOpen?: boolean;
6
7
  onOpenChange?(open: boolean): void;
7
- closable?: boolean;
8
- transformWrapper?: ReactZoomPanPinchProps;
8
+ /** 是否渲染旋转按钮{@default true} */
9
+ showRotate?: boolean;
10
+ /** 是否渲染放大缩小按钮{@default true} */
11
+ showZoom?: boolean;
12
+ /** 是否渲染关闭按钮{@default true }*/
13
+ showClose?: boolean;
14
+ /** 自定义右上角控制按钮 */
15
+ renderControl?: ReactNode;
16
+ transformWrapperProps?: ReactZoomPanPinchProps;
17
+ transformWrapperRef?: Ref<ReactZoomPanPinchContentRef>;
9
18
  }
10
19
  export declare const ImagePreview: import("react").MemoExoticComponent<import("react").ForwardRefExoticComponent<Omit<ImagePreviewProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>>;
@@ -10,23 +10,23 @@ const icons_1 = require("@ant-design/icons");
10
10
  const button_1 = require("../button");
11
11
  const react_zoom_pan_pinch_1 = require("react-zoom-pan-pinch");
12
12
  const tooltip_1 = require("../tooltip");
13
- exports.ImagePreview = (0, react_1.memo)((0, react_1.forwardRef)(({ src = [], defaultOpen = false, open, onOpenChange, closable = true, transformWrapper, ...props }, ref) => {
13
+ exports.ImagePreview = (0, react_1.memo)((0, react_1.forwardRef)(({ src = [], defaultOpen = false, open, onOpenChange, showRotate = true, showZoom = true, showClose = true, renderControl, transformWrapperProps, transformWrapperRef, ...props }, ref) => {
14
14
  const srcArr = Array.isArray(src) ? src : [src];
15
15
  const [innerOpen, setInnerOpen] = (0, utils_1.useControlled)(defaultOpen, open, onOpenChange);
16
16
  const [activeIndex, setActiveIndex] = (0, react_1.useState)(0);
17
- const transformWrapperRef = (0, react_1.useRef)(null);
17
+ const innerTransformWrapperRef = (0, react_1.useRef)(null);
18
18
  const imgLoaded = () => {
19
- transformWrapperRef.current.centerView();
19
+ innerTransformWrapperRef.current.centerView();
20
20
  };
21
21
  const prev = (e) => {
22
22
  e.stopPropagation();
23
23
  setActiveIndex(o => (o - 1 + srcArr.length) % srcArr.length);
24
- transformWrapperRef.current?.resetTransform();
24
+ innerTransformWrapperRef.current?.resetTransform();
25
25
  };
26
26
  const next = (e) => {
27
27
  e.stopPropagation();
28
28
  setActiveIndex(o => (o + 1) % srcArr.length);
29
- transformWrapperRef.current?.resetTransform();
29
+ innerTransformWrapperRef.current?.resetTransform();
30
30
  };
31
31
  const [rotate, setRotate] = (0, react_1.useState)(0);
32
32
  const isPanning = (0, react_1.useRef)(false);
@@ -37,10 +37,19 @@ exports.ImagePreview = (0, react_1.memo)((0, react_1.forwardRef)(({ src = [], de
37
37
  color: 'text'
38
38
  };
39
39
  return ((0, jsx_runtime_1.jsx)(modal_1.Modal, { ...props, ref: ref, css: imagePreview_style_1.style, className: (0, utils_1.classnames)(imagePreview_style_1.classes.root, props.className), open: innerOpen.current, maskProps: {
40
- children: ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("div", { className: imagePreview_style_1.classes.control, children: [(0, jsx_runtime_1.jsx)(tooltip_1.Tooltip, { title: "\u65CB\u8F6C-90\u00B0", children: (0, jsx_runtime_1.jsx)(button_1.Button, { ...commonControlProps, onClick: () => setRotate(rotate - 90), children: (0, jsx_runtime_1.jsx)(icons_1.RotateLeftOutlined, {}) }) }), (0, jsx_runtime_1.jsx)(tooltip_1.Tooltip, { title: "\u65CB\u8F6C90\u00B0", children: (0, jsx_runtime_1.jsx)(button_1.Button, { ...commonControlProps, onClick: () => setRotate(rotate + 90), children: (0, jsx_runtime_1.jsx)(icons_1.RotateRightOutlined, {}) }) }), (0, jsx_runtime_1.jsx)(tooltip_1.Tooltip, { title: "\u7F29\u5C0F", children: (0, jsx_runtime_1.jsx)(button_1.Button, { ...commonControlProps, onClick: () => transformWrapperRef.current.zoomOut(), children: (0, jsx_runtime_1.jsx)(icons_1.ZoomOutOutlined, {}) }) }), (0, jsx_runtime_1.jsx)(tooltip_1.Tooltip, { title: "\u653E\u5927", children: (0, jsx_runtime_1.jsx)(button_1.Button, { ...commonControlProps, onClick: () => transformWrapperRef.current.zoomIn(), children: (0, jsx_runtime_1.jsx)(icons_1.ZoomInOutlined, {}) }) }), (0, jsx_runtime_1.jsx)(tooltip_1.Tooltip, { title: "\u9002\u5E94\u5C4F\u5E55", children: (0, jsx_runtime_1.jsx)(button_1.Button, { ...commonControlProps, onClick: () => transformWrapperRef.current.resetTransform(), children: (0, jsx_runtime_1.jsx)(icons_1.FullscreenOutlined, {}) }) }), closable &&
40
+ ...props.maskProps,
41
+ children: ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("div", { className: imagePreview_style_1.classes.control, children: [renderControl, showRotate &&
42
+ (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(tooltip_1.Tooltip, { title: "\u65CB\u8F6C-90\u00B0", children: (0, jsx_runtime_1.jsx)(button_1.Button, { ...commonControlProps, onClick: () => setRotate(rotate - 90), children: (0, jsx_runtime_1.jsx)(icons_1.RotateLeftOutlined, {}) }) }), (0, jsx_runtime_1.jsx)(tooltip_1.Tooltip, { title: "\u65CB\u8F6C90\u00B0", children: (0, jsx_runtime_1.jsx)(button_1.Button, { ...commonControlProps, onClick: () => setRotate(rotate + 90), children: (0, jsx_runtime_1.jsx)(icons_1.RotateRightOutlined, {}) }) })] }), showZoom &&
43
+ (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(tooltip_1.Tooltip, { title: "\u7F29\u5C0F", children: (0, jsx_runtime_1.jsx)(button_1.Button, { ...commonControlProps, onClick: () => innerTransformWrapperRef.current.zoomOut(), children: (0, jsx_runtime_1.jsx)(icons_1.ZoomOutOutlined, {}) }) }), (0, jsx_runtime_1.jsx)(tooltip_1.Tooltip, { title: "\u653E\u5927", children: (0, jsx_runtime_1.jsx)(button_1.Button, { ...commonControlProps, onClick: () => innerTransformWrapperRef.current.zoomIn(), children: (0, jsx_runtime_1.jsx)(icons_1.ZoomInOutlined, {}) }) }), (0, jsx_runtime_1.jsx)(tooltip_1.Tooltip, { title: "\u9002\u5E94\u5C4F\u5E55", children: (0, jsx_runtime_1.jsx)(button_1.Button, { ...commonControlProps, onClick: () => innerTransformWrapperRef.current.resetTransform(), children: (0, jsx_runtime_1.jsx)(icons_1.FullscreenOutlined, {}) }) })] }), showClose &&
41
44
  (0, jsx_runtime_1.jsx)(button_1.Button, { ...commonControlProps, onClick: () => setInnerOpen(false), children: (0, jsx_runtime_1.jsx)(icons_1.CloseOutlined, {}) })] }), srcArr.length > 1 &&
42
45
  (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("div", { className: imagePreview_style_1.classes.swap, children: [(0, jsx_runtime_1.jsx)(button_1.Button, { ...commonControlProps, onClick: prev, children: (0, jsx_runtime_1.jsx)(icons_1.LeftOutlined, {}) }), (0, jsx_runtime_1.jsx)(button_1.Button, { ...commonControlProps, onClick: next, children: (0, jsx_runtime_1.jsx)(icons_1.RightOutlined, {}) })] }), (0, jsx_runtime_1.jsxs)("div", { className: imagePreview_style_1.classes.counter, children: [activeIndex + 1, " / ", srcArr.length] })] })] }))
43
- }, children: (0, jsx_runtime_1.jsx)(react_zoom_pan_pinch_1.TransformWrapper, { smooth: false, ...transformWrapper, ref: transformWrapperRef, minScale: .2, onPanning: () => isPanning.current = true, onPanningStop: () => isPanning.current && setTimeout(() => isPanning.current = false), children: (0, jsx_runtime_1.jsx)(react_zoom_pan_pinch_1.TransformComponent, { wrapperClass: imagePreview_style_1.classes.imageWrapper, contentClass: imagePreview_style_1.classes.image, wrapperProps: {
46
+ }, children: (0, jsx_runtime_1.jsx)(react_zoom_pan_pinch_1.TransformWrapper, { smooth: false, ...transformWrapperProps, ref: (0, utils_1.cloneRef)(transformWrapperRef, innerTransformWrapperRef), minScale: .2, onPanning: (ref, e) => {
47
+ transformWrapperProps?.onPanning?.(ref, e);
48
+ isPanning.current = true;
49
+ }, onPanningStop: (ref, e) => {
50
+ transformWrapperProps?.onPanningStop?.(ref, e);
51
+ isPanning.current && setTimeout(() => isPanning.current = false);
52
+ }, children: (0, jsx_runtime_1.jsx)(react_zoom_pan_pinch_1.TransformComponent, { wrapperClass: imagePreview_style_1.classes.imageWrapper, contentClass: imagePreview_style_1.classes.image, wrapperProps: {
44
53
  onClick: () => !isPanning.current && setInnerOpen(false)
45
- }, children: (0, jsx_runtime_1.jsx)("img", { src: srcArr[activeIndex], style: { rotate: rotate + 'deg' }, onLoad: imgLoaded }) }) }) }));
54
+ }, children: (0, jsx_runtime_1.jsx)("img", { src: srcArr[activeIndex], style: { rotate: rotate + 'deg' }, onLoad: imgLoaded, alt: "" }) }) }) }));
46
55
  }));
@@ -1 +1,2 @@
1
1
  export * from './image';
2
+ export * from './imagePreview';
@@ -2,3 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./image"), exports);
5
+ tslib_1.__exportStar(require("./imagePreview"), exports);
@@ -64,7 +64,7 @@ exports.DocumentViewer = (0, react_1.memo)((0, react_1.forwardRef)(({ src, filen
64
64
  }
65
65
  // image
66
66
  if (mimeType.includes('image/')) {
67
- return (0, jsx_runtime_1.jsx)(imagePreview_1.ImagePreview, { src: src, open: true, closable: false });
67
+ return (0, jsx_runtime_1.jsx)(imagePreview_1.ImagePreview, { src: src, open: true, showClose: false });
68
68
  }
69
69
  return empty;
70
70
  }));
@@ -1,10 +1,19 @@
1
+ import { Ref, ReactNode } from 'react';
1
2
  import { ModalProps } from '../modal';
2
- import { ReactZoomPanPinchProps } from 'react-zoom-pan-pinch';
3
+ import { ReactZoomPanPinchContentRef, ReactZoomPanPinchProps } from 'react-zoom-pan-pinch';
3
4
  export interface ImagePreviewProps extends ModalProps {
4
5
  src?: string | string[];
5
6
  defaultOpen?: boolean;
6
7
  onOpenChange?(open: boolean): void;
7
- closable?: boolean;
8
- transformWrapper?: ReactZoomPanPinchProps;
8
+ /** 是否渲染旋转按钮{@default true} */
9
+ showRotate?: boolean;
10
+ /** 是否渲染放大缩小按钮{@default true} */
11
+ showZoom?: boolean;
12
+ /** 是否渲染关闭按钮{@default true }*/
13
+ showClose?: boolean;
14
+ /** 自定义右上角控制按钮 */
15
+ renderControl?: ReactNode;
16
+ transformWrapperProps?: ReactZoomPanPinchProps;
17
+ transformWrapperRef?: Ref<ReactZoomPanPinchContentRef>;
9
18
  }
10
19
  export declare const ImagePreview: import("react").MemoExoticComponent<import("react").ForwardRefExoticComponent<Omit<ImagePreviewProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>>;
@@ -1,29 +1,29 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "@emotion/react/jsx-runtime";
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
2
2
  import { forwardRef, memo, useRef, useState } from 'react';
3
3
  import { Modal } from '../modal';
4
- import { classnames, useControlled } from '../../utils';
4
+ import { classnames, cloneRef, useControlled } from '../../utils';
5
5
  import { classes, style } from './imagePreview.style';
6
6
  import { CloseOutlined, FullscreenOutlined, LeftOutlined, RightOutlined, RotateLeftOutlined, RotateRightOutlined, ZoomInOutlined, ZoomOutOutlined } from '@ant-design/icons';
7
7
  import { Button } from '../button';
8
8
  import { TransformComponent, TransformWrapper } from 'react-zoom-pan-pinch';
9
9
  import { Tooltip } from '../tooltip';
10
- export const ImagePreview = memo(forwardRef(({ src = [], defaultOpen = false, open, onOpenChange, closable = true, transformWrapper, ...props }, ref) => {
10
+ export const ImagePreview = memo(forwardRef(({ src = [], defaultOpen = false, open, onOpenChange, showRotate = true, showZoom = true, showClose = true, renderControl, transformWrapperProps, transformWrapperRef, ...props }, ref) => {
11
11
  const srcArr = Array.isArray(src) ? src : [src];
12
12
  const [innerOpen, setInnerOpen] = useControlled(defaultOpen, open, onOpenChange);
13
13
  const [activeIndex, setActiveIndex] = useState(0);
14
- const transformWrapperRef = useRef(null);
14
+ const innerTransformWrapperRef = useRef(null);
15
15
  const imgLoaded = () => {
16
- transformWrapperRef.current.centerView();
16
+ innerTransformWrapperRef.current.centerView();
17
17
  };
18
18
  const prev = (e) => {
19
19
  e.stopPropagation();
20
20
  setActiveIndex(o => (o - 1 + srcArr.length) % srcArr.length);
21
- transformWrapperRef.current?.resetTransform();
21
+ innerTransformWrapperRef.current?.resetTransform();
22
22
  };
23
23
  const next = (e) => {
24
24
  e.stopPropagation();
25
25
  setActiveIndex(o => (o + 1) % srcArr.length);
26
- transformWrapperRef.current?.resetTransform();
26
+ innerTransformWrapperRef.current?.resetTransform();
27
27
  };
28
28
  const [rotate, setRotate] = useState(0);
29
29
  const isPanning = useRef(false);
@@ -34,10 +34,19 @@ export const ImagePreview = memo(forwardRef(({ src = [], defaultOpen = false, op
34
34
  color: 'text'
35
35
  };
36
36
  return (_jsx(Modal, { ...props, ref: ref, css: style, className: classnames(classes.root, props.className), open: innerOpen.current, maskProps: {
37
- children: (_jsxs(_Fragment, { children: [_jsxs("div", { className: classes.control, children: [_jsx(Tooltip, { title: "\u65CB\u8F6C-90\u00B0", children: _jsx(Button, { ...commonControlProps, onClick: () => setRotate(rotate - 90), children: _jsx(RotateLeftOutlined, {}) }) }), _jsx(Tooltip, { title: "\u65CB\u8F6C90\u00B0", children: _jsx(Button, { ...commonControlProps, onClick: () => setRotate(rotate + 90), children: _jsx(RotateRightOutlined, {}) }) }), _jsx(Tooltip, { title: "\u7F29\u5C0F", children: _jsx(Button, { ...commonControlProps, onClick: () => transformWrapperRef.current.zoomOut(), children: _jsx(ZoomOutOutlined, {}) }) }), _jsx(Tooltip, { title: "\u653E\u5927", children: _jsx(Button, { ...commonControlProps, onClick: () => transformWrapperRef.current.zoomIn(), children: _jsx(ZoomInOutlined, {}) }) }), _jsx(Tooltip, { title: "\u9002\u5E94\u5C4F\u5E55", children: _jsx(Button, { ...commonControlProps, onClick: () => transformWrapperRef.current.resetTransform(), children: _jsx(FullscreenOutlined, {}) }) }), closable &&
37
+ ...props.maskProps,
38
+ children: (_jsxs(_Fragment, { children: [_jsxs("div", { className: classes.control, children: [renderControl, showRotate &&
39
+ _jsxs(_Fragment, { children: [_jsx(Tooltip, { title: "\u65CB\u8F6C-90\u00B0", children: _jsx(Button, { ...commonControlProps, onClick: () => setRotate(rotate - 90), children: _jsx(RotateLeftOutlined, {}) }) }), _jsx(Tooltip, { title: "\u65CB\u8F6C90\u00B0", children: _jsx(Button, { ...commonControlProps, onClick: () => setRotate(rotate + 90), children: _jsx(RotateRightOutlined, {}) }) })] }), showZoom &&
40
+ _jsxs(_Fragment, { children: [_jsx(Tooltip, { title: "\u7F29\u5C0F", children: _jsx(Button, { ...commonControlProps, onClick: () => innerTransformWrapperRef.current.zoomOut(), children: _jsx(ZoomOutOutlined, {}) }) }), _jsx(Tooltip, { title: "\u653E\u5927", children: _jsx(Button, { ...commonControlProps, onClick: () => innerTransformWrapperRef.current.zoomIn(), children: _jsx(ZoomInOutlined, {}) }) }), _jsx(Tooltip, { title: "\u9002\u5E94\u5C4F\u5E55", children: _jsx(Button, { ...commonControlProps, onClick: () => innerTransformWrapperRef.current.resetTransform(), children: _jsx(FullscreenOutlined, {}) }) })] }), showClose &&
38
41
  _jsx(Button, { ...commonControlProps, onClick: () => setInnerOpen(false), children: _jsx(CloseOutlined, {}) })] }), srcArr.length > 1 &&
39
42
  _jsxs(_Fragment, { children: [_jsxs("div", { className: classes.swap, children: [_jsx(Button, { ...commonControlProps, onClick: prev, children: _jsx(LeftOutlined, {}) }), _jsx(Button, { ...commonControlProps, onClick: next, children: _jsx(RightOutlined, {}) })] }), _jsxs("div", { className: classes.counter, children: [activeIndex + 1, " / ", srcArr.length] })] })] }))
40
- }, children: _jsx(TransformWrapper, { smooth: false, ...transformWrapper, ref: transformWrapperRef, minScale: .2, onPanning: () => isPanning.current = true, onPanningStop: () => isPanning.current && setTimeout(() => isPanning.current = false), children: _jsx(TransformComponent, { wrapperClass: classes.imageWrapper, contentClass: classes.image, wrapperProps: {
43
+ }, children: _jsx(TransformWrapper, { smooth: false, ...transformWrapperProps, ref: cloneRef(transformWrapperRef, innerTransformWrapperRef), minScale: .2, onPanning: (ref, e) => {
44
+ transformWrapperProps?.onPanning?.(ref, e);
45
+ isPanning.current = true;
46
+ }, onPanningStop: (ref, e) => {
47
+ transformWrapperProps?.onPanningStop?.(ref, e);
48
+ isPanning.current && setTimeout(() => isPanning.current = false);
49
+ }, children: _jsx(TransformComponent, { wrapperClass: classes.imageWrapper, contentClass: classes.image, wrapperProps: {
41
50
  onClick: () => !isPanning.current && setInnerOpen(false)
42
- }, children: _jsx("img", { src: srcArr[activeIndex], style: { rotate: rotate + 'deg' }, onLoad: imgLoaded }) }) }) }));
51
+ }, children: _jsx("img", { src: srcArr[activeIndex], style: { rotate: rotate + 'deg' }, onLoad: imgLoaded, alt: "" }) }) }) }));
43
52
  }));
@@ -1 +1,2 @@
1
1
  export * from './image';
2
+ export * from './imagePreview';
@@ -1 +1,2 @@
1
1
  export * from './image';
2
+ export * from './imagePreview';
@@ -58,7 +58,7 @@ export const DocumentViewer = memo(forwardRef(({ src, filename, onError, type, e
58
58
  }
59
59
  // image
60
60
  if (mimeType.includes('image/')) {
61
- return _jsx(ImagePreview, { src: src, open: true, closable: false });
61
+ return _jsx(ImagePreview, { src: src, open: true, showClose: false });
62
62
  }
63
63
  return empty;
64
64
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canlooks/can-ui",
3
- "version": "0.0.17",
3
+ "version": "0.0.18",
4
4
  "author": "C.CanLiang <canlooks@gmail.com>",
5
5
  "description": "My ui framework",
6
6
  "license": "MIT",