PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.17.0
GiveWP – Donation Plugin and Fundraising Platform v4.17.0
4.17.0 4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 All 256 releases
give / src / MultiFormGoals / resources / js / components / image-control / index.js

index.js in GiveWP – Donation Plugin and Fundraising Platform 4.17.0, at src/MultiFormGoals/resources/js/components/image-control/index.js

57 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Vendor dependencies
3 */
4 import PropTypes from 'prop-types';
5
6 /**
7 * WordPress dependencies
8 */
9 const {useInstanceId} = wp.compose;
10 const {BaseControl, Button} = wp.components;
11 const {MediaUpload} = wp.blockEditor;
12 import { __ } from '@wordpress/i18n'
13
14 const ImageControl = ({name, label, help, className, value, hideLabelFromVision, onChange = null}) => {
15 const instanceId = useInstanceId(ImageControl);
16 const id = `give-image-control-${name}-${instanceId}`;
17 return (
18 <BaseControl label={label} hideLabelFromVision={hideLabelFromVision} id={id} help={help} className={className}>
19 <MediaUpload
20 allowedTypes={['image']}
21 onSelect={(media) => onChange(media.sizes.full.url)}
22 render={({open}) => {
23 return value ? (
24 <div>
25 <img src={value} onClick={open} style={{cursor: 'pointer'}} />
26 <Button isPrimary isSmall onClick={open} id={id}>
27 {__('Change Image', 'give')}
28 </Button>
29 <Button isSecondary isSmall onClick={() => onChange('')} id={id}>
30 {__('Remove Image', 'give')}
31 </Button>
32 </div>
33 ) : (
34 <div>
35 <Button isPrimary onClick={open} id={id}>
36 {__('Select an Image', 'give')}
37 </Button>
38 </div>
39 );
40 }}
41 />
42 </BaseControl>
43 );
44 };
45
46 ImageControl.propTypes = {
47 label: PropTypes.string,
48 value: PropTypes.any.isRequired,
49 onChange: PropTypes.func,
50 name: PropTypes.string.isRequired,
51 help: PropTypes.string,
52 className: PropTypes.string,
53 hideLabelFromVision: PropTypes.bool,
54 };
55
56 export default ImageControl;
57