Class: Primer::CounterComponent
- Defined in:
- app/components/primer/counter_component.rb
Overview
Use Primer::CounterComponent to add a count to navigational elements and buttons.
Constant Summary collapse
- DEFAULT_SCHEME =
:default- SCHEME_MAPPINGS =
{ DEFAULT_SCHEME => "Counter", :gray => "Counter Counter--gray", :light_gray => "Counter Counter--gray-light", }.freeze
Constants included from FetchOrFallbackHelper
FetchOrFallbackHelper::InvalidValueError
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(count: 0, scheme: DEFAULT_SCHEME, limit: 5_000, hide_if_zero: false, text: "", round: false, **system_arguments) ⇒ CounterComponent
constructor
A new instance of CounterComponent.
Methods included from JoinStyleArgumentsHelper
Methods included from FetchOrFallbackHelper
#fetch_or_fallback, #fetch_or_fallback_boolean
Methods included from ClassNameHelper
Constructor Details
#initialize(count: 0, scheme: DEFAULT_SCHEME, limit: 5_000, hide_if_zero: false, text: "", round: false, **system_arguments) ⇒ CounterComponent
Returns a new instance of CounterComponent.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/components/primer/counter_component.rb', line 24 def initialize( count: 0, scheme: DEFAULT_SCHEME, limit: 5_000, hide_if_zero: false, text: "", round: false, **system_arguments ) @count, @limit, @hide_if_zero, @text, @round, @system_arguments = count, limit, hide_if_zero, text, round, system_arguments @has_limit = !@limit.nil? @system_arguments[:title] = title @system_arguments[:tag] = :span @system_arguments[:classes] = class_names( @system_arguments[:classes], SCHEME_MAPPINGS[fetch_or_fallback(SCHEME_MAPPINGS.keys, scheme, DEFAULT_SCHEME)] ) if count == 0 && hide_if_zero @system_arguments[:hidden] = true end end |
Instance Method Details
#call ⇒ Object
47 48 49 |
# File 'app/components/primer/counter_component.rb', line 47 def call render(Primer::BaseComponent.new(**@system_arguments)) { value } end |