Class: Primer::DropdownComponent

Inherits:
Component
  • Object
show all
Includes:
ViewComponent::SlotableV2
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 inherited from Component

Component::STATUSES

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Instance Method Summary collapse

Methods inherited from Component

status

Methods included from ViewHelper

#primer

Methods included from JoinStyleArgumentsHelper

#join_style_arguments

Methods included from FetchOrFallbackHelper

#fetch_or_fallback, #fetch_or_fallback_boolean

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 %>



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

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)


71
72
73
# File 'app/components/primer/dropdown_component.rb', line 71

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