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.4.0 app/javascript/js/controllers/actions_overflow_controller.js
avo-3.3.6 app/javascript/js/controllers/actions_overflow_controller.js
avo-3.3.5 app/javascript/js/controllers/actions_overflow_controller.js
avo-3.3.4 app/javascript/js/controllers/actions_overflow_controller.js
avo-3.3.3 app/javascript/js/controllers/actions_overflow_controller.js
avo-3.3.2 app/javascript/js/controllers/actions_overflow_controller.js
avo-3.3.1 app/javascript/js/controllers/actions_overflow_controller.js
avo-3.3.0 app/javascript/js/controllers/actions_overflow_controller.js
avo-3.2.3 app/javascript/js/controllers/actions_overflow_controller.js
avo-3.0.1.beta23 app/javascript/js/controllers/actions_overflow_controller.js
avo-3.0.1.beta20 app/javascript/js/controllers/actions_overflow_controller.js
avo-3.0.1.beta21 app/javascript/js/controllers/actions_overflow_controller.js
avo-3.0.1.beta17 app/javascript/js/controllers/actions_overflow_controller.js
avo-3.0.1.beta22 app/javascript/js/controllers/actions_overflow_controller.js
avo-3.0.1.beta18 app/javascript/js/controllers/actions_overflow_controller.js
avo-3.0.1.beta19 app/javascript/js/controllers/actions_overflow_controller.js
avo-3.0.1.beta24 app/javascript/js/controllers/actions_overflow_controller.js
avo-3.0.1.beta15 app/javascript/js/controllers/actions_overflow_controller.js
avo-3.0.1.beta16 app/javascript/js/controllers/actions_overflow_controller.js
avo-3.0.1.beta14 app/javascript/js/controllers/actions_overflow_controller.js