Skip to content

Commit feb3274

Browse files
committed
fix: typography font size steps
1 parent 8efb71e commit feb3274

4 files changed

Lines changed: 31 additions & 9 deletions

File tree

src/components/font-size-control/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ const FontSizeControl = props => {
4141
// Change font-size so as not to surprise the user.
4242
if ( props.value !== '' ) {
4343
if ( value === 'em' || value === 'rem' ) {
44-
props.onChange( pxToEm( props.value ) )
44+
props.onChange( String( pxToEm( props.value ) ) )
4545
} else if ( value === 'px' ) {
46-
props.onChange( emToPx( props.value ) )
46+
props.onChange( String( emToPx( props.value ) ) )
4747
}
4848
}
4949

src/global-settings.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,13 +299,13 @@ public function register_global_settings() {
299299
'type' => 'string',
300300
),
301301
'fontSize' => array(
302-
'type' => 'number',
302+
'type' => 'string',
303303
),
304304
'tabletFontSize' => array(
305-
'type' => 'number',
305+
'type' => 'string',
306306
),
307307
'mobileFontSize' => array(
308-
'type' => 'number',
308+
'type' => 'string',
309309
),
310310
'fontSizeUnit' => array(
311311
'type' => 'string',

src/plugins/global-settings/typography/typography-picker.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { i18n } from 'stackable'
99
import { upperFirst, omit } from 'lodash'
1010
import classnames from 'classnames'
1111
import { generateStyles } from '~stackable/block-components'
12+
import { usePresetControls } from '~stackable/hooks'
1213

1314
/**
1415
* WordPress dependencies
@@ -45,9 +46,22 @@ const TypographyPicker = props => {
4546
'ugb-global-settings-typography-control--with-description': createDescription( value ),
4647
} )
4748

49+
const useTypographyAsPresets = useSelect( select =>
50+
select( 'stackable/global-preset-controls.custom' )?.getUseTypographyAsPresets() ?? false
51+
)
52+
53+
const presetMarks = usePresetControls( 'fontSizes' )
54+
?.getPresetMarks( { customOnly: useTypographyAsPresets } ) || null
55+
4856
return (
4957
<TypographyControl
50-
fontSizeProps={ { units: [ 'px', 'em', 'rem' ] } }
58+
fontSizeProps={ {
59+
units: [ 'px', 'em', 'rem' ],
60+
min: [ 0, 0, 0 ],
61+
sliderMax: [ 150, 7, 7 ],
62+
step: [ 1, 0.05, 0.05 ],
63+
marks: presetMarks,
64+
} }
5165
lineHeightUnits={ [ 'px', 'em', 'rem' ] }
5266
className={ mainClasses }
5367
label={ label }

src/util/typography/styles.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ import { camelCase } from 'lodash'
1616
*/
1717
import { sprintf } from '@wordpress/i18n'
1818

19+
const isCSSVarValue = value => {
20+
return typeof value === 'string' && value.startsWith( 'var' )
21+
}
22+
1923
export 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

Comments
 (0)