Skip to content

Commit 9634dee

Browse files
committed
✨Add middle_action similar to right_actions and left_actions, it should be called via location: :middle.
1 parent ebbae30 commit 9634dee

2 files changed

Lines changed: 32 additions & 4 deletions

File tree

app/components/primer/open_project/sub_header.html.erb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@
3131
</div>
3232

3333
<div class="SubHeader-middlePane" data-targets="<%= HIDDEN_FILTER_TARGET_SELECTOR %>">
34+
<% unless @middle_actions.nil? %>
35+
<% @middle_actions.each do |middle_action| %>
36+
<%= render(middle_action[:component]) do |action| %>
37+
<% middle_action[:block]&.call(action) %>
38+
<% end %>
39+
<% end %>
40+
<% end %>
41+
3442
<%= text %>
3543
</div>
3644

app/components/primer/open_project/sub_header.rb

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,13 @@ class SubHeader < Primer::Component
3939
if icon_only
4040
component = Primer::Beta::IconButton.new(**icon_args)
4141
@left_actions ||= []
42+
@middle_actions ||= []
4243
@right_actions ||= []
43-
target_actions = location == :left ? @left_actions : @right_actions
44+
target_actions = case location
45+
when :left then @left_actions
46+
when :middle then @middle_actions
47+
else @right_actions
48+
end
4449
target_actions.push({ component: component, block: block })
4550

4651
component
@@ -55,8 +60,13 @@ class SubHeader < Primer::Component
5560
component = Primer::OpenProject::SubHeader::Button.new(display: DESKTOP_ACTIONS_DISPLAY, **desktop_kwargs)
5661

5762
@left_actions ||= []
63+
@middle_actions ||= []
5864
@right_actions ||= []
59-
target_actions = location == :left ? @left_actions : @right_actions
65+
target_actions = case location
66+
when :left then @left_actions
67+
when :middle then @middle_actions
68+
else @right_actions
69+
end
6070
target_actions.push({ component: component, block: block })
6171

6272
component
@@ -71,8 +81,13 @@ class SubHeader < Primer::Component
7181
component = Primer::OpenProject::SubHeader::ButtonGroup.new(**desktop_kwargs)
7282

7383
@left_actions ||= []
84+
@middle_actions ||= []
7485
@right_actions ||= []
75-
target_actions = location == :left ? @left_actions : @right_actions
86+
target_actions = case location
87+
when :left then @left_actions
88+
when :middle then @middle_actions
89+
else @right_actions
90+
end
7691
target_actions.push({ component: component, block: block })
7792

7893
component
@@ -99,8 +114,13 @@ class SubHeader < Primer::Component
99114
component = Primer::OpenProject::SubHeader::Menu.new(icon_only: icon_only, display: DESKTOP_ACTIONS_DISPLAY, **desktop_kwargs)
100115

101116
@left_actions ||= []
117+
@middle_actions ||= []
102118
@right_actions ||= []
103-
target_actions = location == :left ? @left_actions : @right_actions
119+
target_actions = case location
120+
when :left then @left_actions
121+
when :middle then @middle_actions
122+
else @right_actions
123+
end
104124
target_actions.push({ component: component, block: block })
105125

106126
component

0 commit comments

Comments
 (0)