upend/webui/src/lib/notifications.ts

28 lines
579 B
TypeScript
Raw Normal View History

import mitt from "mitt";
type NotifyEvents = {
notification: UpNotification;
};
2021-12-22 11:56:06 +01:00
export type UpNotificationLevel = "info" | "warning" | "error";
export interface INotification {
id: string;
content: string;
2021-12-22 11:56:06 +01:00
level: UpNotificationLevel;
}
export class UpNotification implements INotification {
id: string;
content: string;
2021-12-22 11:56:06 +01:00
level: UpNotificationLevel;
2021-12-22 11:56:06 +01:00
constructor(content: string, level?: UpNotificationLevel) {
this.id = String(Math.random());
this.content = content;
this.level = level || "info";
}
}
export const notify = mitt<NotifyEvents>();