From ab0c20a7e805c957c1d61200b917422455e1f747 Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 31 Dec 2024 12:45:40 -0500 Subject: [PATCH 1/2] Fix documentation link --- demo/lib/demo_web/live/tabs/demo.html.heex | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/demo/lib/demo_web/live/tabs/demo.html.heex b/demo/lib/demo_web/live/tabs/demo.html.heex index eab8a60..e986587 100644 --- a/demo/lib/demo_web/live/tabs/demo.html.heex +++ b/demo/lib/demo_web/live/tabs/demo.html.heex @@ -75,7 +75,11 @@

- You can also use arbitrary severity levels. If you want to add another level like "warning", refer to [the documentation here](https://hexdocs.pm/live_toast/readme.html#custom-severity-levels). + You can also use arbitrary severity levels. If you want to add another level like "warning", refer to <.link + href="https://hexdocs.pm/live_toast/readme.html#custom-severity-levels" + class="text-blue-700 hover:text-blue-500 underline" + >the + documentation here.

<.button phx-click="flash" phx-value-kind="warn"> From 1975e87e6b555bf1506f5de30ddc882cea7f1143 Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 31 Dec 2024 12:45:50 -0500 Subject: [PATCH 2/2] Implement infinite duration for toasts --- assets/js/live_toast/live_toast.ts | 13 +++--- demo/lib/demo_web/live/tabs/demo.html.heex | 48 ++++++++++++++++++++++ 2 files changed, 56 insertions(+), 5 deletions(-) diff --git a/assets/js/live_toast/live_toast.ts b/assets/js/live_toast/live_toast.ts index acefe8a..87efa09 100644 --- a/assets/js/live_toast/live_toast.ts +++ b/assets/js/live_toast/live_toast.ts @@ -239,12 +239,15 @@ export function createLiveToastHook(duration = 6000, maxItems = 3) { durationOverride = Number.parseInt(this.el.dataset.duration) } - window.setTimeout(async () => { - // animate this element sliding down, opacity to 0, with delay time - await animateOut.bind(this)() + // you can set duration to 0 for infinite duration, basically + if (durationOverride !== 0) { + window.setTimeout(async () => { + // animate this element sliding down, opacity to 0, with delay time + await animateOut.bind(this)() - this.pushEventTo('#toast-group', 'clear', { id: this.el.id }) - }, durationOverride + removalTime) + this.pushEventTo('#toast-group', 'clear', { id: this.el.id }) + }, durationOverride + removalTime) + } } } } diff --git a/demo/lib/demo_web/live/tabs/demo.html.heex b/demo/lib/demo_web/live/tabs/demo.html.heex index e986587..b609cdc 100644 --- a/demo/lib/demo_web/live/tabs/demo.html.heex +++ b/demo/lib/demo_web/live/tabs/demo.html.heex @@ -88,6 +88,54 @@
+
+

Duration

+

+ You can set the duration of different toasts. If you set duration to 0, they will stay until dismissed (like + flashes). The default duration is 6000ms. +

+
+ <.button phx-click={ + JS.push("toast", + value: %{ + "kind" => "info", + "title" => "Duration", + "body" => "This toast will stay for 1000ms.", + "duration" => 1000 + } + ) + }> + Short Toast + + + <.button phx-click={ + JS.push("toast", + value: %{ + "kind" => "info", + "title" => "Duration", + "body" => "This toast will stay for 8000ms.", + "duration" => 8000 + } + ) + }> + Long Toast + + + <.button phx-click={ + JS.push("toast", + value: %{ + "kind" => "info", + "title" => "Duration", + "body" => "This toast will stay until dismissed.", + "duration" => 0 + } + ) + }> + Infinite Toast + +
+
+

Position