-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.ml
91 lines (79 loc) · 2.16 KB
/
main.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
module V = Vdom
type model = Bindings.Popper.placement
let placement_of_string : string -> Bindings.Popper.placement option = function
| "Auto" -> Some Auto
| "AutoStart" -> Some AutoStart
| "AutoEnd" -> Some AutoEnd
| "Top" -> Some Top
| "TopStart" -> Some TopStart
| "TopEnd" -> Some TopEnd
| "Bottom" -> Some Bottom
| "BottomStart" -> Some BottomStart
| "BottomEnd" -> Some BottomEnd
| "Right" -> Some Right
| "RightStart" -> Some RightStart
| "RightEnd" -> Some RightEnd
| "Left" -> Some Left
| "LeftStart" -> Some LeftStart
| "LeftEnd" -> Some LeftEnd
| _ -> None
let string_of_placement : Bindings.Popper.placement -> string = function
| Auto -> "Auto"
| AutoStart -> "AutoStart"
| AutoEnd -> "AutoEnd"
| Top -> "Top"
| TopStart -> "TopStart"
| TopEnd -> "TopEnd"
| Bottom -> "Bottom"
| BottomStart -> "BottomStart"
| BottomEnd -> "BottomEnd"
| Right -> "Right"
| RightStart -> "RightStart"
| RightEnd -> "RightEnd"
| Left -> "Left"
| LeftStart -> "LeftStart"
| LeftEnd -> "LeftEnd"
type msg = Change of Bindings.Popper.placement
let init = V.return Bindings.Popper.Left
let update _ (Change placement) = Vdom.return placement
let view_placement placement =
let open Bindings.Popper in
let options =
[
Auto;
AutoStart;
AutoEnd;
Top;
TopStart;
TopEnd;
Bottom;
BottomStart;
BottomEnd;
Right;
RightStart;
RightEnd;
Left;
LeftStart;
LeftEnd;
]
in
let onchange index = Change (List.nth options index) in
V.elt
~a:[ V.onchange_index onchange ]
"select"
(List.map
(fun option ->
let label = string_of_placement option in
let a = [ V.value label ] in
let a = if option = placement then V.attr "selected" "" :: a else a in
V.elt ~a "option" [ V.text label ])
options)
let view placement =
V.div ~a:[ V.class_ "box" ]
[ Tooltip.tooltip ~placement [ view_placement placement ] ]
let app = V.app ~init ~view ~update ()
open Js_browser
let run () =
let container = Document.body document in
ignore (Vdom_blit.run ~container app)
let () = Window.set_onload window run