@Robin S I was thinking that since a JS callback is necessary to make it do anything, it was simplest just to keep it all JS, contained to one definition. At least for the case that prompted adding this feature (PageEditChildren module). But for cases like what you are describing, what you say makes a lot of sense. I will add an $inputfield->addHeaderAction([ ... ]); that does the same thing, maybe like these examples?
// click action
$inputfield->addHeaderAction([
'icon' => 'hand-stop-o',
'overIcon' => 'hand-peace-o',
'tooltip' => 'Hello world',
'event' => 'myEvent'
]);
// toggle action
$inputfield->addHeaderAction([
'onIcon' => 'toggle-on',
'onEvent' => 'MyOnEvent',
'onTooltip' => 'Click to toggle off',
'offIcon' => 'toggle-off',
'offEvent' => 'MyOffEvent',
'offTooltip' => 'Click to toggle on',
]);
// link action
$inputfield->addHeaderAction([
'icon' => 'fa-link',
'href' => 'https://processwire.com/api/ref/',
'tooltip' => 'API reference',
'target' => '_blank', // or 'modal' or omit for '_self'
]);