Skip to content

Commit

Permalink
fix: handle font family and size, rename onChange prop
Browse files Browse the repository at this point in the history
  • Loading branch information
g-elwell committed Dec 5, 2023
1 parent a69d44b commit f0b01be
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 27 deletions.
6 changes: 3 additions & 3 deletions src/editor/components/StylesTypography/FontFamily.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import { fontFamilyToVar, varToFontFamily } from './helpers';
*
* @param {Object} props Component props
* @param {Array} props.typographyStyles Current typography styles.
* @param {Function} props.handleNewValue Callback to update the theme config.
* @param {Function} props.onChange Callback to run on change.
*/
const FontFamily = ( { typographyStyles, handleNewValue } ) => {
const FontFamily = ( { typographyStyles, onChange } ) => {
const { themeConfig } = useContext( EditorContext );
const fontFamilies = getThemeOption(
'settings.typography.fontFamilies',
Expand All @@ -30,7 +30,7 @@ const FontFamily = ( { typographyStyles, handleNewValue } ) => {
fontFamilies
) }
onChange={ ( newVal ) =>
handleNewValue(
onChange(
fontFamilyToVar( newVal, fontFamilies ),
'fontFamily'
)
Expand Down
6 changes: 3 additions & 3 deletions src/editor/components/StylesTypography/FontSize.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import { parseFontSize, fontSizeToVar, varToFontSize } from './helpers';
*
* @param {Object} props Component props
* @param {Array} props.typographyStyles Current typography styles.
* @param {Function} props.handleNewValue Callback to update the theme config.
* @param {Function} props.onChange Callback to run on change.
*/
const FontSize = ( { typographyStyles, handleNewValue } ) => {
const FontSize = ( { typographyStyles, onChange } ) => {
const { themeConfig } = useContext( EditorContext );
const fontSizes = getThemeOption(
'settings.typography.fontSizes',
Expand All @@ -32,7 +32,7 @@ const FontSize = ( { typographyStyles, handleNewValue } ) => {
withSlider
fontSizes={ fontSizes }
onChange={ ( newVal ) =>
handleNewValue( fontSizeToVar( newVal, fontSizes ), 'fontSize' )
onChange( fontSizeToVar( newVal, fontSizes ), 'fontSize' )
}
disableCustomFontSizes={ false }
withReset={ false }
Expand Down
47 changes: 26 additions & 21 deletions src/editor/components/StylesTypography/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,6 @@ const Typography = ( { selector } ) => {
config = set( config, selector, newTypographyStyles );
setUserConfig( config );
};
const fontAppearance =
! typographyStyles?.fontStyle && ! typographyStyles?.fontWeight
? 'default'
: {
fontStyle: parseFontStyle( typographyStyles?.fontStyle ),
fontWeight: parseFontWeight( typographyStyles?.fontWeight ),
};

return (
<>
Expand All @@ -65,23 +58,35 @@ const Typography = ( { selector } ) => {
</span>
<FontFamily
typographyStyles={ typographyStyles }
handleNewValue={ handleNewValue }
onChange={ ( val ) => handleNewValue( { fontFamily: val } ) }
/>
<div className="themer--blocks-item-component--columns themer--blocks-item-component--columns-2">
<FontSize
typographyStyles={ typographyStyles }
handleNewValue={ handleNewValue }
onChange={ ( val ) => handleNewValue( { fontSize: val } ) }
/>
<FontAppearanceControl
value={ fontAppearance }
value={
! typographyStyles?.fontStyle &&
! typographyStyles?.fontWeight
? 'default'
: {
fontStyle: parseFontStyle(
typographyStyles?.fontStyle
),
fontWeight: parseFontWeight(
typographyStyles?.fontWeight
),
}
}
onChange={ handleNewValue }
size="__unstable-large"
__nextHasNoMarginBottom
/>
<LineHeightControl
value={ parseLineHeight( typographyStyles?.lineHeight ) }
onChange={ ( newVal ) =>
handleNewValue( { lineHeight: newVal } )
onChange={ ( val ) =>
handleNewValue( { lineHeight: val } )
}
size="__unstable-large"
__unstableInputWidth="auto"
Expand All @@ -91,11 +96,11 @@ const Typography = ( { selector } ) => {
value={ parseLetterSpacing(
typographyStyles?.letterSpacing
) }
onChange={ ( newVal ) => {
if ( newVal === '' ) {
onChange={ ( val ) => {
if ( val === '' ) {
handleNewValue( { letterSpacing: '0px' } );
} else {
handleNewValue( { letterSpacing: newVal } );
handleNewValue( { letterSpacing: val } );
}
} }
size="__unstable-large"
Expand All @@ -105,8 +110,8 @@ const Typography = ( { selector } ) => {
label={ __( 'Text columns', 'themer' ) }
max={ MAX_TEXT_COLUMNS }
min={ 1 }
onChange={ ( newVal ) =>
handleNewValue( { textColumns: newVal } )
onChange={ ( val ) =>
handleNewValue( { textColumns: val } )
}
size="__unstable-large"
spinControls="custom"
Expand All @@ -117,16 +122,16 @@ const Typography = ( { selector } ) => {
value={ parseTextDecoration(
typographyStyles?.textDecoration
) }
onChange={ ( newVal ) =>
handleNewValue( { textDecoration: newVal } )
onChange={ ( val ) =>
handleNewValue( { textDecoration: val } )
}
/>
<TextTransformControl
value={ parseTextTransform(
typographyStyles?.textTransform
) }
onChange={ ( newVal ) =>
handleNewValue( { textTransform: newVal } )
onChange={ ( val ) =>
handleNewValue( { textTransform: val } )
}
showNone
/>
Expand Down

0 comments on commit f0b01be

Please sign in to comment.