@ebay/ebayui-core
Version:
Collection of core eBay components; considered to be the building blocks for all composite structures, pages & apps.
37 lines (36 loc) • 1.28 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DropdownUtil = void 0;
const dom_1 = require("@floating-ui/dom");
class DropdownUtil {
constructor(host, overlay, options) {
this.host = host;
this.overlay = overlay;
this.options = options !== null && options !== void 0 ? options : {};
}
show() {
this.cleanupFn = (0, dom_1.autoUpdate)(this.host, this.overlay, this.update.bind(this));
}
update() {
var _a, _b;
(0, dom_1.computePosition)(this.host, this.overlay, {
placement: this.options.reverse ? "bottom-end" : "bottom-start",
strategy: (_a = this.options.strategy) !== null && _a !== void 0 ? _a : "fixed",
middleware: [(0, dom_1.offset)((_b = this.options.offset) !== null && _b !== void 0 ? _b : 4), (0, dom_1.shift)()],
}).then(({ x, y }) => {
Object.assign(this.overlay.style, {
left: `${x}px`,
top: `${y}px`,
});
});
}
cleanup() {
var _a;
(_a = this.cleanupFn) === null || _a === void 0 ? void 0 : _a.call(this);
}
hide() {
if (this.cleanup)
this.cleanup();
}
}
exports.DropdownUtil = DropdownUtil;