Skip to content

Commit

Permalink
Global font sizes: Ensure sizes are unique (#52483)
Browse files Browse the repository at this point in the history
  • Loading branch information
Petter Walbø Johnsgård committed Jul 11, 2023
1 parent 98c01fd commit a25cb9d
Showing 1 changed file with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,21 @@ function useHasTextColumnsControl( settings ) {
return settings?.typography?.textColumns;
}

function getUniqueFontSizesBySlug( settings ) {
const fontSizesPerOrigin = settings?.typography?.fontSizes ?? {};
const fontSizes = []
.concat( fontSizesPerOrigin?.custom ?? [] )
.concat( fontSizesPerOrigin?.theme ?? [] )
.concat( fontSizesPerOrigin.default ?? [] );

return fontSizes.reduce( ( acc, currentSize ) => {
if ( ! acc.some( ( { slug } ) => slug === currentSize.slug ) ) {
acc.push( currentSize );
}
return acc;
}, [] );
}

function TypographyToolsPanel( {
resetAllFilter,
onChange,
Expand Down Expand Up @@ -189,11 +204,8 @@ export default function TypographyPanel( {
// Font Size
const hasFontSizeEnabled = useHasFontSizeControl( settings );
const disableCustomFontSizes = ! settings?.typography?.customFontSize;
const fontSizesPerOrigin = settings?.typography?.fontSizes ?? {};
const fontSizes = []
.concat( fontSizesPerOrigin?.custom ?? [] )
.concat( fontSizesPerOrigin?.theme ?? [] )
.concat( fontSizesPerOrigin.default ?? [] );
const fontSizes = getUniqueFontSizesBySlug( settings );

const fontSize = decodeValue( inheritedValue?.typography?.fontSize );
const setFontSize = ( newValue, metadata ) => {
const actualValue = !! metadata?.slug
Expand Down

0 comments on commit a25cb9d

Please sign in to comment.