1 import {EditorUiStateUpdate, EditorContainerUiElement} from "../core";
2 import {EditorButton} from "../buttons";
3 import {handleDropdown} from "../helpers/dropdowns";
4 import {el} from "../../../utils/dom";
6 export class EditorFormatMenu extends EditorContainerUiElement {
7 buildDOM(): HTMLElement {
8 const childElements: HTMLElement[] = this.getChildren().map(child => child.getDOMElement());
9 const menu = el('div', {
10 class: 'editor-format-menu-dropdown editor-dropdown-menu editor-dropdown-menu-vertical',
14 const toggle = el('button', {
15 class: 'editor-format-menu-toggle editor-button',
17 }, [this.trans('Formats')]);
19 const wrapper = el('div', {
20 class: 'editor-format-menu editor-dropdown-menu-container',
23 handleDropdown({toggle : toggle, menu : menu});
28 updateState(state: EditorUiStateUpdate) {
29 super.updateState(state);
31 for (const child of this.children) {
32 if (child instanceof EditorButton && child.isActive()) {
33 this.updateToggleLabel(child.getLabel());
37 if (child instanceof EditorContainerUiElement) {
38 for (const grandchild of child.getChildren()) {
39 if (grandchild instanceof EditorButton && grandchild.isActive()) {
40 this.updateToggleLabel(grandchild.getLabel());
47 this.updateToggleLabel(this.trans('Formats'));
50 protected updateToggleLabel(text: string): void {
51 const button = this.getDOMElement().querySelector('button');
53 button.innerText = text;