Class: Bs5::SpinnerComponent

Inherits:
ViewComponent::Base
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
app/components/bs5/spinner_component.rb

Constant Summary collapse

STYLES =
%i[primary secondary success danger warning info light dark].freeze
SIZES =
{ small: :sm, large: :lg }.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ SpinnerComponent

Returns a new instance of SpinnerComponent.



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

def initialize(options = {})
  @options = options.symbolize_keys

  @text = @options.delete(:text)
  @color = @options.delete(:color)&.to_sym
  @grow = @options.delete(:grow)
  @size = @options.delete(:size)&.to_sym
end

Instance Attribute Details

#colorObject (readonly)

Returns the value of attribute color.



8
9
10
# File 'app/components/bs5/spinner_component.rb', line 8

def color
  @color
end

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'app/components/bs5/spinner_component.rb', line 8

def options
  @options
end

#sizeObject (readonly)

Returns the value of attribute size.



8
9
10
# File 'app/components/bs5/spinner_component.rb', line 8

def size
  @size
end

#textObject (readonly)

Returns the value of attribute text.



8
9
10
# File 'app/components/bs5/spinner_component.rb', line 8

def text
  @text
end

Instance Method Details

#before_renderObject



22
23
24
# File 'app/components/bs5/spinner_component.rb', line 22

def before_render
  raise errors.full_messages.to_sentence if invalid?
end

#component_attributesObject



26
27
28
29
30
# File 'app/components/bs5/spinner_component.rb', line 26

def component_attributes
  options[:class] = component_class
  options[:role] = 'status'
  options
end

#component_classObject



32
33
34
35
36
37
38
39
# File 'app/components/bs5/spinner_component.rb', line 32

def component_class
  class_names = Array(options[:class])
  class_names << shape_class
  class_names << contextual_class
  class_names << size_class

  class_names.compact.join(' ')
end