UNPKG

2.5 kBJavaScriptView Raw
1function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
3function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
4
5function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
6
7var React = require('react');
8
9var PropTypes = require('prop-types');
10
11var ProgressBarPlugin = require('@uppy/progress-bar');
12
13var uppyPropType = require('./propTypes').uppy;
14
15var h = React.createElement;
16/**
17 * React component that renders a progress bar at the top of the page.
18 */
19
20var ProgressBar = /*#__PURE__*/function (_React$Component) {
21 _inheritsLoose(ProgressBar, _React$Component);
22
23 function ProgressBar() {
24 return _React$Component.apply(this, arguments) || this;
25 }
26
27 var _proto = ProgressBar.prototype;
28
29 _proto.componentDidMount = function componentDidMount() {
30 this.installPlugin();
31 };
32
33 _proto.componentDidUpdate = function componentDidUpdate(prevProps) {
34 if (prevProps.uppy !== this.props.uppy) {
35 this.uninstallPlugin(prevProps);
36 this.installPlugin();
37 }
38 };
39
40 _proto.componentWillUnmount = function componentWillUnmount() {
41 this.uninstallPlugin();
42 };
43
44 _proto.installPlugin = function installPlugin() {
45 var uppy = this.props.uppy;
46
47 var options = _extends({
48 id: 'react:ProgressBar'
49 }, this.props, {
50 target: this.container
51 });
52
53 delete options.uppy;
54 uppy.use(ProgressBarPlugin, options);
55 this.plugin = uppy.getPlugin(options.id);
56 };
57
58 _proto.uninstallPlugin = function uninstallPlugin(props) {
59 if (props === void 0) {
60 props = this.props;
61 }
62
63 var uppy = props.uppy;
64 uppy.removePlugin(this.plugin);
65 };
66
67 _proto.render = function render() {
68 var _this = this;
69
70 return h('div', {
71 ref: function ref(container) {
72 _this.container = container;
73 }
74 });
75 };
76
77 return ProgressBar;
78}(React.Component);
79
80ProgressBar.propTypes = {
81 uppy: uppyPropType,
82 fixed: PropTypes.bool,
83 hideAfterFinish: PropTypes.bool
84};
85ProgressBar.defaultProps = {};
86module.exports = ProgressBar;
\No newline at end of file