import Component from "@glimmer/component"; import { tracked } from "@glimmer/tracking"; import { getOwner } from "@ember/application"; import { action } from "@ember/object"; import { service } from "@ember/service"; import { modifier } from "ember-modifier"; import { and } from "truth-helpers"; 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 { TOOLTIP } from "float-kit/lib/constants"; import DTooltipInstance from "float-kit/lib/d-tooltip-instance"; export default class DTooltip extends Component { @service tooltip; @service internalTooltip; @tracked tooltipInstance = null; registerTrigger = modifier((element, [properties]) => { const options = { ...properties, ...{ listeners: true, beforeTrigger: (instance) => { this.internalTooltip.activeTooltip?.close?.(); this.internalTooltip.activeTooltip = instance; }, }, }; const instance = new DTooltipInstance(getOwner(this), element, options); this.tooltipInstance = instance; this.options.onRegisterApi?.(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, }; } @action allowedProperties() { const properties = {}; Object.keys(TOOLTIP.options).forEach((key) => { const value = TOOLTIP.options[key]; properties[key] = this.args[key] ?? value; }); return properties; } }