Skip to content

Commit 8848683

Browse files
feat: Migrate component Toasts to Svelte 5 (#668)
# Motivation Migrating component `Toasts` to Svelte 5.
1 parent 9c726be commit 8848683

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/lib/components/Toasts.svelte

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,24 @@
22
import { toastsStore } from "$lib/stores/toasts.store";
33
import Toast from "./Toast.svelte";
44
import { layoutBottomOffset } from "$lib/stores/layout.store";
5-
import type { ToastMsg, ToastPosition } from "$lib/types/toast";
5+
import type { ToastPosition } from "$lib/types/toast";
66
7-
export let position: ToastPosition = "bottom";
8-
export let maxVisible: number | undefined = undefined;
7+
interface Props {
8+
position?: ToastPosition;
9+
maxVisible?: number;
10+
}
11+
12+
let { position = "bottom", maxVisible }: Props = $props();
913
10-
let toasts: ToastMsg[] = [];
11-
$: toasts = $toastsStore
12-
.filter(({ position: pos }) => (pos ?? "bottom") === position)
13-
.slice(0, maxVisible);
14+
let toasts = $derived(
15+
$toastsStore
16+
.filter(({ position: pos }) => (pos ?? "bottom") === position)
17+
.slice(0, maxVisible),
18+
);
1419
15-
let hasErrors: boolean;
16-
$: hasErrors =
17-
toasts.find(({ level }) => ["error", "warn"].includes(level)) !== undefined;
20+
let hasErrors = $derived(
21+
toasts.find(({ level }) => ["error", "warn"].includes(level)) !== undefined,
22+
);
1823
</script>
1924

2025
{#if toasts.length > 0}
@@ -41,7 +46,7 @@
4146
// If a bottom sheet is displayed the toasts should have a related offset
4247
bottom: calc(var(--layout-bottom-offset, 0) + var(--padding-2x));
4348
44-
// A little narrowwer than the section to differentiate notifications from content
49+
// A little narrower than the section to differentiate notifications from content
4550
width: calc(100% - var(--padding-8x) - var(--padding-0_5x));
4651
4752
display: flex;
@@ -55,7 +60,7 @@
5560
}
5661
5762
@include media.min-width(medium) {
58-
// A little narrowwer than the section to differentiate notifications from content
63+
// A little narrower than the section to differentiate notifications from content
5964
max-width: calc(var(--section-max-width) - var(--padding-2x));
6065
}
6166
}

0 commit comments

Comments
 (0)