diff --git a/onboarding/src/Components/CustomizeControls/TypographyControl.js b/onboarding/src/Components/CustomizeControls/TypographyControl.js index c8f3d0ac..f682f7f6 100644 --- a/onboarding/src/Components/CustomizeControls/TypographyControl.js +++ b/onboarding/src/Components/CustomizeControls/TypographyControl.js @@ -5,24 +5,42 @@ import classnames from 'classnames'; import SVG from '../../utils/svg'; import { withDispatch, withSelect } from '@wordpress/data'; import { compose } from '@wordpress/compose'; -import { useState } from '@wordpress/element'; -const TypographyControl = ( { siteStyle, handleFontClick, importData } ) => { - const themeMods = importData?.theme_mods; +const FALLBACK_FONT = 'Arial, Helvetica, sans-serif'; - const [ defaultBodyFont ] = useState( - themeMods?.neve_body_font_family || 'Arial, Helvetica, sans-serif' - ); +const getFontPairs = ( importData ) => { + if ( importData && importData.font_pairs && Object.keys( importData.font_pairs ).length ) { + return importData.font_pairs; + } + if ( tiobDash && tiobDash.fontParings ) { + return tiobDash.fontParings; + } + return null; +}; - const [ defaultHeadingsFont ] = useState( - themeMods?.neve_headings_font_family || 'Arial, Helvetica, sans-serif' - ); +const getDefaultFonts = ( importDataDefault ) => { + const themeMods = importDataDefault?.theme_mods; + return { + body: themeMods?.neve_body_font_family || FALLBACK_FONT, + heading: themeMods?.neve_headings_font_family || FALLBACK_FONT, + }; +}; - const { font } = siteStyle; - if ( ! tiobDash || ! tiobDash.fontParings ) { - return; +const TypographyControl = ( { + siteStyle, + handleFontClick, + importData, + importDataDefault, +} ) => { + const fontPairs = getFontPairs( importData ); + if ( ! fontPairs ) { + return null; } + const { body: defaultBodyFont, heading: defaultHeadingsFont } = + getDefaultFonts( importDataDefault ); + const { font } = siteStyle; + return (