-
Notifications
You must be signed in to change notification settings - Fork 1
/
test-2.html
61 lines (49 loc) · 1.71 KB
/
test-2.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
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script type="module">
import { main, h1, sec, lbl, ipt, ul, li, btn } from './markup-js.mjs'
const _ = undefined
const $ = selector => document.body.querySelector(selector)
const centered = { style: 'height: 100%; display: flex; flex-direction: column; justify-content: center; align-items: center;'}
const form = sec( { id: 'form' } , [
lbl( _ , 'Title' ),
ipt( { type: 'text', id: 'title' } ),
lbl( _ , 'Author' ),
ipt( { type: 'text', id: 'author' } ),
lbl( _ , 'Rating' ),
ipt( { type: 'number', id: 'rating' } ),
])
const marginedLabel = text => lbl( { style: 'margin: 0.5em 0.25em;' } , text )
const makeEntry = (title, author, rating) =>
li( { style: 'list-style-type: none;' } , [
marginedLabel( title),
marginedLabel( author),
marginedLabel( rating)
])
function handleInput(){
$('#list').append(
makeEntry(
$('#title').value,
$('#author').value,
$('#rating').value
)
)
}
document.body.append(
main( centered ,
[
h1( _ , 'Your favourite Books!' ),
ul( { id: 'list' } ),
form,
btn( { onclick: handleInput } , 'add!' )
])
)
$('button').addEventListener('click', handleInput)
</script>
</body>
</html>