@gooddata/react-components
Version:
GoodData.UI - A powerful JavaScript library for building analytical applications
66 lines • 3.7 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
// (C) 2007-2018 GoodData Corporation
var React = require("react");
var PositionedMenuContent_1 = require("./PositionedMenuContent");
var RenderChildrenInPortal_1 = require("../utils/RenderChildrenInPortal");
var Wrapper = function (_a) {
var children = _a.children;
return (React.createElement("div", { className: "gd-menuPosition-wrapper" }, children));
};
var PortalIfTopLevelMenu = function (_a) {
var topLevelMenu = _a.topLevelMenu, children = _a.children, portalTarget = _a.portalTarget;
return topLevelMenu ? (React.createElement(RenderChildrenInPortal_1.default, { targetElement: portalTarget }, children)) : (React.createElement(React.Fragment, null, children));
};
var MenuPosition = /** @class */ (function (_super) {
__extends(MenuPosition, _super);
function MenuPosition() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.state = {
togglerElInitialized: false,
};
_this.togglerEl = null;
_this.setTogglerEl = function (el) {
_this.togglerEl = el;
_this.setState({
togglerElInitialized: true,
});
};
return _this;
}
// React Measure is not used because it cannot detect the left/top coordinate
// changes of absolute positioned blocks. This caused problems where left/top
// positions from React Measure were outdated. To solve this we do the
// measurements manually in PositionedMenuContent at the correct time.
MenuPosition.prototype.render = function () {
var _a = this.props, portalTarget = _a.portalTarget, topLevelMenu = _a.topLevelMenu, contentWrapper = _a.contentWrapper, toggler = _a.toggler, opened = _a.opened, alignment = _a.alignment, spacing = _a.spacing, offset = _a.offset, togglerWrapperClassName = _a.togglerWrapperClassName, children = _a.children;
// Top level menu uses React portals to be rendered in body element (or
// any element specified in targetElement prop). Any submenus are rendered
// inside of previous menu, so they do not need any portals.
var ContentWrapper = contentWrapper;
var MaybeWrapper = topLevelMenu ? React.Fragment : Wrapper;
return (React.createElement(MaybeWrapper, null,
React.createElement("div", { className: topLevelMenu ? togglerWrapperClassName : undefined, ref: this.setTogglerEl }, toggler),
React.createElement(PortalIfTopLevelMenu, { portalTarget: portalTarget, topLevelMenu: topLevelMenu }, opened && this.state.togglerElInitialized && (React.createElement(ContentWrapper, null,
React.createElement(PositionedMenuContent_1.default, { alignment: alignment, spacing: spacing, offset: offset, topLevelMenu: topLevelMenu, togglerEl: this.togglerEl }, children))))));
};
MenuPosition.defaultProps = {
contentWrapper: React.Fragment,
};
return MenuPosition;
}(React.Component));
exports.default = MenuPosition;
//# sourceMappingURL=MenuPosition.js.map