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 eab8a60..b609cdc 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.
+ 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. +
+