forked from wojtekmaj/react-pdf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPassingOptions.jsx
124 lines (112 loc) · 2.72 KB
/
PassingOptions.jsx
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import React from 'react';
import PropTypes from 'prop-types';
import { isDataURI } from '../src/shared/utils';
import { isFile } from './shared/propTypes';
export default function PassingOptions({
file,
passMethod,
setPassMethod,
}) {
const sourceType = (() => {
if (file === null) {
return 'null';
}
if (typeof file === 'string') {
if (isDataURI(file)) {
return 'data URI';
}
return 'string';
}
if (typeof file === 'object') {
return file.constructor.name;
}
return typeof file;
})();
function onPassMethodChange(event) {
const nextPassMethod = event.target.value;
setPassMethod(nextPassMethod === 'null' ? null : nextPassMethod);
}
return (
<fieldset id="passingoptions">
<legend htmlFor="passingoptions">
Passing options
</legend>
<div>
<input
checked={passMethod === null}
id="passNormal"
name="passMethod"
onChange={onPassMethodChange}
type="radio"
value="null"
/>
<label htmlFor="passNormal">
Pass as is (
{sourceType}
)
</label>
</div>
<div>
<input
checked={passMethod === 'object'}
id="passObject"
name="passMethod"
onChange={onPassMethodChange}
type="radio"
value="object"
/>
<label htmlFor="passObject">
Pass as a parameter object
</label>
</div>
<div>
<input
checked={passMethod === 'string'}
id="passString"
name="passMethod"
onChange={onPassMethodChange}
type="radio"
value="string"
/>
<label htmlFor="passString">
Pass as a string/data URI
</label>
</div>
<div>
<input
checked={passMethod === 'blob'}
id="passBlob"
name="passMethod"
onChange={onPassMethodChange}
type="radio"
value="blob"
/>
<label htmlFor="passBlob">
Pass as a File/Blob
</label>
</div>
</fieldset>
);
}
const fileTypes = [
PropTypes.string,
PropTypes.instanceOf(ArrayBuffer),
PropTypes.shape({
data: PropTypes.object,
httpHeaders: PropTypes.object,
range: PropTypes.object,
url: PropTypes.string,
withCredentials: PropTypes.bool,
}),
];
if (typeof File !== 'undefined') {
fileTypes.push(PropTypes.instanceOf(File));
}
if (typeof Blob !== 'undefined') {
fileTypes.push(PropTypes.instanceOf(Blob));
}
PassingOptions.propTypes = {
file: isFile,
passMethod: PropTypes.oneOf(['blob', 'normal', 'object', 'string']),
setPassMethod: PropTypes.func.isRequired,
};