UNPKG

@zohodesk/dot

Version:

In this Library, we Provide Some Basic Components to Build Your Application

223 lines (186 loc) 10.6 kB
"use strict"; function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } Object.defineProperty(exports, "__esModule", { value: true }); exports.GlobalNotificationNew = GlobalNotificationNew; exports.GlobalNotificationUI = GlobalNotificationUI; exports["default"] = void 0; var _react = _interopRequireDefault(require("react")); var _defaultProps = require("./props/defaultProps"); var _propTypes = require("./props/propTypes"); var _AutoClose = _interopRequireDefault(require("../../actions/AutoClose")); var _AlertIcons = _interopRequireDefault(require("../alertIcons/AlertIcons")); var _AlertClose = _interopRequireDefault(require("../AlertClose/AlertClose")); var _GlobalNotificationModule = _interopRequireDefault(require("./GlobalNotification.module.css")); var _Layout = require("@zohodesk/components/lib/Layout"); var _Common = require("@zohodesk/components/es/utils/Common"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } var GlobalNotification = /*#__PURE__*/function (_React$Component) { _inherits(GlobalNotification, _React$Component); var _super = _createSuper(GlobalNotification); function GlobalNotification(props) { var _this; _classCallCheck(this, GlobalNotification); _this = _super.call(this, props); _this.hideMessageTimer = null; _this.state = { shadowClose: true }; _this.onClose = _this.onClose.bind(_assertThisInitialized(_this)); return _this; } _createClass(GlobalNotification, [{ key: "componentDidMount", value: function componentDidMount() { var _this$props = this.props, hideMessage = _this$props.hideMessage, hideTime = _this$props.hideTime, id = _this$props.id, needAutoClose = _this$props.needAutoClose; if (needAutoClose) { this.hideMessageTimer = setTimeout(function () { hideMessage(id); }, hideTime); } } }, { key: "componentWillUnmount", value: function componentWillUnmount() { if (this.hideMessageTimer) { clearTimeout(this.hideMessageTimer); } } }, { key: "onClose", value: function onClose(e) { var _this$props2 = this.props, onClose = _this$props2.onClose, hideMessage = _this$props2.hideMessage, id = _this$props2.id; this.setState({ shadowClose: false }); hideMessage && hideMessage(id); onClose && onClose(e); } }, { key: "render", value: function render() { var _this$props3 = this.props, type = _this$props3.type, message = _this$props3.message, hideMessage = _this$props3.hideMessage, onClick = _this$props3.onClick, _this$props3$i18nKeys = _this$props3.i18nKeys, i18nKeys = _this$props3$i18nKeys === void 0 ? {} : _this$props3$i18nKeys, customProps = _this$props3.customProps, dataSelectorId = _this$props3.dataSelectorId, id = _this$props3.id, needShadow = _this$props3.needShadow, shadowCount = _this$props3.shadowCount, eleRef = _this$props3.eleRef; var shadowClose = this.state.shadowClose; var _i18nKeys$closeTitle = i18nKeys.closeTitle, closeTitle = _i18nKeys$closeTitle === void 0 ? 'Close' : _i18nKeys$closeTitle; return /*#__PURE__*/_react["default"].createElement(GlobalNotificationUI, { type: type, message: message, hideMessage: hideMessage, onClick: onClick, closeTitle: closeTitle, customProps: customProps, dataSelectorId: dataSelectorId, id: id, shadowCount: shadowCount, onClose: this.onClose, needShadow: shadowClose && needShadow, eleRef: eleRef }); } }]); return GlobalNotification; }(_react["default"].Component); exports["default"] = GlobalNotification; GlobalNotification.propTypes = _propTypes.propTypes; GlobalNotification.defaultProps = _defaultProps.defaultProps; // if (__DOCS__) { // GlobalNotification.docs = { // componentGroup: 'GlobalNotification', // folderName: 'Alert' // }; // } function GlobalNotificationUI(props) { function onClose(e) { var onClose = props.onClose; (0, _Common.cancelBubblingEffect)(e); onClose && onClose(e); } var _props$type = props.type, type = _props$type === void 0 ? '' : _props$type, message = props.message, onClick = props.onClick, _props$closeTitle = props.closeTitle, closeTitle = _props$closeTitle === void 0 ? '' : _props$closeTitle, _props$customProps = props.customProps, customProps = _props$customProps === void 0 ? {} : _props$customProps, dataSelectorId = props.dataSelectorId, shadowCount = props.shadowCount, needShadow = props.needShadow, eleRef = props.eleRef; var _customProps$ExtraPro = customProps.ExtraProps, ExtraProps = _customProps$ExtraPro === void 0 ? {} : _customProps$ExtraPro; return /*#__PURE__*/_react["default"].createElement("div", _extends({ ref: eleRef, className: " ".concat(_GlobalNotificationModule["default"].message, " \n ").concat(needShadow && shadowCount >= 2 ? shadowCount > 2 ? "".concat(_GlobalNotificationModule["default"].stackShadowTwo, " ").concat(_GlobalNotificationModule["default"].stackShadowOne) : _GlobalNotificationModule["default"].stackShadowOne : '', "\n ").concat(type ? _GlobalNotificationModule["default"][type] : '', "\n "), "data-id": "show_".concat(type, "_message"), "data-test-id": "show_".concat(type, "_message"), tabIndex: 0, "data-selector-id": dataSelectorId }, ExtraProps), /*#__PURE__*/_react["default"].createElement(_Layout.Container, { className: "".concat(_GlobalNotificationModule["default"].container), alignBox: "row", isCover: false, align: "vertical", isInline: true }, /*#__PURE__*/_react["default"].createElement(_Layout.Box, { className: _GlobalNotificationModule["default"].icon }, /*#__PURE__*/_react["default"].createElement(_AlertIcons["default"], { type: type, variant: "secondary" })), /*#__PURE__*/_react["default"].createElement(_Layout.Box, { flexible: true }, /*#__PURE__*/_react["default"].createElement("div", { className: _GlobalNotificationModule["default"].text, onClick: onClick, "data-id": "infoMessage", "data-test-id": "infoMessage", dangerouslySetInnerHTML: { __html: message } })), /*#__PURE__*/_react["default"].createElement(_Layout.Box, { className: _GlobalNotificationModule["default"].close }, /*#__PURE__*/_react["default"].createElement(_AlertClose["default"], { dataId: "close_".concat(type, "_message"), dataTitle: closeTitle, onClose: onClose, type: type })))); } GlobalNotificationUI.propTypes = _propTypes.UI_propTypes; function GlobalNotificationNew(props) { return /*#__PURE__*/_react["default"].createElement(_AutoClose["default"], _extends({}, props, { Element: GlobalNotificationUI })); } GlobalNotificationNew.propTypes = _propTypes.new_propTypes;