Class: Polaris::CharacterCount
- Inherits:
-
Object
- Object
- Polaris::CharacterCount
- Defined in:
- app/components/polaris/character_count.rb
Instance Method Summary collapse
-
#initialize(text_field:, max_length: nil) ⇒ CharacterCount
constructor
A new instance of CharacterCount.
- #label ⇒ Object
- #label_template ⇒ Object
- #text ⇒ Object
- #text_template ⇒ Object
Constructor Details
#initialize(text_field:, max_length: nil) ⇒ CharacterCount
Returns a new instance of CharacterCount.
5 6 7 8 |
# File 'app/components/polaris/character_count.rb', line 5 def initialize(text_field:, max_length: nil) @text_field = text_field @max_length = max_length end |
Instance Method Details
#label ⇒ Object
10 11 12 13 14 |
# File 'app/components/polaris/character_count.rb', line 10 def label return "#{count} of #{@max_length} characters used" if max_length? "#{count} characters" end |
#label_template ⇒ Object
22 23 24 25 26 27 28 |
# File 'app/components/polaris/character_count.rb', line 22 def label_template if max_length? "{count} of #{@max_length} characters used" end "{count} characters" end |
#text ⇒ Object
16 17 18 19 20 |
# File 'app/components/polaris/character_count.rb', line 16 def text return "#{count}/#{@max_length}" if max_length? count.to_s end |
#text_template ⇒ Object
30 31 32 33 34 |
# File 'app/components/polaris/character_count.rb', line 30 def text_template return "{count}/#{@max_length}" if max_length? "{count}" end |