1 import {Component} from './component';
3 export class EditorToolbox extends Component {
7 this.container = this.$el;
8 this.buttons = this.$manyRefs.tabButton;
9 this.contentElements = this.$manyRefs.tabContent;
10 this.toggleButton = this.$refs.toggle;
11 this.editorWrapEl = this.container.closest('.page-editor');
13 this.setupListeners();
15 // Set the first tab as active on load
16 this.setActiveTab(this.contentElements[0].dataset.tabContent);
20 // Toolbox toggle button click
21 this.toggleButton.addEventListener('click', () => this.toggle());
23 this.container.addEventListener('click', event => {
24 const button = event.target.closest('button');
25 if (this.buttons.includes(button)) {
26 const name = button.dataset.tab;
27 this.setActiveTab(name, true);
33 this.container.classList.toggle('open');
34 const isOpen = this.container.classList.contains('open');
35 this.toggleButton.setAttribute('aria-expanded', isOpen ? 'true' : 'false');
36 this.editorWrapEl.classList.toggle('toolbox-open', isOpen);
39 setActiveTab(tabName, openToolbox = false) {
40 // Set button visibility
41 for (const button of this.buttons) {
42 button.classList.remove('active');
43 const bName = button.dataset.tab;
44 if (bName === tabName) button.classList.add('active');
47 // Set content visibility
48 for (const contentEl of this.contentElements) {
49 contentEl.style.display = 'none';
50 const cName = contentEl.dataset.tabContent;
51 if (cName === tabName) contentEl.style.display = 'block';
54 if (openToolbox && !this.container.classList.contains('open')) {