Skip to content

Commit

Permalink
Add ability to customise the button label
Browse files Browse the repository at this point in the history
  • Loading branch information
getdave committed Jan 12, 2023
1 parent 420ba0a commit fa447b9
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions packages/block-editor/src/components/inserter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,25 @@ const defaultRenderToggle = ( {
hasSingleBlockType,
toggleProps = {},
prioritizePatterns,
label,
} ) => {
let label;
if ( hasSingleBlockType ) {
label = sprintf(
let buttonLabel;

if ( label ) {
buttonLabel = label;
} else if ( hasSingleBlockType ) {
buttonLabel = sprintf(
// translators: %s: the name of the block when there is only one
_x( 'Add %s', 'directly add the only allowed block' ),
blockTitle
);
} else if ( prioritizePatterns ) {
label = __( 'Add pattern' );
buttonLabel = __( 'Add pattern' );
} else {
label = _x( 'Add block', 'Generic label for block inserter button' );
buttonLabel = _x(
'Add block',
'Generic label for block inserter button'
);
}

const { onClick, ...rest } = toggleProps;
Expand All @@ -59,7 +66,7 @@ const defaultRenderToggle = ( {
return (
<Button
icon={ plus }
label={ label }
label={ buttonLabel }
tooltipPosition="bottom"
onClick={ handleClick }
className="block-editor-inserter__toggle"
Expand Down Expand Up @@ -109,6 +116,7 @@ class Inserter extends Component {
hasItems,
renderToggle = defaultRenderToggle,
prioritizePatterns,
toggleLabel,
} = this.props;

return renderToggle( {
Expand All @@ -120,6 +128,7 @@ class Inserter extends Component {
directInsertBlock,
toggleProps,
prioritizePatterns,
label: toggleLabel,
} );
}

Expand Down

0 comments on commit fa447b9

Please sign in to comment.