Class: Primer::StateComponent

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

Constant Summary collapse

COLOR_DEFAULT =

Component for rendering the status of an item

title(string): (required) title attribute color(symbol): label background color size(symbol): label size counter(integer): counter value **args(hash): utility parameters for Primer::Classify

:default
COLOR_MAPPINGS =
{
  COLOR_DEFAULT => "",
  :green => "State--green",
  :red => "State--red",
  :purple => "State--purple",
}.freeze
COLOR_OPTIONS =
COLOR_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, :a]

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Instance Method Summary collapse

Methods included from FetchOrFallbackHelper

#fetch_or_fallback

Methods included from ClassNameHelper

#class_names

Constructor Details

#initialize(title:, color: COLOR_DEFAULT, tag: TAG_DEFAULT, size: SIZE_DEFAULT, **kwargs) ⇒ StateComponent

Returns a new instance of StateComponent.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/components/primer/state_component.rb', line 31

def initialize(
  title:,
  color: COLOR_DEFAULT,
  tag: TAG_DEFAULT,
  size: SIZE_DEFAULT,
  **kwargs
)
  @kwargs = kwargs
  @kwargs[:title] = title
  @kwargs[:tag] = fetch_or_fallback(TAG_OPTIONS, tag, TAG_DEFAULT)
  @kwargs[:classes] = class_names(
    @kwargs[:classes],
    "State",
    COLOR_MAPPINGS[fetch_or_fallback(COLOR_OPTIONS, color, COLOR_DEFAULT)],
    SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, SIZE_DEFAULT)]
  )
end

Instance Method Details

#callObject



49
50
51
# File 'app/components/primer/state_component.rb', line 49

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