@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
293 lines (243 loc) • 11.8 kB
JavaScript
"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"] = exports.PopOverTarget = exports.PopOverContainer = void 0;
var _react = _interopRequireDefault(require("react"));
var _defaultProps = require("./props/defaultProps");
var _propTypes = require("./props/propTypes");
var _Popup = _interopRequireDefault(require("../Popup/Popup"));
var _Layout = require("../Layout");
var _ResponsiveDropBox = _interopRequireDefault(require("../ResponsiveDropBox/ResponsiveDropBox"));
var _PopOverModule = _interopRequireDefault(require("./PopOver.module.css"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
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 PopOver = /*#__PURE__*/function (_React$Component) {
_inherits(PopOver, _React$Component);
var _super = _createSuper(PopOver);
function PopOver(props) {
var _this;
_classCallCheck(this, PopOver);
_this = _super.call(this, props);
_this.popOverTargetRef = _this.popOverTargetRef.bind(_assertThisInitialized(_this));
_this.popOverContainerRef = _this.popOverContainerRef.bind(_assertThisInitialized(_this));
_this.togglePopup = _this.togglePopup.bind(_assertThisInitialized(_this));
return _this;
}
_createClass(PopOver, [{
key: "componentDidUpdate",
value: function componentDidUpdate(prevProps) {
var _this$props = this.props,
isPopupOpen = _this$props.isPopupOpen,
onPopupOpen = _this$props.onPopupOpen,
onPopupClose = _this$props.onPopupClose;
if (prevProps.isPopupOpen !== isPopupOpen) {
isPopupOpen && onPopupOpen && onPopupOpen();
!isPopupOpen && onPopupClose && onPopupClose();
}
}
}, {
key: "popOverTargetRef",
value: function popOverTargetRef(el) {
this.popOverTarget = el;
var getTargetRef = this.props.getTargetRef;
getTargetRef(el);
}
}, {
key: "popOverContainerRef",
value: function popOverContainerRef(el) {
this.popOverContainer = el;
var getContainerRef = this.props.getContainerRef;
getContainerRef(el);
}
}, {
key: "togglePopup",
value: function togglePopup(e) {
var _this$props2 = this.props,
togglePopup = _this$props2.togglePopup,
boxPosition = _this$props2.boxPosition;
togglePopup(e, boxPosition);
}
}, {
key: "render",
value: function render() {
var _this2 = this;
var _this$props3 = this.props,
children = _this$props3.children,
isPopupOpen = _this$props3.isPopupOpen,
removeClose = _this$props3.removeClose,
right = _this$props3.right,
left = _this$props3.left,
top = _this$props3.top,
bottom = _this$props3.bottom,
arrowRight = _this$props3.arrowRight,
arrowLeft = _this$props3.arrowLeft,
arrowTop = _this$props3.arrowTop,
arrowBottom = _this$props3.arrowBottom,
isAnimate = _this$props3.isAnimate,
isArrow = _this$props3.isArrow,
arrowPosition = _this$props3.arrowPosition,
position = _this$props3.position,
size = _this$props3.size,
onClick = _this$props3.onClick,
isPopupReady = _this$props3.isPopupReady;
var childrens = _react["default"].Children.map(children, function (child, index) {
var element = index === 1 ? /*#__PURE__*/_react["default"].cloneElement(child, {
isPopupOpen: isPopupOpen,
togglePopup: _this2.togglePopup,
removeClose: removeClose,
right: right,
left: left,
top: top,
bottom: bottom,
arrowRight: arrowRight,
arrowLeft: arrowLeft,
arrowTop: arrowTop,
arrowBottom: arrowBottom,
boxPosition: position,
isAnimate: isAnimate,
isArrow: isArrow,
arrowPosition: arrowPosition,
size: size,
onClick: onClick,
getRef: _this2.popOverContainerRef,
isPopupReady: isPopupReady
}) : /*#__PURE__*/_react["default"].cloneElement(child, {
isPopupOpen: isPopupOpen,
togglePopup: _this2.togglePopup,
removeClose: removeClose,
getRef: _this2.popOverTargetRef
});
return element;
});
return /*#__PURE__*/_react["default"].createElement("div", {
className: _PopOverModule["default"].popup
}, childrens);
}
}]);
return PopOver;
}(_react["default"].Component);
PopOver.defaultProps = _defaultProps.PopOver_defaultProps;
PopOver.propTypes = _propTypes.PopOver_propTypes;
var _default = (0, _Popup["default"])(PopOver);
exports["default"] = _default;
var PopOverTarget = /*#__PURE__*/function (_React$Component2) {
_inherits(PopOverTarget, _React$Component2);
var _super2 = _createSuper(PopOverTarget);
function PopOverTarget(props) {
var _this3;
_classCallCheck(this, PopOverTarget);
_this3 = _super2.call(this, props);
_this3.getRef = _this3.getRef.bind(_assertThisInitialized(_this3));
return _this3;
}
_createClass(PopOverTarget, [{
key: "getRef",
value: function getRef(el) {
var getRef = this.props.getRef;
getRef(el);
}
}, {
key: "render",
value: function render() {
var _this$props4 = this.props,
children = _this$props4.children,
togglePopup = _this$props4.togglePopup;
return /*#__PURE__*/_react["default"].createElement("div", {
className: _PopOverModule["default"].target,
onClick: togglePopup,
ref: this.getRef
}, children);
}
}]);
return PopOverTarget;
}(_react["default"].Component);
exports.PopOverTarget = PopOverTarget;
PopOverTarget.propTypes = _propTypes.PopOverTarget_propTypes;
var PopOverContainer = /*#__PURE__*/function (_React$Component3) {
_inherits(PopOverContainer, _React$Component3);
var _super3 = _createSuper(PopOverContainer);
function PopOverContainer(props) {
var _this4;
_classCallCheck(this, PopOverContainer);
_this4 = _super3.call(this, props);
_this4.handleClick = _this4.handleClick.bind(_assertThisInitialized(_this4));
_this4.getRef = _this4.getRef.bind(_assertThisInitialized(_this4));
return _this4;
}
_createClass(PopOverContainer, [{
key: "getRef",
value: function getRef(el) {
var getRef = this.props.getRef;
getRef && getRef(el);
}
}, {
key: "handleClick",
value: function handleClick(e) {
var _this$props5 = this.props,
onClick = _this$props5.onClick,
removeClose = _this$props5.removeClose;
removeClose && removeClose(e);
onClick && onClick();
}
}, {
key: "render",
value: function render() {
var _this$props6 = this.props,
children = _this$props6.children,
isPopupOpen = _this$props6.isPopupOpen,
isAnimate = _this$props6.isAnimate,
isArrow = _this$props6.isArrow,
size = _this$props6.size,
arrowPosition = _this$props6.arrowPosition,
boxPosition = _this$props6.boxPosition,
right = _this$props6.right,
left = _this$props6.left,
top = _this$props6.top,
bottom = _this$props6.bottom,
arrowRight = _this$props6.arrowRight,
arrowLeft = _this$props6.arrowLeft,
arrowTop = _this$props6.arrowTop,
arrowBottom = _this$props6.arrowBottom,
animationStyle = _this$props6.animationStyle,
getRef = _this$props6.getRef;
return /*#__PURE__*/_react["default"].createElement(_ResponsiveDropBox["default"], {
animationStyle: animationStyle,
arrowBottom: arrowBottom,
arrowLeft: arrowLeft,
arrowPosition: arrowPosition,
arrowRight: arrowRight,
arrowTop: arrowTop,
bottom: bottom,
boxPosition: boxPosition,
getRef: getRef,
isActive: isPopupOpen,
isAnimate: isAnimate,
isArrow: isArrow,
left: left,
right: right,
size: size,
top: top,
alignBox: "row"
}, /*#__PURE__*/_react["default"].createElement(_Layout.Box, {
flexible: true,
shrink: true,
scroll: "vertical"
}, children));
}
}]);
return PopOverContainer;
}(_react["default"].Component);
exports.PopOverContainer = PopOverContainer;
PopOverContainer.defaultProps = _defaultProps.PopOverContainer_defaultProps;
PopOverContainer.propTypes = _propTypes.PopOverContainer_propTypes;