UNPKG

@zohodesk/components

Version:

Dot UI is a customizable React component library built to deliver a clean, accessible, and developer-friendly UI experience. It offers a growing set of reusable components designed to align with modern design systems and streamline application development

212 lines (167 loc) • 10.2 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["default"] = void 0; var _react = _interopRequireDefault(require("react")); var _defaultProps = require("./props/defaultProps"); var _propTypes = require("./props/propTypes"); var _Layout = require("../Layout"); var _Tooltip = _interopRequireDefault(require("../Tooltip/Tooltip")); require("../common/basic.module.css"); require("@zohodesk/variables/assets/colorVariables.module.css"); require("@zohodesk/variables/assets/dotVariables.module.css"); require("@zohodesk/variables/assets/sizeVariables.module.css"); require("@zohodesk/variables/assets/fontsizeVariables.module.css"); require("@zohodesk/variables/es/fontFamilyVariables.module.css"); require("@zohodesk/variables/es/fontWeightVariables.module.css"); require("@zohodesk/variables/assets/transitionVariables.module.css"); require("@zohodesk/variables/assets/no_transitionVariables.module.css"); require("../common/a11y.module.css"); require("../common/boxShadow.module.css"); var _AppContainerModule = _interopRequireDefault(require("./AppContainer.module.css")); var _Config = require("../Provider/Config"); 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 AppContainer = /*#__PURE__*/function (_React$Component) { _inherits(AppContainer, _React$Component); var _super = _createSuper(AppContainer); function AppContainer(props) { var _this; _classCallCheck(this, AppContainer); _this = _super.call(this, props); _this.setTooltipRef = _this.setTooltipRef.bind(_assertThisInitialized(_this)); _this.handleOver = _this.handleOver.bind(_assertThisInitialized(_this)); _this.mouseOverDispatch = _this.mouseOverDispatch.bind(_assertThisInitialized(_this)); _this.removeTimeout = _this.removeTimeout.bind(_assertThisInitialized(_this)); _this.getContainerRef = _this.getContainerRef.bind(_assertThisInitialized(_this)); _this.timer = null; _this.tooltipDebounce = (0, _Config.getLibraryConfig)('tooltipDebounce'); (0, _Config.setLibraryConfig)({ getTooltipContainer: function getTooltipContainer() { return _this.containerElement; } }); return _this; } _createClass(AppContainer, [{ key: "mouseOverDispatch", value: function mouseOverDispatch(e) { if (this.tooltipRef) { this.tooltipRef.handleOver(e, this.containerElement); } } }, { key: "removeTimeout", value: function removeTimeout() { if (this.timer) { this.timer = clearTimeout(this.timer); } } }, { key: "handleOver", value: function handleOver(e) { var _this2 = this; if (this.timer) { this.timer = clearTimeout(this.timer); } this.timer = setTimeout(function () { return _this2.mouseOverDispatch(e); }, this.tooltipDebounce); } }, { key: "getContainerRef", value: function getContainerRef(ref) { var eleRef = this.props.eleRef; this.containerElement = ref; eleRef && eleRef(ref); } }, { key: "setTooltipRef", value: function setTooltipRef(ref) { this.tooltipRef = ref; } }, { key: "componentDidMount", value: function componentDidMount() { var needTooltip = this.props.needTooltip; if (this.containerElement && needTooltip) { this.containerElement.addEventListener('mouseover', this.handleOver, false); this.containerElement.addEventListener('mouseout', this.removeTimeout, false); this.tooltipRef.observeElement(); } } }, { key: "componentWillUnmount", value: function componentWillUnmount() { var needTooltip = this.props.needTooltip; if (this.containerElement && needTooltip) { this.containerElement.removeEventListener('mouseover', this.handleOver, false); this.containerElement.removeEventListener('mouseout', this.removeTimeout, false); this.tooltipRef.unObserveElement(); } (0, _Config.setLibraryConfig)({ getTooltipContainer: function getTooltipContainer() { return null; } }); } }, { key: "render", value: function render() { var _this$props = this.props, className = _this$props.className, children = _this$props.children, tagName = _this$props.tagName, dataId = _this$props.dataId, dataSelectorId = _this$props.dataSelectorId, tooltipClass = _this$props.tooltipClass, tooltipParentClass = _this$props.tooltipParentClass, needTooltip = _this$props.needTooltip, customProps = _this$props.customProps; var _customProps$Containe = customProps.ContainerProps, ContainerProps = _customProps$Containe === void 0 ? {} : _customProps$Containe, _customProps$TooltipP = customProps.TooltipProps, TooltipProps = _customProps$TooltipP === void 0 ? {} : _customProps$TooltipP, _customProps$ExtraPro = customProps.ExtraProps, ExtraProps = _customProps$ExtraPro === void 0 ? {} : _customProps$ExtraPro; return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_Layout.Container, _extends({ className: "".concat(_AppContainerModule["default"].container, " ").concat(className), dataId: dataId, dataSelectorId: dataSelectorId, tagName: tagName, eleRef: this.getContainerRef }, ContainerProps, ExtraProps), /*#__PURE__*/_react["default"].createElement(_Layout.Box, { flexible: true }, children)), needTooltip ? /*#__PURE__*/_react["default"].createElement("div", _extends({}, ExtraProps, { className: "".concat(_AppContainerModule["default"].container, " ").concat(_AppContainerModule["default"].tooltip, " ").concat(tooltipParentClass), "data-id": "".concat(dataId, "_tooltip"), "data-test-id": "".concat(dataId, "_tooltip"), "data-selector-id": "".concat(dataSelectorId, "_tooltip") }), /*#__PURE__*/_react["default"].createElement(_Tooltip["default"], _extends({ ref: this.setTooltipRef, customClass: tooltipClass }, TooltipProps))) : null); } }]); return AppContainer; }(_react["default"].Component); exports["default"] = AppContainer; AppContainer.propTypes = _propTypes.propTypes; AppContainer.defaultProps = _defaultProps.defaultProps; // if (__DOCS__) { // AppContainer.docs = { // componentGroup: 'Template', // folderName: 'Style Guide' // }; // }