@gooddata/react-components
Version:
GoodData.UI - A powerful JavaScript library for building analytical applications
49 lines • 1.89 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 MenuState = /** @class */ (function (_super) {
__extends(MenuState, _super);
function MenuState(props) {
var _this = _super.call(this, props) || this;
_this.isControlled = function () {
return typeof _this.props.opened === "boolean";
};
_this.onOpenedChange = function (openedChangeParams) {
_this.setState({ opened: openedChangeParams.opened }, function () {
if (_this.props.onOpenedChange) {
_this.props.onOpenedChange(openedChangeParams);
}
});
};
_this.state = {
opened: _this.isControlled() ? _this.props.opened : _this.props.defaultOpened,
};
return _this;
}
MenuState.prototype.render = function () {
return this.props.children({
opened: this.isControlled() ? this.props.opened : this.state.opened,
onOpenedChange: this.onOpenedChange,
});
};
MenuState.defaultProps = {
defaultOpened: false,
};
return MenuState;
}(React.Component));
exports.default = MenuState;
//# sourceMappingURL=MenuState.js.map