Skip to content

Instantly share code, notes, and snippets.

Embed
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"
ICONS = {
primary: "info-circle",
success: "check2-circle",
info: "gear",
warning: "exclamation-triangle",
danger: "exclamation-octagon"
}.freeze
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
end
end
end
@ParamagicDev
Copy link
Author

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