dawarich/app/javascript/controllers/removals_controller.js

29 lines
592 B
JavaScript
Raw Normal View History

import BaseController from "./base_controller"
2024-01-03 06:13:00 -05:00
export default class extends BaseController {
2024-12-11 08:21:44 -05:00
static values = {
timeout: Number
}
connect() {
if (this.timeoutValue) {
setTimeout(() => {
this.remove()
}, this.timeoutValue)
}
}
2024-01-03 06:13:00 -05:00
remove() {
2024-12-11 08:21:44 -05:00
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)
2024-01-03 06:13:00 -05:00
}
}