23 lines
663 B
JavaScript
23 lines
663 B
JavaScript
import { Controller } from '@hotwired/stimulus';
|
|
import Toastify from 'toastify-js';
|
|
|
|
/**
|
|
* Turns one flash message into one toast. The element itself stays empty and invisible --
|
|
* Toastify appends its own node to the body, which is why a toast outlives the out-of-band
|
|
* swap of #flashes that spawned it.
|
|
*/
|
|
export default class extends Controller {
|
|
static values = { text: String, class: String };
|
|
|
|
connect() {
|
|
Toastify({
|
|
text: this.textValue,
|
|
className: this.classValue,
|
|
duration: 5000,
|
|
gravity: 'top',
|
|
position: 'right',
|
|
close: true,
|
|
}).showToast();
|
|
}
|
|
}
|