Class: Primer::OpenProject::SubHeader::Menu
- Inherits:
-
Component
- Object
- ViewComponent::Base
- Component
- Primer::OpenProject::SubHeader::Menu
- Defined in:
- app/components/primer/open_project/sub_header/menu.rb
Overview
A Helper class to create an ActionMenu with a required icon on the trigger button. It is meant to be used inside the SubHeader Do not use standalone
Constant Summary
Constants inherited from Component
Component::INVALID_ARIA_LABEL_TAGS
Constants included from Status::Dsl
Constants included from ViewHelper
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
- #before_render ⇒ Object
- #call ⇒ Object
-
#initialize(icon_only: false, leading_icon:, label:, trailing_icon: nil, button_arguments: {}, **system_arguments) ⇒ Menu
constructor
A new instance of Menu.
- #set_show_button(**system_arguments) ⇒ Object
Methods inherited from Component
Methods included from JoinStyleArgumentsHelper
Methods included from TestSelectorHelper
Methods included from FetchOrFallbackHelper
#fetch_or_fallback, #fetch_or_fallback_boolean, #silence_deprecations?
Methods included from ClassNameHelper
Methods included from AttributesHelper
#aria, #data, #extract_data, #merge_aria, #merge_data, #merge_prefixed_attribute_hashes
Methods included from ExperimentalSlotHelpers
Methods included from ExperimentalRenderHelpers
Constructor Details
#initialize(icon_only: false, leading_icon:, label:, trailing_icon: nil, button_arguments: {}, **system_arguments) ⇒ Menu
Returns a new instance of Menu.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/components/primer/open_project/sub_header/menu.rb', line 34 def initialize(icon_only: false, leading_icon:, label:, trailing_icon: nil, button_arguments: {}, **system_arguments) @icon_only = icon_only @leading_icon = leading_icon @trailing_icon = trailing_icon @label = label if @label.nil? || @label.empty? raise ArgumentError, "You need to provide a valid label." end @button_arguments = @menu = Primer::Alpha::ActionMenu.new(**system_arguments) end |
Instance Method Details
#before_render ⇒ Object
52 53 54 55 56 57 |
# File 'app/components/primer/open_project/sub_header/menu.rb', line 52 def before_render if raise ArgumentError, "Do not use the show_button slot within the SubHeader, as it is reserved. Instead provide a leading_icon within the subHeader button slot" end end |
#call ⇒ Object
59 60 61 62 63 64 |
# File 'app/components/primer/open_project/sub_header/menu.rb', line 59 def call render(@menu) do (**@button_arguments) content end end |
#set_show_button(**system_arguments) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/components/primer/open_project/sub_header/menu.rb', line 15 def (**system_arguments) aria_label = aria("label", system_arguments) || @label if @icon_only @menu.(icon: @leading_icon, "aria-label": aria_label, **system_arguments) else @menu.("aria-label": aria_label, **system_arguments) do || .with_leading_visual_icon(icon: @leading_icon) .with_trailing_action_icon(icon: @trailing_icon) unless @trailing_icon.nil? @label end end end |