Class: Polaris::CharacterCount

Inherits:
Object
  • Object
show all
Defined in:
app/components/polaris/character_count.rb

Instance Method Summary collapse

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

#labelObject



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_templateObject



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

#textObject



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_templateObject



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