Class: Primer::Forms::TextField

Inherits:
BaseComponent show all
Defined in:
lib/primer/forms/text_field.rb

Overview

:nodoc:

Constant Summary collapse

INPUT_WRAP_SIZE =
{
  small: "FormControl-input-wrap--small",
  large: "FormControl-input-wrap--large"
}.freeze

Instance Attribute Summary

Attributes included from ActsAsComponent

#template_root_path

Instance Method Summary collapse

Methods inherited from BaseComponent

#content, inherited, #input?, #perform_render, #render?, #to_component, #type

Methods included from ActsAsComponent

#compile!, extended, #renders_templates

Methods included from ClassNameHelper

#class_names

Constructor Details

#initialize(input:) ⇒ TextField

Returns a new instance of TextField.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/primer/forms/text_field.rb', line 14

def initialize(input:)
  @input = input

  @input.add_input_classes(
    "FormControl-input",
    Primer::Forms::Dsl::Input::SIZE_MAPPINGS[@input.size]
  )

  @field_wrap_arguments = {
    class: class_names(
      "FormControl-input-wrap",
      INPUT_WRAP_SIZE[input.size],
      "FormControl-input-wrap--trailingAction": @input.show_clear_button?,
      "FormControl-input-wrap--leadingVisual": @input.leading_visual?
    ),

    hidden: @input.hidden?
  }
end

Instance Method Details

#auto_check_authenticity_tokenObject



34
35
36
37
38
39
40
41
42
43
# File 'lib/primer/forms/text_field.rb', line 34

def auto_check_authenticity_token
  return @auto_check_authenticity_token if defined?(@auto_check_authenticity_token)

  @auto_check_authenticity_token =
    if @input.auto_check_src
      @view_context.form_authenticity_token(
        form_options: { method: :post, action: @input.auto_check_src }
      )
    end
end