-
-
Notifications
You must be signed in to change notification settings - Fork 572
Expand file tree
/
Copy pathtoast_controller.js
More file actions
26 lines (24 loc) · 888 Bytes
/
toast_controller.js
File metadata and controls
26 lines (24 loc) · 888 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { Controller } from "@hotwired/stimulus"
// Connects to data-controller="toast"
// Shows a toastr notification when the element is rendered.
//
// Usage:
// <div data-controller="toast" data-toast-message-value="Hello!" data-toast-type-value="info"></div>
//
export default class extends Controller {
static values = {
message: String,
type: { type: String, default: "info" },
timeout: { type: Number, default: 5000 },
position: { type: String, default: "toast-top-center" }
}
connect() {
const previousTimeout = toastr.options.timeOut;
const previousPosition = toastr.options.positionClass;
toastr.options.timeOut = this.timeoutValue;
toastr.options.positionClass = this.positionValue;
toastr[this.typeValue](this.messageValue);
toastr.options.timeOut = previousTimeout;
toastr.options.positionClass = previousPosition;
}
}