From 4711535321a1f3f4e397737d90917c9fb48469a5 Mon Sep 17 00:00:00 2001 From: Yoonchae Lee Date: Tue, 13 Aug 2024 19:28:18 +0900 Subject: [PATCH 1/2] dynamic height update --- src/lib/components/ToastWrapper.svelte | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/lib/components/ToastWrapper.svelte b/src/lib/components/ToastWrapper.svelte index 406f1d7..a3adabb 100644 --- a/src/lib/components/ToastWrapper.svelte +++ b/src/lib/components/ToastWrapper.svelte @@ -9,11 +9,14 @@ export let toast: DOMToast; export let setHeight: (height: number) => void; - let wrapperEl: HTMLElement; - onMount(() => { - setHeight(wrapperEl.getBoundingClientRect().height); - }); + let clientHeight: number; + function onHeightChange(clientHeight: number) { + if (clientHeight === undefined) return; + setHeight(clientHeight); + } + + $: onHeightChange(clientHeight); $: top = toast.position?.includes('top') ? 0 : null; $: bottom = toast.position?.includes('bottom') ? 0 : null; $: factor = toast.position?.includes('top') ? 1 : -1; @@ -24,7 +27,7 @@
Date: Tue, 13 Aug 2024 19:40:00 +0900 Subject: [PATCH 2/2] change update function to support not clearing timeout --- src/lib/core/store.ts | 4 ++-- src/lib/core/use-toaster.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/core/store.ts b/src/lib/core/store.ts index e563a3f..5fc5c44 100644 --- a/src/lib/core/store.ts +++ b/src/lib/core/store.ts @@ -34,8 +34,8 @@ const clearFromRemoveQueue = (toastId: string) => { } }; -export function update(toast: Partial) { - if (toast.id) { +export function update(toast: Partial, clearTimeout = true) { + if (clearTimeout && toast.id) { clearFromRemoveQueue(toast.id); } toasts.update(($toasts) => $toasts.map((t) => (t.id === toast.id ? { ...t, ...toast } : t))); diff --git a/src/lib/core/use-toaster.ts b/src/lib/core/use-toaster.ts index e93df72..4a34fca 100644 --- a/src/lib/core/use-toaster.ts +++ b/src/lib/core/use-toaster.ts @@ -36,7 +36,7 @@ const handlers = { _endPause(Date.now()); }, updateHeight: (toastId: string, height: number) => { - update({ id: toastId, height }); + update({ id: toastId, height }, false); }, calculateOffset };