-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathFormInput.js
More file actions
106 lines (94 loc) · 2 KB
/
FormInput.js
File metadata and controls
106 lines (94 loc) · 2 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import React from "react";
import PropTypes from "prop-types";
import classNames from "classnames";
import { INPUT_TYPES, AUTOCOMPLETE_TYPES } from "../constants";
/**
* The form input allows you to create various text style inputs such as `text`, `password`, `email`, `number`, `url`, `search` and more.
*/
class FormInput extends React.Component {
constructor(props) {
super(props);
this.ref = null;
this.getRef = this.getRef.bind(this);
this.focus = this.focus.bind(this);
}
getRef(ref) {
if (this.props.innerRef) {
this.props.innerRef(ref);
}
this.ref = ref;
}
focus() {
if (this.ref) {
this.ref.focus();
}
}
render() {
const {
className,
plaintext,
autoComplete,
size,
invalid,
valid,
innerRef,
...attrs
} = this.props;
const classes = classNames(
className,
plaintext ? "form-control-plaintext" : "form-control",
plaintext && "w-100",
size && `form-control-${size}`,
valid && "is-valid",
invalid && "is-invalid"
);
return <input {...attrs} ref={innerRef} className={classes} autoComplete={autoComplete} />;
}
}
FormInput.propTypes = {
/**
* The class name.
*/
className: PropTypes.string,
/**
* The children nodes.
*/
children: PropTypes.node,
/**
* Whether it is inline, or not.
*/
inline: PropTypes.bool,
/**
* The input type.
*/
type: PropTypes.oneOf(INPUT_TYPES),
/**
* Whether it is plaintext, or not.
*/
plaintext: PropTypes.bool,
/**
* Whether it is plaintext, or not.
*/
autoComplete: PropTypes.oneOf(AUTOCOMPLETE_TYPES),
/**
* The input's size.
*/
size: PropTypes.string,
/**
* Whether it is valid, or not.
*/
valid: PropTypes.bool,
/**
* Whether it is invalid, or not.
*/
invalid: PropTypes.bool,
/**
* The inner ref.
*/
innerRef: PropTypes.oneOfType([
PropTypes.object,
PropTypes.func,
PropTypes.string
])
};
export default FormInput;