dawarich/app/javascript/controllers/removals_controller.js
2025-02-15 16:48:03 +01:00

28 lines
592 B
JavaScript

import BaseController from "./base_controller"
export default class extends BaseController {
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)
}
}