aboutsummaryrefslogtreecommitdiff
path: root/src/lib/Notification
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/Notification')
-rw-r--r--src/lib/Notification/Notification.svelte12
-rw-r--r--src/lib/Notification/NotificationsProvider.svelte6
-rw-r--r--src/lib/Notification/options.ts36
-rw-r--r--src/lib/Notification/store.ts38
4 files changed, 47 insertions, 45 deletions
diff --git a/src/lib/Notification/Notification.svelte b/src/lib/Notification/Notification.svelte
index 4e6fd2e7..76775ff3 100644
--- a/src/lib/Notification/Notification.svelte
+++ b/src/lib/Notification/Notification.svelte
@@ -1,20 +1,20 @@
<script lang="ts">
-import settings from '$stores/settings';
-import { onMount } from 'svelte';
-import type { Notification } from './store';
+import settings from "$stores/settings";
+import { onMount } from "svelte";
+import type { Notification } from "./store";
export let notification: Notification;
export let onRemove: () => void = () => {
- return;
+ return;
};
export let removed = false;
onMount(() => setTimeout(remove, notification.duration));
const remove = () => {
- removed = true;
+ removed = true;
- setTimeout(onRemove, 150);
+ setTimeout(onRemove, 150);
};
</script>
diff --git a/src/lib/Notification/NotificationsProvider.svelte b/src/lib/Notification/NotificationsProvider.svelte
index 15e5f2b2..c346aceb 100644
--- a/src/lib/Notification/NotificationsProvider.svelte
+++ b/src/lib/Notification/NotificationsProvider.svelte
@@ -1,11 +1,11 @@
<script lang="ts">
-import { notifications } from './store';
-import EventNotification from './Notification.svelte';
+import { notifications } from "./store";
+import EventNotification from "./Notification.svelte";
export let zIndex = 5000;
const handleRemove = (id: string) => {
- notifications.remove(id);
+ notifications.remove(id);
};
</script>
diff --git a/src/lib/Notification/options.ts b/src/lib/Notification/options.ts
index be972a7e..28eeecb3 100644
--- a/src/lib/Notification/options.ts
+++ b/src/lib/Notification/options.ts
@@ -1,24 +1,26 @@
-type Position = 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left';
+type Position = "top-right" | "top-left" | "bottom-right" | "bottom-left";
export interface Options {
- heading: string;
- description?: string;
- position: Position;
- duration: number;
- id: string;
+ heading: string;
+ description?: string;
+ position: Position;
+ duration: number;
+ id: string;
}
export const options = (preferences: {
- heading: string;
- description?: string;
- position?: string;
- duration?: number;
+ heading: string;
+ description?: string;
+ position?: string;
+ duration?: number;
}): Options => {
- return {
- position: (preferences.position || 'top-right') as Position,
- duration: preferences.duration || 3000,
- heading: preferences.heading,
- description: preferences.description,
- id: Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15)
- };
+ return {
+ position: (preferences.position || "top-right") as Position,
+ duration: preferences.duration || 3000,
+ heading: preferences.heading,
+ description: preferences.description,
+ id:
+ Math.random().toString(36).substring(2, 15) +
+ Math.random().toString(36).substring(2, 15),
+ };
};
diff --git a/src/lib/Notification/store.ts b/src/lib/Notification/store.ts
index 0cb4cf96..4eb163f9 100644
--- a/src/lib/Notification/store.ts
+++ b/src/lib/Notification/store.ts
@@ -1,32 +1,32 @@
-import { writable } from 'svelte/store';
+import { writable } from "svelte/store";
export interface Notification {
- id: string;
- heading: string;
- description?: string;
- duration?: number;
+ id: string;
+ heading: string;
+ description?: string;
+ duration?: number;
}
function createNotificationStore() {
- const { subscribe, update } = writable<Notification[]>([]);
+ const { subscribe, update } = writable<Notification[]>([]);
- return {
- subscribe,
- add: (notification: Omit<Notification, 'id'>) => {
- const id = crypto.randomUUID();
+ return {
+ subscribe,
+ add: (notification: Omit<Notification, "id">) => {
+ const id = crypto.randomUUID();
- update((notifications) => [...notifications, { ...notification, id }]);
+ update((notifications) => [...notifications, { ...notification, id }]);
- return id;
- },
- remove: (id: string) => {
- update((notifications) => notifications.filter((n) => n.id !== id));
- }
- };
+ return id;
+ },
+ remove: (id: string) => {
+ update((notifications) => notifications.filter((n) => n.id !== id));
+ },
+ };
}
export const notifications = createNotificationStore();
-export function addNotification(notification: Omit<Notification, 'id'>) {
- return notifications.add(notification);
+export function addNotification(notification: Omit<Notification, "id">) {
+ return notifications.add(notification);
}