@@ -25,6 +25,8 @@ class PageHeader < Primer::Component
2525 DEFAULT_PARENT_LINK_DISPLAY = [ :block , :none ] . freeze
2626 BREADCRUMB_TRUNCATE_AT = 200
2727
28+ DEFAULT_BUTTON_ACTION_SIZE = :medium
29+
2830 STATE_DEFAULT = :show
2931 STATE_EDIT = :edit
3032 STATE_OPTIONS = [ STATE_DEFAULT , STATE_EDIT ] . freeze
@@ -68,6 +70,7 @@ class PageHeader < Primer::Component
6870 system_arguments [ :icon ] = icon
6971 system_arguments [ :"aria-label" ] ||= label
7072 system_arguments = set_action_arguments ( system_arguments , scheme : scheme )
73+ system_arguments = enforce_consistent_button_size! ( system_arguments )
7174
7275 component = Primer ::Beta ::IconButton
7376 create_mobile_alternatives ( component , mobile_icon , label , scheme , **system_arguments , &block )
@@ -78,6 +81,7 @@ class PageHeader < Primer::Component
7881 deny_tag_argument ( **system_arguments )
7982
8083 system_arguments = set_action_arguments ( system_arguments , scheme : scheme )
84+ system_arguments = enforce_consistent_button_size! ( system_arguments )
8185
8286 component = Primer ::Beta ::Button
8387 create_mobile_alternatives ( component , mobile_icon , mobile_label , scheme , **system_arguments , &block )
@@ -88,6 +92,7 @@ class PageHeader < Primer::Component
8892 deny_tag_argument ( **system_arguments )
8993
9094 system_arguments = set_action_arguments ( system_arguments , scheme : DEFAULT_ACTION_SCHEME )
95+ system_arguments = enforce_consistent_button_size! ( system_arguments )
9196
9297 component = Primer ::OpenProject ::ZenModeButton
9398 create_mobile_alternatives ( component , mobile_icon , mobile_label , DEFAULT_ACTION_SCHEME , **system_arguments , &block )
@@ -120,6 +125,7 @@ class PageHeader < Primer::Component
120125
121126 system_arguments [ :button_arguments ] ||= { }
122127 system_arguments [ :button_arguments ] = set_action_arguments ( system_arguments [ :button_arguments ] )
128+ system_arguments [ :button_arguments ] = enforce_consistent_button_size! ( system_arguments [ :button_arguments ] )
123129
124130 # Add the options individually to the mobile menu in the template
125131 @desktop_menu_block = block
@@ -138,6 +144,7 @@ class PageHeader < Primer::Component
138144 system_arguments [ :button_arguments ] ||= { }
139145 system_arguments [ :button_arguments ] [ :id ] = "dialog-show-#{ system_arguments [ :dialog_arguments ] [ :id ] } "
140146 system_arguments [ :button_arguments ] = set_action_arguments ( system_arguments [ :button_arguments ] )
147+ system_arguments [ :button_arguments ] = enforce_consistent_button_size! ( system_arguments [ :button_arguments ] )
141148
142149 component = Primer ::OpenProject ::PageHeader ::Dialog
143150 create_mobile_alternatives ( component , mobile_icon , mobile_label , :default , **system_arguments , &block )
@@ -291,17 +298,8 @@ def show_state?
291298 private
292299
293300 def set_action_arguments ( system_arguments , scheme : nil )
294- requested_size = system_arguments . key? ( :size ) ? system_arguments [ :size ] : :medium
295- @page_header_action_size ||= requested_size
296-
297- if requested_size != @page_header_action_size
298- raise ArgumentError ,
299- "PageHeader actions must all use the same size. Set the same `size:` for every action (or omit it to use :medium everywhere)."
300- end
301-
302301 system_arguments [ :ml ] ||= 2
303302 system_arguments [ :display ] = %i[ none flex ]
304- system_arguments [ :size ] = requested_size
305303 system_arguments [ :scheme ] = scheme unless scheme . nil?
306304 system_arguments [ :classes ] = class_names (
307305 system_arguments [ :classes ] ,
@@ -312,6 +310,20 @@ def set_action_arguments(system_arguments, scheme: nil)
312310 system_arguments
313311 end
314312
313+ def enforce_consistent_button_size! ( system_arguments )
314+ size = system_arguments . key? ( :size ) ? system_arguments [ :size ] : DEFAULT_BUTTON_ACTION_SIZE
315+ @page_header_button_action_size ||= size
316+
317+ if size != @page_header_button_action_size
318+ raise ArgumentError ,
319+ "PageHeader button actions must all use the same size. " \
320+ "Set the same `size:` for every button-like action (or omit it to use #{ DEFAULT_BUTTON_ACTION_SIZE . inspect } everywhere)."
321+ end
322+
323+ system_arguments [ :size ] = size
324+ system_arguments
325+ end
326+
315327 def create_mobile_alternatives ( component , mobile_icon , mobile_label , scheme , **system_arguments , &block )
316328 # All actions should collapse into a single actionMenu on mobile
317329 add_option_to_mobile_menu ( system_arguments , mobile_icon , mobile_label , scheme )
0 commit comments