import { useRef } from 'react';
import Button from 'elementor-app/ui/molecules/button';
import { arrayToClassName, isOneOf } from 'elementor-app/utils/utils.js';
import './upload-file.scss';
export default function UploadFile( props ) {
const fileInput = useRef( null ),
baseClassName = 'e-app-upload-file',
classes = [ baseClassName, props.className ];
// For 'wp-media' type.
let frame;
return (
'.' + type ).join( ', ' ) }
className="e-app-upload-file__input"
onChange={ ( event ) => {
const file = event.target.files[ 0 ];
if ( file && isOneOf( file.type, props.filetypes ) ) {
props.onFileSelect( file, event, 'browse' );
} else {
fileInput.current.value = '';
props.onError( {
id: 'file_not_allowed',
message: __( 'This file type is not allowed', 'elementor' ),
} );
}
} }
/>
);
}
UploadFile.propTypes = {
className: PropTypes.string,
type: PropTypes.string,
onWpMediaSelect: PropTypes.func,
text: PropTypes.string,
onFileSelect: PropTypes.func,
isLoading: PropTypes.bool,
filetypes: PropTypes.array.isRequired,
onError: PropTypes.func,
variant: PropTypes.string,
color: PropTypes.string,
onButtonClick: PropTypes.func,
onFileChoose: PropTypes.func,
};
UploadFile.defaultProps = {
className: '',
type: 'file-explorer',
text: __( 'Select File', 'elementor' ),
onError: () => {},
variant: 'contained',
color: 'primary',
};