-
Notifications
You must be signed in to change notification settings - Fork 317
/
Copy pathContentPicker.js
80 lines (73 loc) · 2.21 KB
/
ContentPicker.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
/**
* @flow
* @file Base class for the Content Picker 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 ContentPickerPopup from '../content-picker/ContentPickerPopup';
import ContentPickerReactComponent from '../content-picker/ContentPicker';
import { TYPE_FOLDER, TYPE_FILE, TYPE_WEBLINK, CLIENT_NAME_CONTENT_PICKER } from '../../constants';
import type { ModalOptions } from '../common/flowTypes';
import type { BoxItem } from '../../common/types/core';
class ContentPicker extends ES6Wrapper {
/**
* Callback for pressing choose
*
* @param {Array} data - chosen box items
* @return {void}
*/
onChoose = (data: BoxItem[]): void => {
this.emit('choose', data);
};
/**
* Callback for pressing cancel
*
* @return {void}
*/
onCancel = (): void => {
this.emit('cancel');
};
/**
* Returns the type of content picker
*
* @return {void}
*/
getType(): string {
const { type } = this.options || {};
return type || `${TYPE_FOLDER},${TYPE_FILE},${TYPE_WEBLINK}`;
}
/**
* Returns the name for content picker
*
* @return {void}
*/
getClientName(): string {
return CLIENT_NAME_CONTENT_PICKER;
}
/** @inheritdoc */
render() {
const { modal, ...rest }: { modal?: ModalOptions } = this.options;
const PickerComponent = modal ? ContentPickerPopup : ContentPickerReactComponent;
render(
<PickerComponent
clientName={this.getClientName()}
componentRef={this.setComponent}
language={this.language}
messages={this.messages}
modal={((modal: any): ModalOptions)}
onCancel={this.onCancel}
onChoose={this.onChoose}
rootFolderId={this.id}
token={this.token}
type={this.getType()}
{...rest}
/>,
this.container,
);
}
}
export default ContentPicker;