This repository has been archived by the owner on Sep 21, 2021. It is now read-only.
/
Settings.js
150 lines (132 loc) · 3.81 KB
/
Settings.js
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
144
145
146
147
148
149
150
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const React = require("react");
const { Component } = React;
const dom = require("react-dom-factories");
const PropTypes = require("prop-types");
const { showMenu, buildMenu } = require("devtools-contextmenu");
class Settings extends Component {
static get propTypes() {
return {
config: PropTypes.object.isRequired,
setValue: PropTypes.func.isRequired
};
}
constructor(props) {
super(props);
this.onConfigContextMenu = this.onConfigContextMenu.bind(this);
this.onInputHandler = this.onInputHandler.bind(this);
this.renderConfig = this.renderConfig.bind(this);
this.renderFeatures = this.renderFeatures.bind(this);
}
onConfigContextMenu(event, key) {
event.preventDefault();
const { setValue, config } = this.props;
const setConfig = (path, value) => {
setValue(path, value);
};
const ltrMenuItem = {
id: "node-menu-ltr",
label: "ltr",
disabled: config[key] === "ltr",
click: () => setConfig(key, "ltr")
};
const rtlMenuItem = {
id: "node-menu-rtl",
label: "rtl",
disabled: config[key] === "rtl",
click: () => setConfig(key, "rtl")
};
const lightMenuItem = {
id: "node-menu-light",
label: "light",
disabled: config[key] === "light",
click: () => setConfig(key, "light")
};
const darkMenuItem = {
id: "node-menu-dark",
label: "dark",
disabled: config[key] === "dark",
click: () => setConfig(key, "dark")
};
const items = {
"dir": [
{ item: ltrMenuItem },
{ item: rtlMenuItem },
],
"theme": [
{ item: lightMenuItem },
{ item: darkMenuItem },
]
};
showMenu(event, buildMenu(items[key]));
}
onInputHandler(e, path) {
const { setValue } = this.props;
setValue(path, e.target.checked);
}
renderConfig(config) {
const configs = [
{ name: "dir", label: "direction" },
{ name: "theme", label: "theme" }
// Hiding hotReloading option for now. See Issue #242
// { name: "hotReloading", label: "hot reloading", bool: true }
];
return dom.ul(
{ className: "tab-list" },
configs.map(c => {
return dom.li({ key: c.name, className: "tab tab-sides" },
dom.div({ className: "tab-title" }, c.label),
c.bool ? dom.input({
type: "checkbox",
defaultChecked: config[c.name],
onChange: e => this.onInputHandler(e, c.name)
}, null) : dom.div({
className: "tab-value",
onClick: e => this.onConfigContextMenu(e, c.name)
}, config[c.name])
);
})
);
}
renderFeatures(features) {
return dom.ul(
{ className: "tab-list" },
Object.keys(features).map(key => dom.li(
{
className: "tab tab-sides",
key
},
dom.div({ className: "tab-title" },
typeof features[key] == "object" ?
features[key].label :
key
),
dom.div({ className: "tab-value" },
dom.input(
{
type: "checkbox",
defaultChecked: features[key].enabled,
onChange: e => this.onInputHandler(e, `features.${key}.enabled`)
},
)
)
))
);
}
render() {
const { config } = this.props;
return dom.div(
{ className: "launchpad-tabs" },
dom.h3({}, "Configurations"),
this.renderConfig(config),
config.features ?
(
dom.h3({}, "Features"),
this.renderFeatures(config.features)
) : null
);
}
}
module.exports = Settings;