UNPKG

@blueprintjs/core

Version:
93 lines 3.9 kB
/* * Copyright 2016 Palantir Technologies, Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import * as tslib_1 from "tslib"; import classNames from "classnames"; import * as React from "react"; import { polyfill } from "react-lifecycles-compat"; import { AbstractPureComponent2, Classes } from "../../common"; import { DISPLAYNAME_PREFIX } from "../../common/props"; import { safeInvoke } from "../../common/utils"; import { ButtonGroup } from "../button/buttonGroup"; import { AnchorButton, Button } from "../button/buttons"; import { Icon } from "../icon/icon"; var Toast = /** @class */ (function (_super) { tslib_1.__extends(Toast, _super); function Toast() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.handleActionClick = function (e) { safeInvoke(_this.props.action.onClick, e); _this.triggerDismiss(false); }; _this.handleCloseClick = function () { return _this.triggerDismiss(false); }; _this.startTimeout = function () { _this.clearTimeouts(); if (_this.props.timeout > 0) { _this.setTimeout(function () { return _this.triggerDismiss(true); }, _this.props.timeout); } }; return _this; } Toast.prototype.render = function () { var _a = this.props, className = _a.className, icon = _a.icon, intent = _a.intent, message = _a.message; return (React.createElement("div", { className: classNames(Classes.TOAST, Classes.intentClass(intent), className), onBlur: this.startTimeout, onFocus: this.clearTimeouts, onMouseEnter: this.clearTimeouts, onMouseLeave: this.startTimeout, tabIndex: 0 }, React.createElement(Icon, { icon: icon }), React.createElement("span", { className: Classes.TOAST_MESSAGE }, message), React.createElement(ButtonGroup, { minimal: true }, this.maybeRenderActionButton(), React.createElement(Button, { icon: "cross", onClick: this.handleCloseClick })))); }; Toast.prototype.componentDidMount = function () { this.startTimeout(); }; Toast.prototype.componentDidUpdate = function (prevProps) { if (prevProps.timeout !== this.props.timeout) { if (this.props.timeout > 0) { this.startTimeout(); } else { this.clearTimeouts(); } } }; Toast.prototype.componentWillUnmount = function () { this.clearTimeouts(); }; Toast.prototype.maybeRenderActionButton = function () { var action = this.props.action; if (action == null) { return undefined; } else { return React.createElement(AnchorButton, tslib_1.__assign({}, action, { intent: undefined, onClick: this.handleActionClick })); } }; Toast.prototype.triggerDismiss = function (didTimeoutExpire) { this.clearTimeouts(); safeInvoke(this.props.onDismiss, didTimeoutExpire); }; Toast.defaultProps = { className: "", message: "", timeout: 5000, }; Toast.displayName = DISPLAYNAME_PREFIX + ".Toast"; Toast = tslib_1.__decorate([ polyfill ], Toast); return Toast; }(AbstractPureComponent2)); export { Toast }; //# sourceMappingURL=toast.js.map