Sha256: 7463a44fd6836c2f24d7e0f59c0486d746d571d76c0061f28993740908fcceb6

Contents?: true

Size: 1.12 KB

Versions: 3

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

module Tailwinds
  module Form
    # Provides Tailwind-styled forms
    class Builder < Tramway::Views::FormBuilder
      def text_field(attribute, **options, &)
        input = super(attribute, **options.merge(class: text_input_class))
        render(Tailwinds::Form::TextFieldComponent.new(input, attribute, object_name:, **options), &)
      end

      def password_field(attribute, **options, &)
        input = super(attribute, **options.merge(class: text_input_class))
        render(Tailwinds::Form::TextFieldComponent.new(input, attribute, object_name:, **options), &)
      end

      def file_field(attribute, **options, &)
        input = super(attribute, **options.merge(class: :hidden))

        render(Tailwinds::Form::FileFieldComponent.new(input, attribute, object_name:, **options), &)
      end

      def submit(action, **options, &)
        render(Tailwinds::Form::SubmitButtonComponent.new(action, **options), &)
      end

      private

      def text_input_class
        'w-full px-3 py-2 border border-gray-300 rounded focus:outline-none focus:border-red-500'
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tramway-0.3.1.2 app/components/tailwinds/form/builder.rb
tramway-0.3.1.1 app/components/tailwinds/form/builder.rb
tramway-0.3.1 app/components/tailwinds/form/builder.rb