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