@@ -5,24 +5,42 @@ import classnames from 'classnames';
55import SVG from '../../utils/svg' ;
66import { withDispatch , withSelect } from '@wordpress/data' ;
77import { compose } from '@wordpress/compose' ;
8- import { useState } from '@wordpress/element' ;
98
10- const TypographyControl = ( { siteStyle, handleFontClick, importData } ) => {
11- const themeMods = importData ?. theme_mods ;
9+ const FALLBACK_FONT = 'Arial, Helvetica, sans-serif' ;
1210
13- const [ defaultBodyFont ] = useState (
14- themeMods ?. neve_body_font_family || 'Arial, Helvetica, sans-serif'
15- ) ;
11+ const getFontPairs = ( importData ) => {
12+ if ( importData && importData . font_pairs && Object . keys ( importData . font_pairs ) . length ) {
13+ return importData . font_pairs ;
14+ }
15+ if ( tiobDash && tiobDash . fontParings ) {
16+ return tiobDash . fontParings ;
17+ }
18+ return null ;
19+ } ;
1620
17- const [ defaultHeadingsFont ] = useState (
18- themeMods ?. neve_headings_font_family || 'Arial, Helvetica, sans-serif'
19- ) ;
21+ const getDefaultFonts = ( importDataDefault ) => {
22+ const themeMods = importDataDefault ?. theme_mods ;
23+ return {
24+ body : themeMods ?. neve_body_font_family || FALLBACK_FONT ,
25+ heading : themeMods ?. neve_headings_font_family || FALLBACK_FONT ,
26+ } ;
27+ } ;
2028
21- const { font } = siteStyle ;
22- if ( ! tiobDash || ! tiobDash . fontParings ) {
23- return ;
29+ const TypographyControl = ( {
30+ siteStyle,
31+ handleFontClick,
32+ importData,
33+ importDataDefault,
34+ } ) => {
35+ const fontPairs = getFontPairs ( importData ) ;
36+ if ( ! fontPairs ) {
37+ return null ;
2438 }
2539
40+ const { body : defaultBodyFont , heading : defaultHeadingsFont } =
41+ getDefaultFonts ( importDataDefault ) ;
42+ const { font } = siteStyle ;
43+
2644 return (
2745 < div className = "ob-ctrl" >
2846 < div className = "ob-ctrl-head small-gap" >
@@ -45,9 +63,8 @@ const TypographyControl = ( { siteStyle, handleFontClick, importData } ) => {
4563 { __ ( 'Default' , 'templates-patterns-collection' ) }
4664 </ Button >
4765
48- { Object . keys ( tiobDash . fontParings ) . map ( ( slug ) => {
49- const { headingFont, bodyFont } =
50- tiobDash . fontParings [ slug ] ;
66+ { Object . keys ( fontPairs ) . map ( ( slug ) => {
67+ const { headingFont, bodyFont } = fontPairs [ slug ] ;
5168 const headingStyle = {
5269 fontFamily : headingFont . font ,
5370 } ;
@@ -82,15 +99,12 @@ export default compose(
8299 withDispatch (
83100 (
84101 dispatch ,
85- {
86- importData,
87- siteStyle,
88- setSiteStyle,
89- defaultBodyFont,
90- defaultHeadingsFont,
91- }
102+ { importData, importDataDefault, siteStyle, setSiteStyle }
92103 ) => {
93104 const { setImportData, setRefresh } = dispatch ( 'ti-onboarding' ) ;
105+ const fontPairs = getFontPairs ( importData ) ;
106+ const { body : defaultBodyFont , heading : defaultHeadingsFont } =
107+ getDefaultFonts ( importDataDefault ) ;
94108
95109 return {
96110 handleFontClick : ( fontKey ) => {
@@ -100,14 +114,16 @@ export default compose(
100114 } ;
101115 setSiteStyle ( newStyle ) ;
102116
103- const { bodyFont , headingFont } =
104- fontKey !== 'default'
105- ? tiobDash . fontParings [ fontKey ]
117+ const pair =
118+ fontKey !== 'default' && fontPairs && fontPairs [ fontKey ]
119+ ? fontPairs [ fontKey ]
106120 : {
107121 bodyFont : { font : defaultBodyFont } ,
108122 headingFont : { font : defaultHeadingsFont } ,
109123 } ;
110124
125+ const { bodyFont, headingFont } = pair ;
126+
111127 const newImportData = {
112128 ...importData ,
113129 theme_mods : {
0 commit comments