ldc-supportweb/resources/ts/modules/toast.ts

36 lines
1.1 KiB
TypeScript
Raw Normal View History

import Toastify, { Options } from "toastify-js";
2022-08-30 13:21:07 +00:00
export default {
methods: {
toast(
message: string,
duration = 4000,
style: Record<string, string>,
2022-08-30 13:21:07 +00:00
className = "notifications"
): void {
const options: Options = {
duration: duration,
newWindow: false,
close: true,
className: className,
gravity: "top",
offset: {
x: "2em",
y: "3em",
},
style: style,
2022-08-30 13:21:07 +00:00
// * Prevents dismissing of toast on hover
stopOnFocus: true,
};
options.text = message;
Toastify(options).showToast();
},
notify(message: string, duration = 4000, style = {}): void {
this.toast(message, duration, style, "notifications");
2022-08-30 13:21:07 +00:00
},
errorNotify(message: string, duration = 4000, style = {}): void {
this.toast(message, duration, style, "notifications error");
2022-08-30 13:21:07 +00:00
},
},
};