dawarich/app/javascript/controllers/removals_controller.js
2024-12-11 14:21:44 +01:00

28 lines
589 B
JavaScript

import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static values = {
timeout: Number
}
connect() {
if (this.timeoutValue) {
setTimeout(() => {
this.remove()
}, this.timeoutValue)
}
}
remove() {
this.element.classList.add('fade-out')
setTimeout(() => {
this.element.remove()
// Remove the container if it's empty
const container = document.getElementById('flash-messages')
if (container && !container.hasChildNodes()) {
container.remove()
}
}, 150)
}
}