UNPKG

decentraland-ui

Version:

Decentraland's UI components and styles

104 lines (103 loc) 4.56 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Toast = exports.ToastType = void 0; var React = __importStar(require("react")); var classnames_1 = __importDefault(require("classnames")); var Close_1 = require("../Close/Close"); require("./Toast.css"); var ToastType; (function (ToastType) { ToastType["INFO"] = "info"; ToastType["WARN"] = "warn"; ToastType["ERROR"] = "error"; })(ToastType = exports.ToastType || (exports.ToastType = {})); var Toast = /** @class */ (function (_super) { __extends(Toast, _super); function Toast() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.mounted = false; _this.closeTimeoutId = null; _this.handleClose = function () { _this.props.onClose && _this.props.onClose(); }; return _this; } Toast.prototype.componentDidMount = function () { this.mounted = true; if (this.shouldCloseAfterTimeout()) { this.closeAfterTimeout(); } }; Toast.prototype.componentWillUnmount = function () { this.mounted = false; }; Toast.prototype.closeAfterTimeout = function () { var _this = this; var timeout = this.props.timeout; this.closeTimeoutId = window ? window.setTimeout(function () { if (_this.mounted) { _this.handleClose(); } _this.closeTimeoutId = null; }, timeout) : null; }; Toast.prototype.shouldCloseAfterTimeout = function () { var timeout = this.props.timeout; return timeout !== undefined && this.closeTimeoutId === null; }; Toast.prototype.render = function () { var _a = this.props, _b = _a.type, type = _b === void 0 ? ToastType.INFO : _b, title = _a.title, body = _a.body, closable = _a.closable, icon = _a.icon, className = _a.className; return (React.createElement("div", { className: (0, classnames_1.default)('dcl', 'toast', type.toLowerCase(), className) }, React.createElement("div", { className: "toast-info" }, icon && React.createElement("span", { className: "toast-icon" }, icon), React.createElement("div", null, closable ? React.createElement(Close_1.Close, { onClick: this.handleClose }) : null, React.createElement("div", { className: "title" }, title), React.createElement("div", { className: "body" }, body))))); }; return Toast; }(React.PureComponent)); exports.Toast = Toast;