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);
18 this.setActiveTab('files', true);
23 // Toolbox toggle button click
24 this.toggleButton.addEventListener('click', () => this.toggle());
26 this.container.addEventListener('click', event => {
27 const button = event.target.closest('button');
28 if (this.buttons.includes(button)) {
29 const name = button.dataset.tab;
30 this.setActiveTab(name, true);
36 this.container.classList.toggle('open');
37 const expanded = this.container.classList.contains('open') ? 'true' : 'false';
38 this.toggleButton.setAttribute('aria-expanded', expanded);
41 setActiveTab(tabName, openToolbox = false) {
42 // Set button visibility
43 for (const button of this.buttons) {
44 button.classList.remove('active');
45 const bName = button.dataset.tab;
46 if (bName === tabName) button.classList.add('active');
49 // Set content visibility
50 for (const contentEl of this.contentElements) {
51 contentEl.style.display = 'none';
52 const cName = contentEl.dataset.tabContent;
53 if (cName === tabName) contentEl.style.display = 'block';
56 if (openToolbox && !this.container.classList.contains('open')) {