Sha256: ca5c861164593527ae9eb4233f306f6d29d702d23db11e658bd6fb9ed48108b0

Contents?: true

Size: 1.98 KB

Versions: 273

Compression:

Stored size: 1.98 KB

Contents

import PbEnhancedElement from '../pb_enhanced_element'

const ADVANCED_TABLE_SELECTOR = '[data-advanced-table]'
const CONTENT_SELECTOR = '[data-advanced-table-content="id"]'
const DOWN_ARROW_SELECTOR = '#advanced-table_open_icon'
const UP_ARROW_SELECTOR = '#advanced-table_close_icon'

export default class PbAdvancedTable extends PbEnhancedElement {
  static get selector() {
    return ADVANCED_TABLE_SELECTOR
  }

  get target() {
    return document.querySelector(CONTENT_SELECTOR.replace("id", this.element.id))
  }

  connect() {
    this.element.addEventListener('click', () => {
      this.toggleElement(this.target)
    })
  }

  showElement(elem) {
    const getHeight = () => {
      elem.style.display = 'block'
      const height = elem.scrollHeight + 'px'
      elem.style.display = ''
      return height
    }

    const height = getHeight()
    elem.classList.add('is-visible')
    elem.style.height = height
    elem.style.overflow = "hidden"

    window.setTimeout(() => {
      elem.style.height = ''
      elem.style.overflow = "visible"
    }, 250)
  }

  hideElement(elem) {
    elem.style.height = elem.scrollHeight + 'px'

    window.setTimeout(() => {
      elem.style.height = '0'
      elem.style.paddingTop = '0'
      elem.style.paddingBottom = '0'
      elem.style.overflow = "hidden"
    }, 1)

    window.setTimeout(() => {
      elem.classList.remove('is-visible')
      elem.style.overflow = ""
    }, 200)
  }

  toggleElement(elem) {
    if (elem.classList.contains('is-visible')) {
      this.hideElement(elem)
      this.displayDownArrow()
      return
    }

    this.showElement(elem)
    this.displayUpArrow()
  }

  displayDownArrow() {
    this.element.querySelector(DOWN_ARROW_SELECTOR).style.display = 'inline-block'
    this.element.querySelector(UP_ARROW_SELECTOR).style.display = 'none'
  }

  displayUpArrow() {
    this.element.querySelector(UP_ARROW_SELECTOR).style.display = 'inline-block'
    this.element.querySelector(DOWN_ARROW_SELECTOR).style.display = 'none'
  }
}

Version data entries

273 entries across 273 versions & 1 rubygems

Version Path
playbook_ui-14.3.2.pre.alpha.PBNTR515typeaheadmarginbottomredux3785 app/pb_kits/playbook/pb_advanced_table/index.js
playbook_ui-14.3.2.pre.alpha.revert3614PBNTR455ganttchartPOC3783 app/pb_kits/playbook/pb_advanced_table/index.js
playbook_ui-14.4.0.pre.rc.12 app/pb_kits/playbook/pb_advanced_table/index.js
playbook_ui-14.3.2.pre.alpha.play1472newicons3773 app/pb_kits/playbook/pb_advanced_table/index.js
playbook_ui-14.4.0.pre.rc.11 app/pb_kits/playbook/pb_advanced_table/index.js
playbook_ui-14.3.2.pre.alpha.PBNTR490multilevelselect3771 app/pb_kits/playbook/pb_advanced_table/index.js
playbook_ui-14.4.0.pre.rc.10 app/pb_kits/playbook/pb_advanced_table/index.js
playbook_ui-14.3.2.pre.alpha.PBNTR490multilevelselect3766 app/pb_kits/playbook/pb_advanced_table/index.js
playbook_ui-14.4.0.pre.rc.9 app/pb_kits/playbook/pb_advanced_table/index.js
playbook_ui-14.4.0.pre.rc.8 app/pb_kits/playbook/pb_advanced_table/index.js
playbook_ui-14.3.2.pre.alpha.PBNTR480radiocustomchildrenprop3759 app/pb_kits/playbook/pb_advanced_table/index.js
playbook_ui-14.3.2.pre.alpha.PBNTR515typeaheadmarginbottomredux3756 app/pb_kits/playbook/pb_advanced_table/index.js
playbook_ui-14.4.0.pre.rc.7 app/pb_kits/playbook/pb_advanced_table/index.js
playbook_ui-14.3.2 app/pb_kits/playbook/pb_advanced_table/index.js
playbook_ui-14.4.0.pre.rc.6 app/pb_kits/playbook/pb_advanced_table/index.js
playbook_ui-14.3.1.pre.alpha.PBNTR515typeaheadmarginbottomredux3750 app/pb_kits/playbook/pb_advanced_table/index.js
playbook_ui-14.3.1.pre.alpha.PBNTR515typeaheadmarginbottomredux3752 app/pb_kits/playbook/pb_advanced_table/index.js
playbook_ui-14.3.1.pre.alpha.PBNTR515typeaheadmarginbottomredux3751 app/pb_kits/playbook/pb_advanced_table/index.js
playbook_ui-14.3.1.pre.alpha.PBNTR515typeaheadmarginbottomredux3747 app/pb_kits/playbook/pb_advanced_table/index.js
playbook_ui-14.4.0.pre.rc.5 app/pb_kits/playbook/pb_advanced_table/index.js