UNPKG

@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

76 lines 4.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var React = require("react"); var classnames = require("classnames"); var Grid_1 = require("../../Containers/Grid"); var UpModal_1 = require("../../Containers/Modal/UpModal"); var Heading_1 = require("../../Display/Heading"); var iconMap_1 = require("../../../Common/theming/iconMap"); var theming_1 = require("../../../Common/theming"); var styles_1 = require("./styles"); var withTheme_1 = require("../../../Common/theming/withTheme"); var Box_1 = require("../../Containers/Box"); var helpers_1 = require("../../../Common/utils/helpers"); var typestyle_1 = require("typestyle"); var utils_1 = require("../../../Common/theming/utils"); var SvgIcon_1 = require("../SvgIcon"); var UpNotification = function (props) { var children = props.children, message = props.message, intent = props.intent, theme = props.theme, title = props.title, className = props.className, durationBeforeClosing = props.durationBeforeClosing, dismissable = props.dismissable, onCloseClick = props.onCloseClick; var icon = null; var cancelIcon = null; var autoClosingTimeout; var iconSize = props.iconSize || (theme && theme.notificationIconSize != null ? theme.notificationIconSize : 60); var _a = React.useState(true), isVisible = _a[0], setIsVisible = _a[1]; React.useEffect(function () { if (durationBeforeClosing && dismissable) { autoClosingTimeout = new helpers_1.setTimeOutWithPause(function () { setIsVisible(false); }, (durationBeforeClosing * 1000)); } return function () { autoClosingTimeout && autoClosingTimeout.clearTimeout(); }; }, [durationBeforeClosing, dismissable]); if (intent && iconMap_1.default[intent]) { icon = (React.createElement(SvgIcon_1.default, { iconName: iconMap_1.default[intent], width: iconSize, height: iconSize })); } if (onCloseClick || dismissable) { cancelIcon = (React.createElement(SvgIcon_1.default, { iconName: iconMap_1.default['error'], width: '10px', height: '10px' })); } var handleIconClick = function () { setIsVisible(false); if (onCloseClick) onCloseClick(); }; var NotificationRender = function () { return (React.createElement("div", { className: 'up-notification', style: { overflow: 'hidden' } }, React.createElement("div", { className: classnames(styles_1.getStyles(props), className, 'up-notification-container') }, React.createElement(Grid_1.UpGrid, { className: 'up-notification' }, props.displayMode !== 'modal' && title && (React.createElement(Grid_1.UpRow, null, React.createElement(Grid_1.UpCol, { span: 24 }, React.createElement(Heading_1.default, { tag: 'h2', textAlign: 'left', className: typestyle_1.style({ marginLeft: utils_1.toRem(25) }) }, title)))), React.createElement(Grid_1.UpRow, null, React.createElement(Box_1.default, { flexDirection: 'row', alignContent: 'flex-start', justifyContent: 'center', alignItems: 'center' }, React.createElement("div", { className: 'up-notification-icon-container' }, icon), (message || children) && (React.createElement("div", { className: 'up-notification-message' }, message || children)))), React.createElement("div", { className: 'cancel-icon', onClick: handleIconClick }, cancelIcon)), durationBeforeClosing && (React.createElement("div", { className: 'up-notification-progress-bar-container' }, React.createElement("div", { className: 'up-notification-progress-bar' })))))); }; if (!isVisible) { return null; } if (props.displayMode == 'modal') { return (React.createElement(UpModal_1.default, { header: title, showModal: true }, React.createElement(NotificationRender, null))); } return React.createElement(NotificationRender, null); }; exports.UpNotification = UpNotification; UpNotification.defaultProps = { message: '', theme: theming_1.default, displayMode: 'inline', intent: 'info', iconSize: '15px' }; exports.default = withTheme_1.default(UpNotification); //# sourceMappingURL=UpNotification.js.map