|  | 
| 2 | 2 |   import { toastsStore } from "$lib/stores/toasts.store"; | 
| 3 | 3 |   import Toast from "./Toast.svelte"; | 
| 4 | 4 |   import { layoutBottomOffset } from "$lib/stores/layout.store"; | 
| 5 |  | -  import type { ToastMsg, ToastPosition } from "$lib/types/toast"; | 
|  | 5 | +  import type { ToastPosition } from "$lib/types/toast"; | 
| 6 | 6 | 
 | 
| 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(); | 
| 9 | 13 | 
 | 
| 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 | +  ); | 
| 14 | 19 | 
 | 
| 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 | +  ); | 
| 18 | 23 | </script> | 
| 19 | 24 | 
 | 
| 20 | 25 | {#if toasts.length > 0} | 
|  | 
| 41 | 46 |     // If a bottom sheet is displayed the toasts should have a related offset | 
| 42 | 47 |     bottom: calc(var(--layout-bottom-offset, 0) + var(--padding-2x)); | 
| 43 | 48 | 
 | 
| 44 |  | -    // A little narrowwer than the section to differentiate notifications from content | 
|  | 49 | +    // A little narrower than the section to differentiate notifications from content | 
| 45 | 50 |     width: calc(100% - var(--padding-8x) - var(--padding-0_5x)); | 
| 46 | 51 | 
 | 
| 47 | 52 |     display: flex; | 
|  | 
| 55 | 60 |     } | 
| 56 | 61 | 
 | 
| 57 | 62 |     @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 | 
| 59 | 64 |       max-width: calc(var(--section-max-width) - var(--padding-2x)); | 
| 60 | 65 |     } | 
| 61 | 66 |   } | 
|  | 
0 commit comments