open Brr open Brr_note module Js = Js_of_ocaml.Js let popup : title:Jstr.t -> ?form:Forms.Events.t option -> 'a option Note.E.send -> El.t = fun ~title ?(form = None) send -> (* Ensure we keep a track for the signal event. This looks a bit like the old memory magment in C, as it require to destroy the logger each time the popup is removed. *) let log_opt = Option.map (fun (values, _) -> Note.S.log values (fun _ -> ())) form in let close_btn = El.span ~at:At.[class' (Jstr.v "modal-close")] [ El.txt' "×"] in Evr.endless_listen (El.as_target close_btn) Ev.click (fun _ -> Option.iter Note.Logr.destroy log_opt; send None ); let container = match form with | None -> El.div | Some _ -> El.form and body = match form with | None -> El.div [] | Some (_, content) -> content and footer = match form with | None -> El.txt Jstr.empty | Some (values, _) -> let btn = El.input () ~at:At.[type' (Jstr.v "submit")] in Evr.endless_listen (El.as_target btn) Ev.click (fun _ -> Option.iter Note.Logr.force log_opt; let form_content = (Note.S.value values) in Option.iter Note.Logr.destroy log_opt; send (Some form_content)); El.div [ btn ] ~at:At.[class' (Jstr.v "row")] in let el = El.div ~at:At.[class' (Jstr.v "modal")] [ container ~at:At.[class' (Jstr.v "modal-content")] [ El.div ~at:At.[class' (Jstr.v "modal-header")] [ close_btn ; El.h3 [ El.txt title ]] ; El.div ~at:At.[class' (Jstr.v "modal-body")] [ body ] ; El.div ~at:At.[class' (Jstr.v "modal-footer")] [ footer ]]] in El.append_children (Document.body G.document) [ el ] ; el