Skip to content

Commit

Permalink
Simplify getValidTextAlignments function
Browse files Browse the repository at this point in the history
  • Loading branch information
t-hamano committed May 20, 2024
1 parent 4a1d918 commit f75155a
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions packages/block-editor/src/hooks/text-align.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const TEXT_ALIGNMENT_OPTIONS = [
];

const VALID_TEXT_ALIGNMENTS = [ 'left', 'center', 'right' ];
const NO_TEXT_ALIGNMENTS = [];

/**
* Returns the valid text alignments.
Expand All @@ -54,19 +55,13 @@ const VALID_TEXT_ALIGNMENTS = [ 'left', 'center', 'right' ];
* @return {string[]} Valid text alignments.
*/
export function getValidTextAlignments( blockTextAlign ) {
let validTextAlignments;
if ( Array.isArray( blockTextAlign ) ) {
validTextAlignments = VALID_TEXT_ALIGNMENTS.filter( ( textAlign ) =>
return VALID_TEXT_ALIGNMENTS.filter( ( textAlign ) =>
blockTextAlign.includes( textAlign )
);
} else if ( blockTextAlign === true ) {
// `true` includes all alignments...
validTextAlignments = [ ...VALID_TEXT_ALIGNMENTS ];
} else {
validTextAlignments = [];
}

return validTextAlignments;
return blockTextAlign === true ? VALID_TEXT_ALIGNMENTS : NO_TEXT_ALIGNMENTS;
}

function BlockEditTextAlignmentToolbarControlsPure( {
Expand Down

0 comments on commit f75155a

Please sign in to comment.