File tree Expand file tree Collapse file tree 4 files changed +72
-1
lines changed
app/components/primer/open_project/side_panel
previews/primer/open_project
test/components/primer/open_project Expand file tree Collapse file tree 4 files changed +72
-1
lines changed Original file line number Diff line number Diff line change @@ -21,7 +21,18 @@ class Section < Primer::Component
2121 icon : lambda { |**system_arguments , &block |
2222 system_arguments [ :scheme ] ||= :invisible
2323 Primer ::Beta ::IconButton . new ( **system_arguments , &block )
24- }
24+ } ,
25+ menu : lambda { |**system_arguments , &block |
26+ deny_tag_argument ( **system_arguments )
27+
28+ button_arguments = system_arguments . delete ( :button_arguments ) || { }
29+ button_arguments [ :scheme ] ||= :invisible
30+ raise ArgumentError . new ( "button_arguments must contain an icon:" ) if button_arguments [ :icon ] . blank?
31+
32+ Primer ::Alpha ::ActionMenu . new ( **system_arguments ) . tap do |menu |
33+ menu . with_show_button ( **button_arguments )
34+ end
35+ } ,
2536 }
2637
2738 renders_one :description , lambda { |**system_arguments , &block |
Original file line number Diff line number Diff line change @@ -33,6 +33,10 @@ def default
3333 # @label With custom component
3434 def with_component
3535 end
36+
37+ # @label With action menu
38+ def with_action_menu
39+ end
3640 end
3741 end
3842end
Original file line number Diff line number Diff line change 1+ <%=
2+ clazz = Class.new(ViewComponent::Base) do
3+ def self.name
4+ "CustomComponent"
5+ end
6+
7+ def call
8+ render(Primer::OpenProject::SidePanel::Section.new) do |section|
9+ section.with_title { "My custom component" }
10+ section.with_action_menu(
11+ anchor_align: :end,
12+ button_arguments: { icon: :gear, 'aria-label': 'Edit' }
13+ ) do |menu|
14+ menu.with_item(label: "Subitem 1") do |item|
15+ item.with_leading_visual_icon(icon: :paste)
16+ end
17+ menu.with_item(label: "Subitem 2") do |item|
18+ item.with_leading_visual_icon(icon: :log)
19+ end
20+ end
21+
22+ "Section content"
23+ end
24+ end
25+ end
26+
27+ render(Primer::Alpha::Layout.new) do |component|
28+ component.with_main do
29+ "Main content"
30+ end
31+ component.with_sidebar(row_placement: :start, col_placement: :end) do
32+ render(Primer::OpenProject::SidePanel.new) do |panel|
33+ panel.with_section(clazz.new)
34+ end
35+ end
36+ end
37+ %>
Original file line number Diff line number Diff line change @@ -62,6 +62,25 @@ def call
6262 assert_text ( "custom content" )
6363 end
6464
65+ def test_renders_action_menu
66+ render_inline ( Primer ::OpenProject ::SidePanel . new ) do |component |
67+ component . with_section do |section |
68+ section . with_title { "Section with menu" }
69+ section . with_action_menu ( button_arguments : { icon : :pencil , "aria-label" : "Menu" } ) do |menu |
70+ menu . with_item { "Menu item" }
71+ end
72+
73+ "Section content"
74+ end
75+ end
76+
77+ assert_selector ( ".SidePanel" )
78+ assert_selector ( ".SidePanel section" , count : 1 )
79+ assert_selector ( ".SidePanel .Button--iconOnly[aria-label='Menu']" )
80+ assert_selector ( ".SidePanel .ActionMenu" )
81+ assert_selector ( "li.ActionLIistItem" , count : 1 )
82+ end
83+
6584 def test_no_renders_empty_section
6685 render_inline ( Primer ::OpenProject ::SidePanel . new ) do |component |
6786 component . with_section do |section |
You can’t perform that action at this time.
0 commit comments