Sha256: 3a7e81bfcce1f324a0e2e356526e7f06f700a379585cfc8ef183cc337e0e308c

Contents?: true

Size: 1.47 KB

Versions: 5

Compression:

Stored size: 1.47 KB

Contents

# frozen_string_literal: true

module Primer
  module Dropdown
    # This component is part of `Dropdown` and should not be
    # used as a standalone component.
    class MenuComponent < Primer::Component
      SCHEME_DEFAULT = :default
      SCHEME_MAPPINGS = {
        SCHEME_DEFAULT => "",
        :dark => "dropdown-menu-dark"
      }.freeze

      DIRECTION_DEFAULT = :se
      DIRECTION_OPTIONS = [DIRECTION_DEFAULT, :sw, :w, :e, :ne, :s].freeze

      renders_many :items, lambda { |divider: false, **system_arguments|
        system_arguments[:tag] = :li
        system_arguments[:role] = :none if divider
        system_arguments[:classes] = class_names(
          system_arguments[:classes],
          "dropdown-item" => !divider,
          "dropdown-divider" => divider
        )

        Primer::BaseComponent.new(**system_arguments)
      }

      def initialize(direction: DIRECTION_DEFAULT, scheme: SCHEME_DEFAULT, header: nil, **system_arguments)
        @header = header
        @direction = direction
        @system_arguments = system_arguments

        @system_arguments[:tag] = "details-menu"
        @system_arguments[:role] = "menu"

        @system_arguments[:classes] = class_names(
          @system_arguments[:classes],
          "dropdown-menu",
          "dropdown-menu-#{fetch_or_fallback(DIRECTION_OPTIONS, direction, DIRECTION_DEFAULT)}",
          SCHEME_MAPPINGS[fetch_or_fallback(SCHEME_MAPPINGS.keys, scheme, SCHEME_DEFAULT)]
        )
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
primer_view_components-0.0.43 app/components/primer/dropdown/menu_component.rb
primer_view_components-0.0.42 app/components/primer/dropdown/menu_component.rb
primer_view_components-0.0.41 app/components/primer/dropdown/menu_component.rb
primer_view_components-0.0.40 app/components/primer/dropdown/menu_component.rb
primer_view_components-0.0.39 app/components/primer/dropdown/menu_component.rb