PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 2.0.2
GenerateBlocks v2.0.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 / components / image-upload / ImageUpload.jsx
generateblocks / src / components / image-upload Last commit date
ImageUpload.jsx 1 year ago editor.scss 1 year ago index.js 1 year ago
ImageUpload.jsx
75 lines
1 import { __ } from '@wordpress/i18n';
2 import { BaseControl, Button, TextControl, useBaseControlProps } from '@wordpress/components';
3 import { MediaUpload, MediaUploadCheck } from '@wordpress/block-editor';
4 import { Stack } from '@edge22/components';
5 import { DynamicTagModal } from '../../dynamic-tags';
6 import './editor.scss';
7
8 export function ImageUpload( {
9 label = __( 'Image', 'generateblocks' ),
10 value,
11 onInsert,
12 onSelectImage,
13 showInput = true,
14 previewUrl = '',
15 allowDynamicTags = false,
16 onInsertDynamicTag,
17 context,
18 } ) {
19 const { baseControlProps, controlProps } = useBaseControlProps( {
20 label,
21 } );
22
23 return (
24 <BaseControl { ...baseControlProps }>
25 <Stack
26 className="gb-image-upload-stack"
27 layout="flex"
28 direction="horizontal"
29 gap="5px"
30 wrap={ false }
31 >
32 { !! showInput && (
33 <TextControl
34 { ...controlProps }
35 value={ value }
36 onChange={ ( newValue ) => onInsert( newValue ) }
37 style={ { marginBottom: 0 } }
38 />
39 ) }
40
41 { !! previewUrl && (
42 <img
43 src={ previewUrl }
44 alt=""
45 style={ { width: 'auto', height: '32px', objectFit: 'cover' } }
46 />
47 ) }
48
49 <MediaUploadCheck>
50 <MediaUpload
51 onSelect={ ( media ) => onSelectImage( media ) }
52 allowedTypes={ [ 'image' ] }
53 render={ ( { open } ) => (
54 <Button
55 onClick={ open }
56 variant="secondary"
57 >
58 { __( 'Browse', 'generateblocks' ) }
59 </Button>
60 ) }
61 />
62 </MediaUploadCheck>
63
64 { allowDynamicTags && (
65 <DynamicTagModal
66 onInsert={ ( newValue ) => onInsertDynamicTag( newValue ) }
67 selectedText={ value?.startsWith( '{{' ) ? value : '' }
68 context={ context }
69 />
70 ) }
71 </Stack>
72 </BaseControl>
73 );
74 }
75