package bonsai

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file bonsai_web_ui_nav_link.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
open Core
open Bonsai_web

let make' ?(attrs = []) ~set_url ~page_to_string page children =
  let attrs =
    attrs
    @ [ Vdom.Attr.href (page_to_string page)
      ; Vdom.Attr.on_click (fun event ->
          if List.exists
               [ event##.ctrlKey; event##.shiftKey; event##.altKey; event##.metaKey ]
               ~f:Js_of_ocaml.Js.to_bool
          then
            (* If any modifier key is pressed, let the browser handle it as a normal
               <a>: Ctrl-Click opens in a new tab, etc *)
            Effect.Ignore
          else
            (* Otherwise perform an on-page navigation. *)
            Effect.Many [ set_url page; Effect.Prevent_default ])
      ]
  in
  Vdom.Node.a ~attrs children
;;

let make ?attrs ~set_url ~page_to_string page text =
  make' ?attrs ~set_url ~page_to_string page [ Vdom.Node.text text ]
;;