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

#textObject (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

#titleObject (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

#variantObject (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_colorObject



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_classesObject



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