UNPKG

sws-frontend

Version:

sws frontend project

93 lines 4.35 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __assign = (this && this.__assign) || Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; Object.defineProperty(exports, "__esModule", { value: true }); var React = require("react"); var react_bootstrap_1 = require("react-bootstrap"); require("./alert.scss"); exports.buildAlert = function (_title, _msg, _proceedCallback, proceedLabel, _dismissCallback, dismissLabel) { return _title ? { title: _title, msg: _msg, proceedCallback: _proceedCallback, proceedLabel: proceedLabel ? proceedLabel : 'Ok', dismissCallback: _dismissCallback, dismissLabel: dismissLabel ? dismissLabel : 'Cancel' } : undefined; }; exports.Alert = function (p) { var proceedLabel = p.proceedLabel, dismissLabel = p.dismissLabel; var _bsStyle = p.bsStyle ? p.bsStyle : 'danger'; return (React.createElement("div", { className: "alert-container" }, React.createElement(react_bootstrap_1.Alert, { className: 'alertMain', bsStyle: _bsStyle, autoFocus: true }, React.createElement("div", { className: 'alertTitle' }, React.createElement("h4", null, React.createElement("b", null, p.title))), React.createElement("div", { className: 'alertMessages' }, p.msg.map(function (m, index) { return React.createElement("p", { key: index }, m); })), React.createElement("div", { className: 'alertButtons' }, React.createElement(react_bootstrap_1.Button, { onClick: p.proceedCallback, bsStyle: _bsStyle }, proceedLabel ? proceedLabel : "Proceed"), p.dismissCallback && React.createElement(react_bootstrap_1.Button, { onClick: p.dismissCallback }, dismissLabel ? dismissLabel : "Cancel"))))); }; exports.default = exports.Alert; var helpers_1 = require("../commons/helpers"); var Alerted = (function (_super) { __extends(Alerted, _super); // private displayAlert: Function; function Alerted(p, context) { var _this = _super.call(this, p, context) || this; _this.state = {}; return _this; // this.displayAlert = this.displayWarns } Alerted.prototype.getChildContext = function () { return { displayAlert: this.displayWarns }; }; Alerted.prototype.displayWarns = function (_title, _msg, proceedCallback, proceedLabel, dismissCallback, dismissLabel) { var _this = this; var state = this.state; var alert = _title ? exports.buildAlert(_title, _msg, proceedCallback, proceedLabel ? proceedLabel : 'Ok', dismissCallback ? dismissCallback : function () { return _this.displayWarns(); }, dismissLabel ? dismissLabel : 'Cancel') : undefined; this.setState(helpers_1.merge(this.state, { alert: alert })); }; Alerted.prototype.render = function () { var p = this.props; var children = p.children; var alert = this.state.alert; var props = helpers_1.merge(p, { displayAlert: this.displayWarns }); var child = React.cloneElement(React.Children.only(children), props); return React.createElement("div", null, child, alert && React.createElement("div", null, React.createElement(exports.Alert, __assign({}, alert)), React.createElement("p", null))); }; Alerted.childContextTypes = { displayAlert: React.PropTypes.func.isRequired }; return Alerted; }(React.Component)); exports.Alerted = Alerted; //# sourceMappingURL=alert.js.map