Skip to content

Commit c817ada

Browse files
committed
chore: move other functions to utils
1 parent bbe3dca commit c817ada

File tree

2 files changed

+30
-18
lines changed

2 files changed

+30
-18
lines changed

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

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { GlobalTypographyStyles } from './editor-loader'
55
import TypographyPicker from './typography-picker'
66
import { getThemeStyles } from './get-theme-styles'
77
import FREE_FONT_PAIRS from './font-pairs.json'
8+
import { getAppliedTypeScale } from './utils'
89

910
/**
1011
* External dependencies
@@ -256,24 +257,6 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography',
256257
return [ ...FONT_PAIRS, ...customFontPairs ].find( fontPair => fontPair.name === selectedFontPairName )
257258
}
258259

259-
const getAppliedTypeScale = value => {
260-
const typeScale = Number( value )
261-
if ( Number.isNaN( typeScale ) ) {
262-
return
263-
}
264-
return {
265-
h1: { fontSize: Number( Math.pow( typeScale, 6 ).toFixed( 3 ) ), fontSizeUnit: 'rem' },
266-
h2: { fontSize: Number( Math.pow( typeScale, 5 ).toFixed( 3 ) ), fontSizeUnit: 'rem' },
267-
h3: { fontSize: Number( Math.pow( typeScale, 4 ).toFixed( 3 ) ), fontSizeUnit: 'rem' },
268-
h4: { fontSize: Number( Math.pow( typeScale, 3 ).toFixed( 3 ) ), fontSizeUnit: 'rem' },
269-
h5: { fontSize: Number( Math.pow( typeScale, 2 ).toFixed( 3 ) ), fontSizeUnit: 'rem' },
270-
h6: { fontSize: Number( typeScale.toFixed( 3 ) ), fontSizeUnit: 'rem' },
271-
p: { fontSize: 1, fontSizeUnit: 'rem' },
272-
'.stk-subtitle': { fontSize: Number( ( 1 / typeScale ).toFixed( 3 ) ), fontSizeUnit: 'rem' },
273-
'.stk-button__inner-text': { fontSize: 1, fontSizeUnit: 'rem' },
274-
}
275-
}
276-
277260
const updateTypography = newSettings => {
278261
setTypographySettings( newSettings )
279262

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Generates a typographic scale based on the given value.
3+
*
4+
* This function returns an object where each key represents a text element
5+
* (e.g., `h1`, `h2`, `p`, etc.) and its value contains a `fontSize` and `fontSizeUnit`,
6+
* calculated using an exponential scale.
7+
*
8+
* @param {string|number} value - The base number to use for the typographic scale.
9+
* @return {Object|undefined} An object mapping CSS selectors to their corresponding
10+
* font size settings. Returns `undefined` if input is invalid.
11+
*/
12+
13+
export const getAppliedTypeScale = value => {
14+
const typeScale = Number( value )
15+
if ( Number.isNaN( typeScale ) ) {
16+
return
17+
}
18+
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' },
28+
}
29+
}

0 commit comments

Comments
 (0)