HEX
Server: Apache/2.4.68 (Debian)
System: Linux as-cs-widget-demo-us-central1 6.1.0-44-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.164-1 (2026-03-09) x86_64
User: root (0)
PHP: 8.2.32
Disabled: NONE
Upload Files
File: /var/www/html/wp-content/plugins/wp-recipe-maker/assets/js/admin-modal/fields/FieldImage.js
import React from 'react';

import Media from '../general/Media';
import Button from 'Shared/Button';
import { __wprm } from 'Shared/Translations';
 
const FieldImage = (props) => {
    const hasImage = props.id > 0;

    const selectImage = (e) => {
        e.preventDefault();

        Media.selectImage((attachment) => {
            if ( props.hasOwnProperty( 'requirements' ) ) {
                let warnings = [];

                if ( props.requirements.hasOwnProperty( 'width' ) && attachment.width && attachment.width < props.requirements.width ) {
                    warnings.push( `${ __wprm( 'The image should have at least this width:' ) } ${ props.requirements.width }px` );
                }
                if ( props.requirements.hasOwnProperty( 'height' ) && attachment.height && attachment.height < props.requirements.height ) {
                    warnings.push( `${ __wprm( 'The image should have at least this height:' ) } ${ props.requirements.width }px` );
                }

                if ( warnings.length ) {
                    alert( `${ __wprm( 'Warning! We recommend making sure the image meets the following requirements:' ) }\n\n${ warnings.join( '\n' ) }` );
                }
            }

            props.onChange( attachment.id, attachment.url );
        });
    }

    return (
        <div className="wprm-admin-modal-field-image">
            {
                hasImage
                ?
                <div className="wprm-admin-modal-field-image-preview">
                    <img
                        onClick={ selectImage }
                        src={ props.url }
                    />
                    <a
                        href="#"
                        tabIndex={ props.disableTab ? '-1' : null }
                        onClick={ (e) => {
                            e.preventDefault();
                            props.onChange( 0, '' );
                        } }
                    >{ __wprm( 'Remove Image' ) }</a>
                </div>
                :
                <Button
                    required={ props.required }
                    disableTab={ props.disableTab }
                    onClick={ selectImage }
                    
                >{ __wprm( 'Select Image' ) }</Button>
            }
        </div>
    );
}
export default FieldImage;