-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathtypography-example.js
64 lines (59 loc) · 1.62 KB
/
typography-example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* WordPress dependencies
*/
import { useContext } from '@wordpress/element';
import { __unstableMotion as motion } from '@wordpress/components';
import { _x } from '@wordpress/i18n';
import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
/**
* Internal dependencies
*/
import { mergeBaseAndUserConfigs } from './global-styles-provider';
import { unlock } from '../../lock-unlock';
import { getFamilyPreviewStyle } from './font-library-modal/utils/preview-styles';
import { getFontFamilies } from './utils';
const { GlobalStylesContext } = unlock( blockEditorPrivateApis );
export default function PreviewTypography( { fontSize, variation } ) {
const { base } = useContext( GlobalStylesContext );
let config = base;
if ( variation ) {
config = mergeBaseAndUserConfigs( base, variation );
}
const [ bodyFontFamilies, headingFontFamilies ] = getFontFamilies( config );
const bodyPreviewStyle = bodyFontFamilies
? getFamilyPreviewStyle( bodyFontFamilies )
: {};
const headingPreviewStyle = headingFontFamilies
? getFamilyPreviewStyle( headingFontFamilies )
: {};
if ( fontSize ) {
bodyPreviewStyle.fontSize = fontSize;
headingPreviewStyle.fontSize = fontSize;
}
return (
<motion.div
animate={ {
scale: 1,
opacity: 1,
} }
initial={ {
scale: 0.1,
opacity: 0,
} }
transition={ {
delay: 0.3,
type: 'tween',
} }
style={ {
textAlign: 'center',
} }
>
<span style={ headingPreviewStyle }>
{ _x( 'A', 'Uppercase letter A' ) }
</span>
<span style={ bodyPreviewStyle }>
{ _x( 'a', 'Lowercase letter A' ) }
</span>
</motion.div>
);
}