PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 1.8.3
GenerateBlocks v1.8.3
trunk 1.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 2.0.0 2.0.1 2.0.2 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.3.0
generateblocks / src / extend / inspector-control / controls / typography / index.js
generateblocks / src / extend / inspector-control / controls / typography Last commit date
components 2 years ago attributes.js 2 years ago editor.scss 3 years ago google-fonts.json 2 years ago index.js 2 years ago options.js 2 years ago
index.js
125 lines
1 import PanelArea from '../../../../components/panel-area';
2 import { __ } from '@wordpress/i18n';
3 import getIcon from '../../../../utils/get-icon';
4 import { useContext } from '@wordpress/element';
5 import ControlsContext from '../../../../block-context';
6 import FontSize from './components/font-size';
7 import FontWeight from './components/font-weight';
8 import TextTransform from './components/text-transform';
9 import LetterSpacing from './components/letter-spacing';
10 import LineHeight from './components/line-height';
11 import FontFamily from './components/font-family';
12 import Alignment from './components/alignment';
13 import getAttribute from '../../../../utils/get-attribute';
14 import FlexControl from '../../../../components/flex-control';
15 import getDeviceType from '../../../../utils/get-device-type';
16 import getResponsivePlaceholder from '../../../../utils/get-responsive-placeholder';
17 import './editor.scss';
18
19 export default function Typography( { attributes, setAttributes, computedStyles } ) {
20 const device = getDeviceType();
21 const { id, supports: { typography: typographySupports } } = useContext( ControlsContext );
22 const { typography } = attributes;
23 const isDesktop = 'Desktop' === device;
24
25 return (
26 <PanelArea
27 title={ __( 'Typography', 'generateblocks' ) }
28 initialOpen={ false }
29 icon={ getIcon( 'typography' ) }
30 className="gblocks-panel-label"
31 id={ `${ id }Typography` }
32 >
33 { typographySupports.alignment &&
34 <Alignment
35 value={ getAttribute( 'textAlign', { attributes: typography, deviceType: device } ) }
36 onChange={ ( value ) => {
37 setAttributes( {
38 typography: {
39 [ getAttribute( 'textAlign', { attributes: typography, deviceType: device }, true ) ]: value,
40 },
41 } );
42 } }
43 />
44 }
45
46 { !! isDesktop && ( typographySupports.fontWeight || typographySupports.textTransform ) &&
47 <FlexControl>
48 <FontWeight
49 value={ typography?.fontWeight }
50 onChange={ ( value ) => {
51 setAttributes( {
52 typography: {
53 [ getAttribute( 'fontWeight', { attributes: typography, deviceType: device }, true ) ]: value,
54 },
55 } );
56 } }
57 />
58
59 <TextTransform
60 value={ typography?.textTransform }
61 onChange={ ( value ) => {
62 setAttributes( {
63 typography: {
64 [ getAttribute( 'textTransform', { attributes: typography, deviceType: device }, true ) ]: value,
65 },
66 } );
67 } }
68 />
69 </FlexControl>
70 }
71
72 { typographySupports.fontSize &&
73 <FontSize
74 value={ getAttribute( 'fontSize', { attributes: typography, deviceType: device } ) }
75 placeholder={ getResponsivePlaceholder( 'fontSize', typography, device, computedStyles.fontSize ) }
76 onChange={ ( value ) => {
77 setAttributes( {
78 typography: {
79 [ getAttribute( 'fontSize', { attributes: typography, deviceType: device }, true ) ]: value,
80 },
81 } );
82 } }
83 />
84 }
85
86 { typographySupports.lineHeight &&
87 <LineHeight
88 defaultUnit="em"
89 value={ getAttribute( 'lineHeight', { attributes: typography, deviceType: device } ) }
90 placeholder={ getResponsivePlaceholder( 'lineHeight', typography, device, computedStyles.lineHeight ) }
91 onChange={ ( value ) => {
92 setAttributes( {
93 typography: {
94 [ getAttribute( 'lineHeight', { attributes: typography, deviceType: device }, true ) ]: value,
95 },
96 } );
97 } }
98 />
99 }
100
101 { typographySupports.letterSpacing &&
102 <LetterSpacing
103 defaultUnit="em"
104 value={ getAttribute( 'letterSpacing', { attributes: typography, deviceType: device } ) }
105 placeholder={ getResponsivePlaceholder( 'letterSpacing', typography, device, computedStyles.letterSpacing ) }
106 onChange={ ( value ) => {
107 setAttributes( {
108 typography: {
109 [ getAttribute( 'letterSpacing', { attributes: typography, deviceType: device }, true ) ]: value,
110 },
111 } );
112 } }
113 />
114 }
115
116 { typographySupports.fontFamily && isDesktop &&
117 <FontFamily
118 attributes={ attributes }
119 setAttributes={ setAttributes }
120 />
121 }
122 </PanelArea>
123 );
124 }
125