-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathsettings.tsx
139 lines (129 loc) · 3.24 KB
/
settings.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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import React from "react";
import { withStyles } from "@material-ui/core/styles";
import { CreateCSSProperties } from "@material-ui/core/styles/withStyles";
import TextField from "@material-ui/core/TextField";
import Input from "@material-ui/core/Input";
import FormHelperText from "@material-ui/core/FormHelperText";
import FormControl from "@material-ui/core/FormControl";
import Select from "@material-ui/core/Select";
import MenuItem from "@material-ui/core/MenuItem";
import FormControlLabel from "@material-ui/core/FormControlLabel";
import Checkbox from "@material-ui/core/Checkbox";
import I18n from "@iobroker/adapter-react/i18n";
const styles = (): Record<string, CreateCSSProperties> => ({
input: {
marginTop: 0,
minWidth: 400,
},
button: {
marginRight: 20,
},
card: {
maxWidth: 345,
textAlign: "center",
},
media: {
height: 180,
},
column: {
display: "inline-block",
verticalAlign: "top",
marginRight: 20,
},
columnLogo: {
width: 350,
marginRight: 0,
},
columnSettings: {
width: "calc(100% - 370px)",
},
controlElement: {
//background: "#d2d2d2",
marginBottom: 5,
},
});
interface SettingsProps {
classes: Record<string, string>;
native: Record<string, any>;
onChange: (attr: string, value: any) => void;
}
interface SettingsState {
// add your state properties here
dummy?: undefined;
}
class Settings extends React.Component<SettingsProps, SettingsState> {
constructor(props: SettingsProps) {
super(props);
this.state = {};
}
renderInput(title: AdminWord, attr: string, type: string) {
return (
<TextField
label={I18n.t(title)}
className={`${this.props.classes.input} ${this.props.classes.controlElement}`}
value={this.props.native[attr]}
type={type || "text"}
onChange={(e) => this.props.onChange(attr, e.target.value)}
margin="normal"
/>
);
}
renderSelect(
title: AdminWord,
attr: string,
options: { value: string; title: AdminWord }[],
style?: React.CSSProperties,
) {
return (
<FormControl
className={`${this.props.classes.input} ${this.props.classes.controlElement}`}
style={{
paddingTop: 5,
...style
}}
>
<Select
value={this.props.native[attr] || "_"}
onChange={(e) => this.props.onChange(attr, e.target.value === "_" ? "" : e.target.value)}
input={<Input name={attr} id={attr + "-helper"} />}
>
{options.map((item) => (
<MenuItem key={"key-" + item.value} value={item.value || "_"}>
{I18n.t(item.title)}
</MenuItem>
))}
</Select>
<FormHelperText>{I18n.t(title)}</FormHelperText>
</FormControl>
);
}
renderCheckbox(title: AdminWord, attr: string, style?: React.CSSProperties) {
return (
<FormControlLabel
key={attr}
style={{
paddingTop: 5,
...style
}}
className={this.props.classes.controlElement}
control={
<Checkbox
checked={this.props.native[attr]}
onChange={() => this.props.onChange(attr, !this.props.native[attr])}
color="primary"
/>
}
label={I18n.t(title)}
/>
);
}
render() {
return (
<form className={this.props.classes.tab}>
{this.renderCheckbox("option1", "option1")}<br />
{this.renderInput("option2", "option2", "text")}
</form>
);
}
}
export default withStyles(styles)(Settings);