Sha256: 59a201fb7f9442d3afe4542371843851185f5a0d471ccdc9df862d1db92c3621

Contents?: true

Size: 1.9 KB

Versions: 120

Compression:

Stored size: 1.9 KB

Contents

# frozen_string_literal: true

module Primer
  module Alpha
    # `Dropdown` is a lightweight context menu for housing navigation and actions.
    # They're great for instances where you don't need the full power (and code) of the SelectMenu.
    class Dropdown < Primer::Component
      status :alpha

      # Required trigger for the dropdown. Has the same arguments as <%= link_to_component(Primer::ButtonComponent) %>,
      # but it is locked as a `summary` tag.
      renders_one :button, lambda { |**system_arguments|
        @button_arguments = system_arguments
        @button_arguments[:button] = true
        @button_arguments[:dropdown] = @with_caret

        Primer::Content.new
      }

      # Required context menu for the dropdown.
      #
      # @param as [Symbol] When `as` is `:list`, wraps the menu in a `<ul>` with a `<li>` for each item.
      # @param direction [Symbol] <%= one_of(Primer::Alpha::Dropdown::Menu::DIRECTION_OPTIONS) %>
      # @param scheme [Symbol] Pass `:dark` for dark mode theming
      # @param header [String] Optional string to display as the header
      # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
      renders_one :menu, "Primer::Alpha::Dropdown::Menu"

      # @param overlay [Symbol] <%= one_of(Primer::Beta::Details::OVERLAY_MAPPINGS.keys) %>
      # @param with_caret [Boolean] Whether or not a caret should be rendered in the button.
      # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
      def initialize(overlay: :default, with_caret: false, **system_arguments)
        @with_caret = with_caret

        @system_arguments = system_arguments
        @system_arguments[:overlay] = overlay
        @system_arguments[:reset] = true
        @system_arguments[:classes] = class_names(
          @system_arguments[:classes],
          "dropdown"
        )
      end

      def render?
        button? && menu?
      end
    end
  end
end

Version data entries

120 entries across 120 versions & 2 rubygems

Version Path
primer_view_components-0.30.0 app/components/primer/alpha/dropdown.rb
openproject-primer_view_components-0.39.1 app/components/primer/alpha/dropdown.rb
openproject-primer_view_components-0.39.0 app/components/primer/alpha/dropdown.rb
openproject-primer_view_components-0.38.0 app/components/primer/alpha/dropdown.rb
primer_view_components-0.29.0 app/components/primer/alpha/dropdown.rb
primer_view_components-0.28.0 app/components/primer/alpha/dropdown.rb
openproject-primer_view_components-0.37.1 app/components/primer/alpha/dropdown.rb
openproject-primer_view_components-0.37.0 app/components/primer/alpha/dropdown.rb
openproject-primer_view_components-0.36.2 app/components/primer/alpha/dropdown.rb
openproject-primer_view_components-0.36.1 app/components/primer/alpha/dropdown.rb
openproject-primer_view_components-0.36.0 app/components/primer/alpha/dropdown.rb
primer_view_components-0.27.0 app/components/primer/alpha/dropdown.rb
openproject-primer_view_components-0.35.2 app/components/primer/alpha/dropdown.rb
openproject-primer_view_components-0.35.1 app/components/primer/alpha/dropdown.rb
primer_view_components-0.26.1 app/components/primer/alpha/dropdown.rb
openproject-primer_view_components-0.35.0 app/components/primer/alpha/dropdown.rb
primer_view_components-0.26.0 app/components/primer/alpha/dropdown.rb
openproject-primer_view_components-0.34.0 app/components/primer/alpha/dropdown.rb
openproject-primer_view_components-0.33.2 app/components/primer/alpha/dropdown.rb
openproject-primer_view_components-0.33.1 app/components/primer/alpha/dropdown.rb