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
# File 'lib/bootstrap5_helper/spinner.rb', line 18

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

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

Instance Method Details

#to_sString

String representation of the object.

Returns:

  • (String)


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

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