mobilizon/js/src/plugins/notifier.ts

52 lines
1.1 KiB
TypeScript

/* eslint-disable no-shadow */
import VueInstance from "vue";
import { ColorModifiers } from "buefy/types/helpers.d";
import { App } from "vue";
declare module "vue" {
interface Vue {
$notifier: {
success: (message: string) => void;
error: (message: string) => void;
info: (message: string) => void;
};
}
}
export class Notifier {
private readonly vue: typeof VueInstance;
constructor(vue: App) {
this.vue = vue;
}
success(message: string): void {
this.notification(message, "is-success");
}
error(message: string): void {
this.notification(message, "is-danger");
}
info(message: string): void {
this.notification(message, "is-info");
}
private notification(message: string, type: ColorModifiers) {
this.vue.config.globalProperties.$buefy.notification.open({
message,
duration: 5000,
position: "is-bottom-right",
type,
hasIcon: true,
});
}
}
/* eslint-disable */
export const NotifierPlugin = {
install(app: App) {
app.config.globalProperties.$notifier = new Notifier(app);
},
};