Skip to content

Commit 4827508

Browse files
committed
fix: set the font family of current font pair as default
1 parent a252a80 commit 4827508

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

src/components/advanced-autosuggest-control/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,10 @@ class AdvancedAutosuggestControl extends Component {
223223
label={ this.props.label }
224224
screens={ this.props.screens }
225225
value={ this.props.value }
226+
defaultValue={ this.props?.defaultValue ?? '' }
226227
onChange={ value => { // Will be used to reset.
227-
if ( value === '' ) {
228-
this.onChange( null, { newValue: '' } )
228+
if ( value === '' || this.props?.defaultValue ) {
229+
this.onChange( null, { newValue: value } )
229230
}
230231
} }
231232
allowReset={ this.props.allowReset }

src/components/typography-control/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ const TypographyControl = props => {
6060
label={ __( 'Font Family', i18n ) }
6161
onChange={ props.onChangeFontFamily }
6262
value={ props.fontFamily }
63+
defaultValue={ props?.defaultFontFamily }
6364
helpTooltip={ {
6465
video: 'typography-family',
6566
description: __( 'Sets the font set to be used for the element', i18n ),

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

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography',
116116
}
117117
}, [ isPanelOpen ] )
118118

119+
const getCurrentFontPair = () => {
120+
return [ ...FONT_PAIRS, ...customFontPairs ].find( fontPair => fontPair.name === selectedFontPairName )
121+
}
122+
119123
const updateTypography = newSettings => {
120124
setTypographySettings( newSettings )
121125

@@ -152,6 +156,14 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography',
152156
}, 500 )
153157
}
154158

159+
const changeApplySettingsTo = value => {
160+
setApplySettingsTo( value )
161+
const model = new models.Settings( {
162+
stackable_global_typography_apply_to: value, // eslint-disable-line
163+
} )
164+
model.save()
165+
}
166+
155167
const changeStyles = typography => {
156168
const newSettings = { ...typographySettings }
157169

@@ -183,7 +195,7 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography',
183195

184196
const resetStyles = selector => {
185197
let newSettings = {}
186-
const currentFontPair = [ ...FONT_PAIRS, ...customFontPairs ].find( fontPair => fontPair.name === selectedFontPairName )
198+
const currentFontPair = getCurrentFontPair()
187199
if ( ! isEditingFontPair && currentFontPair ) {
188200
newSettings = { ...typographySettings, [ selector ]: currentFontPair.typography[ selector ] }
189201
}
@@ -193,16 +205,15 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography',
193205
updateTypography( newSettings )
194206
}
195207

196-
const changeApplySettingsTo = value => {
197-
setApplySettingsTo( value )
198-
const model = new models.Settings( {
199-
stackable_global_typography_apply_to: value, // eslint-disable-line
200-
} )
201-
model.save()
208+
const getDefaultFontFamily = selector => {
209+
const currentFontPair = getCurrentFontPair()
210+
if ( ! isEditingFontPair && currentFontPair ) {
211+
return currentFontPair.typography[ selector ]?.fontFamily ?? ''
212+
}
202213
}
203214

204215
const getIsAllowReset = selector => {
205-
const currentFontPair = [ ...FONT_PAIRS, ...customFontPairs ].find( fontPair => fontPair.name === selectedFontPairName )
216+
const currentFontPair = getCurrentFontPair()
206217
const typographyStyle = typographySettings[ selector ]
207218
if ( ! isEditingFontPair && currentFontPair ) {
208219
const fontPairStyle = currentFontPair.typography[ selector ]
@@ -358,6 +369,7 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography',
358369
label={ label }
359370
selector={ selector }
360371
value={ ( typographySettings[ selector ] ) || {} }
372+
defaultFontFamily={ getDefaultFontFamily( selector ) }
361373
isAllowReset={ getIsAllowReset( selector ) }
362374
onChange={ styles => changeStyles( { [ selector ]: styles } ) }
363375
onReset={ () => resetStyles( selector ) }

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ const TypographyPicker = props => {
5555
showSecondFontSize={ false }
5656
allowReset={ true }
5757
fontFamily={ value.fontFamily }
58+
defaultFontFamily={ props?.defaultFontFamily }
5859
fontSize={ value.fontSize }
5960
htmlTag={ props.selector }
6061
tabletFontSize={ value.tabletFontSize }

0 commit comments

Comments
 (0)