Class: Ariadne::Forms::Dsl::TextFieldInput

Inherits:
Input
  • Object
show all
Defined in:
lib/ariadne/forms/dsl/text_field_input.rb

Overview

:nodoc:

Constant Summary

Constants inherited from Input

Input::DEFAULT_SIZE, Input::SIZE_MAPPINGS, Input::SIZE_OPTIONS, Input::SPACE_DELIMITED_ARIA_ATTRIBUTES

Instance Attribute Summary collapse

Attributes inherited from Input

#base_id, #builder, #caption, #form, #form_control, #ids, #input_attributes, #label_attributes, #validation_message

Instance Method Summary collapse

Methods inherited from Input

#add_input_aria, #add_input_classes, #add_input_data, #autofocus!, #caption?, #caption_id, #caption_template?, #disabled?, #hidden?, #id, #input?, #invalid?, #merge_input_attributes!, #remove_input_data, #render_caption_template, #required?, #size, #supports_validation?, #valid?, #validation_id, #validation_messages

Methods included from ClassNameHelper

#merge_class_names

Constructor Details

#initialize(name:, label:, **options) ⇒ TextFieldInput

Returns a new instance of TextFieldInput.



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ariadne/forms/dsl/text_field_input.rb', line 12

def initialize(name:, label:, **options)
  @name = name
  @label = label

  @show_clear_button = options.delete(:show_clear_button)
  @inset = options.delete(:inset)
  @monospace = options.delete(:monospace)
  @auto_check_src = options.delete(:auto_check_src)

  super(**options)

  add_input_data(:target, "ariadne-text-field.inputElement #{@input_attributes.dig(:data, :target) || ""}".rstrip)
end

Instance Attribute Details

#auto_check_srcObject (readonly)

Returns the value of attribute auto_check_src.



8
9
10
# File 'lib/ariadne/forms/dsl/text_field_input.rb', line 8

def auto_check_src
  @auto_check_src
end

#clear_button_idObject (readonly)

Returns the value of attribute clear_button_id.



8
9
10
# File 'lib/ariadne/forms/dsl/text_field_input.rb', line 8

def clear_button_id
  @clear_button_id
end

#field_wrap_classesObject (readonly)

Returns the value of attribute field_wrap_classes.



8
9
10
# File 'lib/ariadne/forms/dsl/text_field_input.rb', line 8

def field_wrap_classes
  @field_wrap_classes
end

#insetObject (readonly)

Returns the value of attribute inset.



8
9
10
# File 'lib/ariadne/forms/dsl/text_field_input.rb', line 8

def inset
  @inset
end

#labelObject (readonly)

Returns the value of attribute label.



8
9
10
# File 'lib/ariadne/forms/dsl/text_field_input.rb', line 8

def label
  @label
end

#leading_visualObject (readonly)

Returns the value of attribute leading_visual.



8
9
10
# File 'lib/ariadne/forms/dsl/text_field_input.rb', line 8

def leading_visual
  @leading_visual
end

#monospaceObject (readonly)

Returns the value of attribute monospace.



8
9
10
# File 'lib/ariadne/forms/dsl/text_field_input.rb', line 8

def monospace
  @monospace
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/ariadne/forms/dsl/text_field_input.rb', line 8

def name
  @name
end

#show_clear_buttonObject (readonly)

Returns the value of attribute show_clear_button.



8
9
10
# File 'lib/ariadne/forms/dsl/text_field_input.rb', line 8

def show_clear_button
  @show_clear_button
end

#visually_hide_labelObject (readonly)

Returns the value of attribute visually_hide_label.



8
9
10
# File 'lib/ariadne/forms/dsl/text_field_input.rb', line 8

def visually_hide_label
  @visually_hide_label
end

Instance Method Details

#focusable?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/ariadne/forms/dsl/text_field_input.rb', line 41

def focusable?
  true
end

#to_componentObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/ariadne/forms/dsl/text_field_input.rb', line 26

def to_component
  html_attrs = @input_attributes || {}
  html_attrs[:placeholder] = @placeholder if @placeholder.present?
  html_attrs[:disabled] = true if @disabled
  leading_visual_heroicon = @options.delete(:leading_visual_heroicon)

  text = Ariadne::Form::TextField::Component.new(name: @name, label: @label, caption: @caption, html_attrs: html_attrs, **@options)
  text.with_leading_visual_heroicon(**leading_visual_heroicon) if leading_visual_heroicon.present?
  text
end

#typeObject



37
38
39
# File 'lib/ariadne/forms/dsl/text_field_input.rb', line 37

def type
  :text_field
end

#validation_argumentsObject



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/ariadne/forms/dsl/text_field_input.rb', line 45

def validation_arguments
  if auto_check_src.present?
    super.merge(
      data: {
        target: "primer-text-field.validationElement",
      },
    )
  else
    super
  end
end

#validation_error_icon_targetObject



61
62
63
# File 'lib/ariadne/forms/dsl/text_field_input.rb', line 61

def validation_error_icon_target
  "primer-text-field.validationErrorIcon"
end

#validation_message_argumentsObject



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/ariadne/forms/dsl/text_field_input.rb', line 65

def validation_message_arguments
  if auto_check_src.present?
    super.merge(
      data: {
        target: "primer-text-field.validationMessageElement",
      },
    )
  else
    super
  end
end

#validation_success_icon_targetObject



57
58
59
# File 'lib/ariadne/forms/dsl/text_field_input.rb', line 57

def validation_success_icon_target
  "primer-text-field.validationSuccessIcon"
end