aboutsummaryrefslogtreecommitdiff
path: root/blog
diff options
context:
space:
mode:
Diffstat (limited to 'blog')
-rwxr-xr-xblog/dune8
-rwxr-xr-xblog/sidebar.ml131
2 files changed, 139 insertions, 0 deletions
diff --git a/blog/dune b/blog/dune
new file mode 100755
index 0000000..532a7ee
--- /dev/null
+++ b/blog/dune
@@ -0,0 +1,8 @@
+(library
+ (name blog)
+ (libraries
+ brr
+ brr.note
+ js_of_ocaml-tyxml)
+ (preprocess (pps tyxml-ppx))
+ )
diff --git a/blog/sidebar.ml b/blog/sidebar.ml
new file mode 100755
index 0000000..ed4b856
--- /dev/null
+++ b/blog/sidebar.ml
@@ -0,0 +1,131 @@
+open StdLabels
+open Brr
+open Brr_note
+open Note
+
+(** Return the sidebar *)
+let get
+ : unit -> El.t option
+ = fun () ->
+
+ List.find_opt (El.children @@ Document.body G.document)
+ ~f:(fun t -> El.has_tag_name El.Name.aside t)
+
+let rec clean
+ : El.t -> unit
+ = fun el ->
+ List.iter (El.children el)
+ ~f:(fun el ->
+ (* Remove the links from the sidebar, keep h1 and other stuff *)
+ if (El.has_tag_name (Jstr.v "nav") el)
+ || (El.has_tag_name (Jstr.v "ul") el) then
+ El.remove el
+ else
+ clean el
+ )
+
+(** Create a slider element, and the event on change *)
+let slider ~at =
+ let slider =
+ El.input ~at () in
+
+ let event =
+ Evr.on_el
+ Ev.input
+ (fun _ ->
+ let raw_value = El.prop El.Prop.value slider in
+ Jstr.to_int raw_value)
+ slider
+ in
+ slider, event
+
+let click_event el =
+ Evr.on_el
+ Ev.click
+ Evr.unit
+ el
+
+let show_value = function
+ | None -> El.txt' ""
+ | Some input ->
+ El.txt (Jstr.of_int input)
+
+let add_button
+ : El.t -> unit E.t
+ = fun element ->
+
+ let open El in
+
+ let delete =
+ button
+ [ El.i
+ ~at:At.[ class' (Jstr.v "fas")
+ ; class' (Jstr.v "fa-times-circle") ]
+ []
+ ; txt' "Delete "] in
+
+ let delete_event = click_event delete in
+
+ let export =
+ button
+ [ El.i
+ ~at:At.[ class' (Jstr.v "fas")
+ ; class' (Jstr.v "fa-download") ]
+ []
+ ; txt' "Download"] in
+
+
+ let nib_size, value =
+ slider
+ ~at:At.[ type' (Jstr.v "range")
+ ; v (Jstr.v "min") (Jstr.v "0")
+ ; v (Jstr.v "max") (Jstr.v "50")
+ ; id (Jstr.v "nib_size")
+ ] in
+
+ let width = El.div [] in
+ Elr.set_children
+ width
+ ~on:(value
+ |> E.map (fun v ->
+ [ txt' "Width : "
+ ; show_value v ]
+ )
+ );
+
+ let input_angle, angle_event =
+ slider
+ ~at:At.[ type' (Jstr.v "range")
+ ; v (Jstr.v "min") (Jstr.v "0")
+ ; v (Jstr.v "max") (Jstr.v "90")] in
+ let angle = El.div [] in
+ Elr.set_children
+ angle
+ ~on:(angle_event
+ |> E.map (fun v ->
+ [ txt' "Angle : "
+ ; show_value v
+ ; txt' "°" ]
+ )
+ );
+
+ let click = Evr.on_el Ev.click Evr.unit delete in
+ let _ = click in
+
+ let () =
+ El.append_children element
+ [ hr ()
+ ; delete
+ ; export
+ ; hr ()
+
+ ; width
+ ; nib_size
+ ; El.br ()
+
+ ; angle
+ ; input_angle
+
+ ]
+ in
+ delete_event