@@ -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 )
@@ -293,7 +300,6 @@ def show_state?
293300 def set_action_arguments ( system_arguments , scheme : nil )
294301 system_arguments [ :ml ] ||= 2
295302 system_arguments [ :display ] = %i[ none flex ]
296- system_arguments [ :size ] = :medium
297303 system_arguments [ :scheme ] = scheme unless scheme . nil?
298304 system_arguments [ :classes ] = class_names (
299305 system_arguments [ :classes ] ,
@@ -304,6 +310,17 @@ def set_action_arguments(system_arguments, scheme: nil)
304310 system_arguments
305311 end
306312
313+ def enforce_consistent_button_size! ( system_arguments )
314+ size = system_arguments . fetch ( :size , DEFAULT_BUTTON_ACTION_SIZE )
315+ @page_header_button_action_size ||= size
316+ unless size == @page_header_button_action_size
317+ raise ArgumentError ,
318+ "PageHeader button actions must all use the same size. " \
319+ "Set the same `size:` for every button-like action (or omit it to use #{ DEFAULT_BUTTON_ACTION_SIZE . inspect } everywhere)."
320+ end
321+ system_arguments . merge ( size : @page_header_button_action_size )
322+ end
323+
307324 def create_mobile_alternatives ( component , mobile_icon , mobile_label , scheme , **system_arguments , &block )
308325 # All actions should collapse into a single actionMenu on mobile
309326 add_option_to_mobile_menu ( system_arguments , mobile_icon , mobile_label , scheme )
0 commit comments