Class: Bs5::ToastComponent

Inherits:
ViewComponent::Base
  • Object
show all
Includes:
ComponentsHelper, ViewComponent::SlotableV2
Defined in:
app/components/bs5/toast_component.rb

Constant Summary

Constants included from ComponentsHelper

ComponentsHelper::COMPONENTS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ComponentsHelper

#bs5_collapse, #bs5_popover, #bs5_tooltip

Constructor Details

#initialize(options = {}) ⇒ ToastComponent

Returns a new instance of ToastComponent.



14
15
16
17
18
19
# File 'app/components/bs5/toast_component.rb', line 14

def initialize(options = {})
  @options = options.symbolize_keys
  @color = @options.delete(:color)
  @close_button = @options.fetch(:close_button, true)
  @data_options = @options.extract!(:animation, :autohide, :delay)
end

Instance Attribute Details

#colorObject (readonly)

Returns the value of attribute color.



9
10
11
# File 'app/components/bs5/toast_component.rb', line 9

def color
  @color
end

Instance Method Details

#component_attributesObject



25
26
27
28
29
30
31
32
33
34
35
# File 'app/components/bs5/toast_component.rb', line 25

def component_attributes
  default_options = {
    role: :alert,
    aria: { live: 'assertive', atomic: true },
    data: data_options
  }

  @options[:class] = component_class

  @options.merge(default_options)
end

#header?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'app/components/bs5/toast_component.rb', line 21

def header?
  !!header
end

#white_text?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'app/components/bs5/toast_component.rb', line 37

def white_text?
  color? && color.in?(i[primary secondary success danger dark])
end