Sha256: cdeb8c6afc892f097e1f3f432bfab19ec78082c21335595f022bc93f0956bf73

Contents?: true

Size: 1.78 KB

Versions: 32

Compression:

Stored size: 1.78 KB

Contents

# frozen_string_literal: true

module Primer
  module OpenProject
    # A layouting component used to arrange multiple components next / below each other
    class FlexLayout < Primer::Component
      status :open_project

      renders_many :rows, lambda { |**system_arguments, &block|
        child_component(system_arguments, &block)
      }
      renders_many :columns, lambda { |**system_arguments, &block|
        child_component(system_arguments, &block)
      }
      # boxes are used when direction is set to row or column based on responsive breakpoints
      renders_many :boxes, lambda { |**system_arguments, &block|
        child_component(system_arguments, &block)
      }

      # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
      def initialize(**system_arguments)
        super

        @system_arguments = deny_tag_argument(**system_arguments) || {}
        @system_arguments[:display] = :flex
      end

      private

      def render?
        # no slot provided
        raise ArgumentError, "You have to provide either rows, columns or boxes as a slot" if rows.empty? && columns.empty? && boxes.empty?

        if [rows, columns, boxes].count { |arr| !arr.empty? } == 1
          # only rows or columns or boxes are used
          true
        elsif [rows, columns, boxes].count { |arr| !arr.empty? } > 1
          # rows, columns and boxes are used together, which is not allowed
          raise ArgumentError, "You can't mix row, column and box slots"
        end
      end

      def child_component(system_arguments, &block)
        if system_arguments[:flex_layout] == true
          Primer::OpenProject::FlexLayout.new(**system_arguments.except(:flex_layout), &block)
        else
          Primer::Box.new(**system_arguments || {})
        end
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
openproject-primer_view_components-0.35.0 app/components/primer/open_project/flex_layout.rb
openproject-primer_view_components-0.34.0 app/components/primer/open_project/flex_layout.rb
openproject-primer_view_components-0.33.2 app/components/primer/open_project/flex_layout.rb
openproject-primer_view_components-0.33.1 app/components/primer/open_project/flex_layout.rb
openproject-primer_view_components-0.33.0 app/components/primer/open_project/flex_layout.rb
openproject-primer_view_components-0.32.1 app/components/primer/open_project/flex_layout.rb
openproject-primer_view_components-0.32.0 app/components/primer/open_project/flex_layout.rb
openproject-primer_view_components-0.29.1 app/components/primer/open_project/flex_layout.rb
openproject-primer_view_components-0.29.0 app/components/primer/open_project/flex_layout.rb
openproject-primer_view_components-0.28.1 app/components/primer/open_project/flex_layout.rb
openproject-primer_view_components-0.28.0 app/components/primer/open_project/flex_layout.rb
openproject-primer_view_components-0.27.0 app/components/primer/open_project/flex_layout.rb
openproject-primer_view_components-0.26.0 app/components/primer/open_project/flex_layout.rb
openproject-primer_view_components-0.25.1 app/components/primer/open_project/flex_layout.rb
openproject-primer_view_components-0.25.0 app/components/primer/open_project/flex_layout.rb
openproject-primer_view_components-0.24.0 app/components/primer/open_project/flex_layout.rb
openproject-primer_view_components-0.23.0 app/components/primer/open_project/flex_layout.rb
openproject-primer_view_components-0.22.2 app/components/primer/open_project/flex_layout.rb
openproject-primer_view_components-0.22.1 app/components/primer/open_project/flex_layout.rb
openproject-primer_view_components-0.22.0 app/components/primer/open_project/flex_layout.rb