Class: Practical::Views::FlashMessagesComponent
- Inherits:
-
BaseComponent
- Object
- ViewComponent::Base
- BaseComponent
- Practical::Views::FlashMessagesComponent
- Defined in:
- app/components/practical/views/flash_messages_component.rb
Instance Method Summary collapse
- #alert_toast ⇒ Object
- #call ⇒ Object
- #notice_toast ⇒ Object
- #render_toast(color_variant:, data:, default_icon:) ⇒ Object
- #success_toast ⇒ Object
- #toasts ⇒ Object
Methods included from ElementHelper
Instance Method Details
#alert_toast ⇒ Object
35 36 37 38 39 40 41 |
# File 'app/components/practical/views/flash_messages_component.rb', line 35 def alert_toast render_toast( color_variant: :warning, data: helpers.flash[:alert], default_icon: icon_set.alert_icon ) end |
#call ⇒ Object
4 5 6 7 8 9 |
# File 'app/components/practical/views/flash_messages_component.rb', line 4 def call = toasts tag.aside(class: 'notification-messages wa-stack') do safe_join() if .present? end end |
#notice_toast ⇒ Object
27 28 29 30 31 32 33 |
# File 'app/components/practical/views/flash_messages_component.rb', line 27 def notice_toast render_toast( color_variant: :neutral, data: helpers.flash[:notice], default_icon: icon_set.info_icon ) end |
#render_toast(color_variant:, data:, default_icon:) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/components/practical/views/flash_messages_component.rb', line 43 def render_toast(color_variant:, data:, default_icon:) return nil if data.nil? case data when String = data icon = default_icon when Hash data = data.with_indifferent_access = data[:message] icon = data[:icon] end component = Practical::Views::ToastComponent.new(color_variant: color_variant) render component do |component| if icon.present? && (icon.is_a?(Hash) || icon.is_a?(ViewComponent::Base)) if icon.is_a?(Hash) icon = Practical::Views::IconComponent.new(**icon.to_h.symbolize_keys) end component.with_icon do render icon end end end end |
#success_toast ⇒ Object
19 20 21 22 23 24 25 |
# File 'app/components/practical/views/flash_messages_component.rb', line 19 def success_toast render_toast( color_variant: :success, data: helpers.flash[:success], default_icon: icon_set.success_icon ) end |
#toasts ⇒ Object
11 12 13 14 15 16 17 |
# File 'app/components/practical/views/flash_messages_component.rb', line 11 def toasts [ alert_toast, notice_toast, success_toast, ].compact end |