generateblocks
/
src
/
extend
/
inspector-control
/
controls
/
background-panel
/
components
/
image-url.js
generateblocks
/
src
/
extend
/
inspector-control
/
controls
/
background-panel
/
components
Last commit date
attachment.js
3 years ago
background-color-overlay.js
3 years ago
background-options.js
2 years ago
image-opacity.js
3 years ago
image-size.js
3 years ago
image-url.js
3 years ago
position.js
3 years ago
repeat.js
3 years ago
selector.js
3 years ago
size.js
3 years ago
use-inline-style.js
3 years ago
image-url.js
82 lines
| 1 | import { __ } from '@wordpress/i18n'; |
| 2 | import { BaseControl, Button, Notice, TextControl, Tooltip } from '@wordpress/components'; |
| 3 | import { MediaUpload } from '@wordpress/block-editor'; |
| 4 | |
| 5 | export default function ImageUrl( { bgImage, setAttributes, isUsingFeaturedImage } ) { |
| 6 | return ( |
| 7 | <> |
| 8 | <BaseControl |
| 9 | id="gblocks-background-image-upload" |
| 10 | label={ __( 'Image URL', 'generateblocks' ) } |
| 11 | > |
| 12 | <div className="gblocks-bg-image-wrapper"> |
| 13 | <TextControl |
| 14 | type={ 'text' } |
| 15 | value={ !! bgImage ? bgImage.image.url : '' } |
| 16 | onChange={ ( value ) => { |
| 17 | if ( ! value ) { |
| 18 | setAttributes( { bgImage: null } ); |
| 19 | } else { |
| 20 | setAttributes( { |
| 21 | bgImage: { |
| 22 | id: '', |
| 23 | image: { |
| 24 | url: value, |
| 25 | }, |
| 26 | }, |
| 27 | } ); |
| 28 | } |
| 29 | } } |
| 30 | /> |
| 31 | |
| 32 | <div className="gblocks-background-image-action-buttons"> |
| 33 | <MediaUpload |
| 34 | title={ __( 'Set background image', 'generateblocks' ) } |
| 35 | onSelect={ ( media ) => { |
| 36 | let size = generateBlocksDefaults.container.bgImageSize; |
| 37 | |
| 38 | if ( 'undefined' === typeof media.sizes[ size ] ) { |
| 39 | size = 'full'; |
| 40 | } |
| 41 | |
| 42 | setAttributes( { |
| 43 | bgImage: { |
| 44 | id: media.id, |
| 45 | image: media.sizes[ size ], |
| 46 | }, |
| 47 | } ); |
| 48 | } } |
| 49 | onClose={ () => { |
| 50 | document.querySelector( '.gblocks-bg-image-wrapper input' ).focus(); |
| 51 | } } |
| 52 | allowedTypes={ [ 'image' ] } |
| 53 | value={ !! bgImage ? bgImage.id : '' } |
| 54 | modalClass="editor-gb-container-background__media-modal" |
| 55 | render={ ( { open } ) => ( |
| 56 | <Tooltip text={ __( 'Open the Media Library', 'generateblocks' ) }> |
| 57 | <Button |
| 58 | onClick={ open } |
| 59 | className="is-secondary is-small" |
| 60 | > |
| 61 | { __( 'Browse', 'generateblocks' ) } |
| 62 | </Button> |
| 63 | </Tooltip> |
| 64 | ) } |
| 65 | /> |
| 66 | </div> |
| 67 | </div> |
| 68 | </BaseControl> |
| 69 | |
| 70 | { isUsingFeaturedImage && |
| 71 | <Notice |
| 72 | className="gblocks-option-notice" |
| 73 | status="info" |
| 74 | isDismissible={ false } |
| 75 | > |
| 76 | { __( 'Using featured image as dynamic background.', 'generateblocks' ) } |
| 77 | </Notice> |
| 78 | } |
| 79 | </> |
| 80 | ); |
| 81 | } |
| 82 |