Sha256: 2572d357abd0881c145bba066b463626d9afd43e58973427b54986f7ac25602b

Contents?: true

Size: 935 Bytes

Versions: 25

Compression:

Stored size: 935 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.buttonTarget.style, {
          left: `${x}px`,
          top: `${y}px`,
        })
      })
    })
  }
}

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
ariadne_view_components-0.0.92 app/components/ariadne/ui/popover/component.ts
ariadne_view_components-0.0.91 app/components/ariadne/ui/popover/component.ts
ariadne_view_components-0.0.90 app/components/ariadne/ui/popover/component.ts
ariadne_view_components-0.0.89.1 app/components/ariadne/ui/popover/component.ts
ariadne_view_components-0.0.89 app/components/ariadne/ui/popover/component.ts
ariadne_view_components-0.0.88 app/components/ariadne/ui/popover/component.ts
ariadne_view_components-0.0.87 app/components/ariadne/ui/popover/component.ts
ariadne_view_components-0.0.86.9 app/components/ariadne/ui/popover/component.ts
ariadne_view_components-0.0.86.8 app/components/ariadne/ui/popover/component.ts
ariadne_view_components-0.0.86.7 app/components/ariadne/ui/popover/component.ts
ariadne_view_components-0.0.86.6 app/components/ariadne/ui/popover/component.ts
ariadne_view_components-0.0.86.5 app/components/ariadne/ui/popover/component.ts
ariadne_view_components-0.0.86.4 app/components/ariadne/ui/popover/component.ts
ariadne_view_components-0.0.86.3 app/components/ariadne/ui/popover/component.ts
ariadne_view_components-0.0.86.2 app/components/ariadne/ui/popover/component.ts
ariadne_view_components-0.0.86.1 app/components/ariadne/ui/popover/component.ts
ariadne_view_components-0.0.86 app/components/ariadne/ui/popover/component.ts
ariadne_view_components-0.0.85 app/components/ariadne/ui/popover/component.ts
ariadne_view_components-0.0.84 app/components/ariadne/ui/popover/component.ts
ariadne_view_components-0.0.83.3 app/components/ariadne/ui/popover/component.ts