Class: Primer::LabelComponent
- Defined in:
- app/components/primer/label_component.rb
Overview
Use labels to add contextual metadata to a design.
Constant Summary collapse
- NEW_SCHEME_MAPPINGS =
{ primary: "Label--primary", secondary: "Label--secondary", info: "Label--info", success: "Label--success", warning: "Label--warning", danger: "Label--danger" }.freeze
- DEPRECATED_SCHEME_MAPPINGS =
{ gray: "Label--gray", dark_gray: "Label--gray-darker", yellow: "Label--yellow", orange: "Label--orange", red: "Label--red", green: "Label--green", blue: "Label--blue", purple: "Label--purple", pink: "Label--pink", outline: "Label--outline", green_outline: "Label--outline-green" }.freeze
- SCHEME_MAPPINGS =
NEW_SCHEME_MAPPINGS.merge(DEPRECATED_SCHEME_MAPPINGS)
- SCHEME_OPTIONS =
SCHEME_MAPPINGS.keys << nil
- VARIANT_MAPPINGS =
{ large: "Label--large", inline: "Label--inline" }.freeze
- VARIANT_OPTIONS =
VARIANT_MAPPINGS.keys << nil
Constants inherited from Component
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 inherited from Component
Methods included from ViewHelper
Methods included from JoinStyleArgumentsHelper
Methods included from FetchOrFallbackHelper
#fetch_or_fallback, #fetch_or_fallback_boolean
Methods included from ClassNameHelper
Constructor Details
#initialize(title:, scheme: nil, variant: nil, **system_arguments) ⇒ LabelComponent
Returns a new instance of LabelComponent.
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/components/primer/label_component.rb', line 54 def initialize(title:, scheme: nil, variant: nil, **system_arguments) @system_arguments = system_arguments @system_arguments[:bg] = :blue if scheme.nil? @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)], VARIANT_MAPPINGS[fetch_or_fallback(VARIANT_OPTIONS, variant)] ) end |
Instance Method Details
#call ⇒ Object
67 68 69 |
# File 'app/components/primer/label_component.rb', line 67 def call render(Primer::BaseComponent.new(**@system_arguments)) { content } end |