Class: Primer::Beta::ButtonGroup::MenuButton

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

Overview

Renders a button in a <%= link_to_component(Primer::Beta::ButtonGroup) %> that displays an <%= link_to_component(Primer::Alpha::ActionMenu) %> when clicked. This component should not be used outside of a ‘ButtonGroup` context.

This component yields both the button and the list to the block when rendered.

“‘erb <%= render(Primer::Beta::ButtonGroup.new) do |group| %>

<% group.with_menu_button do |menu, button| %>
  <% menu.with_item(label: "Item 1") %>
  <% button.with_trailing_visual_icon(icon: "triangle-down") %>
<% end %>

<% end %> “‘

Constant Summary

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 AttributesHelper

AttributesHelper::PLURAL_ARIA_ATTRIBUTES, AttributesHelper::PLURAL_DATA_ATTRIBUTES

Instance Method Summary collapse

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 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(menu_arguments: {}, button_arguments: {}) ⇒ MenuButton

Returns a new instance of MenuButton.

Parameters:

  • menu_arguments (Hash) (defaults to: {})

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

  • button_arguments (Hash) (defaults to: {})

    The arguments accepted by <%= link_to_component(Primer::Beta::Button) %> or <%= link_to_component(Primer::Beta::IconButton) %>, depending on the value of the ‘icon:` argument.



105
106
107
108
# File 'app/components/primer/beta/button_group.rb', line 105

def initialize(menu_arguments: {}, button_arguments: {})
  @menu = Primer::Alpha::ActionMenu.new(**menu_arguments)
  @button = @menu.with_show_button(icon: "triangle-down", **button_arguments)
end

Instance Method Details

#before_renderObject



116
117
118
# File 'app/components/primer/beta/button_group.rb', line 116

def before_render
  content
end

#callObject



120
121
122
# File 'app/components/primer/beta/button_group.rb', line 120

def call
  render(@menu)
end

#render_in(view_context, &block) ⇒ Object



110
111
112
113
114
# File 'app/components/primer/beta/button_group.rb', line 110

def render_in(view_context, &block)
  super(view_context) do
    block.call(@menu, @button)
  end
end