1 import {EditorUiStateUpdate, EditorContainerUiElement} from "../core";
2 import {EditorButton} from "../buttons";
3 import {el} from "../../../utils/dom";
5 export class EditorFormatMenu extends EditorContainerUiElement {
6 buildDOM(): HTMLElement {
7 const childElements: HTMLElement[] = this.getChildren().map(child => child.getDOMElement());
8 const menu = el('div', {
9 class: 'editor-format-menu-dropdown editor-dropdown-menu editor-dropdown-menu-vertical',
13 const toggle = el('button', {
14 class: 'editor-format-menu-toggle editor-button',
16 }, [this.trans('Formats')]);
18 const wrapper = el('div', {
19 class: 'editor-format-menu editor-dropdown-menu-container',
22 this.getContext().manager.dropdowns.handle({toggle : toggle, menu : menu});
24 this.onEvent('button-action', () => {
25 this.getContext().manager.dropdowns.closeAll();
31 updateState(state: EditorUiStateUpdate) {
32 super.updateState(state);
34 for (const child of this.children) {
35 if (child instanceof EditorButton && child.isActive()) {
36 this.updateToggleLabel(child.getLabel());
40 if (child instanceof EditorContainerUiElement) {
41 for (const grandchild of child.getChildren()) {
42 if (grandchild instanceof EditorButton && grandchild.isActive()) {
43 this.updateToggleLabel(grandchild.getLabel());
50 this.updateToggleLabel(this.trans('Formats'));
53 protected updateToggleLabel(text: string): void {
54 const button = this.getDOMElement().querySelector('button');
56 button.innerText = text;