Class: Primer::LabelComponent
- Defined in:
- app/components/primer/label_component.rb
Overview
Use ‘Label` to add contextual metadata to a design.
Constant Summary collapse
- DEFAULT_TAG =
:span- TAG_OPTIONS =
[DEFAULT_TAG, :summary, :a, :div].freeze
- DEFAULT_SCHEME =
:default- SCHEME_MAPPINGS =
{ DEFAULT_SCHEME => "", :primary => "Label--primary", :secondary => "Label--secondary", :accent => "Label--accent", :success => "Label--success", :attention => "Label--attention", :danger => "Label--danger", :severe => "Label--severe", :done => "Label--done", :sponsors => "Label--sponsors", # deprecated :info => "Label--info", :warning => "Label--warning", :orange => "Label--orange", :purple => "Label--purple" }.freeze
- DEPRECATED_SCHEME_OPTIONS =
[:info, :warning, :orange, :purple].freeze
- SCHEME_OPTIONS =
(SCHEME_MAPPINGS.keys - DEPRECATED_SCHEME_OPTIONS).freeze
- VARIANT_MAPPINGS =
{ large: "Label--large", inline: "Label--inline" }.freeze
- VARIANT_OPTIONS =
VARIANT_MAPPINGS.keys << nil
Constants inherited from Component
Component::INVALID_ARIA_LABEL_TAGS
Constants included from Status::Dsl
Constants included from ViewHelper
Constants included from TestSelectorHelper
TestSelectorHelper::TEST_SELECTOR_TAG
Constants included from FetchOrFallbackHelper
FetchOrFallbackHelper::InvalidValueError
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(tag: DEFAULT_TAG, scheme: DEFAULT_SCHEME, variant: nil, **system_arguments) ⇒ LabelComponent
constructor
A new instance of LabelComponent.
Methods included from JoinStyleArgumentsHelper
Methods included from TestSelectorHelper
Methods included from FetchOrFallbackHelper
#fetch_or_fallback, #fetch_or_fallback_boolean, #silence_deprecations?
Methods included from ClassNameHelper
Constructor Details
#initialize(tag: DEFAULT_TAG, scheme: DEFAULT_SCHEME, variant: nil, **system_arguments) ⇒ LabelComponent
Returns a new instance of LabelComponent.
61 62 63 64 65 66 67 68 69 70 |
# File 'app/components/primer/label_component.rb', line 61 def initialize(tag: DEFAULT_TAG, scheme: DEFAULT_SCHEME, variant: nil, **system_arguments) @system_arguments = system_arguments @system_arguments[:tag] = fetch_or_fallback(TAG_OPTIONS, tag, DEFAULT_TAG) @system_arguments[:classes] = class_names( "Label", system_arguments[:classes], SCHEME_MAPPINGS[fetch_or_fallback(SCHEME_OPTIONS, scheme, deprecated_values: DEPRECATED_SCHEME_OPTIONS)], VARIANT_MAPPINGS[fetch_or_fallback(VARIANT_OPTIONS, variant)] ) end |
Instance Method Details
#call ⇒ Object
72 73 74 |
# File 'app/components/primer/label_component.rb', line 72 def call render(Primer::BaseComponent.new(**@system_arguments)) { content } end |