kkallio@6
|
1 datatype menuState = Open | Closed
|
kkallio@6
|
2
|
kkallio@6
|
3 type formatCtl = {FormatMenu : xbody -> xbody -> xbody,
|
kkallio@7
|
4 WrapMenu : xbody -> xbody,
|
kkallio@6
|
5 OpenCtl : transaction unit -> xbody,
|
kkallio@6
|
6 CloseCtl : transaction unit -> xbody}
|
kkallio@6
|
7
|
kkallio@7
|
8 val defaultFormat = {FormatMenu = fn ctl menu => <xml>{ctl}{menu}</xml>,
|
kkallio@7
|
9 WrapMenu = fn menu => <xml><ul>{menu}</ul></xml>,
|
kkallio@6
|
10 OpenCtl = fn behaviour => <xml><button value="Open" onclick={behaviour}/></xml>,
|
kkallio@6
|
11 CloseCtl = fn behaviour => <xml><button value="Close" onclick={behaviour}/></xml>}
|
kkallio@6
|
12
|
kkallio@6
|
13 open Navbar
|
kkallio@6
|
14
|
kkallio@6
|
15 con popupNav t = {MenuState : source menuState,
|
kkallio@6
|
16 FormatCtl : formatCtl,
|
kkallio@6
|
17 NavBar : navBar t}
|
kkallio@6
|
18
|
kkallio@6
|
19 fun create [t ::: Type] (f : formatCtl) (m : mode t) (bar : navBar t) : transaction (popupNav t) =
|
kkallio@6
|
20 state <- source Closed;
|
kkallio@6
|
21
|
kkallio@6
|
22 return {MenuState = state,
|
kkallio@6
|
23 FormatCtl = f,
|
kkallio@6
|
24 NavBar = bar}
|
kkallio@6
|
25
|
kkallio@6
|
26 fun render [t ::: Type] (m : mode t) (popup : popupNav t) =
|
kkallio@6
|
27 popup.FormatCtl.FormatMenu
|
kkallio@6
|
28 <xml>
|
kkallio@6
|
29 <dyn signal={c <- signal popup.MenuState;
|
kkallio@6
|
30 return
|
kkallio@6
|
31 (case c of
|
kkallio@6
|
32 Open => <xml>{popup.FormatCtl.CloseCtl (set popup.MenuState Closed)}</xml>
|
kkallio@6
|
33 | Closed => <xml>{popup.FormatCtl.OpenCtl (set popup.MenuState Open)}</xml>)
|
kkallio@6
|
34 }/>
|
kkallio@6
|
35 </xml>
|
kkallio@6
|
36
|
kkallio@6
|
37 <xml>
|
kkallio@6
|
38 <dyn signal={c <- signal popup.MenuState;
|
kkallio@6
|
39 return
|
kkallio@6
|
40 (case c of
|
kkallio@7
|
41 Open => <xml>{popup.FormatCtl.WrapMenu (navBarToXml popup.NavBar)}</xml>
|
kkallio@6
|
42 | Closed => <xml/>)
|
kkallio@6
|
43 }/>
|
kkallio@6
|
44 </xml>
|