ds4/src/module/ui/notifications.ts

38 lines
1.2 KiB
TypeScript
Raw Normal View History

const notifications = {
info: (message: string, { permanent = false }: { permanent?: boolean } = {}): void => {
if (ui.notifications) {
ui.notifications.info(message, { permanent });
} else {
console.info(message);
}
},
warn: (message: string, { permanent = false }: { permanent?: boolean } = {}): void => {
if (ui.notifications) {
ui.notifications.warn(message, { permanent });
} else {
console.log(message);
}
},
error: (message: string, { permanent = false }: { permanent?: boolean } = {}): void => {
if (ui.notifications) {
ui.notifications.error(message, { permanent });
} else {
console.warn(message);
}
},
notify: (
message: string,
type: "info" | "warning" | "error" = "info",
{ permanent = false }: { permanent?: boolean } = {},
): void => {
if (ui.notifications) {
ui.notifications.notify(message, type, { permanent });
} else {
const log = { info: console.info, warning: console.warn, error: console.error }[type];
log(message);
}
},
};
export default notifications;