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_SIZE, 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?, #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) ⇒ 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
|
# 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?
end
|
Instance Method Details
#character_limit? ⇒ Boolean
76
77
78
|
# File 'app/lib/primer/forms/dsl/text_field_input.rb', line 76
def character_limit?
@character_limit.present?
end
|
#focusable? ⇒ Boolean
72
73
74
|
# File 'app/lib/primer/forms/dsl/text_field_input.rb', line 72
def focusable?
true
end
|
#leading_visual? ⇒ Boolean
60
61
62
|
# File 'app/lib/primer/forms/dsl/text_field_input.rb', line 60
def leading_visual?
!!@leading_visual
end
|
#to_component ⇒ Object
64
65
66
|
# File 'app/lib/primer/forms/dsl/text_field_input.rb', line 64
def to_component
TextField.new(input: self)
end
|
#trailing_visual? ⇒ Boolean
56
57
58
|
# File 'app/lib/primer/forms/dsl/text_field_input.rb', line 56
def trailing_visual?
!!@trailing_visual
end
|
#type ⇒ Object
68
69
70
|
# File 'app/lib/primer/forms/dsl/text_field_input.rb', line 68
def type
:text_field
end
|
#validation_arguments ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
|
# File 'app/lib/primer/forms/dsl/text_field_input.rb', line 80
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
96
97
98
|
# File 'app/lib/primer/forms/dsl/text_field_input.rb', line 96
def validation_error_icon_target
"primer-text-field.validationErrorIcon"
end
|
#validation_message_arguments ⇒ Object
100
101
102
103
104
105
106
107
108
109
110
|
# File 'app/lib/primer/forms/dsl/text_field_input.rb', line 100
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
92
93
94
|
# File 'app/lib/primer/forms/dsl/text_field_input.rb', line 92
def validation_success_icon_target
"primer-text-field.validationSuccessIcon"
end
|