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 type EditorDropdownButtonOptions = {
8 direction?: 'vertical'|'horizontal';
9 button: EditorBasicButtonDefinition|EditorButton;
12 const defaultOptions: EditorDropdownButtonOptions = {
14 direction: 'horizontal',
15 button: {label: 'Menu'},
18 export class EditorDropdownButton extends EditorContainerUiElement {
19 protected button: EditorButton;
20 protected childItems: EditorUiElement[];
21 protected open: boolean = false;
22 protected options: EditorDropdownButtonOptions;
24 constructor(options: EditorDropdownButtonOptions, children: EditorUiElement[]) {
26 this.childItems = children;
27 this.options = Object.assign({}, defaultOptions, options);
29 if (options.button instanceof EditorButton) {
30 this.button = options.button;
32 this.button = new EditorButton({
43 this.addChildren(this.button);
46 insertItems(...items: EditorUiElement[]) {
47 this.addChildren(...items);
48 this.childItems.push(...items);
51 protected buildDOM(): HTMLElement {
52 const button = this.button.getDOMElement();
54 const childElements: HTMLElement[] = this.childItems.map(child => child.getDOMElement());
55 const menu = el('div', {
56 class: `editor-dropdown-menu editor-dropdown-menu-${this.options.direction}`,
60 const wrapper = el('div', {
61 class: 'editor-dropdown-menu-container',
64 handleDropdown({toggle: button, menu : menu,
65 showOnHover: this.options.showOnHover,
68 this.getContext().manager.triggerStateUpdateForElement(this.button);
71 this.getContext().manager.triggerStateUpdateForElement(this.button);