Class: Primer::CounterComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/primer/counter_component.rb

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

Methods included from FetchOrFallbackHelper

#fetch_or_fallback

Methods included from ClassNameHelper

#class_names

Constructor Details

#initialize(count: 0, scheme: DEFAULT_SCHEME, limit: 5_000, hide_if_zero: false, text: "", round: false, **kwargs) ⇒ CounterComponent

Returns a new instance of CounterComponent.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/components/primer/counter_component.rb', line 12

def initialize(
  count: 0,
  scheme: DEFAULT_SCHEME,
  limit: 5_000,
  hide_if_zero: false,
  text: "",
  round: false,
  **kwargs
)
  @count, @limit, @hide_if_zero, @text, @round, @kwargs = count, limit, hide_if_zero, text, round, kwargs

  @kwargs[:title] = title
  @kwargs[:tag] = :span
  @kwargs[:classes] = class_names(
    @kwargs[:classes],
    SCHEME_MAPPINGS[fetch_or_fallback(SCHEME_MAPPINGS.keys, scheme, DEFAULT_SCHEME)]
  )
  if count == 0 && hide_if_zero
    @kwargs[:hidden] = true
  end
end

Instance Method Details

#callObject



34
35
36
# File 'app/components/primer/counter_component.rb', line 34

def call
  render(Primer::BaseComponent.new(**@kwargs)) { value }
end