@uiw-admin/components
Version:
62 lines • 1.81 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
var _excluded = ["uploadType", "value", "readonly", "maxNumber"];
import React from 'react';
import { FileInput, Icon, Modal, Button } from 'uiw';
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
var Upload = _ref => {
var {
uploadType,
value,
readonly = false,
maxNumber
} = _ref,
others = _objectWithoutPropertiesLoose(_ref, _excluded);
var [visible, setVisible] = React.useState(false);
var [src, setSrc] = React.useState('');
var renderBtn = () => {
if (readonly) return null;
if (uploadType === 'card') return /*#__PURE__*/_jsx(Icon, {
type: "plus"
});
if (uploadType === 'picture' || uploadType === 'text') return /*#__PURE__*/_jsx(Button, {
type: "primary",
children: "\u65B0\u589E"
});
return null;
};
return /*#__PURE__*/_jsxs(React.Fragment, {
children: [/*#__PURE__*/_jsx(FileInput, _extends({
uploadType: uploadType,
readonly: readonly,
value: value,
maxNumber: maxNumber,
onPreview: file => {
setSrc(file == null ? void 0 : file.dataURL);
setVisible(true);
}
}, others, {
children: renderBtn()
})), /*#__PURE__*/_jsx(Modal, {
isOpen: visible,
onClosed: () => setVisible(false),
width: 600,
confirmButtonProps: {
style: {
display: 'none'
}
},
children: /*#__PURE__*/_jsx("img", {
crossOrigin: "anonymous",
src: src,
alt: "",
style: {
width: '100%',
height: '100%'
}
})
})]
});
};
export default Upload;