Skip to content

Commit 901851a

Browse files
committed
fix: proper resetting in editingMode and in not
1 parent 2b1e944 commit 901851a

File tree

4 files changed

+40
-13
lines changed

4 files changed

+40
-13
lines changed

src/components/font-pair-picker/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ import { __ } from '@wordpress/i18n'
1919
const FontPairPicker = props => {
2020
const headingStyles = props.fontPair.typography.h1
2121
const paragraphStyles = props.fontPair.typography.p
22-
if ( headingStyles.fontFamily ) {
22+
if ( headingStyles?.fontFamily ) {
2323
loadGoogleFont( headingStyles.fontFamily )
2424
}
25-
if ( paragraphStyles.fontFamily ) {
25+
if ( paragraphStyles?.fontFamily ) {
2626
loadGoogleFont( paragraphStyles.fontFamily )
2727
}
2828

@@ -32,7 +32,7 @@ const FontPairPicker = props => {
3232
style={ omit( { ...headingStyles }, [ 'fontSize', 'lineHeight' ] ) }
3333
className="ugb-global-settings-font-pair__label"
3434
>
35-
{ headingStyles.fontFamily ? headingStyles.fontFamily : 'Theme Heading Default' }
35+
{ headingStyles?.fontFamily ? headingStyles.fontFamily : 'Theme Heading Default' }
3636
</span>
3737
<span
3838
style={ omit( { ...paragraphStyles }, [ 'fontSize', 'lineHeight' ] ) }

src/components/typography-control/index.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,7 @@ const TypographyControl = props => {
3535
label={ props.label }
3636
popoverLabel={ props.popoverLabel }
3737
onReset={ props.onReset }
38-
allowReset={
39-
props.fontFamily ||
40-
props.fontSize || props.tabletFontSize || props.mobileFontSize ||
41-
props.fontWeight ||
42-
props.textTransform ||
43-
props.lineHeight || props.tabletLineHeight || props.mobileLineHeight ||
44-
props.letterSpacing || props.tabletLetterSpacing || props.mobileLetterSpacing
45-
}
38+
allowReset={ props?.isAllowReset }
4639
resetPopoverTitle={ props.resetPopoverTitle }
4740
resetPopoverDescription={ props.resetPopoverDescription }
4841
className={ props.className }

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

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ import {
1414
} from '~stackable/components'
1515
import { fetchSettings } from '~stackable/util'
1616
import { i18n, isPro } from 'stackable'
17-
import { omit, head } from 'lodash'
17+
import {
18+
omit, head, isEqual,
19+
} from 'lodash'
1820

1921
/**
2022
* WordPress dependencies
@@ -183,7 +185,17 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography',
183185
}
184186

185187
const resetStyles = selector => {
186-
const newSettings = omit( typographySettings, [ selector ] )
188+
let newSettings
189+
const currentFontPair = [ ...FONT_PAIRS, ...customFontPairs ].find( fontPair => fontPair.name === selectedFontPairName )
190+
if ( ! editingFontPairName ) {
191+
newSettings = { ...typographySettings, [ selector ]: currentFontPair.typography[ selector ] }
192+
} else {
193+
newSettings = omit( typographySettings, [ selector ] )
194+
const updatedCustomFontPairs = customFontPairs
195+
.map( fontPair => fontPair.name === editingFontPairName ? { ...fontPair, typography: newSettings } : fontPair )
196+
updateCustomFontPairs( updatedCustomFontPairs )
197+
}
198+
187199
doAction( 'stackable.global-settings.typography-update-global-styles', newSettings )
188200

189201
updateTypography( newSettings )
@@ -197,6 +209,26 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography',
197209
model.save()
198210
}
199211

212+
const getIsAllowReset = selector => {
213+
const currentFontPair = [ ...FONT_PAIRS, ...customFontPairs ].find( fontPair => fontPair.name === selectedFontPairName )
214+
const fontPairStyle = currentFontPair.typography[ selector ]
215+
const typographyStyle = typographySettings[ selector ]
216+
if ( ! editingFontPairName ) {
217+
if ( ! isEqual( fontPairStyle, typographyStyle ) ) {
218+
return true
219+
}
220+
return false
221+
} else if ( typographyStyle && ( typographyStyle.fontFamily ||
222+
typographyStyle.fontSize || typographyStyle.tabletFontSize || typographyStyle.mobileFontSize ||
223+
typographyStyle.fontWeight ||
224+
typographyStyle.textTransform ||
225+
typographyStyle.lineHeight || typographyStyle.tabletLineHeight || typographyStyle.mobileLineHeight ||
226+
typographyStyle.letterSpacing || typographyStyle.tabletLetterSpacing || typographyStyle.mobileLetterSpacing ) ) {
227+
return true
228+
}
229+
return false
230+
}
231+
200232
const CustomFontPairPickers = applyFilters(
201233
'stackable.global-settings.typography.font-pairs.customPicker',
202234
Fragment,
@@ -316,6 +348,7 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography',
316348
label={ label }
317349
selector={ selector }
318350
value={ ( typographySettings[ selector ] ) || {} }
351+
isAllowReset={ getIsAllowReset( selector ) }
319352
onChange={ styles => changeStyles( { [ selector ]: styles } ) }
320353
onReset={ () => resetStyles( selector ) }
321354
/>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ const TypographyPicker = props => {
9494
onReset={ () => props.onReset( props.selector ) }
9595
resetPopoverTitle={ sprintf( __( 'Reset %s Global Typography Style', i18n ), props.selector === 'p' ? __( 'Body Text', i18n ) : props.selector.toUpperCase() ) }
9696
resetPopoverDescription={ __( 'Resetting this typography style will revert all typography to its original style. Proceed?', i18n ) }
97+
isAllowReset={ props?.isAllowReset }
9798
/>
9899
)
99100
}

0 commit comments

Comments
 (0)