Sha256: 80aa99624ea2fc8a2db249cc8754ac2e5ee9f41e5fa7110ca013ed5d3f9806cb

Contents?: true

Size: 904 Bytes

Versions: 12

Compression:

Stored size: 904 Bytes

Contents

# frozen_string_literal: true

require "primer/classify"

module Primer
  module Forms
    # :nodoc:
    class Group < BaseComponent
      VERTICAL = :vertical
      HORIZONTAL = :horizontal
      DEFAULT_LAYOUT = VERTICAL
      LAYOUTS = [VERTICAL, HORIZONTAL].freeze

      def initialize(inputs:, builder:, form:, layout: DEFAULT_LAYOUT, **system_arguments)
        @inputs = inputs
        @builder = builder
        @form = form
        @layout = layout
        @system_arguments = system_arguments

        @system_arguments[:display] = :none if inputs.all?(&:hidden?)

        @system_arguments[:classes] = class_names(
          @system_arguments.delete(:classes),
          "FormControl-horizontalGroup" => horizontal?,
          "FormControl-spacingWrapper" => !horizontal? && inputs.size > 1
        )
      end

      def horizontal?
        @layout == HORIZONTAL
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
primer_view_components-0.36.5 app/lib/primer/forms/group.rb
openproject-primer_view_components-0.52.2 app/lib/primer/forms/group.rb
primer_view_components-0.36.4 app/lib/primer/forms/group.rb
openproject-primer_view_components-0.52.1 app/lib/primer/forms/group.rb
openproject-primer_view_components-0.52.0 app/lib/primer/forms/group.rb
primer_view_components-0.36.3 app/lib/primer/forms/group.rb
openproject-primer_view_components-0.51.0 app/lib/primer/forms/group.rb
primer_view_components-0.36.2 app/lib/primer/forms/group.rb
openproject-primer_view_components-0.50.1 app/lib/primer/forms/group.rb
openproject-primer_view_components-0.50.0 app/lib/primer/forms/group.rb
primer_view_components-0.36.1 app/lib/primer/forms/group.rb
primer_view_components-0.36.0 app/lib/primer/forms/group.rb