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. The disappearing toast uses ‘sdr_view_components/toast_controller` to remove itself from the DOM after its fade-out animation completes.
Instance Attribute Summary collapse
-
#close_text ⇒ Object
readonly
Returns the value of attribute close_text.
-
#disappearing ⇒ Object
readonly
Returns the value of attribute disappearing.
-
#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
- #classes ⇒ Object
- #data ⇒ Object
-
#initialize(title:, text: nil, close_text: nil, variant: :black, disappearing: false) ⇒ 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, disappearing: false) ⇒ ToastComponent
Returns a new instance of ToastComponent.
9 10 11 12 13 14 15 16 |
# File 'app/components/sdr_view_components/elements/toast_component.rb', line 9 def initialize(title:, text: nil, close_text: nil, variant: :black, disappearing: false) @title = title @text = text @close_text = close_text @variant = variant @disappearing = disappearing super() end |
Instance Attribute Details
#close_text ⇒ Object (readonly)
Returns the value of attribute close_text.
18 19 20 |
# File 'app/components/sdr_view_components/elements/toast_component.rb', line 18 def close_text @close_text end |
#disappearing ⇒ Object (readonly)
Returns the value of attribute disappearing.
18 19 20 |
# File 'app/components/sdr_view_components/elements/toast_component.rb', line 18 def disappearing @disappearing end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
18 19 20 |
# File 'app/components/sdr_view_components/elements/toast_component.rb', line 18 def text @text end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
18 19 20 |
# File 'app/components/sdr_view_components/elements/toast_component.rb', line 18 def title @title end |
#variant ⇒ Object (readonly)
Returns the value of attribute variant.
18 19 20 |
# File 'app/components/sdr_view_components/elements/toast_component.rb', line 18 def variant @variant end |
Instance Method Details
#background_color ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/components/sdr_view_components/elements/toast_component.rb', line 32 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 |
#classes ⇒ Object
20 21 22 |
# File 'app/components/sdr_view_components/elements/toast_component.rb', line 20 def classes merge_classes('toast align-items-center show', ('toast-disappear' if disappearing)) end |
#data ⇒ Object
28 29 30 |
# File 'app/components/sdr_view_components/elements/toast_component.rb', line 28 def data { controller: 'sdr-toast' } if disappearing end |
#toast_body_classes ⇒ Object
24 25 26 |
# File 'app/components/sdr_view_components/elements/toast_component.rb', line 24 def toast_body_classes merge_classes([background_color], %w[toast-body text-white]) end |