Class: Primer::Beta::Label
- Defined in:
- app/components/primer/beta/label.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
- DEFAULT_SIZE =
:medium
- SIZE_MAPPINGS =
{ DEFAULT_SIZE => nil, :large => "Label--large" }.freeze
- SIZE_OPTIONS =
SIZE_MAPPINGS.keys
- DEFAULT_VARIANT =
:none
- VARIANT_OPTIONS =
[DEFAULT_VARIANT].freeze
- DEPRECATED_VARIANT_OPTIONS =
[:large, :inline].freeze
- INLINE_CLASS =
"Label--inline"
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
Constants included from AttributesHelper
AttributesHelper::PLURAL_ARIA_ATTRIBUTES, AttributesHelper::PLURAL_DATA_ATTRIBUTES
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(tag: DEFAULT_TAG, scheme: DEFAULT_SCHEME, size: DEFAULT_SIZE, inline: false, variant: DEFAULT_VARIANT, **system_arguments) ⇒ Label
constructor
A new instance of Label.
Methods inherited from Component
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
Methods included from AttributesHelper
#aria, #data, #extract_data, #merge_aria, #merge_data, #merge_prefixed_attribute_hashes
Methods included from ExperimentalSlotHelpers
Methods included from ExperimentalRenderHelpers
Constructor Details
#initialize(tag: DEFAULT_TAG, scheme: DEFAULT_SCHEME, size: DEFAULT_SIZE, inline: false, variant: DEFAULT_VARIANT, **system_arguments) ⇒ Label
Returns a new instance of Label.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/components/primer/beta/label.rb', line 56 def initialize(tag: DEFAULT_TAG, scheme: DEFAULT_SCHEME, size: DEFAULT_SIZE, inline: false, variant: DEFAULT_VARIANT, **system_arguments) @system_arguments = system_arguments @variant = fetch_or_fallback(VARIANT_OPTIONS, variant, nil, deprecated_values: DEPRECATED_VARIANT_OPTIONS) @scheme = fetch_or_fallback(SCHEME_OPTIONS, scheme, DEFAULT_SCHEME, deprecated_values: DEPRECATED_SCHEME_OPTIONS) @size = fetch_or_fallback(SIZE_OPTIONS, size, DEFAULT_SIZE) @size = :large if @variant == :large @inline = inline || @variant == :inline @system_arguments[:tag] = fetch_or_fallback(TAG_OPTIONS, tag, DEFAULT_TAG) @system_arguments[:classes] = class_names( "Label", system_arguments[:classes], SCHEME_MAPPINGS[@scheme], SIZE_MAPPINGS[@size], @inline ? INLINE_CLASS : nil ) end |
Instance Method Details
#call ⇒ Object
75 76 77 |
# File 'app/components/primer/beta/label.rb', line 75 def call render(Primer::BaseComponent.new(**@system_arguments)) { content } end |