Class: NitroKit::Toast::FlashMessages
- Inherits:
-
Toast
- Object
- Toast
- NitroKit::Toast::FlashMessages
- Defined in:
- app/components/nitro_kit/toast.rb
Constant Summary collapse
- VARIANT_BY_SEVERITY =
{ "alert" => :error, "error" => :error, "warning" => :warning, "success" => :success, "info" => :info, "notice" => :default }.freeze
Instance Attribute Summary collapse
-
#flash ⇒ Object
readonly
Returns the value of attribute flash.
Instance Method Summary collapse
-
#initialize(flash:, duration: 5_000, label: I18n.t("nitro_kit.toast.label"), id: DEFAULT_ID, html: {}, aria: {}, data: {}, desperately_need_a_class: nil) ⇒ FlashMessages
constructor
A new instance of FlashMessages.
- #view_template ⇒ Object
Constructor Details
#initialize(flash:, duration: 5_000, label: I18n.t("nitro_kit.toast.label"), id: DEFAULT_ID, html: {}, aria: {}, data: {}, desperately_need_a_class: nil) ⇒ FlashMessages
Returns a new instance of FlashMessages.
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'app/components/nitro_kit/toast.rb', line 109 def initialize( flash:, duration: 5_000, label: I18n.t("nitro_kit.toast.label"), id: DEFAULT_ID, html: {}, aria: {}, data: {}, desperately_need_a_class: nil ) unless flash.respond_to?(:each) raise ArgumentError, "Toast::FlashMessages flash must be enumerable" end @flash = flash super( duration:, label:, id:, html:, aria:, data:, desperately_need_a_class: ) end |
Instance Attribute Details
#flash ⇒ Object (readonly)
Returns the value of attribute flash.
136 137 138 |
# File 'app/components/nitro_kit/toast.rb', line 136 def flash @flash end |
Instance Method Details
#view_template ⇒ Object
138 139 140 141 142 143 144 145 146 147 |
# File 'app/components/nitro_kit/toast.rb', line 138 def view_template super do |toast| flash.each do |severity, | toast.item( description: .to_s, variant: VARIANT_BY_SEVERITY.fetch(severity.to_s, :default) ) end end end |