@arche-mc2/arche-controls
Version:
We know that there are a ton of react UI library projects to choose from. Our hope with this one is to provide the next generation of react components that you can use to bootstrap your next project, or as a reference for building a UIKit. Read on to get
68 lines • 3.33 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var React = require("react");
var classnames = require("classnames");
var Heading_1 = require("../Heading");
var helpers_1 = require("../../../Common/utils/helpers");
var theming_1 = require("../../../Common/theming");
var Notification_1 = require("../Notification");
var SvgIcon_1 = require("../SvgIcon");
var styles_1 = require("./styles");
var UpToast = function (props) {
var manualClosingTimeout;
var autoClosingTimeout;
var message = props.message, children = props.children, intent = props.intent, title = props.title, duration = props.duration, theme = props.theme, autoDismissable = props.autoDismissable;
var _a = React.useState(true), isVisible = _a[0], setIsVisible = _a[1];
var _b = React.useState(false), isUnmounting = _b[0], setIsUnmounting = _b[1];
React.useEffect(function () {
if (duration && autoDismissable) {
setIsUnmounting(false);
setIsVisible(true);
autoClosingTimeout = new helpers_1.setTimeOutWithPause(function () {
handleClose();
}, duration);
}
return function () {
autoClosingTimeout && autoClosingTimeout.clearTimeout();
manualClosingTimeout && clearTimeout(manualClosingTimeout);
};
}, [duration, autoDismissable]);
var handleClose = function () {
setIsUnmounting(true);
manualClosingTimeout = setTimeout(function () {
if (props.onClose) {
props.onClose();
}
setIsUnmounting(false);
setIsVisible(false);
}, 1000);
};
var onMouseOver = function () {
if (autoClosingTimeout)
autoClosingTimeout.pause();
};
var onMouseLeave = function () {
if (autoClosingTimeout)
autoClosingTimeout.resume();
};
if (!isVisible) {
return null;
}
;
return (React.createElement("div", { className: classnames(styles_1.wrapperToastStyle(isUnmounting), styles_1.getIntentStyle(intent, theme)), onMouseEnter: onMouseOver, onMouseLeave: onMouseLeave },
title &&
React.createElement(React.Fragment, null,
React.createElement(Heading_1.default, { tag: 'h4', margin: 'none', className: classnames(styles_1.toastTitleStyle, 'up-toast-title') }, title),
React.createElement("div", { className: classnames(styles_1.buttonStyle, 'up-toast-close'), onClick: handleClose },
React.createElement(SvgIcon_1.default, { width: '15px', height: '15px', iconName: 'x' }))),
React.createElement("div", { className: 'up-toast-body' }, (message != null || children != null) && (React.createElement(Notification_1.default, { iconSize: '32px', className: 'up-toast-message', message: message, intent: intent, onCloseClick: !title && handleClose, durationBeforeClosing: props.autoDismissable && styles_1.convertDurationFromMsToSecond(duration) }, children)))));
};
exports.UpToast = UpToast;
UpToast.defaultProps = {
intent: 'default',
duration: 3000,
autoDismissable: true,
theme: theming_1.default
};
exports.default = theming_1.withTheme(UpToast);
//# sourceMappingURL=UpToast.js.map