Class: Bootstrap5Helper::Spinner

Inherits:
Component show all
Defined in:
lib/bootstrap5_helper/spinner.rb

Overview

Builds a simple CSS spinner component.

Instance Method Summary collapse

Methods inherited from Component

#capture, #concat, #config, #content_tag, #parse_arguments, #parse_context_or_options, #parse_tag_or_options, #parse_text_or_options, #uuid

Constructor Details

#initialize(template, opts = {}, &block) ⇒ Spinner

Note:

The different support types are: :border and :grow

Class constructor

Parameters:

  • template (ActionView)
  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :type (Symbol)
  • :size (Symbol)
  • :id (String)
  • :class (String)
  • :data (Hash)


18
19
20
21
22
23
24
25
26
27
28
# File 'lib/bootstrap5_helper/spinner.rb', line 18

def initialize(template, opts = {}, &block)
  super(template)

  @attrs   = opts
  @type    = @attrs.delete(:type)  { :border }
  @size    = @attrs.delete(:size)  { nil }
  @id      = @attrs.delete(:id)    { uuid }
  @class   = @attrs.delete(:class) { '' }
  @data    = @attrs.delete(:data)  { {} }
  @content = block || proc { '' }
end

Instance Method Details

#to_sString

String representation of the object.

Returns:

  • (String)


34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/bootstrap5_helper/spinner.rb', line 34

def to_s
  (
    :span,
    {
      id:    @id,
      class: component_classes,
      role:  'status',
      aria:  { hidden: true },
      data:  @data
    }.merge(@attrs)
  ) do
     :span, 'Loading', class: 'visually-hidden'
  end
end