UNPKG

3.13 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _react = require('react');
8
9var React = _interopRequireWildcard(_react);
10
11var _Icon = require('./Icon');
12
13var _Icon2 = _interopRequireDefault(_Icon);
14
15function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
16
17function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } }
18
19function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; }
20
21function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
22
23function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
24
25function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); }
26
27;
28;
29
30var Uploader = function (_React$Component) {
31 _inherits(Uploader, _React$Component);
32
33 function Uploader() {
34 _classCallCheck(this, Uploader);
35
36 var _this = _possibleConstructorReturn(this, _React$Component.apply(this, arguments));
37
38 _this.onClick = function () {
39 var el = _this.refs.file;
40 if (!el) {
41 return;
42 }
43 el.click();
44 };
45 _this.selectFile = function (ev) {
46 var file = _this.refs.file.files[0];
47 _this.props.onSelectImage(file);
48 };
49 return _this;
50 }
51
52 Uploader.prototype.render = function render() {
53 var _props = this.props,
54 prefixCls = _props.prefixCls,
55 accept = _props.accept;
56
57 return React.createElement("button", { className: prefixCls + '-btn ' + prefixCls + '-btn-ghost', type: "ghost", onClick: this.onClick }, React.createElement("input", { type: "file", ref: "file", accept: accept, style: { display: 'none' }, onChange: this.selectFile }), this.props.children || React.createElement("span", null, React.createElement(_Icon2["default"], { type: "upload" }), " Click to Upload "));
58 };
59
60 return Uploader;
61}(React.Component);
62
63exports["default"] = Uploader;
64module.exports = exports['default'];
\No newline at end of file