2024-06-19 21:19:07 +00:00
|
|
|
import { Controller } from "stimulus";
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Solo se puede mostrar una notificación a la vez
|
|
|
|
*/
|
|
|
|
export default class extends Controller {
|
|
|
|
// @todo Stimulus >1
|
|
|
|
get showClasses() {
|
|
|
|
return (this.element.dataset?.notificationShowClass || "").split(" ").filter(x => x);
|
|
|
|
}
|
|
|
|
|
|
|
|
// @todo Stimulus >1
|
|
|
|
get hideClasses() {
|
|
|
|
return (this.element.dataset?.notificationHideClass || "").split(" ").filter(x => x);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Al recibir el evento de mostrar, si no está dirigido al elemento
|
|
|
|
* actual, se oculta.
|
|
|
|
*/
|
|
|
|
show(event = undefined) {
|
2024-07-04 19:51:08 +00:00
|
|
|
if (event?.detail?.value !== this.element.id) {
|
|
|
|
this.hide({ detail: { value: this.element.id } });
|
2024-06-19 21:19:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.element.classList.remove("d-none");
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
this.element.classList.remove(...this.hideClasses);
|
|
|
|
this.element.classList.add(...this.showClasses);
|
|
|
|
}, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
hide(event = undefined) {
|
2024-07-04 19:51:08 +00:00
|
|
|
if (event?.detail?.value !== this.element.id) return;
|
2024-06-19 21:19:07 +00:00
|
|
|
|
|
|
|
this.element.classList.remove(...this.showClasses);
|
|
|
|
this.element.classList.add(...this.hideClasses);
|
|
|
|
|
|
|
|
setTimeout(() => this.element.classList.add("d-none"), 150);
|
|
|
|
}
|
|
|
|
}
|