UNPKG

@guardian/threads

Version:
45 lines 1.93 kB
import { __extends } from "tslib"; import React, { createRef, Component, Fragment } from 'react'; import { PopOver } from '../../PopOver/PopOver'; import { Button } from '../../Button/Button'; var WithPopOver = /** @class */ (function (_super) { __extends(WithPopOver, _super); function WithPopOver() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.proxyRef = createRef(); _this.state = { isOpen: false, openAt: [0, 0], }; return _this; } WithPopOver.prototype.setOpen = function (isOpen) { var current = this.proxyRef.current; if (current) { var clientRect = current.getBoundingClientRect(); var origin_1 = this.props.origin; this.setState({ isOpen: isOpen, openAt: [ clientRect.x + (origin_1 === 'left' ? 0 : clientRect.width), clientRect.y + clientRect.height, ], }); } }; WithPopOver.prototype.render = function () { var _this = this; var _a = this.state, isOpen = _a.isOpen, openAt = _a.openAt; var _b = this.props, children = _b.children, persistent = _b.persistent, origin = _b.origin, proxy = _b.proxy; return (React.createElement(Fragment, null, React.createElement("div", { ref: this.proxyRef, onClick: function () { _this.setOpen(true); } }, proxy ? proxy : React.createElement(Button, null, isOpen ? 'Close' : 'open')), isOpen && (React.createElement(PopOver, { origin: origin, left: openAt[0], top: openAt[1], persistent: persistent, onClose: function () { _this.setOpen(false); } }, children)))); }; return WithPopOver; }(Component)); export { WithPopOver }; //# sourceMappingURL=WithPopOver.js.map