From 38e42723a916b7d5c2a15e514b3f3e6dcab398dd Mon Sep 17 00:00:00 2001 From: Joris Date: Sat, 8 Aug 2020 21:04:28 +0200 Subject: Propose already defined colors in the form --- src/View/Form.ml | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'src/View/Form.ml') diff --git a/src/View/Form.ml b/src/View/Form.ml index db73b0c..cc95210 100644 --- a/src/View/Form.ml +++ b/src/View/Form.ml @@ -15,7 +15,17 @@ let input id label init_value on_input = [| |] |] -let color_input id label init_value on_input = +let color_input default_colors id label init_value on_input = + let + input = + H.input + [| HA.id id + ; HE.on_input (fun e -> on_input (Element.value (Event.target e))) + ; HA.value init_value + ; HA.type_ "color" + |] + [| |] + in H.div [| HA.class_ "g-Form__Field" |] [| H.div @@ -24,13 +34,20 @@ let color_input id label init_value on_input = [| HA.for_ id |] [| H.text label |] |] - ; H.input - [| HA.id id - ; HE.on_input (fun e -> on_input (Element.value (Event.target e))) - ; HA.value init_value - ; HA.type_ "color" - |] + ; Layout.line [| |] + (default_colors + |> Js.Array.map (fun color -> + Button.raw + [| HA.class_ "g-Form__DefaultColor" + ; HA.style ("background-color: " ^ color) + ; HE.on_click (fun _ -> + let () = Element.set_value input color in + on_input color) + ; HA.type_ "button" + |] + [| |]) + |> (fun xs -> Js.Array.concat xs [| input |])) |] let textarea id label init_value on_input = -- cgit v1.2.3