-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.tsx
82 lines (75 loc) · 2.22 KB
/
index.tsx
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
import { render } from 'skruv'
import { css, cssTextGenerator } from 'skruv/utils/css.js'
import { createState } from 'skruv/utils/state.js'
import { syncify, hydrationPromise } from 'skruv/utils/syncify.js'
const state = createState({ todos: ['Write todos'] })
const styles = css`
:scope {
color: #f1f1f1;
background: #0f0f0f;
}
body {
max-width: 40ch;
margin: 0 auto;
}
form { display: flex; }
input { flex: 1; }
a { color: #9b9b9b; }
`
const doRender = async (): Promise<void> => {
await hydrationPromise
render(
syncify(
<html lang='en-US' class={styles}>
<head>
<title>{state.todos.getGenerator(0)}</title>
<meta name='viewport' content='width=device-width, initial-scale=1' />
<skruvHeader name='X-Test-Header' value='test' />
<skruvComment>test</skruvComment>
<style>{cssTextGenerator}</style>
</head>
<body>
<main>
<h1>{state.todos.getGenerator(0)}</h1>
<form onsubmit={e => {
e.preventDefault()
const todo = new FormData(e.currentTarget).get('todo')?.toString()
if (todo !== undefined) state.todos.unshift(todo)
e.currentTarget.reset()
}}
>
<input name='todo' />
<button>New!</button>
</form>
<ol>
{async function * () {
for await (const todos of state.todos) {
yield todos.map((todo, i) => (
<li>{todo}
<a
href='#'
onclick={e => {
e.preventDefault()
todos.splice(i, 1)
}}
>x
</a>
</li>
))
}
}}
</ol>
</main>
<script type='module'>
{
// @ts-expect-error this property is not defined in a client environment but used on the server
globalThis.skruvSSRScript
}
</script>
</body>
</html>
)
)
}
void doRender()
export default doRender