blob: 91c6f54d4ad1f69a8e0afdb9d2af2398b2afb97c (
plain)
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
140
141
142
143
|
import * as Uebersicht from "uebersicht";
import * as Utils from "../../utils";
const { React } = Uebersicht;
/**
* Item component to render different types of settings inputs.
* @param {Object} props - Component properties.
* @param {string} props.code - Unique code for the setting.
* @param {React.Component} props.Component - Custom component for the setting.
* @param {any} props.defaultValue - Default value of the setting.
* @param {string} props.label - Label for the setting.
* @param {string} props.type - Type of the setting input.
* @param {Array} [props.options] - Options for select or radio inputs.
* @param {string} [props.placeholder] - Placeholder for text inputs.
* @param {number} [props.minHeight] - Minimum height for textarea inputs.
* @param {Function} props.onChange - Change handler for the setting input.
*/
export default function SettingsItem({
code,
Component,
defaultValue,
label,
type,
options,
placeholder,
minHeight,
onChange,
}) {
const onClick = (e) => Utils.clickEffect(e);
if (type === "component") {
return <Component defaultValue={defaultValue} onChange={onChange} />;
}
if (type === "select") {
return (
<React.Fragment>
<label htmlFor={code} dangerouslySetInnerHTML={{ __html: label }} />
<select
id={code}
className="settings__select"
onChange={onChange}
defaultValue={defaultValue}
>
{options.map((option) => (
<option key={option.code} value={option.code}>
{option.name}
</option>
))}
</select>
</React.Fragment>
);
}
if (type === "radio") {
return options.map((option) => (
<div className="settings__item-option" key={option} onClick={onClick}>
<input
name={code}
id={option}
value={option}
type="radio"
defaultChecked={option === defaultValue}
/>
<label
htmlFor={option}
dangerouslySetInnerHTML={{ __html: `${option} ${label}` }}
/>
</div>
));
}
if (type === "text" || type === "color") {
return (
<React.Fragment>
<label htmlFor={code} dangerouslySetInnerHTML={{ __html: label }} />
{type === "color" && (
<div
className="settings__item-color-pill"
style={{ backgroundColor: defaultValue || "transparent" }}
/>
)}
<input
id={code}
type="text"
defaultValue={defaultValue}
placeholder={placeholder}
onChange={onChange}
autoComplete="off"
autoCorrect="off"
autoCapitalize="off"
spellCheck={false}
/>
</React.Fragment>
);
}
if (type === "number") {
return (
<React.Fragment>
<label htmlFor={code} dangerouslySetInnerHTML={{ __html: label }} />
<input
id={code}
type="number"
value={defaultValue}
placeholder={placeholder}
onChange={onChange}
autoComplete="off"
/>
</React.Fragment>
);
}
if (type === "textarea") {
return (
<React.Fragment>
<label htmlFor={code} dangerouslySetInnerHTML={{ __html: label }} />
<textarea
id={code}
defaultValue={defaultValue}
placeholder={placeholder}
onChange={onChange}
autoComplete="off"
autoCorrect="off"
autoCapitalize="off"
spellCheck={false}
style={{ minHeight }}
/>
</React.Fragment>
);
}
return (
<React.Fragment>
<input
id={code}
type="checkbox"
defaultChecked={defaultValue}
onChange={onChange}
onClick={onClick}
/>
<label
htmlFor={code}
onClick={onClick}
dangerouslySetInnerHTML={{ __html: label }}
/>
</React.Fragment>
);
}
|