aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@dailly.me>2025-06-22 18:19:53 +0200
committerSébastien Dailly <sebastien@dailly.me>2025-06-22 18:19:53 +0200
commiteec8622f3a195553c9888949b8f53ae306bb7a35 (patch)
treec171bc1649c99fb33a3a77f74dcae54e041487b6
parent78121f4ef2a2f8e0783a22554a01cf2efc409e6a (diff)
Update
-rw-r--r--js/content.ml40
-rw-r--r--js/elements.ml35
-rw-r--r--js/elements.mli8
3 files changed, 51 insertions, 32 deletions
diff --git a/js/content.ml b/js/content.ml
index b666c37..7096524 100644
--- a/js/content.ml
+++ b/js/content.ml
@@ -1,30 +1,5 @@
module OptionInfix = Operators.Binding (Option)
-let add_field : label:Jstr.t -> id':Jstr.t -> value':Jstr.t -> Brr.El.t =
- fun ~label ~id' ~value' ->
- Brr.El.div
- ~at:Brr.At.[ class' (Jstr.v "field is-horizontal") ]
- [
- Brr.El.label
- ~at:Brr.At.[ for' id'; class' (Jstr.v "field-label is-normal") ]
- [ Brr.El.txt label ];
- Brr.El.div
- ~at:Brr.At.[ class' (Jstr.v "field-body") ]
- [
- Brr.El.input
- ~at:
- Brr.At.
- [
- class' (Jstr.v "input");
- type' (Jstr.v "text");
- name id';
- id id';
- value value';
- ]
- ();
- ];
- ]
-
module State = struct
type t = { word : string; len : int; counter : int }
@@ -50,12 +25,12 @@ module State = struct
[
Brr.El.form
[
- add_field ~id':(Jstr.v "text_state")
- ~label:(Jstr.v "Word received") ~value':(Jstr.v word);
- add_field ~id':(Jstr.v "nbcar_state")
- ~label:(Jstr.v "Nb of car") ~value':(Jstr.of_int len);
- add_field ~id':(Jstr.v "counter_state")
- ~label:(Jstr.v "Request sent") ~value':(Jstr.of_int counter);
+ Elements.input_field ~label:(Jstr.v "Word received")
+ ~value':(Jstr.v word) ();
+ Elements.input_field ~label:(Jstr.v "Nb of car")
+ ~value':(Jstr.of_int len) ();
+ Elements.input_field ~label:(Jstr.v "Request sent")
+ ~value':(Jstr.of_int counter) ();
];
];
];
@@ -91,7 +66,8 @@ let main () =
let form =
Brr.El.form
[
- add_field ~id':(Jstr.v "text") ~label:(Jstr.v "Text") ~value':Jstr.empty;
+ Elements.input_field ~name:(Jstr.v "text") ~id':(Jstr.v "text")
+ ~label:(Jstr.v "Text") ();
Brr.El.div
~at:Brr.At.[ class' (Jstr.v "field is-horizontal") ]
[
diff --git a/js/elements.ml b/js/elements.ml
new file mode 100644
index 0000000..b3c07a2
--- /dev/null
+++ b/js/elements.ml
@@ -0,0 +1,35 @@
+let input_field :
+ ?name:Jstr.t ->
+ ?id':Jstr.t ->
+ ?value':Jstr.t ->
+ label:Jstr.t ->
+ unit ->
+ Brr.El.t =
+ fun ?name ?id' ?(value' = Jstr.empty) ~label () ->
+ let name' = name in
+ let input =
+ Brr.El.input
+ ~at:
+ Brr.At.
+ [
+ if_some (Option.map Brr.At.id id');
+ if_some (Option.map Brr.At.name name');
+ class' (Jstr.v "input");
+ type' (Jstr.v "text");
+ value value';
+ ]
+ ()
+ and label =
+ Brr.El.label
+ ~at:
+ Brr.At.
+ [
+ if_some (Option.map Brr.At.for' id');
+ class' (Jstr.v "field-label is-normal");
+ ]
+ [ Brr.El.txt label ]
+ in
+
+ Brr.El.div
+ ~at:Brr.At.[ class' (Jstr.v "field is-horizontal") ]
+ [ label; Brr.El.div ~at:Brr.At.[ class' (Jstr.v "field-body") ] [ input ] ]
diff --git a/js/elements.mli b/js/elements.mli
new file mode 100644
index 0000000..fcb5588
--- /dev/null
+++ b/js/elements.mli
@@ -0,0 +1,8 @@
+val input_field :
+ ?name:Jstr.t ->
+ ?id':Jstr.t ->
+ ?value':Jstr.t ->
+ label:Jstr.t ->
+ unit ->
+ Brr.El.t
+(** Create a new input element *)