Repository navigation
Expand file tree
/
Copy pathFormControlInput.js
More file actions
95 lines (88 loc) · 1.98 KB
/
Copy pathFormControlInput.js
File metadata and controls
95 lines (88 loc) · 1.98 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
import { withStyles } from "@material-ui/core/styles";
import FormControl from "@material-ui/core/FormControl";
import Input from "@material-ui/core/Input";
import InputLabel from "@material-ui/core/InputLabel";
import FormHelperText from "@material-ui/core/FormHelperText";
import teal from "@material-ui/core/colors/teal";
const styles = (theme) => ({
input: {
height: "initial",
},
label: {
"&$focused": {
color: teal[500],
},
},
focused: {},
underline: {
"&:after": {
borderBottomColor: teal[500],
},
},
helperText: {
marginTop: 0,
lineHeight: "1.5rem",
overflow: "auto",
"-webkit-overflow-scrolling": "touch",
},
});
const FormControlInput = (props) => {
const {
classes,
className,
id,
label,
value,
type,
error,
errorMessage,
onChange,
autoFocus,
multiline,
rows,
required,
} = props;
let wrapperProps = {};
let inputProps = {};
if (className) wrapperProps.className = className;
if (multiline && rows) inputProps.rows = rows;
return (
<FormControl {...wrapperProps} fullWidth>
<InputLabel
htmlFor={id}
error={props.error}
classes={{
root: classes.label,
focused: classes.focused,
}}
>
{label}
</InputLabel>
<Input
error={error}
id={id}
value={value}
type={type || "string"}
classes={{
underline: classes.underline,
}}
inputProps={{
className: classes.input,
required: required || false,
}}
onChange={onChange}
required={required}
autoFocus={autoFocus}
fullWidth
multiline={multiline || false}
{...inputProps}
/>
{!!error && (
<FormHelperText className={classes.helperText}>
{errorMessage}
</FormHelperText>
)}
</FormControl>
);
};
export default withStyles(styles, { withTheme: true })(FormControlInput);