UNPKG

uppy

Version:

Almost as cute as a Puppy :dog:

87 lines (67 loc) 3.74 kB
'use strict'; var _appendChild = require('yo-yoify/lib/appendChild'); var _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; }; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _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; } function _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) : subClass.__proto__ = superClass; } var Plugin = require('./Plugin'); /** * Informer * Shows rad message bubbles * used like this: `uppy.info('hello world', 'info', 5000)` * or for errors: `uppy.info('Error uploading img.jpg', 'error', 5000)` * */ module.exports = function (_Plugin) { _inherits(Informer, _Plugin); function Informer(core, opts) { _classCallCheck(this, Informer); var _this = _possibleConstructorReturn(this, _Plugin.call(this, core, opts)); _this.type = 'progressindicator'; _this.id = 'Informer'; _this.title = 'Informer'; // this.timeoutID = undefined // set default options var defaultOptions = { typeColors: { info: { text: '#fff', bg: '#000' }, warning: { text: '#fff', bg: '#F6A623' }, error: { text: '#fff', bg: '#e74c3c' }, success: { text: '#fff', bg: '#7ac824' } } // merge default options with the ones set by user };_this.opts = _extends({}, defaultOptions, opts); _this.render = _this.render.bind(_this); return _this; } Informer.prototype.render = function render(state) { var _p, _uppy, _span; var _state$info = state.info, isHidden = _state$info.isHidden, type = _state$info.type, message = _state$info.message, details = _state$info.details; var style = 'background-color: ' + this.opts.typeColors[type].bg + '; color: ' + this.opts.typeColors[type].text + ';'; // @TODO add aria-live for screen-readers return _uppy = document.createElement('div'), _uppy.setAttribute('style', '' + String(style) + ''), _uppy.setAttribute('aria-hidden', '' + String(isHidden) + ''), _uppy.setAttribute('class', 'Uppy UppyTheme--default UppyInformer'), _appendChild(_uppy, [' ', (_p = document.createElement('p'), _appendChild(_p, [' ', message, ' ', details ? (_span = document.createElement('span'), _span.setAttribute('style', 'color: ' + String(this.opts.typeColors[type].bg) + ''), _span.setAttribute('data-balloon', '' + String(details) + ''), _span.setAttribute('data-balloon-pos', 'up'), _span.setAttribute('data-balloon-length', 'large'), _span.textContent = '?', _span) : null, ' ']), _p), ' ']), _uppy; }; Informer.prototype.install = function install() { var target = this.opts.target; var plugin = this; this.target = this.mount(target, plugin); }; return Informer; }(Plugin); //# sourceMappingURL=Informer.js.map