UNPKG

molstar

Version:

A comprehensive macromolecular library.

57 lines 3.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Toasts = void 0; var tslib_1 = require("tslib"); var jsx_runtime_1 = require("react/jsx-runtime"); /** * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info. * * Adapted from LiteMol (c) David Sehnal * * @author David Sehnal <david.sehnal@gmail.com> */ var base_1 = require("./base"); var common_1 = require("./controls/common"); var icons_1 = require("./controls/icons"); var ToastEntry = /** @class */ (function (_super) { (0, tslib_1.__extends)(ToastEntry, _super); function ToastEntry() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.hide = function () { var entry = _this.props.entry; (entry.hide || function () { }).call(null); }; return _this; } ToastEntry.prototype.render = function () { var _this = this; var entry = this.props.entry; var message = typeof entry.message === 'string' ? (0, jsx_runtime_1.jsx)("div", { dangerouslySetInnerHTML: { __html: entry.message } }, void 0) : (0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)(entry.message, {}, void 0) }, void 0); return (0, jsx_runtime_1.jsxs)("div", (0, tslib_1.__assign)({ className: 'msp-toast-entry' }, { children: [(0, jsx_runtime_1.jsx)("div", (0, tslib_1.__assign)({ className: 'msp-toast-title', onClick: function () { return _this.hide(); } }, { children: entry.title }), void 0), (0, jsx_runtime_1.jsx)("div", (0, tslib_1.__assign)({ className: 'msp-toast-message' }, { children: message }), void 0), (0, jsx_runtime_1.jsx)("div", { className: 'msp-toast-clear' }, void 0), (0, jsx_runtime_1.jsx)("div", (0, tslib_1.__assign)({ className: 'msp-toast-hide' }, { children: (0, jsx_runtime_1.jsx)(common_1.IconButton, { svg: icons_1.CancelSvg, onClick: this.hide, title: 'Hide', className: 'msp-no-hover-outline' }, void 0) }), void 0)] }), void 0); }; return ToastEntry; }(base_1.PluginUIComponent)); var Toasts = /** @class */ (function (_super) { (0, tslib_1.__extends)(Toasts, _super); function Toasts() { return _super !== null && _super.apply(this, arguments) || this; } Toasts.prototype.componentDidMount = function () { var _this = this; this.subscribe(this.plugin.managers.toast.events.changed, function () { return _this.forceUpdate(); }); }; Toasts.prototype.render = function () { var state = this.plugin.managers.toast.state; if (!state.entries.count()) return null; var entries = []; state.entries.forEach(function (t, k) { return entries.push(t); }); entries.sort(function (x, y) { return x.serialNumber - y.serialNumber; }); return (0, jsx_runtime_1.jsx)("div", (0, tslib_1.__assign)({ className: 'msp-toast-container' }, { children: entries.map(function (e) { return (0, jsx_runtime_1.jsx)(ToastEntry, { entry: e }, e.serialNumber); }) }), void 0); }; return Toasts; }(base_1.PluginUIComponent)); exports.Toasts = Toasts; //# sourceMappingURL=toast.js.map