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;
11 constructor(button: EditorBasicButtonDefinition|EditorButton, children: EditorUiElement[]) {
13 this.childItems = children
15 if (button instanceof EditorButton) {
18 this.button = new EditorButton({
29 this.addChildren(this.button);
32 insertItems(...items: EditorUiElement[]) {
33 this.addChildren(...items);
34 this.childItems.push(...items);
37 protected buildDOM(): HTMLElement {
38 const button = this.button.getDOMElement();
40 const childElements: HTMLElement[] = this.childItems.map(child => child.getDOMElement());
41 const menu = el('div', {
42 class: 'editor-dropdown-menu',
46 const wrapper = el('div', {
47 class: 'editor-dropdown-menu-container',
50 handleDropdown(button, menu, () => {
52 this.getContext().manager.triggerStateUpdateForElement(this.button);
55 this.getContext().manager.triggerStateUpdateForElement(this.button);