UNPKG

hrw-certificate-editor

Version:

Design Editor Tools with React.js + ant.design + fabric.js

104 lines 4.26 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const react_1 = __importStar(require("react")); const prop_types_1 = __importDefault(require("prop-types")); const antd_1 = require("antd"); const { Dragger } = antd_1.Upload; class FileUpload extends react_1.Component { constructor() { super(...arguments); this.state = { fileList: this.props.value ? [this.props.value] : [], }; } UNSAFE_componentWillReceiveProps(nextProps) { this.setState({ fileList: nextProps.value ? [nextProps.value] : [], }); } render() { const { accept, limit, isBackgroundImage } = this.props; console.log("🚀 ~ isBackgroundImage", isBackgroundImage); const { fileList } = this.state; const props = { accept, name: 'file', multiple: false, onChange: info => { console.log("🚀 ~ info", info); console.log("🚀 ~ info", info.file); const isLimit = info.file.size / 1024 / 1024 < limit; if (!isLimit) { message.error(`Limited to ${limit}MB or less`); return false; } const { onChange } = this.props; onChange(info.file); console.log("🚀 ~ onChange", onChange); }, onRemove: file => { this.setState(({ fileList }) => { const index = fileList.indexOf(file); const newFileList = fileList.slice(); newFileList.splice(index, 1); return { fileList: newFileList, }; }, () => { const { onChange } = this.props; onChange(null); }); }, beforeUpload: file => { const isLimit = file.size / 1024 / 1024 < limit; if (!isLimit) { return false; } this.setState({ fileList: [file], }); return false; }, fileList, }; return (react_1.default.createElement(Dragger, Object.assign({}, props), react_1.default.createElement("p", { className: "ant-upload-drag-icon" }, react_1.default.createElement(antd_1.Icon, { type: "inbox" })), react_1.default.createElement("p", { className: "ant-upload-text" }, "K\u00E9o th\u1EA3 file ho\u1EB7c Ch\u1ECDn file t\u1EEB m\u00E1y t\u00EDnh"), react_1.default.createElement("p", { className: "ant-upload-hint" }, isBackgroundImage ? `Chọn ảnh nền (600x450px)` : ''))); } } FileUpload.propTypes = { onChange: prop_types_1.default.func, limit: prop_types_1.default.number, accept: prop_types_1.default.string, isBackgroundImage: prop_types_1.default.bool, }; FileUpload.defaultProps = { limit: 30, isBackgroundImage: true, }; exports.default = FileUpload; //# sourceMappingURL=FileUpload.js.map