PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 1.5.2
GenerateBlocks v1.5.2
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 / blocks / button / edit.js
generateblocks / src / blocks / button Last commit date
components 4 years ago css 4 years ago attributes.js 4 years ago block.js 4 years ago deprecated.js 5 years ago edit.js 4 years ago editor.scss 4 years ago save.js 4 years ago
edit.js
84 lines
1 import BlockControls from './components/BlockControls';
2 import InspectorControls from './components/InspectorControls';
3 import InspectorAdvancedControls from './components/InspectorAdvancedControls';
4 import ComponentCSS from './components/ComponentCSS';
5 import GoogleFontLink from '../../components/google-font-link';
6 import { Fragment, useRef, useState, useEffect } from '@wordpress/element';
7 import { useDeviceType } from '../../hooks';
8 import { compose } from '@wordpress/compose';
9 import { withButtonLegacyMigration, withUniqueId } from '../../hoc';
10 import withDynamicContent from '../../extend/dynamic-content/hoc/withDynamicContent';
11 import ButtonContentRenderer from './components/ButtonContentRenderer';
12
13 const ButtonEdit = ( props ) => {
14 const {
15 attributes,
16 setAttributes,
17 clientId,
18 ContentRenderer = ButtonContentRenderer,
19 } = props;
20
21 const {
22 anchor,
23 ariaLabel,
24 fontFamily,
25 googleFont,
26 googleFontVariants,
27 isBlockPreview = false,
28 } = attributes;
29
30 const ref = useRef( null );
31 const [ computedStyles, setComputedStyles ] = useState( {} );
32 const [ deviceType, setDeviceType ] = useDeviceType( 'Desktop' );
33
34 useEffect( () => {
35 const computedButtonStyles = getComputedStyle( ref.current );
36
37 setComputedStyles( {
38 fontSize: parseInt( computedButtonStyles.fontSize ) || '',
39 } );
40 }, [] );
41
42 return (
43 <Fragment>
44 <BlockControls
45 clientId={ clientId }
46 attributes={ attributes }
47 setAttributes={ setAttributes }
48 />
49
50 <InspectorControls
51 { ...props }
52 deviceType={ deviceType }
53 setDeviceType={ setDeviceType }
54 state={ { deviceType } }
55 blockDefaults={ generateBlocksDefaults.button }
56 computedStyles={ computedStyles }
57 />
58
59 <InspectorAdvancedControls
60 anchor={ anchor }
61 ariaLabel={ ariaLabel }
62 setAttributes={ setAttributes }
63 />
64
65 <ComponentCSS { ...props } deviceType={ deviceType } />
66
67 <GoogleFontLink
68 fontFamily={ fontFamily }
69 googleFont={ googleFont }
70 googleFontVariants={ googleFontVariants }
71 isBlockPreview={ isBlockPreview }
72 />
73
74 <ContentRenderer { ...props } buttonRef={ ref } />
75 </Fragment>
76 );
77 };
78
79 export default compose(
80 withDynamicContent,
81 withUniqueId,
82 withButtonLegacyMigration
83 )( ButtonEdit );
84