UNPKG

@attivio/suit

Version:

Attivio SUIT, the Search UI Toolkit, is a library for creating search clients for searching the Attivio platform.

134 lines (112 loc) 4.6 kB
var _class, _temp; 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; } import React from 'react'; import Glyphicon from 'react-bootstrap/lib/Glyphicon'; import { css } from 'glamor'; import { ToastContainer, toast, Slide } from 'react-toastify'; import 'react-toastify/dist/ReactToastify.css'; import StyleUtils from '../util/StyleUtils'; var Notifiable = (_temp = _class = function (_React$Component) { _inherits(Notifiable, _React$Component); function Notifiable() { _classCallCheck(this, Notifiable); return _possibleConstructorReturn(this, _React$Component.apply(this, arguments)); } /** * This does all the work of setting up colors and the contents of the notifications... */ Notifiable.showNotification = function showNotification(message, type, requireDismissal) { var icon = void 0; var mainColor = void 0; var label = void 0; switch (type) { case toast.TYPE.ERROR: icon = 'exclamation-sign'; mainColor = '#d9534f'; label = 'Error'; break; case toast.TYPE.WARNING: icon = 'alert'; mainColor = '#f0ad4e'; label = 'Warning'; break; case toast.TYPE.SUCCESS: icon = 'ok'; mainColor = '#5cb85c'; label = 'Success'; break; case toast.TYPE.INFO: default: icon = 'info-sign'; mainColor = '#5bc0de'; label = 'Note'; break; } var backgroundColor = StyleUtils.lightenColor(mainColor, 0.5); var autoClose = requireDismissal ? false : 5000; var contents = React.createElement( 'div', null, React.createElement( 'div', { style: { float: 'left', color: mainColor, marginRight: '10px', fontSize: '18px' } }, React.createElement(Glyphicon, { glyph: icon }) ), React.createElement( 'div', null, React.createElement( 'div', { style: { color: mainColor, fontWeight: 'bold', fontSize: '1.2em' } }, label ), message ) ); var options = { type: toast.TYPE.ERROR, autoClose: autoClose, className: css({ backgroundColor: backgroundColor, color: 'black', borderRadius: '4px', borderTop: '4px solid ' + mainColor }) }; toast(contents, options); }; Notifiable.error = function error(message) { var requireDismissal = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; Notifiable.showNotification(message, toast.TYPE.ERROR, requireDismissal); }; Notifiable.warn = function warn(message) { var requireDismissal = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; Notifiable.showNotification(message, toast.TYPE.WARNING, requireDismissal); }; Notifiable.info = function info(message) { var requireDismissal = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; Notifiable.showNotification(message, toast.TYPE.INFO, requireDismissal); }; Notifiable.success = function success(message) { var requireDismissal = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; Notifiable.showNotification(message, toast.TYPE.SUCCESS, requireDismissal); }; Notifiable.prototype.render = function render() { return React.createElement( 'div', null, React.createElement(ToastContainer, { position: 'top-center', closeButton: false, transition: Slide, hideProgressBar: true, draggable: false }), this.props.children ); }; return Notifiable; }(React.Component), _class.displayName = 'Notifiable', _temp); export { Notifiable as default };