Skip to content

Commit

Permalink
re-use getNewIndexFromPresets
Browse files Browse the repository at this point in the history
  • Loading branch information
matiasbenedetto committed Jun 13, 2024
1 parent 19307c0 commit 8465ece
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions packages/edit-site/src/components/global-styles/font-sizes.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,7 @@ import { unlock } from '../../lock-unlock';
const { useGlobalSetting } = unlock( blockEditorPrivateApis );
import Subtitle from './subtitle';
import { NavigationButtonAsItem } from './navigation-button';

function getAvailableIndex( sizes ) {
// Filter the slug field that ends with custom-{number}.
const indexes = sizes.map( ( size ) => {
const match = size.slug.match( /custom-(\d+)$/ );
return match ? parseInt( match[ 1 ], 10 ) : 0;
} );
return Math.max( ...indexes ) + 1;
}
import { getNewIndexFromPresets } from './utils';

function FontSizes() {
const [ fontSizes, setFontSizes ] = useGlobalSetting(
Expand All @@ -39,7 +31,7 @@ function FontSizes() {
const sizes = fontSizes.theme ?? fontSizes.default;

const handleAddFontSize = () => {
const index = getAvailableIndex( sizes );
const index = getNewIndexFromPresets( sizes, 'custom-' );
const newFontSize = {
/* translators: %d: font size index */
name: sprintf( __( 'New Font Size %d' ), index ),
Expand Down

0 comments on commit 8465ece

Please sign in to comment.