Sha256: 433a8dca85ff6c2829b11ad7734398fb2ae15cdc7a28b3894830cf3998369c81

Contents?: true

Size: 935 Bytes

Versions: 5

Compression:

Stored size: 935 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

5 entries across 5 versions & 1 rubygems

Version Path
spina-2.15.1 app/components/spina/forms/text_field_component.rb
spina-2.15.0 app/components/spina/forms/text_field_component.rb
spina-2.14.0 app/components/spina/forms/text_field_component.rb
spina-2.13.1 app/components/spina/forms/text_field_component.rb
spina-2.13.0 app/components/spina/forms/text_field_component.rb