Class: Primer::LabelComponent
- Defined in:
- app/components/primer/label_component.rb
Overview
Use labels to add contextual metadata to a design.
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
- #call ⇒ Object
-
#initialize(title:, scheme: nil, variant: nil, **kwargs) ⇒ LabelComponent
constructor
A new instance of LabelComponent.
Methods included from FetchOrFallbackHelper
Methods included from ClassNameHelper
Constructor Details
#initialize(title:, scheme: nil, variant: nil, **kwargs) ⇒ LabelComponent
Returns a new instance of LabelComponent.
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/components/primer/label_component.rb', line 48 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
#call ⇒ Object
61 62 63 |
# File 'app/components/primer/label_component.rb', line 61 def call render(Primer::BaseComponent.new(**@kwargs)) { content } end |