Class: Primer::DropdownComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/primer/dropdown_component.rb

Overview

Dropdowns are lightweight context menus for housing navigation and actions. They’re great for instances where you don’t need the full power (and code) of the select menu.

Constant Summary

Constants included from Status::Dsl

Status::Dsl::STATUSES

Constants included from ViewHelper

ViewHelper::HELPERS

Constants included from TestSelectorHelper

TestSelectorHelper::TEST_SELECTOR_TAG

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Instance Method Summary collapse

Methods included from JoinStyleArgumentsHelper

#join_style_arguments

Methods included from TestSelectorHelper

#add_test_selector

Methods included from FetchOrFallbackHelper

#fetch_or_fallback, #fetch_or_fallback_boolean, #silence_deprecations?

Methods included from ClassNameHelper

#class_names

Constructor Details

#initialize(overlay: :default, reset: true, summary_classes: "", **system_arguments) ⇒ DropdownComponent

Returns a new instance of DropdownComponent.

Examples:

Default

<div>
  <%= render(Primer::DropdownComponent.new) do |c| %>
    <% c.button do %>
      Dropdown
    <% end %>

    <%= c.menu(header: "Options") do |menu|
      menu.item { "Item 1" }
      menu.item { "Item 2" }
      menu.item(divider: true)
      menu.item { "Item 3" }
      menu.item { "Item 4" }
    end %>
  <% end %>
</div>

With Direction

<div>
  <%= render(Primer::DropdownComponent.new) do |c| %>
    <% c.button do %>
      Dropdown
    <% end %>

    <%= c.menu(header: "Options", direction: :s) do |menu|
      menu.item { "Item 1" }
      menu.item { "Item 2" }
      menu.item(divider: true)
      menu.item { "Item 3" }
      menu.item { "Item 4" }
    end %>
  <% end %>
</div>

Parameters:

  • overlay (Symbol) (defaults to: :default)

    <%= one_of(Primer::DetailsComponent::OVERLAY_MAPPINGS.keys) %>

  • reset (Boolean) (defaults to: true)

    Whether to hide the default caret on the button

  • summary_classes (String) (defaults to: "")

    Custom classes to add to the button

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



57
58
59
60
61
62
63
64
65
66
67
# File 'app/components/primer/dropdown_component.rb', line 57

def initialize(overlay: :default, reset: true, summary_classes: "", **system_arguments)
  @system_arguments = system_arguments
  @system_arguments[:overlay] = overlay
  @system_arguments[:reset] = reset
  @system_arguments[:position] = :relative
  @system_arguments[:classes] = class_names(
    @system_arguments[:classes],
    "dropdown"
  )
  @summary_classes = summary_classes
end

Instance Method Details

#render?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'app/components/primer/dropdown_component.rb', line 69

def render?
  button.present? && menu.present?
end