Back to Woocommerce

MediaUploader

packages/js/components/src/media-uploader/README.md

10.8.0-dev2.1 KB
Original Source

MediaUploader

This component adds an upload button and a dropzone for uploading media to a site.

Usage

By default this will use the functionality from @wordpress/media-utils which provides access and uploads to the WP media library and uses the WP media modal.

jsx
<MediaUploader
	label={ 'Click the button below to upload' }
	onSelect={ ( file ) => setImages( [ ...images, file ] ) }
	onUpload={ ( files ) => setImages( [ ...images, ...files ] ) }
/>

Props

NameTypeDefaultDescription
allowedMediaTypesString[][ 'image ]Allowed media types
buttonTextStringChoose imagesText to use for button
hasDropZoneBooleantrueWhether or not to allow the dropzone
labelStringDrag images here or click to uploadString to use for the text shown inside the component
MediaUploadComponentJSX.ElementMediaModalThe component to use for the media uploader
onErrorFunction() => nullCallback function to run when an error occurs
onUploadFunction() => nullCallback function to run when an upload occurs aftering dragging and dropping files
onSelectFunction() => nullCallback function to run when selecting media from the opened media modal