sezaru

sezaru

Hey everyone,

I made a small library to extend the current flash notification functionality from Phoenix and LiveView.

Flashy is a simple replacement for the built-in flash support and components that ships with Phoenix.

Features:

  • Keep notifications between redirects;
  • Support rendering function and live components as notifications;
  • Support auto-hide;
  • Supports creation of custom notifications;
  • No Javascript library is used.

Here is small video showing it is practice:

You can check it out here: GitHub - sezaru/flashy: Flashy is a small library that extends LiveView's flash support to function and live components. · GitHub
If you want to test it out first, you can clone my example project here: GitHub - sezaru/flashy_example: Small project showing Flashy features · GitHub

Showing Posts 1 to 10

TwistingTwists

TwistingTwists

Lovely stuff. Would give this a spin on first chance I get. :slight_smile:

christhekeele

christhekeele

This looks amazing, I’ll try to incorporate it into my next project for sure, if they are customizable enough in animation direction!

Morotai

Morotai

awesome stuff. I imaging these notifications (including the default flash) could be trigger on any page say when I am looking at a list but I have another important list I want to monitor that is not on the current page?

sezaru

sezaru OP

I didn’t make it customizable in that regard.

TBH I think the library can be more flexible in some regards like this one, for example, the code that do the transitions are in this file: flashy/lib/flashy/helpers.ex at master · sezaru/flashy · GitHub

We could make it like a behavior so you can replace it with something else, but I didn’t do it yet since I was not sure what are people requirements and use cases.

sezaru

sezaru OP

I’m not sure if I got the question right, but you should expect similar behavior to Phoenix flash since it uses it behind the scenes. As long as you have access to the page socket, you can add notifications to it and also to another page if you redirect.

Just to give some more context, what I mean as using flash behind the scenes is because that the built-in flash architecture from phoenix working like a key, value map.

Normally, with the flash_group component, you will send the kind of flash (:info, :error , etc) as the key and flash_group will show that. That’s why you can’t stack multiple :info flashs at the same time, because they will have the same key and its value will just be replaced.

What flashy does is two things, the first it use something else as the key, to be more specific I use a string like this as the key:

    key =
      :erlang.unique_integer([:positive, :monotonic])
      |> to_string()
      |> then(&"flashy-#{&1}")

    LiveView.put_flash(socket, key, notification)

That guarantees that each notification is unique and will not conflict one with another when showing them in the screen.

The other thing is that flashy uses a notification struct as the value, not a message. You can put whatever data you want inside that struct, but the only requirement is that you implement the Flashy.Protocol for it. That protocol will tell Flashy which component/live component to render.

christhekeele

christhekeele

Definitely the right call—better to not introduce the wrong abstraction early on until you have more use-cases.

For context, I maintain two LiveView PWAs and so to look good on mobile devices, my notifications tend to be banners that animate down from the top of the viewport; full-width on mobile and fixed-width on larger devices.

Those are nice, clean Phoenix.LiveView.JS structs that should be easy to let be more configurable! If I were tasked to make it more extensible, I’d probably start with allowing per-notification animations similar to other options, ex a @notification.options.show_animation, with fallbacks to your existing implementation.

I imagine after letting that cook for a while, some patterns for re-use would emerge out of realworld codebases—perhaps a callback module, or extra options to use Flashy.Normal, or project-wide config :flashy, :animations-type stuff!

sezaru

sezaru OP

Hey everyone,

I just pushed a new version of Flashy 0.2.0.

The main features of this version are:

  • Fixed a bug that would not show notifications in the correct order;
  • Added support to fully customize the components CSS and transitions.

@christhekeele I think this version will have all the customization you probably need.

I added a new section to the README explaining step-by-step how to customize the notifications to make them show in the left side as an example, you can find it here:
https://github.com/sezaru/flashy#customizing-css

I also added a branch called left_side_notifications to the flashy_example repo with these customization in case someone want to just see it in action.

victorbjorklund

victorbjorklund

Fantastic package! Been wanting this for a while! Just one question, perhaps I made a mistake, but it doesn’t seem to work at all on dead views. For example if we have a redirect due to “require_authenticated_user” plug and we add a message it crashes even if it redirects to a LiveView page. Is this expected behaviour or do I miss something?

sezaru

sezaru OP

Oh, I never tested deadviews, do you have a small code example that triggers the problem for me to try it by any chance?

lc0815

lc0815

love it mucho , thanks for your effort

Where Next? Top

Trending in Announcing Top

woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
MRdotB
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New
woylie
I released Doggo, a collection of unstyled Phoenix components. https://github.com/woylie/doggo Features Unstyled Phoenix components....
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
anuaralfetahe
Hello Published a new library - ProcessHub! ProcessHub is a library designed to manage process distribution within the Elixir cluster. ...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
sergio
It’s not that it’s vocabulary is too advanced. It’s something worse. I get lost trying to follow even a paragraph written by Claude. It’...
New
AstonJ
This showed up on my feed.. anyone heard of it? Just hype? Ox Alpha is a reasoning model designed for coding, sustained ag...
New
bartblast
Hey folks, I just published a post about Hologram’s funding and where the project goes next - the short version: Curiosum as Main Spons...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews