Class: Railsboot::SpinnerComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/railsboot/spinner_component.rb

Overview

ViewComponent: renders the spinner block.

Constant Summary collapse

STYLES =

Styles.

%w[border grow].freeze
DEFAULT_STYLE =

Default style.

"border".freeze

Instance Method Summary collapse

Constructor Details

#initialize(style: DEFAULT_STYLE, color: DEFAULT_COLOR, **html_attributes) ⇒ SpinnerComponent

Returns a new instance of SpinnerComponent.

Parameters:

  • style (String) (defaults to: DEFAULT_STYLE)

    the style option

  • color (String) (defaults to: DEFAULT_COLOR)

    the color option

  • html_attributes (Hash)

    additional HTML attributes applied to the rendered element

Options Hash (**html_attributes):

  • :class (String)

    additional CSS classes, merged with the component's own classes

  • :tag (String)

    HTML tag to render for the element



14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/components/railsboot/spinner_component.rb', line 14

def initialize(style: DEFAULT_STYLE, color: DEFAULT_COLOR, **html_attributes)
  @style = fetch_or_raise(style, STYLES)
  @color = fetch_or_raise(color, COLORS)
  @html_attributes = html_attributes

  @html_attributes[:tag] = "div"
  @html_attributes[:class] = class_names(
    "spinner-#{@style}",
    "text-#{@color}",
    html_attributes.delete(:class)
  )
end