mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-26 15:06:22 +00:00
44 lines
1.1 KiB
JavaScript
44 lines
1.1 KiB
JavaScript
|
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) {
|
||
|
if (event?.detail?.id !== this.element.id) {
|
||
|
this.hide({ detail: { id: this.element.id } });
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
this.element.classList.remove("d-none");
|
||
|
|
||
|
setTimeout(() => {
|
||
|
this.element.classList.remove(...this.hideClasses);
|
||
|
this.element.classList.add(...this.showClasses);
|
||
|
}, 1);
|
||
|
}
|
||
|
|
||
|
hide(event = undefined) {
|
||
|
if (event?.detail?.id !== this.element.id) return;
|
||
|
|
||
|
this.element.classList.remove(...this.showClasses);
|
||
|
this.element.classList.add(...this.hideClasses);
|
||
|
|
||
|
setTimeout(() => this.element.classList.add("d-none"), 150);
|
||
|
}
|
||
|
}
|