Files
fizzy/app/javascript/controllers/dialog_controller.js
T
2024-10-06 10:36:51 -04:00

35 lines
597 B
JavaScript

import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static targets = [ "dialog" ]
static values = {
modal: { type: Boolean, default: false }
}
open() {
const modal = this.modalValue
if (modal) {
this.dialogTarget.showModal()
} else {
this.dialogTarget.show()
}
}
toggle() {
if (this.dialogTarget.open) {
this.close()
} else {
this.open()
}
}
close() {
this.dialogTarget.close()
}
closeOnClickOutside({ target }) {
if (!this.element.contains(target)) this.close()
}
}