UNPKG

@nteract/mythic-notifications

Version:

A notification system based on blueprintjs toasters and the myths redux framework

74 lines 3.12 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.NotificationRoot = exports.blueprintjsNotificationSystem = void 0; const core_1 = require("@blueprintjs/core"); const myths_1 = require("@nteract/myths"); const react_1 = __importDefault(require("react")); const styled_components_1 = __importDefault(require("styled-components")); const initialize_system_1 = require("../myths/initialize-system"); const FloatRight = styled_components_1.default.div ` float: right; `; const calloutStyle = { margin: "-11px 0 -11px -11px", background: "transparent", }; const callbackOf = (action, dispatch) => { if ("callback" in action) { return action.callback; } if ("dispatch" in action) { return () => dispatch(action.dispatch); } }; exports.blueprintjsNotificationSystem = (toaster, dispatch) => ({ addNotification: (msg) => { var _a, _b; const intent = { "in-progress": core_1.Intent.PRIMARY, info: core_1.Intent.PRIMARY, success: core_1.Intent.SUCCESS, warning: core_1.Intent.WARNING, error: core_1.Intent.DANGER, }[(_a = msg.level) !== null && _a !== void 0 ? _a : "info"]; toaster.show({ message: (react_1.default.createElement(react_1.default.Fragment, null, msg.level === "in-progress" ? react_1.default.createElement(FloatRight, null, react_1.default.createElement(core_1.Spinner, { size: 20, intent: intent })) : null, react_1.default.createElement(core_1.Callout, { icon: msg.icon, title: msg.title, intent: intent, style: calloutStyle }, msg.message))), action: msg.action ? { icon: (_b = msg.action.icon) !== null && _b !== void 0 ? _b : "arrow-right", text: msg.action.label, onClick: callbackOf(msg.action, dispatch), } : undefined, timeout: msg.action || msg.level === "in-progress" ? 0 : 10000, }, msg.key); }, }); const DoNotPrint = styled_components_1.default.div ` @media print { display: none; } `; exports.NotificationRoot = initialize_system_1.initializeSystem.createConnectedComponent("NotificationRoot", class extends myths_1.MythicComponent { postConstructor() { this.toaster = react_1.default.createRef(); } componentDidMount() { this.props.initializeSystem(exports.blueprintjsNotificationSystem(this.toaster.current, this.props.dispatch)); } render() { return (react_1.default.createElement(DoNotPrint, null, react_1.default.createElement(core_1.Toaster, { ref: this.toaster, position: "top-right", className: this.props.darkTheme ? core_1.Classes.DARK : undefined, usePortal: false }))); } }); //# sourceMappingURL=blueprintjs.js.map