@atlaskit/editor-core
Version:
A package contains Atlassian editor core functionality
45 lines • 2.45 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var React = require("react");
var react_1 = require("react");
var dropdown_menu_1 = require("@atlaskit/dropdown-menu");
var Popup_1 = require("../Popup");
/**
* Wrapper around @atlaskit/dropdown-menu which uses Popup and Portal to render
* dropdown-menu outside of "overflow: hidden" containers when needed.
*
* Also it controls popper's placement.
*/
var DropdownMenuWrapper = (function (_super) {
tslib_1.__extends(DropdownMenuWrapper, _super);
function DropdownMenuWrapper(props) {
var _this = _super.call(this, props) || this;
_this.handleRef = function (target) {
_this.setState({ target: target });
};
_this.updatePopupPlacement = function (placement) {
_this.setState({ popupPlacement: placement });
};
_this.state = {
popupPlacement: ['bottom', 'left']
};
return _this;
}
DropdownMenuWrapper.prototype.renderDropdownMenu = function () {
var _a = this.state, target = _a.target, popupPlacement = _a.popupPlacement;
var _b = this.props, items = _b.items, mountTo = _b.mountTo, boundariesElement = _b.boundariesElement, onOpenChange = _b.onOpenChange, onItemActivated = _b.onItemActivated, fitHeight = _b.fitHeight, fitWidth = _b.fitWidth;
return (React.createElement(Popup_1.default, { target: target, mountTo: mountTo, boundariesElement: boundariesElement, onPlacementChanged: this.updatePopupPlacement, fitHeight: fitHeight, fitWidth: fitWidth },
React.createElement(dropdown_menu_1.default, { defaultOpen: true, onOpenChange: onOpenChange, onItemActivated: onItemActivated, appearance: "tall", position: popupPlacement.join(' '), shouldFlip: false, shouldFitContainer: true, isTriggerNotTabbable: true, items: items },
React.createElement("div", { style: { height: 0, minWidth: fitWidth || 0 } }))));
};
DropdownMenuWrapper.prototype.render = function () {
var _a = this.props, children = _a.children, isOpen = _a.isOpen;
return (React.createElement("div", null,
React.createElement("div", { ref: this.handleRef }, children),
isOpen ? this.renderDropdownMenu() : null));
};
return DropdownMenuWrapper;
}(react_1.PureComponent));
exports.default = DropdownMenuWrapper;
//# sourceMappingURL=index.js.map