UNPKG

linkmore-design

Version:

🌈 🚀lm组件库。🚀

57 lines (54 loc) 2.18 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import React, { useCallback } from 'react'; import cn from 'classnames'; import UploadPicture from "./UploadPicture"; // 上传核心 // 渲染上传区域样式, 仅用于触发上传事件 // type: 'card' 图片 | 'drag' 拖拽 var UploadCore = function UploadCore(_ref) { var _inputRef$current3; var instance = _ref.instance; var inputRef = React.useRef(null); var accept = instance.accept, disabled = instance.disabled, children = instance.children, beforeUpload = instance.beforeUpload, getUploadStatus = instance.getUploadStatus, getIsMaxCount = instance.getIsMaxCount, multiple = instance.multiple; // 点击事件触发文件上传 var handleClick = useCallback(function () { var _inputRef$current; if (disabled) return; var isUploading = getUploadStatus().uploading; if (isUploading) return; inputRef === null || inputRef === void 0 ? void 0 : (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.click(); }, [disabled, getUploadStatus]); // 上传触发事件 var uploadChange = useCallback(function (e) { var _inputRef$current2; beforeUpload === null || beforeUpload === void 0 ? void 0 : beforeUpload(e); if ((_inputRef$current2 = inputRef.current) !== null && _inputRef$current2 !== void 0 && _inputRef$current2.value) { inputRef.current.value = ''; } }, [beforeUpload, (_inputRef$current3 = inputRef.current) === null || _inputRef$current3 === void 0 ? void 0 : _inputRef$current3.value]); var inputConfig = { type: 'file', accept: accept, title: '', onChange: uploadChange, multiple: multiple, style: { display: 'none' } }; return !getIsMaxCount() && /*#__PURE__*/React.createElement("div", { onClick: handleClick, className: cn('lm_upload_core', disabled && 'disabled') }, children || /*#__PURE__*/React.createElement(UploadPicture, { instance: instance }), /*#__PURE__*/React.createElement("input", _extends({ ref: inputRef }, inputConfig))); }; export default /*#__PURE__*/React.memo(UploadCore);