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;
12 this.setupListeners();
14 // Set the first tab as active on load
15 this.setActiveTab(this.contentElements[0].dataset.tabContent);
19 // Toolbox toggle button click
20 this.toggleButton.addEventListener('click', () => this.toggle());
22 this.container.addEventListener('click', event => {
23 const button = event.target.closest('button');
24 if (this.buttons.includes(button)) {
25 const name = button.dataset.tab;
26 this.setActiveTab(name, true);
32 this.container.classList.toggle('open');
33 const expanded = this.container.classList.contains('open') ? 'true' : 'false';
34 this.toggleButton.setAttribute('aria-expanded', expanded);
37 setActiveTab(tabName, openToolbox = false) {
39 // Set button visibility
40 for (const button of this.buttons) {
41 button.classList.remove('active');
42 const bName = button.dataset.tab;
43 if (bName === tabName) button.classList.add('active');
46 // Set content visibility
47 for (const contentEl of this.contentElements) {
48 contentEl.style.display = 'none';
49 const cName = contentEl.dataset.tabContent;
50 if (cName === tabName) contentEl.style.display = 'block';
53 if (openToolbox && !this.container.classList.contains('open')) {