Class: Primer::Beta::Counter
- Defined in:
- app/components/primer/beta/counter.rb
Overview
Use ‘Counter` to add a count to navigational elements and buttons.
Constant Summary collapse
- DEFAULT_SCHEME =
:default
- SCHEME_MAPPINGS =
{ DEFAULT_SCHEME => "", :primary => "Counter--primary", :secondary => "Counter--secondary", # deprecated :gray => "Counter--primary", :light_gray => "Counter--secondary" }.freeze
- DEPRECATED_SCHEME_OPTIONS =
[:gray, :light_gray].freeze
- SCHEME_OPTIONS =
(SCHEME_MAPPINGS.keys - DEPRECATED_SCHEME_OPTIONS).freeze
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(count: 0, scheme: DEFAULT_SCHEME, limit: 5_000, hide_if_zero: false, text: "", round: false, **system_arguments) ⇒ Counter
constructor
A new instance of Counter.
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(count: 0, scheme: DEFAULT_SCHEME, limit: 5_000, hide_if_zero: false, text: "", round: false, **system_arguments) ⇒ Counter
Returns a new instance of Counter.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/components/primer/beta/counter.rb', line 33 def initialize( count: 0, scheme: DEFAULT_SCHEME, limit: 5_000, hide_if_zero: false, text: "", round: false, **system_arguments ) @count = count @limit = limit @hide_if_zero = hide_if_zero @text = text @round = round @system_arguments = deny_tag_argument(**system_arguments) @has_limit = !@limit.nil? @system_arguments[:title] = title @system_arguments[:tag] = :span @system_arguments[:classes] = class_names( "Counter", @system_arguments[:classes], SCHEME_MAPPINGS[fetch_or_fallback(SCHEME_OPTIONS, scheme, DEFAULT_SCHEME, deprecated_values: DEPRECATED_SCHEME_OPTIONS)] ) @system_arguments[:hidden] = true if count == 0 && hide_if_zero end |
Instance Method Details
#call ⇒ Object
60 61 62 |
# File 'app/components/primer/beta/counter.rb', line 60 def call render(Primer::BaseComponent.new(**@system_arguments)) { value } end |