Class: SdrViewComponents::Elements::ToastComponent
- Inherits:
-
BaseComponent
- Object
- ViewComponent::Base
- BaseComponent
- SdrViewComponents::Elements::ToastComponent
- Defined in:
- app/components/sdr_view_components/elements/toast_component.rb
Overview
Component for rendering a toast element.
Instance Attribute Summary collapse
-
#close_text ⇒ Object
readonly
Returns the value of attribute close_text.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#variant ⇒ Object
readonly
Returns the value of attribute variant.
Instance Method Summary collapse
- #background_color ⇒ Object
-
#initialize(title:, text: nil, close_text: nil, variant: :black) ⇒ ToastComponent
constructor
A new instance of ToastComponent.
- #toast_body_classes ⇒ Object
Methods inherited from BaseComponent
#args_for, #merge_actions, #merge_classes
Constructor Details
#initialize(title:, text: nil, close_text: nil, variant: :black) ⇒ ToastComponent
Returns a new instance of ToastComponent.
7 8 9 10 11 12 13 |
# File 'app/components/sdr_view_components/elements/toast_component.rb', line 7 def initialize(title:, text: nil, close_text: nil, variant: :black) @title = title @text = text @close_text = close_text @variant = variant super() end |
Instance Attribute Details
#close_text ⇒ Object (readonly)
Returns the value of attribute close_text.
15 16 17 |
# File 'app/components/sdr_view_components/elements/toast_component.rb', line 15 def close_text @close_text end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
15 16 17 |
# File 'app/components/sdr_view_components/elements/toast_component.rb', line 15 def text @text end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
15 16 17 |
# File 'app/components/sdr_view_components/elements/toast_component.rb', line 15 def title @title end |
#variant ⇒ Object (readonly)
Returns the value of attribute variant.
15 16 17 |
# File 'app/components/sdr_view_components/elements/toast_component.rb', line 15 def variant @variant end |
Instance Method Details
#background_color ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/components/sdr_view_components/elements/toast_component.rb', line 21 def background_color case variant when :red 'bg-stanford-digital-red' when :green 'bg-stanford-digital-green' when :poppy 'bg-poppy-dark' else 'bg-stanford-black' end end |
#toast_body_classes ⇒ Object
17 18 19 |
# File 'app/components/sdr_view_components/elements/toast_component.rb', line 17 def toast_body_classes merge_classes([background_color], %w[toast-body text-white]) end |