# frozen_string_literal: true module Ariadne module Forms module Dsl # :nodoc: class TextFieldInput < Input attr_reader( :name, :label, :show_clear_button, :leading_visual, :clear_button_id, :visually_hide_label, :inset, :monospace, :field_wrap_classes, :auto_check_src ) 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 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 def type :text_field end def focusable? true end def validation_arguments if auto_check_src.present? super.merge( data: { target: "primer-text-field.validationElement", }, ) else super end end def validation_success_icon_target "primer-text-field.validationSuccessIcon" end def validation_error_icon_target "primer-text-field.validationErrorIcon" end def validation_message_arguments if auto_check_src.present? super.merge( data: { target: "primer-text-field.validationMessageElement", }, ) else super end end end end end end