Class: Primer::Beta::Spinner

Inherits:
Component
  • Object
show all
Defined in:
app/components/primer/beta/spinner.rb

Overview

Use ‘Spinner` to let users know that content is being loaded.

Constant Summary collapse

DEFAULT_SIZE =
:medium
SIZE_MAPPINGS =
{
  :small => 16,
  DEFAULT_SIZE => 32,
  :large => 64
}.freeze
DEFAULT_SR_TEXT =
"Loading"
SIZE_OPTIONS =
SIZE_MAPPINGS.keys
DEFAULT_STYLE =

Setting ‘box-sizing: content-box` allows consumers to add padding to the spinner without shrinking the icon

"box-sizing: content-box; color: var(--color-icon-primary);"

Constants inherited from Component

Component::INVALID_ARIA_LABEL_TAGS

Constants included from Status::Dsl

Status::Dsl::STATUSES

Constants included from ViewHelper

ViewHelper::HELPERS

Constants included from TestSelectorHelper

TestSelectorHelper::TEST_SELECTOR_TAG

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Constants included from AttributesHelper

AttributesHelper::PLURAL_ARIA_ATTRIBUTES, AttributesHelper::PLURAL_DATA_ATTRIBUTES

Instance Method Summary collapse

Methods inherited from Component

deprecated?, generate_id

Methods included from JoinStyleArgumentsHelper

#join_style_arguments

Methods included from TestSelectorHelper

#add_test_selector

Methods included from FetchOrFallbackHelper

#fetch_or_fallback, #fetch_or_fallback_boolean, #silence_deprecations?

Methods included from ClassNameHelper

#class_names

Methods included from AttributesHelper

#aria, #data, #extract_data, #merge_aria, #merge_data, #merge_prefixed_attribute_hashes

Methods included from ExperimentalSlotHelpers

included

Methods included from ExperimentalRenderHelpers

included

Constructor Details

#initialize(size: DEFAULT_SIZE, style: DEFAULT_STYLE, sr_text: DEFAULT_SR_TEXT, **system_arguments) ⇒ Spinner

Returns a new instance of Spinner.

Parameters:

  • size (Symbol) (defaults to: DEFAULT_SIZE)

    <%= one_of(Primer::Beta::Spinner::SIZE_MAPPINGS) %>

  • style (String) (defaults to: DEFAULT_STYLE)

    Custom element styles.

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/components/primer/beta/spinner.rb', line 26

def initialize(size: DEFAULT_SIZE, style: DEFAULT_STYLE, sr_text: DEFAULT_SR_TEXT, **system_arguments)
  @system_arguments = deny_tag_argument(**system_arguments)
  @system_arguments[:tag] = :svg
  @system_arguments[:style] ||= style
  @system_arguments[:animation] = :rotate
  @system_arguments[:width] = SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, DEFAULT_SIZE)]
  @system_arguments[:height] = SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, DEFAULT_SIZE)]
  @system_arguments[:viewBox] = "0 0 16 16"
  @system_arguments[:fill] = :none
  @system_arguments[:aria] ||= {}
  @sr_text = sr_text

  if no_aria_label?
    @system_arguments[:aria][:hidden] = true
  else
    @system_arguments[:role] = "img"
  end

  @target = extract_data(:target, @system_arguments)
  @hidden = @system_arguments.delete(:hidden)
end

Instance Method Details

#no_aria_label?Boolean

Returns:

  • (Boolean)


48
49
50
51
# File 'app/components/primer/beta/spinner.rb', line 48

def no_aria_label?
  !@system_arguments[:aria][:label] && !@system_arguments[:"aria-label"] &&
      !@system_arguments[:aria][:labelledby] && !@system_arguments[:"aria-labelledby"]
end