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.5.0.pre.alpha.PLAY1548intltelinputupdatelatest4037 app/pb_kits/playbook/pb_advanced_table/index.js
playbook_ui-14.5.0.pre.alpha.20241007playbookwebsiteaddrdbms4036 app/pb_kits/playbook/pb_advanced_table/index.js
playbook_ui-14.5.0.pre.alpha.PBNTR606multilevelselectreset4035 app/pb_kits/playbook/pb_advanced_table/index.js
playbook_ui-14.5.0.pre.alpha.PLAY1548intltelinputupdatelatest4032 app/pb_kits/playbook/pb_advanced_table/index.js
playbook_ui-14.5.0.pre.alpha.PLAY1548intltelinputupdatelatest4028 app/pb_kits/playbook/pb_advanced_table/index.js
playbook_ui-14.6.0.pre.rc.12 app/pb_kits/playbook/pb_advanced_table/index.js
playbook_ui-14.6.0.pre.rc.11 app/pb_kits/playbook/pb_advanced_table/index.js
playbook_ui-14.6.0.pre.rc.10 app/pb_kits/playbook/pb_advanced_table/index.js
playbook_ui-14.6.0.pre.rc.9 app/pb_kits/playbook/pb_advanced_table/index.js
playbook_ui-14.6.0.pre.rc.8 app/pb_kits/playbook/pb_advanced_table/index.js
playbook_ui-14.6.0.pre.rc.7 app/pb_kits/playbook/pb_advanced_table/index.js
playbook_ui-14.6.0.pre.rc.6 app/pb_kits/playbook/pb_advanced_table/index.js
playbook_ui-14.6.0.pre.rc.5 app/pb_kits/playbook/pb_advanced_table/index.js
playbook_ui-14.5.0.pre.alpha.PLAY1510railsformloading3977 app/pb_kits/playbook/pb_advanced_table/index.js
playbook_ui-14.5.0.pre.alpha.PLAY1510railsformloading3976 app/pb_kits/playbook/pb_advanced_table/index.js
playbook_ui-14.5.0.pre.alpha.PLAY1510railsformloading3975 app/pb_kits/playbook/pb_advanced_table/index.js
playbook_ui-14.6.0.pre.rc.4 app/pb_kits/playbook/pb_advanced_table/index.js
playbook_ui-14.6.0.pre.rc.3 app/pb_kits/playbook/pb_advanced_table/index.js
playbook_ui-14.6.0.pre.rc.2 app/pb_kits/playbook/pb_advanced_table/index.js
playbook_ui-14.5.0.pre.alpha.PLAY1486highchartscssdrivenPOC3954 app/pb_kits/playbook/pb_advanced_table/index.js