UNPKG

@gooddata/react-components

Version:

GoodData.UI - A powerful JavaScript library for building analytical applications

60 lines 2.69 kB
"use strict"; 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 MenuOpener_1 = require("./menuOpener/MenuOpener"); var ControlledMenu = /** @class */ (function (_super) { __extends(ControlledMenu, _super); function ControlledMenu() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.closeMenu = function () { _this.props.onOpenedChange({ opened: false, source: "SCROLL" }); }; _this.addScrollListeners = function () { window.addEventListener("scroll", _this.closeMenu, true); }; _this.removeScrollListeners = function () { window.removeEventListener("scroll", _this.closeMenu, true); }; return _this; } ControlledMenu.prototype.componentDidMount = function () { if (this.props.closeOnScroll) { this.addScrollListeners(); } }; ControlledMenu.prototype.componentWillUnmount = function () { if (this.props.closeOnScroll) { this.removeScrollListeners(); } }; ControlledMenu.prototype.componentDidUpdate = function (prevProps) { if (prevProps.closeOnScroll !== this.props.closeOnScroll) { if (this.props.closeOnScroll) { this.addScrollListeners(); } else { this.removeScrollListeners(); } } }; ControlledMenu.prototype.render = function () { return (React.createElement(MenuOpener_1.default, { opened: this.props.opened, onOpenedChange: this.props.onOpenedChange, openAction: this.props.openAction, alignment: this.props.alignment, spacing: this.props.spacing, offset: this.props.offset, portalTarget: this.props.portalTarget, toggler: this.props.toggler, togglerWrapperClassName: this.props.togglerWrapperClassName, topLevelMenu: true }, this.props.children)); }; return ControlledMenu; }(React.Component)); exports.default = ControlledMenu; //# sourceMappingURL=ControlledMenu.js.map