blob: 8183a02221c49ab8a12df202821de71f9967dcc1 (
plain)
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
|
(* Element creation *)
let h tag ?(attributes = [||]) ?(eventListeners = [||]) ?(children = [||]) () :
Dom.element =
let element =
if tag == "svg" || tag == "path" then
Document.createElementNS "http://www.w3.org/2000/svg" tag
else Document.createElement tag
in
let () =
Js.Array.forEach
(fun (name, value) -> Element.setAttribute element name value)
attributes
in
let () =
Js.Array.forEach
(fun (name, eventListener) ->
Element.addEventListener element name eventListener)
eventListeners
in
let () =
Js.Array.forEach (fun child -> Element.appendChild element child) children
in
element
(* Node creation *)
let text = Document.createTextNode
let div = h "div"
let span = h "span"
let header = h "header"
let button = h "button"
let section = h "section"
let svg = h "svg"
let path = h "path"
let form = h "form"
let label = h "label"
let input_ = h "input"
(* Attribute creation *)
let id v = ("id", v)
let className v = ("class", v)
let viewBox v = ("viewBox", v)
let d v = ("d", v)
let type_ v = ("type", v)
let min_ v = ("min", v)
let value v = ("value", v)
(* Event listeners *)
let onClick f = ("click", f)
let onInput f = ("input", f)
let onSubmit f = ("submit", f)
|