-
-
Notifications
You must be signed in to change notification settings - Fork 43
/
ConfigItem.jsx
79 lines (69 loc) · 2.71 KB
/
ConfigItem.jsx
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
/*
* File: ConfigItem.jsx
* Project: discord-rpc
* File Created: Sunday, 12th February 2023 2:50:08 pm
* Author: Tee ([email protected])
* Github: https://github.com/teeteeteeteetee
* Discord: Tee#0001
*
* Last Modified: Sunday, 7th April 2024 12:25:20 pm
* Modified By: Tee ([email protected])
*
* Copyright (c) 2023 Tee, Stainless Love
*/
import React, { useState } from "react";
import "../discord.css";
export default function ConfigItem({ title, template, group, config, setConfig }) {
const checkbox = (id) => {
if(Object.keys(config).length > 0){
const [checked, setChecked] = useState(config[group][id].enabled)
return (
<div className="checkbox-container my-auto">
<input checked={checked} onChange={() => {
setChecked(!checked)
config[group][id].enabled = !checked
setConfig(config)
}} className="checkbox" id={id} type="checkbox" />
<div className="checkbox-visual outline-none border-none focus:ring-0">
<div></div>
</div>
</div>
);
}
}
const dropdown = (id) => {
if(Object.keys(config).length > 0){
return (
<div>
<select onChange={(e) => config[group][id].value = e.target.value} id={id} className="bg-dropdown outline-none w-32 px-2 rounded-md" name="logo">
<option value="old">Old</option>
<option value="new">Updated</option>
<option value="custom">Custom</option>
</select>
</div>
)
}
}
const list = Object.keys(template)
.filter(key => !template[key].hidden)
.map((key) => {
if (typeof template[key] !== "string") {
return (
<li key={key}>
<div className="flex flex-row text-white">
<label className="select-none" htmlFor={key}>{template[key].name}</label>
<div className="grow pr-2" />
{template[key].type === "dropdown" && dropdown(key)}
{template[key].type === "checkbox" && checkbox(key)}
</div>
</li>
);
}
});
return (
<div className="pl-2">
<p className="text-lg text-white">{title}</p>
<ul className="text-white p-2">{list}</ul>
</div>
);
}