Skip to content

Commit 2285c7d

Browse files
committed
feat: add confirmation when changing font pair while dirty
1 parent 901851a commit 2285c7d

File tree

1 file changed

+28
-0
lines changed
  • src/plugins/global-settings/typography

1 file changed

+28
-0
lines changed

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,25 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography',
229229
return false
230230
}
231231

232+
const getIsChangeConfirmed = () => {
233+
// No need to confirm when the current font pair is custom
234+
// since changes are saved
235+
if ( customFontPairs.find( fontPair => fontPair.name === selectedFontPairName ) ) {
236+
return true
237+
}
238+
239+
const isDirty = TYPOGRAPHY_TAGS.some( ( { selector } ) => {
240+
return getIsAllowReset( selector )
241+
} )
242+
243+
if ( isDirty ) {
244+
// eslint-disable-next-line no-alert
245+
const confirmChange = window.confirm( __( 'Changing font pair will override the previous changes. Do you want to proceed?', i18n ) )
246+
return confirmChange
247+
}
248+
return true
249+
}
250+
232251
const CustomFontPairPickers = applyFilters(
233252
'stackable.global-settings.typography.font-pairs.customPicker',
234253
Fragment,
@@ -287,6 +306,9 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography',
287306
fontPair={ FONT_PAIRS[ 0 ] }
288307
isSelected={ selectedFontPairName === FONT_PAIRS[ 0 ].name }
289308
onClick={ () => {
309+
if ( ! getIsChangeConfirmed() ) {
310+
return
311+
}
290312
updateSelectedFontPair( FONT_PAIRS[ 0 ].name )
291313
changeStyles( FONT_PAIRS[ 0 ].typography )
292314
} }
@@ -296,6 +318,9 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography',
296318
customFontPairs={ customFontPairs }
297319
selected={ selectedFontPairName }
298320
onClick={ ( name, typography ) => {
321+
if ( ! getIsChangeConfirmed() ) {
322+
return
323+
}
299324
updateSelectedFontPair( name )
300325
changeStyles( typography )
301326
} }
@@ -312,6 +337,9 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography',
312337
fontPair={ fontPair }
313338
isSelected={ selectedFontPairName === fontPair.name }
314339
onClick={ () => {
340+
if ( ! getIsChangeConfirmed() ) {
341+
return
342+
}
315343
updateSelectedFontPair( fontPair.name )
316344
changeStyles( fontPair.typography )
317345
} }

0 commit comments

Comments
 (0)