From bfd5644ff0d85165f9fa40873091f98480d503d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=97=E5=B0=8F=E5=8C=97?= Date: Mon, 18 May 2020 19:22:45 +0800 Subject: [PATCH] Add crop image demo for Upload (#24174) * chore: add antd-img-crop * docs: add crop image demo for upload * fix: move antd-img-crop to devDependencies * fix: fix eslint warning * test: update snapshot --- .../__tests__/__snapshots__/demo.test.js.snap | 117 ++++++++++++++++++ components/upload/demo/crop-image.md | 66 ++++++++++ package.json | 1 + 3 files changed, 184 insertions(+) create mode 100644 components/upload/demo/crop-image.md diff --git a/components/upload/__tests__/__snapshots__/demo.test.js.snap b/components/upload/__tests__/__snapshots__/demo.test.js.snap index f31b48aa3f..3860ae03cf 100644 --- a/components/upload/__tests__/__snapshots__/demo.test.js.snap +++ b/components/upload/__tests__/__snapshots__/demo.test.js.snap @@ -106,6 +106,123 @@ exports[`renders ./components/upload/demo/basic.md correctly 1`] = ` `; +exports[`renders ./components/upload/demo/crop-image.md correctly 1`] = ` + +
+
+ +
+ + + + + + + + + + + +
+
+
+
+
+ + + + Upload + +
+
+`; + exports[`renders ./components/upload/demo/defaultFileList.md correctly 1`] = ` { + const [fileList, setFileList] = useState([ + { + uid: '-1', + name: 'image.png', + status: 'done', + url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png', + }, + ]); + + const onChange = ({ fileList: newFileList }) => { + setFileList(newFileList); + }; + + const onPreview = async file => { + let src = file.url; + if (!src) { + src = await new Promise(resolve => { + const reader = new FileReader(); + reader.readAsDataURL(file.originFileObj); + reader.onload = () => resolve(reader.result); + }); + } + const image = new Image(); + image.src = src; + const imgWindow = window.open(src); + imgWindow.document.write(image.outerHTML); + }; + + return ( + + + {fileList.length < 5 && '+ Upload'} + + + ); +}; + +ReactDOM.render(, mountNode); +``` diff --git a/package.json b/package.json index c88d7d0cf3..23fbdbeea4 100644 --- a/package.json +++ b/package.json @@ -168,6 +168,7 @@ "@types/warning": "^3.0.0", "@typescript-eslint/eslint-plugin": "^2.19.0", "@typescript-eslint/parser": "^2.19.0", + "antd-img-crop": "^3.1.1", "antd-pro-merge-less": "^3.0.3", "antd-theme-generator": "^1.1.6", "babel-eslint": "^10.0.1",