diff options
author | Joris | 2020-07-26 18:16:59 +0200 |
---|---|---|
committer | Joris | 2020-07-26 18:16:59 +0200 |
commit | 4ee0dfae75fda3a8b6347d55c728b50ce5c210d9 (patch) | |
tree | 5f73adaf57354e0070acaa9a6b60dc49c0c48526 /src/Lib/Dom/H.ml | |
parent | 447f43995ae8d83c82d98d9d8968e90d6c4518e7 (diff) |
Allow to customize icons
Diffstat (limited to 'src/Lib/Dom/H.ml')
-rw-r--r-- | src/Lib/Dom/H.ml | 49 |
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" |