A view component for using Shoelace alerts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What the 5 flashes look like: