Class: Ariadne::CounterComponent
- Defined in:
- app/components/ariadne/counter_component.rb
Overview
Use CounterComponent to add a count to navigational elements and buttons.
Constant Summary collapse
- DEFAULT_CLASSES =
"ariadne-inline-flex ariadne-items-center ariadne-p-1 ariadne-border ariadne-border-transparent ariadne-rounded-full ariadne-shadow-sm focus:ariadne-outline-none focus:ariadne-ring-2 focus:ariadne-ring-offset-2"
Constants inherited from Component
Ariadne::Component::BASE_BODY_CLASSES, Ariadne::Component::BASE_HTML_CLASSES, Ariadne::Component::BASE_MAIN_CLASSES, Ariadne::Component::BASE_WRAPPER_CLASSES, Ariadne::Component::INVALID_ARIA_LABEL_TAGS
Constants included from ActionViewExtensions::FormHelper
ActionViewExtensions::FormHelper::DEFAULT_FORM_CLASSES
Constants included from Status::Dsl
Constants included from ViewHelper
Constants included from FetchOrFallbackHelper
FetchOrFallbackHelper::INTEGER_TYPES, 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 ActionViewExtensions::FormHelper
Methods included from ClassNameHelper
Methods included from LoggerHelper
#logger, #silence_deprecations?, #silence_warnings?
Methods included from FetchOrFallbackHelper
#check_incoming_attribute, #check_incoming_tag, #check_incoming_value, #fetch_or_raise, #fetch_or_raise_boolean, #fetch_or_raise_integer
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 |