UNPKG

2.47 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 DashboardPlugin = require('@uppy/dashboard');
10
11var basePropTypes = require('./propTypes').dashboard;
12
13var h = React.createElement;
14/**
15 * React Component that renders a Dashboard for an Uppy instance. This component
16 * renders the Dashboard inline, so you can put it anywhere you want.
17 */
18
19var Dashboard = /*#__PURE__*/function (_React$Component) {
20 _inheritsLoose(Dashboard, _React$Component);
21
22 function Dashboard() {
23 return _React$Component.apply(this, arguments) || this;
24 }
25
26 var _proto = Dashboard.prototype;
27
28 _proto.componentDidMount = function componentDidMount() {
29 this.installPlugin();
30 };
31
32 _proto.componentDidUpdate = function componentDidUpdate(prevProps) {
33 if (prevProps.uppy !== this.props.uppy) {
34 this.uninstallPlugin(prevProps);
35 this.installPlugin();
36 }
37 };
38
39 _proto.componentWillUnmount = function componentWillUnmount() {
40 this.uninstallPlugin();
41 };
42
43 _proto.installPlugin = function installPlugin() {
44 var uppy = this.props.uppy;
45
46 var options = _extends({
47 id: 'react:Dashboard'
48 }, this.props, {
49 target: this.container
50 });
51
52 delete options.uppy;
53 uppy.use(DashboardPlugin, options);
54 this.plugin = uppy.getPlugin(options.id);
55 };
56
57 _proto.uninstallPlugin = function uninstallPlugin(props) {
58 if (props === void 0) {
59 props = this.props;
60 }
61
62 var uppy = props.uppy;
63 uppy.removePlugin(this.plugin);
64 };
65
66 _proto.render = function render() {
67 var _this = this;
68
69 return h('div', {
70 ref: function ref(container) {
71 _this.container = container;
72 }
73 });
74 };
75
76 return Dashboard;
77}(React.Component);
78
79Dashboard.propTypes = basePropTypes;
80Dashboard.defaultProps = {
81 inline: true
82};
83module.exports = Dashboard;
\No newline at end of file