-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
157 lines (143 loc) · 4.61 KB
/
index.html
File metadata and controls
157 lines (143 loc) · 4.61 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
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
151
152
153
154
155
156
157
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap" rel="stylesheet">
<title>Gretcha</title>
</head>
<body>
<div id="entry"></div>
<script src="./grecha.js"></script>
<script>
// state
const state = State()
state.set('count',0)
state.set('awesome',false)
state.set('windowSize',{})
// components
const Title =()=>{
return h1(state.get('awesome') ? 'this is cool' : 'this is awesome').att$('class', 'title').listen$('onmouseenter',function(e) {
console.log(e.target)
}).listen$('onmouseleave',function(e) {
console.log(e.target)
})
}
const Menu =()=>{
return div(
div(a("Foo").att$("href", "#/foo?color=blue")),
div(a("Bar").att$("href", "#/bar"))
).att$('class', 'menu')
}
const Group =(name,...children)=>{
return div(...children).att$('class',`${name}`)
}
const Home =(...children)=>{
return div(...children).att$('class','home')
}
const Counter =()=>{
return div(
div("Counter: " + state.get('count')),
div(
input('button').att$("value", "OK!").att$("class", "button").listen$('onclick',function () {
state.set("count", state.get("count") + 1);
state.set('awesome',!state.get('awesome'));
routes.refresh();
}),
input('button').att$("value", "Reset!").att$("class", "button").listen$('onclick',function () {
state.set("count", 0);
state.set('awesome',false);
routes.refresh();
})
)).att$('class','counter')
}
//css
const styles=()=>{
return {
body: {
margin: "0",
padding: "0",
width:"100%",
fontFamily: "Arial, sans-serif",
},
h1: {
color: state.get('count') % 2 === 0 ? "#AAA" : "#333",
textAlign: "center",
},
".title": {
fontSize: "4em",
margin: "0.5em 0",
},
".menu" :{
display: "flex",
flexDirection:"row",
alignItems:"center",
justifyContent:"space-around",
},
".counter":{
display:"flex",
alignItems:"center",
padding:"10px",
flexDirection:'column',
},
".menu a": {
color: "#007BFF",
textDecoration: "none",
},
".menu a:hover": {
textDecoration: "underline",
},
"#main":{
backgroundColor:"red",
}
};
}
/*
.listen$('onhashchange',(e)=>{
console.log('hash changed')
console.log(e)
window.removeEventListener("hashchange", ()=>console.log('event removed'));
},true),
*/
let stack = 0
// routes
const routes = Router({
"/": () => Home(
Title('hello world'),
Menu(),
Counter(),
).att$('id','home').unmount$(()=>{
state.set('count',0)
console.log('hello')
}),
"/foo": (params) => Group('foo',
h1("Foo"),
p(LOREM).style$( {color: params.get('color')}),
div(a("Home").att$("href", "#")),
),
"/bar": () => Group('bar',
h1("Bar"),
p(LOREM).style$( {color:"blue"}).callback$(function(elem){
elem.style.color = "purple";
}),
div(a("Home").att$("href", "#")),
canvas("main",400,300).callback$(function(elem){
const ctx = elem.getContext('2d');
ctx.fillStyle = 'blue';
ctx.fillRect(10, 10, 100, 100);
})
),
"/404": () => div(
h1("404 Not Found"),
p("The page you are looking for does not exist."),
div(a("Home").att$("href", "#"))
),
});
entry.appendChild(routes);
// window.onresize = ()=>{
// state.set('window',{width: window.innerWidth, height:window.innerHeight})
// console.log(state.get('window'))
// }
</script>
</body>
</html>