-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththeme.js
More file actions
59 lines (50 loc) · 1.56 KB
/
theme.js
File metadata and controls
59 lines (50 loc) · 1.56 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
function ChangeColorView (props) {
var style = props.changeColStyle;
style.backgroundColor = props.palette.primary;
return (
<a id="changecolor"
style={style}
onClick={(e) => {
e.preventDefault();
props.changeTheme(props.palette);
}
}/>
);
}
function currentTheme() {
let curTheme =
themes.find(
theme => getComputedStyle(document.documentElement).getPropertyValue('--background-color').includes(theme.primary)
)
return curTheme != undefined ? curTheme : default_theme;
}
class ColorPalettesView extends React.Component {
constructor(props){
super(props)
this.state = { theme : currentTheme()};
this.changeTheme = this.changeTheme.bind(this);
this.changeTheme(this.state.theme);
}
changeTheme (palette) {
if(palette.name === this.state.theme) return;
let root = document.documentElement;
root.style.setProperty("--background-color", palette.primary);
root.style.setProperty("--font-color", palette.secondary);
root.style.setProperty("--highlight-color", palette.highlight);
this.setState({ theme : palette });
}
render() {
return (
<div className="ColorPalettesView" style={this.props.paletteStyle}>
{
themes.map((theme) => {
if(theme == this.state.theme) return;
return <ChangeColorView changeColStyle = {this.props.changeColStyle}
palette = {theme}
changeTheme = {this.changeTheme}/>
})
}
</div>
);
}
}