Sha256: acac46a299281761a8770c93d400cd03a12e3ada2281b02992a4a890e50237b0

Contents?: true

Size: 983 Bytes

Versions: 22

Compression:

Stored size: 983 Bytes

Contents

module Spina
  module Forms
    class TextFieldComponent < ApplicationComponent
      attr_accessor :f, :method, :size, :autofocus
      
      def initialize(f, method, size: "md", autofocus: false)
        @f = f
        @method = method
        @size = size
        @autofocus = autofocus
      end
      
      def controllers
        contr = []
        contr << "autofocus" if autofocus
        contr.join(" ")
      end
      
      def size_styles
        case size
        when "lg"
          "px-4 py-3"
        else
          "text-sm"
        end
      end
      
      def error_styles
        if has_errors?
          "border-red-500 ring-red-500 ring-1"
        else
          ""
        end
      end
      
      def error_messages
        f.object.errors[method.to_sym]
      end
      
      def has_errors?
        error_messages.present?
      end
      
      def placeholder
        f.object.class.human_attribute_name(method)
      end
      
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
spina-2.12.0 app/components/spina/forms/text_field_component.rb
spina-2.11.0 app/components/spina/forms/text_field_component.rb
spina-2.10.0 app/components/spina/forms/text_field_component.rb
spina-2.9.1 app/components/spina/forms/text_field_component.rb
spina-2.9.0 app/components/spina/forms/text_field_component.rb
spina-2.8.1 app/components/spina/forms/text_field_component.rb
spina-2.8.0 app/components/spina/forms/text_field_component.rb
spina-2.7.0 app/components/spina/forms/text_field_component.rb
spina-2.6.2 app/components/spina/forms/text_field_component.rb
spina-2.6.1 app/components/spina/forms/text_field_component.rb
spina-2.6.0 app/components/spina/forms/text_field_component.rb
spina-2.5.0 app/components/spina/forms/text_field_component.rb
spina-2.4.0 app/components/spina/forms/text_field_component.rb
spina-2.3.5 app/components/spina/forms/text_field_component.rb
spina-2.3.4 app/components/spina/forms/text_field_component.rb
spina-2.3.3 app/components/spina/forms/text_field_component.rb
spina-2.3.2 app/components/spina/forms/text_field_component.rb
spina-2.3.1 app/components/spina/forms/text_field_component.rb
spina-2.3.0 app/components/spina/forms/text_field_component.rb
spina-2.2.0 app/components/spina/forms/text_field_component.rb