Skip to content

Commit 1384c6e

Browse files
committed
fix: saving of new typography
1 parent 7e588d2 commit 1384c6e

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,17 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography',
302302
return
303303
}
304304

305+
// Merge the new styles with the previous, while overwritting similar styles.
306+
// This allow adding styles without removing the previous ones.
307+
// Check if the object is empty, used for resetting the whole setting.
305308
if ( Object.keys( styles ).length !== 0 ) {
306309
styles = { ...newSettings[ selector ], ...styles }
307310
}
308-
311+
/**
312+
* Delete the object keys with empty strings.
313+
* Otherwise, the API will throw an error code 400
314+
* because of incompatible schema type.
315+
*/
309316
Object.keys( styles ).forEach( key => {
310317
if ( styles[ key ] === '' ) {
311318
delete styles[ key ]
@@ -320,6 +327,8 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography',
320327
doAction( 'stackable.global-settings.typography-update-global-styles', newSettings )
321328
}
322329

330+
updateTypography( newSettings )
331+
323332
return newSettings
324333
} )
325334
}

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ export const getAppliedTypeScale = value => {
1616
return
1717
}
1818
return {
19-
h1: { fontSize: Number( Math.pow( typeScale, 6 ).toFixed( 3 ) ), fontSizeUnit: 'rem' },
20-
h2: { fontSize: Number( Math.pow( typeScale, 5 ).toFixed( 3 ) ), fontSizeUnit: 'rem' },
21-
h3: { fontSize: Number( Math.pow( typeScale, 4 ).toFixed( 3 ) ), fontSizeUnit: 'rem' },
22-
h4: { fontSize: Number( Math.pow( typeScale, 3 ).toFixed( 3 ) ), fontSizeUnit: 'rem' },
23-
h5: { fontSize: Number( Math.pow( typeScale, 2 ).toFixed( 3 ) ), fontSizeUnit: 'rem' },
24-
h6: { fontSize: Number( typeScale.toFixed( 3 ) ), fontSizeUnit: 'rem' },
25-
p: { fontSize: 1, fontSizeUnit: 'rem' },
26-
'.stk-subtitle': { fontSize: Number( ( 1 / typeScale ).toFixed( 3 ) ), fontSizeUnit: 'rem' },
27-
'.stk-button__inner-text': { fontSize: 1, fontSizeUnit: 'rem' },
19+
h1: { fontSize: String( Math.pow( typeScale, 6 ).toFixed( 3 ) ), fontSizeUnit: 'rem' },
20+
h2: { fontSize: String( Math.pow( typeScale, 5 ).toFixed( 3 ) ), fontSizeUnit: 'rem' },
21+
h3: { fontSize: String( Math.pow( typeScale, 4 ).toFixed( 3 ) ), fontSizeUnit: 'rem' },
22+
h4: { fontSize: String( Math.pow( typeScale, 3 ).toFixed( 3 ) ), fontSizeUnit: 'rem' },
23+
h5: { fontSize: String( Math.pow( typeScale, 2 ).toFixed( 3 ) ), fontSizeUnit: 'rem' },
24+
h6: { fontSize: String( typeScale.toFixed( 3 ) ), fontSizeUnit: 'rem' },
25+
p: { fontSize: '1', fontSizeUnit: 'rem' },
26+
'.stk-subtitle': { fontSize: String( ( 1 / typeScale ).toFixed( 3 ) ), fontSizeUnit: 'rem' },
27+
'.stk-button__inner-text': { fontSize: '1', fontSizeUnit: 'rem' },
2828
}
2929
}

0 commit comments

Comments
 (0)