aboutsummaryrefslogtreecommitdiff
path: root/src/Lib/Dom/H.ml
diff options
context:
space:
mode:
Diffstat (limited to 'src/Lib/Dom/H.ml')
-rw-r--r--src/Lib/Dom/H.ml49
1 files changed, 21 insertions, 28 deletions
diff --git a/src/Lib/Dom/H.ml b/src/Lib/Dom/H.ml
index 8183a02..d547a70 100644
--- a/src/Lib/Dom/H.ml
+++ b/src/Lib/Dom/H.ml
@@ -1,7 +1,10 @@
(* Element creation *)
-let h tag ?(attributes = [||]) ?(eventListeners = [||]) ?(children = [||]) () :
- Dom.element =
+type attribute =
+ | TextAttr of string * string
+ | EventAttr of string * (Dom.event -> unit)
+
+let h tag attributes children =
let element =
if tag == "svg" || tag == "path" then
Document.createElementNS "http://www.w3.org/2000/svg" tag
@@ -9,17 +12,19 @@ let h tag ?(attributes = [||]) ?(eventListeners = [||]) ?(children = [||]) () :
in
let () =
Js.Array.forEach
- (fun (name, value) -> Element.setAttribute element name value)
+ (fun attr ->
+ match attr with
+ | TextAttr (name, value) ->
+ Element.setAttribute element name value
+
+ | EventAttr (name, eventListener) ->
+ Element.addEventListener element name eventListener)
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
+ (fun child -> Element.appendChild element child)
+ children
in
element
@@ -45,28 +50,16 @@ 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 input = h "input"
-let min_ v = ("min", v)
+let textarea = h "textarea"
-let value v = ("value", v)
+let i = h "i"
-(* Event listeners *)
+let a = h "a"
-let onClick f = ("click", f)
+let h1 = h "h1"
-let onInput f = ("input", f)
+let h2 = h "h2"
-let onSubmit f = ("submit", f)
+let h3 = h "h3"