-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
117 lines (101 loc) · 2.02 KB
/
index.html
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
<!DOCTYPE html>
<html dir="en" dir="ltr">
<head>
<title>First Theme Switcher using MithrilJS</title>
<style type="text/css">
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
.app, html, body {
height:100%;
}
.app {
display: flex;
align-items: center;
justify-content: center;
font-family: Arial;
}
.switch-container {
margin-left: 20px;
}
.switch-container input[type="checkbox"]{
display: none;
}
.slider{
position: relative;
display: inline-block;
width: 90px;
height: 47px;
left: 0;
background-color: #34495e;
border: 2px solid #34495e;
border-radius: 40px;
cursor: pointer;
}
.slider::before{
position: absolute;
width: 35px;
height: 35px;
top: 5px;
right: 5px;
content: ' ';
background-color: #ffffff;
border-radius: 50%;
transition: right .2s, background-color .2s;
}
input[type="checkbox"]:checked + .slider::before{
right: 46px;
background-color: #34495e;
}
input[type="checkbox"]:checked + .slider{
background-color: #ffffff;
}
</style>
</head>
<body>
<script type="text/javascript" src="mithril.js"></script>
<script type="text/javascript">
const root = document.body
const context = {
'LIGHT': {
bgTheme: '#ffffff',
fgTheme: '#34495e',
checked: false
},
'DARK': {
bgTheme: '#34495e',
fgTheme: '#ffffff',
checked: true
}
}
const state = {
theme: 'LIGHT',
changeTheme: (newTheme) => {
state.theme = newTheme
},
toggleTheme: () => {
if(state.theme === 'LIGHT') {
state.changeTheme('DARK')
} else {
state.changeTheme('LIGHT')
}
}
}
const page = {
view: () => {
return m("div", {class: "app",style: "background-color:"+context[state.theme].bgTheme}, [
m("h2", {style: "color:"+context[state.theme].fgTheme}, "Theme switcher"),
m("label", {class: "switch-container"}, [
m("input", {type: "checkbox", onchange: state.toggleTheme, checked: context[state.theme].checked}),
m("span", {class: "slider"})
])
]
)
}
}
m.mount(root, page)
</script>
</body>
</html>