UNPKG

@zohodesk/dot

Version:

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

190 lines (151 loc) 11.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["default"] = void 0; var _react = _interopRequireWildcard(require("react")); var _defaultProps = require("./props/defaultProps"); var _propTypes = require("./props/propTypes"); var _FreezeLayer = _interopRequireDefault(require("../../FreezeLayer/FreezeLayer")); var _Layout = require("@zohodesk/components/lib/Layout"); var _LookupModule = _interopRequireDefault(require("./Lookup.module.css")); var _FocusScope = _interopRequireDefault(require("@zohodesk/a11y/es/FocusScope/FocusScope")); var _excluded = ["role", "ariaLabelledby", "ariaDescribedby", "ariaLabel", "ariaModal"]; function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } 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 _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } 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); } /*eslint-disable react/forbid-component-props */ var Lookup = /*#__PURE__*/function (_Component) { _inherits(Lookup, _Component); var _super = _createSuper(Lookup); function Lookup(props) { var _this; _classCallCheck(this, Lookup); _this = _super.call(this, props); _this.handleKeyDown = _this.handleKeyDown.bind(_assertThisInitialized(_this)); _this.createRef = /*#__PURE__*/_react["default"].createRef(); return _this; } _createClass(Lookup, [{ key: "componentDidUpdate", value: function componentDidUpdate(prevProps) { var isActive = this.props.isActive; if (prevProps.isActive !== isActive) { isActive ? document.addEventListener('keydown', this.handleKeyDown) : document.removeEventListener('keydown', this.handleKeyDown); } } }, { key: "componentWillUnmount", value: function componentWillUnmount() { document.removeEventListener('keydown', this.handleKeyDown); } }, { key: "handleKeyDown", value: function handleKeyDown(e) { var onKeyDown = this.props.onKeyDown; onKeyDown && onKeyDown(e); } }, { key: "render", value: function render() { var _this$props = this.props, isActive = _this$props.isActive, children = _this$props.children, size = _this$props.size, dataId = _this$props.dataId, forwardRef = _this$props.forwardRef, onClick = _this$props.onClick, customClass = _this$props.customClass, htmlId = _this$props.htmlId, a11y = _this$props.a11y, childAnimationName = _this$props.childAnimationName, onClose = _this$props.onClose, needFocusScope = _this$props.needFocusScope, customProps = _this$props.customProps, isMinHeight = _this$props.isMinHeight, lookupClass = _this$props.lookupClass; var _a11y$role = a11y.role, role = _a11y$role === void 0 ? 'dialog' : _a11y$role, ariaLabelledby = a11y.ariaLabelledby, ariaDescribedby = a11y.ariaDescribedby, ariaLabel = a11y.ariaLabel, _a11y$ariaModal = a11y.ariaModal, ariaModal = _a11y$ariaModal === void 0 ? isActive ? true : undefined : _a11y$ariaModal, a11yAttributes = _objectWithoutProperties(a11y, _excluded); var _customProps$focusSco = customProps.focusScopeProps, focusScopeProps = _customProps$focusSco === void 0 ? {} : _customProps$focusSco; var _focusScopeProps$need = focusScopeProps.needAutoFocus, needAutoFocus = _focusScopeProps$need === void 0 ? true : _focusScopeProps$need, _focusScopeProps$need2 = focusScopeProps.needRestoreFocus, needRestoreFocus = _focusScopeProps$need2 === void 0 ? true : _focusScopeProps$need2, _focusScopeProps$need3 = focusScopeProps.needListNavigation, needListNavigation = _focusScopeProps$need3 === void 0 ? false : _focusScopeProps$need3, _focusScopeProps$need4 = focusScopeProps.needFocusLoop, needFocusLoop = _focusScopeProps$need4 === void 0 ? true : _focusScopeProps$need4, _focusScopeProps$need5 = focusScopeProps.needEnterAction, needEnterAction = _focusScopeProps$need5 === void 0 ? true : _focusScopeProps$need5; var content = /*#__PURE__*/_react["default"].createElement("div", _extends({ ref: this.createRef, tabIndex: "-1", "data-a11y-need-focus-style": "false", role: role, "aria-labelledby": ariaLabelledby, "aria-describedby": ariaDescribedby, "aria-label": ariaLabel, "aria-modal": ariaModal, id: htmlId, className: "".concat(_LookupModule["default"].box, " ").concat(_LookupModule["default"]["".concat(size, "Size")], " ").concat(lookupClass ? lookupClass : ''), "data-id": dataId, "data-test-id": dataId }, a11yAttributes), /*#__PURE__*/_react["default"].createElement(_Layout.Container, { "data-drag-container": "true", isCover: false, className: isMinHeight ? "".concat(_LookupModule["default"].wrapper) : "".concat(_LookupModule["default"].coverwrap) }, children)); return /*#__PURE__*/_react["default"].createElement(_FreezeLayer["default"], { align: "horizontal", animationName: "fade", childAnimationName: childAnimationName, isActive: isActive, palette: "snow", forwardRef: forwardRef, onClick: onClick, customClass: customClass }, /*#__PURE__*/_react["default"].createElement(_Layout.Container, { alignBox: "row", className: _LookupModule["default"].container, dataId: "fldValue" }, needFocusScope ? /*#__PURE__*/_react["default"].createElement(_FocusScope["default"], { needFocusLoop: needFocusLoop, needListNavigation: needListNavigation, elementRef: this.createRef, needAutoFocus: needAutoFocus, needRestoreFocus: needRestoreFocus, onClose: onClose, needEnterAction: needEnterAction }, content) : content)); } }]); return Lookup; }(_react.Component); exports["default"] = Lookup; Lookup.propTypes = _propTypes.propTypes; Lookup.defaultProps = _defaultProps.defaultProps; // if (__DOCS__) { // Lookup.docs = { // componentGroup: 'Lookup' // }; // }