Skip to content

Commit

Permalink
Add support for registered font sizes with decimals.
Browse files Browse the repository at this point in the history
  • Loading branch information
ndiego committed Nov 16, 2021
1 parent f323d96 commit 495f20c
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions packages/components/src/font-size-picker/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,11 @@ const CUSTOM_FONT_SIZE_OPTION = {
* Helper util to split a font size to its numeric value
* and its `unit`, if exists.
*
* @param {string|number} size Font size.
* @param {string} size Font size.
* @return {[number, string]} An array with the numeric value and the unit if exists.
*/
export function splitValueAndUnitFromSize( size ) {
/**
* The first matched result is ignored as it's the left
* hand side of the capturing group in the regex.
*/
const [ , numericValue, unit ] = size.split( /(\d+)/ );
const [ numericValue, unit ] = size.match( /[\d\.]+|\D+/g );
return [ numericValue, unit ];
}

Expand All @@ -38,7 +34,7 @@ export function splitValueAndUnitFromSize( size ) {
* @return {boolean} Whether the value is a simple css value.
*/
export function isSimpleCssValue( value ) {
const sizeRegex = /^(?!0)\d+(px|em|rem|vw|vh|%)?$/i;
const sizeRegex = /^(?!0)[\d\.]+(px|em|rem|vw|vh|%)?$/i;
return sizeRegex.test( value );
}

Expand Down Expand Up @@ -75,7 +71,7 @@ function getSelectOptions( optionsArray, disableCustomFontSizes ) {
name,
size,
__experimentalHint:
size && isSimpleCssValue( size ) && parseInt( size ),
size && isSimpleCssValue( size ) && parseFloat( size ),
} ) );
}

Expand Down

0 comments on commit 495f20c

Please sign in to comment.