import Component from "@glimmer/component"; import { modifier } from "ember-modifier"; import { tracked } from "@glimmer/tracking"; import { inject as service } from "@ember/service"; import DButton from "discourse/components/d-button"; import DFloatBody from "float-kit/components/d-float-body"; import concatClass from "discourse/helpers/concat-class"; import { getOwner } from "discourse-common/lib/get-owner"; import DMenuInstance from "float-kit/lib/d-menu-instance"; export default class DMenu extends Component { @service menu; @tracked menuInstance = null; registerTrigger = modifier((element) => { const options = { ...this.args, ...{ autoUpdate: true, listeners: true, beforeTrigger: () => { this.menu.close(); }, }, }; const instance = new DMenuInstance(getOwner(this), element, options); this.menuInstance = instance; return () => { instance.destroy(); if (this.isDestroying) { this.menuInstance = null; } }; }); get menuId() { return `d-menu-${this.menuInstance.id}`; } get options() { return this.menuInstance?.options ?? {}; } get componentArgs() { return { close: this.menu.close, data: this.options.data, }; } }