PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 2.0.0
GenerateBlocks v2.0.0
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 / image / components / BlockControls.js
generateblocks / src / blocks / image / components Last commit date
inspector-controls 2 years ago AlignmentControls.js 4 years ago AnchorTag.js 4 years ago BlockControls.js 2 years ago ComponentCSS.js 1 year ago Image.js 4 years ago ImageContentRenderer.js 3 years ago ImagePlaceholder.js 4 years ago
BlockControls.js
94 lines
1 import { BlockControls, MediaReplaceFlow } from '@wordpress/block-editor';
2 import { MenuItem, ToolbarGroup, ToolbarButton, TextControl } from '@wordpress/components';
3 import { __ } from '@wordpress/i18n';
4 import LinkControl from '../../../components/link-control';
5 import { useDispatch } from '@wordpress/data';
6 import { createBlock } from '@wordpress/blocks';
7 import { useInnerBlocksCount } from '../../../hooks';
8 import getIcon from '../../../utils/get-icon';
9 import AlignmentControls from './AlignmentControls';
10
11 export default function ImageBlockControls( props ) {
12 const {
13 attributes,
14 setAttributes,
15 onSelectImage,
16 onUploadError,
17 onResetImage,
18 imageUrl,
19 canUploadImage,
20 clientId,
21 deviceType,
22 } = props;
23
24 const { mediaId, caption } = attributes;
25
26 const { insertBlocks } = useDispatch( 'core/block-editor' );
27 const innerBlocksCount = useInnerBlocksCount( clientId );
28
29 return (
30 <BlockControls>
31 <AlignmentControls
32 attributes={ attributes }
33 setAttributes={ setAttributes }
34 deviceType={ deviceType }
35 />
36
37 { 0 === innerBlocksCount &&
38 <ToolbarGroup>
39 <ToolbarButton
40 className="gblocks-add-new-button"
41 icon={ getIcon( 'caption' ) }
42 label={ __( 'Add Caption', 'generateblocks' ) }
43 onClick={ () => {
44 insertBlocks( createBlock( 'generateblocks/headline', {
45 element: 'figcaption',
46 content: caption,
47 isCaption: true,
48 } ), undefined, clientId );
49 } }
50 showTooltip
51 />
52 </ToolbarGroup>
53 }
54
55 { !! imageUrl &&
56 <ToolbarGroup>
57 <LinkControl
58 attributes={ attributes }
59 setAttributes={ setAttributes }
60 />
61 </ToolbarGroup>
62 }
63
64 { !! imageUrl && canUploadImage &&
65 <ToolbarGroup>
66 <MediaReplaceFlow
67 mediaId={ mediaId }
68 mediaURL={ imageUrl }
69 allowedTypes={ [ 'image' ] }
70 accept="image/*"
71 onSelect={ onSelectImage }
72 onError={ onUploadError }
73 >
74 <>
75 { imageUrl && ! mediaId &&
76 <div className="gb-image-replace-url">
77 <TextControl
78 label={ __( 'Image URL', 'generateblocks' ) }
79 value={ imageUrl }
80 onChange={ ( mediaUrl ) => setAttributes( { mediaUrl } ) }
81 />
82 </div>
83 }
84 <MenuItem onClick={ onResetImage }>
85 { __( 'Reset' ) }
86 </MenuItem>
87 </>
88 </MediaReplaceFlow>
89 </ToolbarGroup>
90 }
91 </BlockControls>
92 );
93 }
94