livewire-flash icon indicating copy to clipboard operation
livewire-flash copied to clipboard

[Request] Add autodismiss option

Open sat-on-site opened this issue 3 years ago • 5 comments

Hello, good package! First of all, thank you for your work.

I think it would be interesting to include a auto-dismiss option.

sat-on-site avatar Jul 12 '21 17:07 sat-on-site

Hey, thanks! Glad the package is coming in handy.

I have thought about this too, and would like to see this implemented. I'll see what I can do here but my time is a bit limited. My thoughts:

  • should be vanilla Javascript
  • should be able to get basic POC via conditionally adding a setTimeout for calling @this.dismiss() inside the message component.

Some nice-to-have:

  • would like to have some sort of a visual indicator on the message itself that it will disappear... progress bar or something.
  • would also be nice if hovering over the alert would pause the auto-dismiss

If you have any suggestions, or even a quick PR, that would be great. Thanks!

mattlibera avatar Jul 16 '21 14:07 mattlibera

@sat-on-site Naturally I ended up poking at this today to satisfy my curiosity.

I think I have a rough solution that checks all the boxes, but could probably use some tweaking / cleaning up.

If you would like to play around, please feel free to use the feature/auto-dismiss-v2 branch. Syntax should be:

flash('My Message')->dismissAfter(4)->info()->livewire($this);

My biggest concern is figuring out how to get the additional JS and CSS that are needed loaded in properly. But this should at least be a starting point.

mattlibera avatar Jul 16 '21 20:07 mattlibera

did you get this working? would be nice to have this in the main branch

MACscr avatar Jan 20 '22 00:01 MACscr

Hey @MACscr - I will need to see if I can find some time to review what I hacked together. I remember feeling OK-but-not-great about what I ended up doing.

Have you been using the feature branch? If so, any feedback?

mattlibera avatar Feb 01 '22 21:02 mattlibera

Hey @mattlibera thanks for the package!

For a quick and dirty auto dismiss here, what I use:

<div class="mx-5"  x-data="{showFlash: true}" x-show="showFlash" x-init="setTimeout(() => showFlash = false, 2000)">
    <livewire:flash-container/>
</div>

Maybe helps for others until you publish the new version.

Gelidan avatar May 09 '23 13:05 Gelidan