Sha256: 0e50bb96f86f14745deb0c574e8ae8d193e0a138330d75b2197b7298cfd5c053

Contents?: true

Size: 1.77 KB

Versions: 131

Compression:

Stored size: 1.77 KB

Contents

import { Controller } from '@hotwired/stimulus'

export default class extends Controller {
  static targets = ['content']

  static values = {
    panelList: Boolean,
  }

  // get the table or grid component, if both null, get the panel body (for show page for example)
  get parentTarget() {
    return document.querySelector('[data-component-name="avo/index/resource_table_component"]')
      || document.querySelector('[data-component-name="avo/index/resource_grid_component"]')
      || document.querySelector('[data-target="panel-body"]')
  }

  childDimensions = null

  parentDimensions = null

  connect() {
    // We need to make the element visible in order to get it's position
    this.element.style.display = 'block'
    this.childDimensions = this.contentTarget.getBoundingClientRect()
    this.element.style.display = ''
    this.parentDimensions = this.parentTarget.getBoundingClientRect()

    this.adjustOverflow()
  }

  adjustOverflow() {
    this.adjustVerticalOverflow()
    this.adjustHorizontalOverflow()
  }

  adjustVerticalOverflow() {
    if (this.contentBottomOverflow) {
      this.contentTarget.classList.remove('top-full', 'mt-2')
      this.contentTarget.classList.add('bottom-full', 'mb-2')
    }
  }

  adjustHorizontalOverflow() {
    if (this.contentLeftOverflow) {
      this.contentTarget.classList.remove('xl:right-0', 'sm:right-0')
      this.contentTarget.classList.add('xl:left-0', 'sm:left-0')
    }
  }

  get contentBottomOverflow() {
    // If the list is on panel header, we don't want to adjust the vertical overflow
    if (this.panelListValue === true) {
      return false
    }

    return this.parentDimensions.bottom < this.childDimensions.bottom
  }

  get contentLeftOverflow() {
    return this.parentDimensions.left > this.childDimensions.left
  }
}

Version data entries

131 entries across 131 versions & 1 rubygems

Version Path
avo-3.0.0.pre13 app/javascript/js/controllers/actions_overflow_controller.js
avo-3.0.0.pre12 app/javascript/js/controllers/actions_overflow_controller.js
avo-3.0.0.pre10 app/javascript/js/controllers/actions_overflow_controller.js
avo-3.0.0.pre11 app/javascript/js/controllers/actions_overflow_controller.js
avo-3.0.0.pre8 app/javascript/js/controllers/actions_overflow_controller.js
avo-3.0.0.pre9 app/javascript/js/controllers/actions_overflow_controller.js
avo-3.0.0.pre7 app/javascript/js/controllers/actions_overflow_controller.js
avo-3.0.0.pre5 app/javascript/js/controllers/actions_overflow_controller.js
avo-3.0.0.pre6 app/javascript/js/controllers/actions_overflow_controller.js
avo-3.0.0.pre4 app/javascript/js/controllers/actions_overflow_controller.js
avo-3.0.0.pre3 app/javascript/js/controllers/actions_overflow_controller.js
avo-3.0.0.pre2 app/javascript/js/controllers/actions_overflow_controller.js
avo-3.0.0.pre1 app/javascript/js/controllers/actions_overflow_controller.js
avo-3.2.2 app/javascript/js/controllers/actions_overflow_controller.js
avo-3.2.1 app/javascript/js/controllers/actions_overflow_controller.js
avo-3.2.0 app/javascript/js/controllers/actions_overflow_controller.js
avo-3.1.7 app/javascript/js/controllers/actions_overflow_controller.js
avo-3.1.6 app/javascript/js/controllers/actions_overflow_controller.js
avo-3.1.5 app/javascript/js/controllers/actions_overflow_controller.js
avo-3.1.4 app/javascript/js/controllers/actions_overflow_controller.js