-
Notifications
You must be signed in to change notification settings - Fork 317
/
Copy pathContentUploader.js
95 lines (86 loc) · 2.96 KB
/
ContentUploader.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**
* @flow
* @file Base class for the Content Uploader ES6 wrapper
* @author Box
*/
import * as React from 'react';
// TODO switch to createRoot when upgrading to React 18
// eslint-disable-next-line react/no-deprecated
import { render } from 'react-dom';
import ES6Wrapper from './ES6Wrapper';
import ContentUploaderPopup from '../content-uploader/ContentUploaderPopup';
import WrappedContentUploaderComponent from '../content-uploader/ContentUploader';
import type { UploadFileWithAPIOptions } from '../../common/types/upload';
import type { BoxItem } from '../../common/types/core';
import type { ModalOptions } from '../common/flowTypes';
class ContentUploader extends ES6Wrapper {
/**
* Callback on closing uploader. Emits 'close' event.
*
* @return {void}
*/
onClose = (): void => {
this.emit('close');
};
/**
* Callback when all files finish uploading. Emits 'complete' event with Box File objects of uploaded items as data.
*
* @param {Array} data - Completed upload items
* @return {void}
*/
onComplete = (data: BoxItem[]): void => {
this.emit('complete', data);
};
/**
* Callback on a single upload error. Emits 'uploaderror' event with information about the failed upload.
*
* @param {Object} data - File and error info about failed upload
* @return {void}
*/
onError = (data: any): void => {
this.emit('error', data);
};
/**
* Callback on a single pre-uploaded file. Emits 'beforeupload' event with the Box File object pre-upload.
*
* @param {Object} data - Upload item
* @return {void}
*/
onBeforeUpload = (data: UploadFileWithAPIOptions | File): void => {
this.emit('beforeupload', data);
};
/**
* Callback on a single successful upload. Emits 'uploadsuccess' event with Box File object of uploaded item.
*
* @param {BoxItem} data - Successfully uploaded item
* @return {void}
*/
onUpload = (data: BoxItem): void => {
this.emit('upload', data);
};
/** @inheritdoc */
render() {
const { modal, ...rest }: { modal?: ModalOptions } = this.options;
const UploaderComponent = modal ? ContentUploaderPopup : WrappedContentUploaderComponent;
render(
<UploaderComponent
language={this.language}
messages={this.messages}
componentRef={this.setComponent}
rootFolderId={this.id}
token={this.token}
onClose={this.onClose}
onComplete={this.onComplete}
onError={this.onError}
onBeforeUpload={this.onBeforeUpload}
onUpload={this.onUpload}
modal={((modal: any): ModalOptions)}
{...rest}
/>,
this.container,
);
}
}
global.Box = global.Box || {};
global.Box.ContentUploader = ContentUploader;
export default ContentUploader;