Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A view component for using Shoelace alerts
class FlashComponent < ViewComponent::Base
extend Dry::Initializer
# notice, warning, and error can be set by default in redirect_to.
# For additional flashes, you must do flash[:type] = "message"
primary: "info-circle",
success: "check2-circle",
info: "gear",
warning: "exclamation-triangle",
danger: "exclamation-octagon"
option :type, proc(&:to_s)
option :message, proc(&:to_s)
option :icon, default: proc { |value| (value || ICONS[type.to_sym]).to_s }
option :duration, default: proc { "Infinity" }
option :open, default: proc { true }
option :closable, default: proc { true }
def call
helpers.tag.sl_alert(type: type, open: open, closable: closable, duration: duration) do
helpers.tag.sl_icon(slot: "icon", name: icon) + "\n" + @message
Copy link

ParamagicDev commented Nov 25, 2021

What the 5 flashes look like:

Screen Shot 2021-11-24 at 11 51 30 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment