Class: Primer::LabelComponent

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

Constant Summary collapse

SCHEME_MAPPINGS =
{
  # gray
  gray: "Label--gray",
  dark_gray: "Label--gray-darker",

  # colored
  yellow: "Label--yellow",
  orange: "Label--orange",
  red: "Label--red",
  green: "Label--green",
  blue: "Label--blue",
  purple: "Label--purple",
  pink: "Label--pink",

  # Deprecated
  outline: "Label--outline",
  green_outline: "Label--outline-green",
}.freeze
SCHEME_OPTIONS =
SCHEME_MAPPINGS.keys << nil
VARIANT_MAPPINGS =
{
  large: "Label--large",
  inline: "Label--inline",
}.freeze
VARIANT_OPTIONS =
VARIANT_MAPPINGS.keys << nil

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:, scheme: nil, variant: nil, **kwargs) ⇒ LabelComponent

Returns a new instance of LabelComponent.



31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/components/primer/label_component.rb', line 31

def initialize(title:, scheme: nil, variant: nil, **kwargs)
  @kwargs = kwargs
  @kwargs[:bg] = :blue if scheme.nil?
  @kwargs[:tag] ||= :span
  @kwargs[:title] = title
  @kwargs[:classes] = class_names(
    "Label",
    kwargs[:classes],
    SCHEME_MAPPINGS[fetch_or_fallback(SCHEME_OPTIONS, scheme)],
    VARIANT_MAPPINGS[fetch_or_fallback(VARIANT_OPTIONS, variant)]
  )
end

Instance Method Details

#callObject



44
45
46
# File 'app/components/primer/label_component.rb', line 44

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