@@ -16,6 +16,10 @@ import { camelCase } from 'lodash'
1616 */
1717import { sprintf } from '@wordpress/i18n'
1818
19+ const isCSSVarValue = value => {
20+ return typeof value === 'string' && value . startsWith ( 'var' )
21+ }
22+
1923export const createTypographyStyles = ( attrNameTemplate = '%s' , screen = 'desktop' , blockAttributes = { } , options = { } ) => {
2024 const getAttrName = attrName => camelCase ( sprintf ( attrNameTemplate , attrName ) )
2125 const getValue = __getValue ( blockAttributes , getAttrName , '' )
@@ -34,10 +38,14 @@ export const createTypographyStyles = ( attrNameTemplate = '%s', screen = 'deskt
3438 const tabletFontSize = getValue ( 'TabletFontSize' )
3539 const mobileFontSize = getValue ( 'MobileFontSize' )
3640
41+ const desktopFontSizeUnit = isCSSVarValue ( desktopFontSize ) ? '' : getValue ( 'FontSizeUnit' ) || 'px'
42+ const tabletFontSizeUnit = isCSSVarValue ( tabletFontSize ) ? '' : getValue ( 'FontSizeUnit' ) || 'px'
43+ const mobileFontSizeUnit = isCSSVarValue ( mobileFontSize ) ? '' : getValue ( 'FontSizeUnit' ) || 'px'
44+
3745 if ( screen !== 'tablet' && screen !== 'mobile' ) { // Desktop.
3846 styles = {
3947 fontFamily : getValue ( 'FontFamily' ) !== '' ? getFontFamily ( getValue ( 'FontFamily' ) ) : undefined ,
40- fontSize : desktopFontSize !== '' ? appendImportant ( `${ desktopFontSize } ${ getValue ( 'FontSizeUnit' ) || 'px' } ` , importantSize ) : undefined ,
48+ fontSize : desktopFontSize !== '' ? appendImportant ( `${ desktopFontSize } ${ desktopFontSizeUnit } ` , importantSize ) : undefined ,
4149 fontWeight : getValue ( 'FontWeight' ) !== '' ? getValue ( 'FontWeight' ) : undefined ,
4250 textTransform : getValue ( 'TextTransform' ) !== '' ? getValue ( 'TextTransform' ) : undefined ,
4351 letterSpacing : getValue ( 'LetterSpacing' ) !== '' ? `${ getValue ( 'LetterSpacing' ) } px` : undefined ,
@@ -56,7 +64,7 @@ export const createTypographyStyles = ( attrNameTemplate = '%s', screen = 'deskt
5664 }
5765 }
5866 if ( tabletFontSize ) {
59- styles . fontSize = getValue ( 'TabletFontSize' , `%s${ getValue ( 'TabletFontSizeUnit' ) || 'px' } ` )
67+ styles . fontSize = getValue ( 'TabletFontSize' , `%s${ tabletFontSizeUnit } ` )
6068 }
6169 } else { // Mobile.
6270 styles = {
@@ -79,7 +87,7 @@ export const createTypographyStyles = ( attrNameTemplate = '%s', screen = 'deskt
7987 }
8088 }
8189 if ( mobileFontSize ) {
82- styles . fontSize = getValue ( 'MobileFontSize' , `%s${ getValue ( 'MobileFontSizeUnit' ) || 'px' } ` )
90+ styles . fontSize = getValue ( 'MobileFontSize' , `%s${ mobileFontSizeUnit } ` )
8391 }
8492 }
8593
0 commit comments