Sha256: 0ec34b5067869daca28e587e62c496f52bf0c0a516e4b6130d4b1916f7702640

Contents?: true

Size: 1.42 KB

Versions: 18

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

module Primer
  module Alpha
    # StackItem is a layout component designed to be used as the child of a Stack.
    class StackItem < Primer::Component
      DEFAULT_TAG = :div

      # StackItem's grow argument. Used internally.
      class GrowArg < Primer::ResponsiveArg
        attr_reader :values
        DEFAULT = false
        OPTIONS = [
          nil,
          DEFAULT,
          true
        ].freeze

        def initialize(values)
          @values = fetch_or_fallback_all(OPTIONS, values, DEFAULT)
        end

        def self.arg_name
          :grow
        end
      end

      ARG_CLASSES = [GrowArg].freeze

      # @param tag [Symbol] Customize the element type of the rendered container.
      # @param grow [Boolean] Allow item to keep size or expand to fill the available space.
      # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
      def initialize(tag: DEFAULT_TAG, grow: false, **system_arguments)
        @tag = tag
        @grow = grow
        @system_arguments = system_arguments
        @system_arguments[:tag] = tag

        @system_arguments[:classes] = class_names(
          @system_arguments.delete(:classes),
          "StackItem"
        )

        @system_arguments[:data] = merge_data(
          @system_arguments, {
            data: {
              **GrowArg.for(grow).to_data_attributes
            }
          }
        )
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
primer_view_components-0.36.5 app/components/primer/alpha/stack_item.rb
openproject-primer_view_components-0.52.2 app/components/primer/alpha/stack_item.rb
primer_view_components-0.36.4 app/components/primer/alpha/stack_item.rb
openproject-primer_view_components-0.52.1 app/components/primer/alpha/stack_item.rb
openproject-primer_view_components-0.52.0 app/components/primer/alpha/stack_item.rb
primer_view_components-0.36.3 app/components/primer/alpha/stack_item.rb
openproject-primer_view_components-0.51.0 app/components/primer/alpha/stack_item.rb
primer_view_components-0.36.2 app/components/primer/alpha/stack_item.rb
openproject-primer_view_components-0.50.1 app/components/primer/alpha/stack_item.rb
openproject-primer_view_components-0.50.0 app/components/primer/alpha/stack_item.rb
primer_view_components-0.36.1 app/components/primer/alpha/stack_item.rb
primer_view_components-0.36.0 app/components/primer/alpha/stack_item.rb
openproject-primer_view_components-0.49.2 app/components/primer/alpha/stack_item.rb
primer_view_components-0.35.2 app/components/primer/alpha/stack_item.rb
openproject-primer_view_components-0.49.1 app/components/primer/alpha/stack_item.rb
openproject-primer_view_components-0.49.0 app/components/primer/alpha/stack_item.rb
primer_view_components-0.35.1 app/components/primer/alpha/stack_item.rb
primer_view_components-0.35.0 app/components/primer/alpha/stack_item.rb