Class: SdrViewComponents::Elements::ToastComponent

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/sdr_view_components/elements/toast_component.rb

Overview

Component for rendering a toast element.

Instance Attribute Summary collapse

Instance Method Summary collapse

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.



7
8
9
10
11
12
13
14
# File 'app/components/sdr_view_components/elements/toast_component.rb', line 7

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_textObject (readonly)

Returns the value of attribute close_text.



16
17
18
# File 'app/components/sdr_view_components/elements/toast_component.rb', line 16

def close_text
  @close_text
end

#disappearingObject (readonly)

Returns the value of attribute disappearing.



16
17
18
# File 'app/components/sdr_view_components/elements/toast_component.rb', line 16

def disappearing
  @disappearing
end

#textObject (readonly)

Returns the value of attribute text.



16
17
18
# File 'app/components/sdr_view_components/elements/toast_component.rb', line 16

def text
  @text
end

#titleObject (readonly)

Returns the value of attribute title.



16
17
18
# File 'app/components/sdr_view_components/elements/toast_component.rb', line 16

def title
  @title
end

#variantObject (readonly)

Returns the value of attribute variant.



16
17
18
# File 'app/components/sdr_view_components/elements/toast_component.rb', line 16

def variant
  @variant
end

Instance Method Details

#background_colorObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/components/sdr_view_components/elements/toast_component.rb', line 26

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

#classesObject



18
19
20
# File 'app/components/sdr_view_components/elements/toast_component.rb', line 18

def classes
  merge_classes('toast align-items-center show', ('toast-disappear' if disappearing))
end

#toast_body_classesObject



22
23
24
# File 'app/components/sdr_view_components/elements/toast_component.rb', line 22

def toast_body_classes
  merge_classes([background_color], %w[toast-body text-white])
end