Class: Ariadne::CounterComponent
- Defined in:
- app/components/ariadne/counter_component.rb
Overview
Use ‘Counter` to add a count to navigational elements and buttons.
Constant Summary collapse
- DEFAULT_CLASSES =
"inline-flex items-center p-1 border border-transparent rounded-full shadow-sm text-white bg-gray-600 hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-500"
Constants inherited from Component
Ariadne::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, FetchOrFallbackHelper::TRUE_OR_FALSE
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(tag: :span, count: 0, limit: 9_000, hide_if_zero: false, text: "", round: false, classes: "", attributes: {}) ⇒ CounterComponent
constructor
A new instance of CounterComponent.
Methods included from LoggerHelper
#logger, #silence_deprecations?, #silence_warnings?
Methods included from JoinStyleArgumentsHelper
Methods included from TestSelectorHelper
Methods included from FetchOrFallbackHelper
#check_incoming_attribute, #check_incoming_tag, #check_incoming_value, #fetch_or_raise, #fetch_or_raise_boolean
Methods included from ClassNameHelper
Constructor Details
#initialize(tag: :span, count: 0, limit: 9_000, hide_if_zero: false, text: "", round: false, classes: "", attributes: {}) ⇒ CounterComponent
Returns a new instance of CounterComponent.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/components/ariadne/counter_component.rb', line 28 def initialize( tag: :span, count: 0, limit: 9_000, hide_if_zero: false, text: "", round: false, classes: "", attributes: {} ) @count = count @limit = limit @hide_if_zero = hide_if_zero @text = text @round = round @attributes = attributes @has_limit = !@limit.nil? @tag = check_incoming_tag(:span, tag) @attributes[:title] = title @classes = class_names( DEFAULT_CLASSES, classes ) @attributes[:hidden] = true if count == 0 && hide_if_zero end |
Instance Method Details
#call ⇒ Object
58 59 60 |
# File 'app/components/ariadne/counter_component.rb', line 58 def call render(Ariadne::BaseComponent.new(tag: @tag, classes: @classes, attributes: @attributes)) { value } end |