@@ -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 ) }
0 commit comments