constructor()

in doc/src/js/options/Folder.js [11:44]


  constructor(opts) {
    const options = opts ?? {};
    this.container = document.createElement('div');

    this.parent = options.parent;
    if (!this.parent) {
      this.container.classList.add('example-option-container');
    }
    this.folder = document.createElement('div');
    this.folder.classList.add(this.parent ? 'folder' : 'root');
    if (options.open) {
      this.folder.classList.add('active');
    }
    const rootName = options.open ? 'Close Controls' : 'Open Controls';
    this.name = document.createElement('span');
    this.name.textContent = options.parent ? options.name : rootName;
    this.folder.appendChild(this.name);

    this.content = document.createElement('div');
    this.content.style.display = options.open ? 'block' : 'none';
    this.content.classList.add('content');
    this.container.appendChild(this.folder);
    this.container.appendChild(this.content);

    this.folder.addEventListener('click', () => {
      const display = this.content.style.display === 'block' ? 'none' : 'block';
      if (!this.parent) {
        this.name.textContent =
          display === 'block' ? 'Close Controls' : 'Open Controls';
      }
      this.folder.classList.toggle('active');
      this.content.style.display = display;
    });
  }