25 lines
617 B
JavaScript
25 lines
617 B
JavaScript
import { Toast } from 'bootstrap/dist/js/bootstrap.js';
|
|
import { Controller } from "@hotwired/stimulus"
|
|
|
|
export default class ToastController extends Controller {
|
|
static targets = ['title', 'body'];
|
|
|
|
initialize() {
|
|
this._toast = new Toast(this.element);
|
|
}
|
|
|
|
showToast(ev) {
|
|
let toastDetails = ev.detail;
|
|
if (!toastDetails) {
|
|
return;
|
|
}
|
|
|
|
this.titleTarget.innerText = toastDetails.title || "Title";
|
|
this.bodyTarget.innerText = toastDetails.body || "Body";
|
|
|
|
if (!this._toast.isShown()) {
|
|
this._toast.show();
|
|
}
|
|
}
|
|
}
|