| 1 |
/** |
| 2 |
* WordPress dependencies |
| 3 |
*/ |
| 4 |
import { MediaUpload } from '@wordpress/block-editor'; |
| 5 |
import { Button, FocalPointPicker, TextControl, BaseControl } from '@wordpress/components'; |
| 6 |
import { __ } from '@wordpress/i18n'; |
| 7 |
|
| 8 |
/** |
| 9 |
* External dependencies |
| 10 |
*/ |
| 11 |
import classnames from 'classnames'; |
| 12 |
|
| 13 |
const Preview = ({ |
| 14 |
url, |
| 15 |
id, |
| 16 |
alt = '', |
| 17 |
label = '', |
| 18 |
onSelect, |
| 19 |
onClick, |
| 20 |
focalPoint = false, |
| 21 |
focalValue, |
| 22 |
onFocalPointChange, |
| 23 |
videoType = false, |
| 24 |
editing = true |
| 25 |
}) => { |
| 26 |
return ( |
| 27 |
<BaseControl label={label} id="gutslider-image-preview"> |
| 28 |
<div |
| 29 |
className={classnames('gutslider-image-preview', { |
| 30 |
'has-focal-point': focalPoint, |
| 31 |
'has-video': videoType |
| 32 |
})} |
| 33 |
> |
| 34 |
{videoType ? ( |
| 35 |
<TextControl label={__('Video URL', 'slider-blocks')} value={url} readonly={true} /> |
| 36 |
) : ( |
| 37 |
<> |
| 38 |
{focalPoint ? ( |
| 39 |
<FocalPointPicker url={url} value={focalValue} onChange={v => onFocalPointChange(v)} /> |
| 40 |
) : ( |
| 41 |
<img src={url} alt={alt || 'placeholder alt'} /> |
| 42 |
)} |
| 43 |
</> |
| 44 |
)} |
| 45 |
{editing && ( |
| 46 |
<> |
| 47 |
<MediaUpload |
| 48 |
onSelect={media => onSelect(media)} |
| 49 |
allowedTypes={videoType ? '*' : ['image']} |
| 50 |
value={id} |
| 51 |
render={({ open }) => <Button onClick={open} className="edit-btn" icon="edit" />} |
| 52 |
/> |
| 53 |
<Button className="remove-btn" icon="no-alt" onClick={() => onClick()} /> |
| 54 |
</> |
| 55 |
)} |
| 56 |
</div> |
| 57 |
</BaseControl> |
| 58 |
); |
| 59 |
}; |
| 60 |
|
| 61 |
export default Preview; |
| 62 |
|