forked from reactstrap/reactstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInput.js
More file actions
82 lines (69 loc) · 1.87 KB
/
Copy pathInput.js
File metadata and controls
82 lines (69 loc) · 1.87 KB
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
/* eslint react/prefer-stateless-function: 0 */
import React, { PropTypes } from 'react';
import classNames from 'classnames';
import { mapToCssModules } from './utils';
const propTypes = {
children: PropTypes.node,
type: PropTypes.string,
size: PropTypes.string,
state: PropTypes.string,
tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
getRef: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
static: PropTypes.bool,
addon: PropTypes.bool,
className: PropTypes.string,
cssModule: PropTypes.object,
};
const defaultProps = {
tag: 'p',
type: 'text',
};
class Input extends React.Component {
render() {
const {
className,
cssModule,
type,
size,
state,
tag,
addon,
static: staticInput,
getRef,
...attributes
} = this.props;
const checkInput = ['radio', 'checkbox'].indexOf(type) > -1;
const fileInput = type === 'file';
const textareaInput = type === 'textarea';
const selectInput = type === 'select';
let Tag = selectInput || textareaInput ? type : 'input';
let formControlClass = 'form-control';
if (staticInput) {
formControlClass = `${formControlClass}-static`;
Tag = tag;
} else if (fileInput) {
formControlClass = `${formControlClass}-file`;
} else if (checkInput) {
if (addon) {
formControlClass = null;
} else {
formControlClass = 'form-check-input';
}
}
const classes = mapToCssModules(classNames(
className,
state ? `form-control-${state}` : false,
size ? `form-control-${size}` : false,
formControlClass
), cssModule);
if (Tag === 'input') {
attributes.type = type;
}
return (
<Tag {...attributes} ref={getRef} className={classes} />
);
}
}
Input.propTypes = propTypes;
Input.defaultProps = defaultProps;
export default Input;