Sha256: 4837b1af0fc317355a9d415e0ff27af80f526f38800e9af79d2fd258fa06aa7a

Contents?: true

Size: 993 Bytes

Versions: 25

Compression:

Stored size: 993 Bytes

Contents

import { Controller } from "@hotwired/stimulus"
import { useClickOutside } from 'stimulus-use'

// simple controller to hide/show the filter modal
export default class extends Controller {
  static targets = ["frame"]

  static values = {
    src: String,
    isOpen: {type: Boolean, default: false}
  }

  connect() {
    useClickOutside(this)
    this.boundHandleKeyUp = this.handleKeyUp.bind(this)
    document.addEventListener("keyup", this.boundHandleKeyUp)
  }

  disconnect() {
    document.removeEventListener("keyup", this.boundHandleKeyUp)
  }

  show(event) {
    event.preventDefault()
    this.frameTarget.src = this.srcValue;
    this.isOpenValue = true
  }

  hide(event) {
    if (this.isOpenValue) {
      event?.preventDefault()
      this.frameTarget.innerHTML = "";
      this.isOpenValue = false
    }
  }

  clickOutside(event) {
    this.hide(event)
  }

  handleKeyUp(event) {
    if (event.key === "Escape" || event.key === "Esc") {
      this.hide(event)
    }
  }
}

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
refine-rails-2.9.4 app/javascript/controllers/refine/popup-controller.js
refine-rails-2.9.3 app/javascript/controllers/refine/popup-controller.js
refine-rails-2.9.2 app/javascript/controllers/refine/popup-controller.js
refine-rails-2.9.1 app/javascript/controllers/refine/popup-controller.js
refine-rails-2.9.0 app/javascript/controllers/refine/popup-controller.js