Class: Primer::Beta::State

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

Overview

Use ‘State` for rendering the status of an item.

Constant Summary collapse

SCHEME_DEFAULT =
:default
NEW_SCHEME_MAPPINGS =
{
  open: "State--open",
  closed: "State--closed",
  merged: "State--merged"
}.freeze
DEPRECATED_SCHEME_MAPPINGS =
{
  SCHEME_DEFAULT => "",
  :green => "State--open",
  :red => "State--closed",
  :purple => "State--merged"
}.freeze
SCHEME_MAPPINGS =
NEW_SCHEME_MAPPINGS.merge(DEPRECATED_SCHEME_MAPPINGS)
SCHEME_OPTIONS =
SCHEME_MAPPINGS.keys
SIZE_DEFAULT =
:default
SIZE_MAPPINGS =
{
  SIZE_DEFAULT => "",
  :small => "State--small"
}.freeze
SIZE_OPTIONS =
SIZE_MAPPINGS.keys
TAG_DEFAULT =
:span
TAG_OPTIONS =
[TAG_DEFAULT, :div].freeze

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, #merge_aria, #merge_data, #merge_prefixed_attribute_hashes

Constructor Details

#initialize(title:, scheme: SCHEME_DEFAULT, tag: TAG_DEFAULT, size: SIZE_DEFAULT, **system_arguments) ⇒ State

Returns a new instance of State.

Parameters:

  • title (String)

    ‘title` HTML attribute.

  • scheme (Symbol) (defaults to: SCHEME_DEFAULT)

    Background color. <%= one_of(Primer::Beta::State::SCHEME_OPTIONS) %>

  • tag (Symbol) (defaults to: TAG_DEFAULT)

    HTML tag for element. <%= one_of(Primer::Beta::State::TAG_OPTIONS) %>

  • size (Symbol) (defaults to: SIZE_DEFAULT)

    <%= one_of(Primer::Beta::State::SIZE_OPTIONS) %>

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/components/primer/beta/state.rb', line 40

def initialize(
  title:,
  scheme: SCHEME_DEFAULT,
  tag: TAG_DEFAULT,
  size: SIZE_DEFAULT,
  **system_arguments
)
  @system_arguments = system_arguments
  @system_arguments[:title] = title
  @system_arguments[:tag] = fetch_or_fallback(TAG_OPTIONS, tag, TAG_DEFAULT)
  @system_arguments[:classes] = class_names(
    @system_arguments[:classes],
    "State",
    SCHEME_MAPPINGS[fetch_or_fallback(SCHEME_OPTIONS, scheme, SCHEME_DEFAULT)],
    SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, SIZE_DEFAULT)]
  )
end

Instance Method Details

#callObject



58
59
60
# File 'app/components/primer/beta/state.rb', line 58

def call
  render(Primer::BaseComponent.new(**@system_arguments)) { content }
end