Sha256: 7738c31dcd8ba598ee36ad941e0bbd381e03887265f362fbf46888d89e0aefae

Contents?: true

Size: 929 Bytes

Versions: 7

Compression:

Stored size: 929 Bytes

Contents

import {controllerFactory} from '@utils/createController'
import {computePosition, computePosition, autoUpdate, offset, flip, shift} from '@floating-ui/dom'

export default class PopoverController extends controllerFactory()({
  targets: {
    button: HTMLButtonElement,
    popover: HTMLElement,
  },
  values: {
    placement: String,
  },
}) {
  connect() {
    this.popoverTarget.addEventListener('toggle', (event: ToggleEvent) => {
      if (event.newState === 'open') {
        this.updatePosition()
      }
    })
  }

  updatePosition() {
    autoUpdate(this.buttonTarget, this.popoverTarget, () => {
      computePosition(this.buttonTarget, this.popoverTarget, {
        placement: this.placementValue,
        middleware: [offset(5), flip(), shift({padding: 5})],
      }).then(({x, y}) => {
        Object.assign(this.target.style, {
          left: `${x}px`,
          top: `${y}px`,
        })
      })
    })
  }
}

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ariadne_view_components-0.0.80.3 app/components/ariadne/ui/popover/component.ts
ariadne_view_components-0.0.79.2 app/components/ariadne/ui/popover/component.ts
ariadne_view_components-0.0.79.1 app/components/ariadne/ui/popover/component.ts
ariadne_view_components-0.0.79 app/components/ariadne/ui/popover/component.ts
ariadne_view_components-0.0.78 app/components/ariadne/ui/popover/component.ts
ariadne_view_components-0.0.77 app/components/ariadne/ui/popover/component.ts
ariadne_view_components-0.0.76.1 app/components/ariadne/ui/popover/component.ts