import Component from "@glimmer/component"; import { modifier } from "ember-modifier"; import { tracked } from "@glimmer/tracking"; import icon from "discourse-common/helpers/d-icon"; import { inject as service } from "@ember/service"; import DFloatBody from "float-kit/components/d-float-body"; import concatClass from "discourse/helpers/concat-class"; import DTooltipInstance from "float-kit/lib/d-tooltip-instance"; import { getOwner } from "@ember/application"; import and from "truth-helpers/helpers/and"; export default class DTooltip extends Component { @service tooltip; @tracked tooltipInstance = null; registerTrigger = modifier((element) => { const options = { ...this.args, ...{ listeners: true, beforeTrigger: () => { this.tooltip.close(); }, }, }; const instance = new DTooltipInstance(getOwner(this), element, options); this.tooltipInstance = instance; return () => { instance.destroy(); if (this.isDestroying) { this.tooltipInstance = null; } }; }); get options() { return this.tooltipInstance?.options; } get componentArgs() { return { close: this.tooltip.close, data: this.options.data, }; } }