Class: Primer::Alpha::ActionMenu::PrimaryMenu

Inherits:
Menu
  • Object
show all
Defined in:
app/components/primer/alpha/action_menu/primary_menu.rb

Overview

This component is part of <%= link_to_component(Primer::Alpha::ActionMenu) %> and should not be used as a standalone component.

Constant Summary collapse

DEFAULT_ANCHOR_ALIGN =
:start
DEFAULT_ANCHOR_SIDE =
:outside_bottom

Constants inherited from Menu

Menu::DEFAULT_PRELOAD, Menu::DEFAULT_SELECT_VARIANT, Menu::SELECT_VARIANT_OPTIONS

Constants inherited from Component

Component::INVALID_ARIA_LABEL_TAGS

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

Constants included from Primer::AttributesHelper

Primer::AttributesHelper::PLURAL_ARIA_ATTRIBUTES, Primer::AttributesHelper::PLURAL_DATA_ATTRIBUTES

Instance Attribute Summary collapse

Attributes inherited from Menu

#anchor_align, #anchor_side, #form_arguments, #list, #menu_id, #preload, #select_variant, #src

Instance Method Summary collapse

Methods inherited from Menu

#with_sub_menu_item

Methods inherited from Component

deprecated?, generate_id

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

Methods included from Primer::AttributesHelper

#aria, #data, #extract_data, #merge_aria, #merge_data, #merge_prefixed_attribute_hashes

Methods included from ExperimentalSlotHelpers

included

Methods included from ExperimentalRenderHelpers

included

Constructor Details

#initialize(anchor_align: DEFAULT_ANCHOR_ALIGN, anchor_side: DEFAULT_ANCHOR_SIDE, dynamic_label: false, dynamic_label_prefix: nil, **system_arguments) ⇒ PrimaryMenu

Returns a new instance of PrimaryMenu.

Parameters:

  • anchor_align (Symbol) (defaults to: DEFAULT_ANCHOR_ALIGN)

    <%= one_of(Primer::Alpha::Overlay::ANCHOR_ALIGN_OPTIONS) %>

  • anchor_side (Symbol) (defaults to: DEFAULT_ANCHOR_SIDE)

    <%= one_of(Primer::Alpha::Overlay::ANCHOR_SIDE_OPTIONS) %>

  • dynamic_label (Boolean) (defaults to: false)

    Whether or not to display the text of the currently selected item in the show button.

  • dynamic_label_prefix (String) (defaults to: nil)

    If provided, the prefix is prepended to the dynamic label and displayed in the show button.

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/components/primer/alpha/action_menu/primary_menu.rb', line 51

def initialize(
  anchor_align: DEFAULT_ANCHOR_ALIGN,
  anchor_side: DEFAULT_ANCHOR_SIDE,
  dynamic_label: false,
  dynamic_label_prefix: nil,
  **system_arguments
)
  @dynamic_label = dynamic_label
  @dynamic_label_prefix = dynamic_label_prefix

  system_arguments[:list_arguments] ||= {}

  system_arguments[:list_arguments][:data] = merge_data(
    system_arguments[:list_arguments],
    { data: { target: "action-menu.list" } }
  )

  super(
    anchor_align: anchor_align,
    anchor_side: anchor_side,
    **system_arguments
  )
end

Instance Attribute Details

#dynamic_labelObject (readonly)

Returns the value of attribute dynamic_label.



13
14
15
# File 'app/components/primer/alpha/action_menu/primary_menu.rb', line 13

def dynamic_label
  @dynamic_label
end

#dynamic_label_prefixObject (readonly)

Returns the value of attribute dynamic_label_prefix.



13
14
15
# File 'app/components/primer/alpha/action_menu/primary_menu.rb', line 13

def dynamic_label_prefix
  @dynamic_label_prefix
end

Instance Method Details

#itemsArray<ViewComponent::Slot>

Gets the list of configured menu items, which includes regular items, avatar items, groups, and dividers.

Returns:

  • (Array<ViewComponent::Slot>)


28
29
# File 'app/components/primer/alpha/action_menu/primary_menu.rb', line 28

def items
end

#with_avatar_item(**system_arguments) ⇒ Object

Adds an avatar item to the menu.

Parameters:

  • system_arguments (Hash)

    The arguments accepted by <%= link_to_component(Primer::Alpha::ActionList) %>‘s `item` slot.



10
11
# File 'app/components/primer/alpha/action_menu/primary_menu.rb', line 10

def with_avatar_item(**system_arguments)
end

#with_divider(**system_arguments) ⇒ Object

Adds a divider to the list. Dividers visually separate items.

Parameters:

  • system_arguments (Hash)

    The arguments accepted by <%= link_to_component(Primer::Alpha::ActionList::Divider) %>.



16
17
# File 'app/components/primer/alpha/action_menu/primary_menu.rb', line 16

def with_divider(**system_arguments)
end

#with_group(**system_arguments) ⇒ Object

Adds a group to the menu. Groups are a logical set of items with a header.

Parameters:

  • system_arguments (Hash)

    The arguments accepted by <%= link_to_component(Primer::Alpha::ActionMenu::Group) %>.



22
23
# File 'app/components/primer/alpha/action_menu/primary_menu.rb', line 22

def with_group(**system_arguments)
end

#with_item(**system_arguments) ⇒ Object

Adds an item to the menu.

Parameters:

  • system_arguments (Hash)

    The arguments accepted by <%= link_to_component(Primer::Alpha::ActionList) %>‘s `item` slot.



4
5
# File 'app/components/primer/alpha/action_menu/primary_menu.rb', line 4

def with_item(**system_arguments)
end

#with_show_button(**system_arguments, &block) ⇒ Object

Button to activate the menu.

Parameters:

  • system_arguments (Hash)

    The arguments accepted by <%= link_to_component(Primer::Alpha::Overlay) %>‘s `show_button` slot.



78
79
80
81
82
# File 'app/components/primer/alpha/action_menu/primary_menu.rb', line 78

def with_show_button(**system_arguments, &block)
  @overlay.with_show_button(**system_arguments, id: "#{@menu_id}-button", controls: "#{@menu_id}-list") do |button|
    evaluate_block(button, &block)
  end
end