Skip to content

Instantly share code, notes, and snippets.

@KonnorRogers
Last active March 31, 2023 19:20
Show Gist options
  • Save KonnorRogers/5dc17dea9e8ab414d227461ae521f011 to your computer and use it in GitHub Desktop.
Save KonnorRogers/5dc17dea9e8ab414d227461ae521f011 to your computer and use it in GitHub Desktop.
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
@KonnorRogers
Copy link
Author

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