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 =
{ primary: "Label--primary", secondary: "Label--secondary", info: "Label--info", success: "Label--success", warning: "Label--warning", danger: "Label--danger", # deprecated orange: "Label--orange", purple: "Label--purple" }.freeze
- DEPRECATED_SCHEME_OPTIONS =
[:orange, :purple].freeze
- SCHEME_OPTIONS =
([*SCHEME_MAPPINGS.keys, nil] - DEPRECATED_SCHEME_OPTIONS).freeze
- VARIANT_MAPPINGS =
{ large: "Label--large", inline: "Label--inline" }.freeze
- VARIANT_OPTIONS =
VARIANT_MAPPINGS.keys << nil
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(title:, scheme: nil, 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(title:, scheme: nil, variant: nil, **system_arguments) ⇒ LabelComponent
Returns a new instance of LabelComponent.
45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/components/primer/label_component.rb', line 45 def initialize(title:, scheme: nil, variant: nil, **system_arguments) @system_arguments = system_arguments @system_arguments[:tag] ||= :span @system_arguments[:title] = title @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
57 58 59 |
# File 'app/components/primer/label_component.rb', line 57 def call render(Primer::BaseComponent.new(**@system_arguments)) { content } end |