PluginProbe ʕ •ᴥ•ʔ
Starter Sites & Templates by Neve / trunk
Starter Sites & Templates by Neve vtrunk
1.4.0 1.3.0 1.2.29 1.2.28 1.2.6 1.2.7 1.2.8 1.2.9 trunk 1.0.10 1.0.11 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 1.1.20 1.1.21 1.1.22 1.1.23 1.1.24 1.1.25 1.1.26 1.1.27 1.1.28 1.1.29 1.1.3 1.1.30 1.1.31 1.1.32 1.1.33 1.1.34 1.1.35 1.1.36 1.1.37 1.1.38 1.1.39 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.3 1.2.4 1.2.5
templates-patterns-collection / onboarding / src / Components / CustomizeControls / TypographyControl.js
templates-patterns-collection / onboarding / src / Components / CustomizeControls Last commit date
FeaturesControl.js 1 year ago ImportOptionsControl.js 1 year ago LogoControl.js 1 year ago PaletteControl.js 1 year ago SiteNameControl.js 1 year ago TypographyControl.js 2 months ago
TypographyControl.js
142 lines
1 /* global tiobDash */
2 import { __ } from '@wordpress/i18n';
3 import { Button } from '@wordpress/components';
4 import classnames from 'classnames';
5 import SVG from '../../utils/svg';
6 import { withDispatch, withSelect } from '@wordpress/data';
7 import { compose } from '@wordpress/compose';
8
9 const FALLBACK_FONT = 'Arial, Helvetica, sans-serif';
10
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 };
20
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 };
28
29 const TypographyControl = ( {
30 siteStyle,
31 handleFontClick,
32 importData,
33 importDataDefault,
34 } ) => {
35 const fontPairs = getFontPairs( importData );
36 if ( ! fontPairs ) {
37 return null;
38 }
39
40 const { body: defaultBodyFont, heading: defaultHeadingsFont } =
41 getDefaultFonts( importDataDefault );
42 const { font } = siteStyle;
43
44 return (
45 <div className="ob-ctrl">
46 <div className="ob-ctrl-head small-gap">
47 <h3>{ __( 'Typography', 'templates-patterns-collection' ) }</h3>
48 <Button
49 icon={ SVG.redo }
50 onClick={ () => handleFontClick( 'default' ) }
51 />
52 </div>
53 <div className="ob-ctrl-wrap font">
54 <Button
55 className={ classnames( [
56 'ob-font-pair',
57 'ob-font-default',
58 { 'ob-active': 'default' === font },
59 ] ) }
60 title={ `${ defaultHeadingsFont } / ${ defaultBodyFont }` }
61 onClick={ () => handleFontClick( 'default' ) }
62 >
63 { __( 'Default', 'templates-patterns-collection' ) }
64 </Button>
65
66 { Object.keys( fontPairs ).map( ( slug ) => {
67 const { headingFont, bodyFont } = fontPairs[ slug ];
68 const headingStyle = {
69 fontFamily: headingFont.font,
70 };
71
72 return (
73 <Button
74 key={ slug }
75 className={ classnames( [
76 'ob-font-pair',
77 { 'ob-active': slug === font },
78 ] ) }
79 style={ headingStyle }
80 title={ `${ headingFont.font } / ${ bodyFont.font }` }
81 onClick={ () => handleFontClick( slug ) }
82 >
83 Abc
84 </Button>
85 );
86 } ) }
87 </div>
88 </div>
89 );
90 };
91
92 export default compose(
93 withSelect( ( select ) => {
94 const { getImportData } = select( 'ti-onboarding' );
95 return {
96 importData: getImportData(),
97 };
98 } ),
99 withDispatch(
100 (
101 dispatch,
102 { importData, importDataDefault, siteStyle, setSiteStyle }
103 ) => {
104 const { setImportData, setRefresh } = dispatch( 'ti-onboarding' );
105 const fontPairs = getFontPairs( importData );
106 const { body: defaultBodyFont, heading: defaultHeadingsFont } =
107 getDefaultFonts( importDataDefault );
108
109 return {
110 handleFontClick: ( fontKey ) => {
111 const newStyle = {
112 ...siteStyle,
113 font: fontKey,
114 };
115 setSiteStyle( newStyle );
116
117 const pair =
118 fontKey !== 'default' && fontPairs && fontPairs[ fontKey ]
119 ? fontPairs[ fontKey ]
120 : {
121 bodyFont: { font: defaultBodyFont },
122 headingFont: { font: defaultHeadingsFont },
123 };
124
125 const { bodyFont, headingFont } = pair;
126
127 const newImportData = {
128 ...importData,
129 theme_mods: {
130 ...importData.theme_mods,
131 neve_body_font_family: bodyFont.font,
132 neve_headings_font_family: headingFont.font,
133 },
134 };
135 setImportData( newImportData );
136 setRefresh( true );
137 },
138 };
139 }
140 )
141 )( TypographyControl );
142