-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInput.tsx
76 lines (71 loc) · 1.97 KB
/
Input.tsx
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
import React from 'react'
import PropTypes from 'prop-types'
import { IInputProps } from './Dropzone'
const Input = (props: IInputProps) => {
const {
className,
labelClassName,
labelWithFilesClassName,
style,
labelStyle,
labelWithFilesStyle,
getFilesFromEvent,
accept,
multiple,
disabled,
content,
withFilesContent,
onFiles,
files,
} = props
return (
<label
className={files.length > 0 ? labelWithFilesClassName : labelClassName}
style={files.length > 0 ? labelWithFilesStyle : labelStyle}
>
{files.length > 0 ? withFilesContent : content}
<input
className={className}
style={style}
type="file"
accept={accept}
multiple={multiple}
disabled={disabled}
onChange={async e => {
const target = e.target
const chosenFiles = await getFilesFromEvent(e)
onFiles(chosenFiles)
//@ts-ignore
target.value = null
}}
/>
</label>
)
}
Input.propTypes = {
className: PropTypes.string,
labelClassName: PropTypes.string,
labelWithFilesClassName: PropTypes.string,
style: PropTypes.object,
labelStyle: PropTypes.object,
labelWithFilesStyle: PropTypes.object,
getFilesFromEvent: PropTypes.func.isRequired,
accept: PropTypes.string.isRequired,
multiple: PropTypes.bool.isRequired,
disabled: PropTypes.bool.isRequired,
content: PropTypes.node,
withFilesContent: PropTypes.node,
onFiles: PropTypes.func.isRequired,
files: PropTypes.arrayOf(PropTypes.any).isRequired,
extra: PropTypes.shape({
active: PropTypes.bool.isRequired,
reject: PropTypes.bool.isRequired,
dragged: PropTypes.arrayOf(PropTypes.any).isRequired,
accept: PropTypes.string.isRequired,
multiple: PropTypes.bool.isRequired,
minSizeBytes: PropTypes.number.isRequired,
maxSizeBytes: PropTypes.number.isRequired,
maxFiles: PropTypes.number.isRequired,
}).isRequired,
}
export default Input