Class: Primer::Forms::Dsl::TextFieldInput
- Inherits:
-
Input
- Object
- Input
- Primer::Forms::Dsl::TextFieldInput
show all
- Defined in:
- app/lib/primer/forms/dsl/text_field_input.rb
Overview
Constant Summary
Constants inherited
from Input
Input::DEFAULT_INPUT_WIDTH, Input::DEFAULT_SIZE, Input::INPUT_WIDTH_MAPPINGS, Input::INPUT_WIDTH_OPTIONS, Input::SIZE_MAPPINGS, Input::SIZE_OPTIONS, Input::SPACE_DELIMITED_ARIA_ATTRIBUTES
Instance Attribute Summary
Attributes inherited from Input
#base_id, #builder, #caption, #form, #form_control, #ids, #input_arguments, #label_arguments, #validation_message
Instance Method Summary
collapse
Methods inherited from Input
#add_input_aria, #add_input_classes, #add_input_data, #add_label_classes, #autofocus!, #caption?, #caption_id, #caption_template?, #character_limit_id, #character_limit_target_prefix, #disabled?, #full_width?, #hidden?, #id, #input?, #input_width, #invalid?, #label, #merge_input_arguments!, #name, #remove_input_data, #render_caption_template, #required?, #size, #supports_validation?, #valid?, #validation_id, #validation_messages, #value, #values_disambiguate_template_names?
#class_names
Constructor Details
#initialize(name:, label:, **system_arguments) {|_self| ... } ⇒ TextFieldInput
Returns a new instance of TextFieldInput.
15
16
17
18
19
20
21
22
23
24
25
26
27
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
|
# File 'app/lib/primer/forms/dsl/text_field_input.rb', line 15
def initialize(name:, label:, **system_arguments)
@name = name
@label = label
@show_clear_button = system_arguments.delete(:show_clear_button)
@leading_visual = system_arguments.delete(:leading_visual)
@trailing_visual = system_arguments.delete(:trailing_visual)
@leading_spinner = !!system_arguments.delete(:leading_spinner)
@clear_button_id = system_arguments.delete(:clear_button_id) || SecureRandom.uuid
@clear_button_label = system_arguments.delete(:clear_button_label)
@inset = system_arguments.delete(:inset)
@monospace = system_arguments.delete(:monospace)
@auto_check_src = system_arguments.delete(:auto_check_src)
@character_limit = system_arguments.delete(:character_limit)
if @character_limit.present? && @character_limit.to_i <= 0
raise ArgumentError, "character_limit must be a positive integer, got #{@character_limit}"
end
if @leading_visual
@leading_visual[:classes] = class_names(
"FormControl-input-leadingVisual",
@leading_visual[:classes]
)
end
if @leading_spinner && !@leading_visual
raise ArgumentError, "text fields that request a leading spinner must also specify a leading visual"
end
super(**system_arguments)
add_input_data(:target, "primer-text-field.inputElement #{system_arguments.dig(:data, :target) || ''}")
add_input_classes("FormControl-inset") if inset?
add_input_classes("FormControl-monospace") if monospace?
yield(self) if block_given?
end
|
Instance Method Details
#character_limit? ⇒ Boolean
78
79
80
|
# File 'app/lib/primer/forms/dsl/text_field_input.rb', line 78
def character_limit?
@character_limit.present?
end
|
#focusable? ⇒ Boolean
74
75
76
|
# File 'app/lib/primer/forms/dsl/text_field_input.rb', line 74
def focusable?
true
end
|
#leading_visual? ⇒ Boolean
62
63
64
|
# File 'app/lib/primer/forms/dsl/text_field_input.rb', line 62
def leading_visual?
!!@leading_visual
end
|
#to_component ⇒ Object
66
67
68
|
# File 'app/lib/primer/forms/dsl/text_field_input.rb', line 66
def to_component
TextField.new(input: self)
end
|
#trailing_visual? ⇒ Boolean
58
59
60
|
# File 'app/lib/primer/forms/dsl/text_field_input.rb', line 58
def trailing_visual?
!!@trailing_visual
end
|
#type ⇒ Object
70
71
72
|
# File 'app/lib/primer/forms/dsl/text_field_input.rb', line 70
def type
:text_field
end
|
#validation_arguments ⇒ Object
82
83
84
85
86
87
88
89
90
91
92
|
# File 'app/lib/primer/forms/dsl/text_field_input.rb', line 82
def validation_arguments
if auto_check_src.present?
super.merge(
data: {
target: "primer-text-field.validationElement"
}
)
else
super
end
end
|
#validation_error_icon_target ⇒ Object
98
99
100
|
# File 'app/lib/primer/forms/dsl/text_field_input.rb', line 98
def validation_error_icon_target
"primer-text-field.validationErrorIcon"
end
|
#validation_message_arguments ⇒ Object
102
103
104
105
106
107
108
109
110
111
112
|
# File 'app/lib/primer/forms/dsl/text_field_input.rb', line 102
def validation_message_arguments
if auto_check_src.present?
super.merge(
data: {
target: "primer-text-field.validationMessageElement"
}
)
else
super
end
end
|
#validation_success_icon_target ⇒ Object
94
95
96
|
# File 'app/lib/primer/forms/dsl/text_field_input.rb', line 94
def validation_success_icon_target
"primer-text-field.validationSuccessIcon"
end
|