1 import {el} from "../../../helpers";
2 import {handleDropdown} from "../helpers/dropdowns";
3 import {EditorContainerUiElement, EditorUiElement} from "../core";
4 import {EditorBasicButtonDefinition, EditorButton} from "../buttons";
6 export class EditorDropdownButton extends EditorContainerUiElement {
7 protected button: EditorButton;
8 protected childItems: EditorUiElement[];
9 protected open: boolean = false;
10 protected showOnHover: boolean = false;
12 constructor(button: EditorBasicButtonDefinition|EditorButton, showOnHover: boolean, children: EditorUiElement[]) {
14 this.childItems = children;
15 this.showOnHover = showOnHover;
17 if (button instanceof EditorButton) {
20 this.button = new EditorButton({
31 this.addChildren(this.button);
34 insertItems(...items: EditorUiElement[]) {
35 this.addChildren(...items);
36 this.childItems.push(...items);
39 protected buildDOM(): HTMLElement {
40 const button = this.button.getDOMElement();
42 const childElements: HTMLElement[] = this.childItems.map(child => child.getDOMElement());
43 const menu = el('div', {
44 class: 'editor-dropdown-menu',
48 const wrapper = el('div', {
49 class: 'editor-dropdown-menu-container',
52 handleDropdown({toggle : button, menu : menu,
53 showOnHover: this.showOnHover,
56 this.getContext().manager.triggerStateUpdateForElement(this.button);
59 this.getContext().manager.triggerStateUpdateForElement(this.button);