Sha256: 9307fe21f60265bb571a95a10dab14d5e69b5fd996913409e0cf69b382bd6b3f

Contents?: true

Size: 1.71 KB

Versions: 27

Compression:

Stored size: 1.71 KB

Contents

# frozen_string_literal: true

module Primer
  module Forms
    module Dsl
      # :nodoc:
      class TextFieldInput < Input
        attr_reader(
          *%i[
            name label show_clear_button leading_visual clear_button_id
            visually_hide_label inset monospace field_wrap_classes
          ]
        )

        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)
          @clear_button_id = system_arguments.delete(:clear_button_id)
          @inset = system_arguments.delete(:inset)
          @monospace = system_arguments.delete(:monospace)

          super(**system_arguments)

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

          add_input_classes("FormControl-inset") if inset?
          add_input_classes("FormControl-monospace") if monospace?

          @field_wrap_classes = class_names(
            "FormControl-input-wrap",
            Primer::Forms::Dsl::Input::SIZE_MAPPINGS[size],
            "FormControl-input-wrap--trailingAction": show_clear_button?,
            "FormControl-input-wrap--leadingVisual": leading_visual?
          )
        end

        alias show_clear_button? show_clear_button
        alias inset? inset
        alias monospace? monospace

        def to_component
          TextField.new(input: self)
        end

        def type
          :text_field
        end

        def focusable?
          true
        end

        def leading_visual?
          !!@leading_visual
        end
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
primer_view_components-0.0.112 lib/primer/forms/dsl/text_field_input.rb
primer_view_components-0.0.111 lib/primer/forms/dsl/text_field_input.rb
primer_view_components-0.0.110 lib/primer/forms/dsl/text_field_input.rb
primer_view_components-0.0.109 lib/primer/forms/dsl/text_field_input.rb
primer_view_components-0.0.108 lib/primer/forms/dsl/text_field_input.rb
primer_view_components-0.0.107 lib/primer/forms/dsl/text_field_input.rb
primer_view_components-0.0.106 lib/primer/forms/dsl/text_field_input.rb
primer_view_components-0.0.105 lib/primer/forms/dsl/text_field_input.rb
primer_view_components-0.0.104 lib/primer/forms/dsl/text_field_input.rb
primer_view_components-0.0.103 lib/primer/forms/dsl/text_field_input.rb
primer_view_components-0.0.102 lib/primer/forms/dsl/text_field_input.rb
primer_view_components-0.0.101 lib/primer/forms/dsl/text_field_input.rb
primer_view_components-0.0.100 lib/primer/forms/dsl/text_field_input.rb
primer_view_components-0.0.99 lib/primer/forms/dsl/text_field_input.rb
primer_view_components-0.0.98 lib/primer/forms/dsl/text_field_input.rb
primer_view_components-0.0.97 lib/primer/forms/dsl/text_field_input.rb
primer_view_components-0.0.96 lib/primer/forms/dsl/text_field_input.rb
primer_view_components-0.0.95 lib/primer/forms/dsl/text_field_input.rb
primer_view_components-0.0.94 lib/primer/forms/dsl/text_field_input.rb
primer_view_components-0.0.93 lib/primer/forms/dsl/text_field_input.rb