import { __ } from '@wordpress/i18n'; import { Button, BaseControl, DropZone } from '@wordpress/components'; import { MediaUpload, MediaUploadCheck } from '@wordpress/block-editor'; import clsx from 'clsx'; interface MediaItem { id: number; url?: string; [ key: string ]: any; } interface ImageUploadProps { className?: string; sKey: string; val: number | undefined; url: string; help: undefined | string | JSX.Element; setAttributes: ( attributes: Record< string, any > ) => void; } const ImageUpload = ( { className, sKey, val, url, help, setAttributes }: ImageUploadProps ) => { const mediaUploadInstructions = (

{ __( 'To edit the featured image, you need permission to upload media.' ) }

); const containerClasses = clsx( 'editor-post-featured-image__container', className ); const mediaUploadRender = ( open: () => void ) => { return (
); }; const handleSelect = ( media: MediaItem ) => { setAttributes( { [ sKey ]: media.id.toString(), [ `${ sKey }_url` ]: media.url || '', } ); }; const handleRemove = () => { setAttributes( { [ sKey ]: '', [ `${ sKey }_url` ]: '', } ); }; return ( mediaUploadRender( open ) } value={ val } /> { !! val && !! url && ( ( ) } /> ) } { !! val && ( ) } ); }; export default ImageUpload;