Sha256: 188dc9c0ebe503f69d62a52062dd962995b24b3db94a711df59682c9fca0383f

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

class Bootstrap
  class Component
    class HorizontalForm < Form
      def left_col_width
        @child_args.last && @child_args.last[0] || 2
      end

      def right_col_width
        @child_args.last && @child_args.last[1] || 10
      end

      add_tag_method :form, "form-horizontal"

      add_tag_method :label, "control-label" do |opts, _extra_args|
        prepend_class opts, "col-sm-#{left_col_width}"
        opts
      end

      add_div_method :input, nil do |opts, extra_args|
        type, label = extra_args
        prepend { tag :label, nil, for: opts[:id] } if label
        insert { inner_input opts.merge(type: type) }
        { class: "col-sm-#{right_col_width}" }
      end
      add_tag_method :inner_input, "form-control", tag: :input
      add_div_method :inner_checkbox, "checkbox"

      add_div_method :checkbox, nil do |opts, extra_args|
        inner_checkbox do
          label do
            inner_input "checkbox", extra_args.first, opts
          end
        end
        { class: "col-sm-offset-#{left_col_width} col-sm-#{right_col_width}" }
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
card-1.91 mod/bootstrap/lib/bootstrap/component/horizontal_form.rb
card-1.21.0 mod/bootstrap/lib/bootstrap/component/horizontal_form.rb