summaryrefslogtreecommitdiff
path: root/demo/more/expandable.ur
blob: 92d8743c7bf214c66523a9a7fc9bb37e08f9fb91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
con t ctx = source bool * xml ctx [] []

fun create [ctx] (x : xml ctx [] []) =
    s <- source False;
    return (s, x)

fun expand [ctx] (t : t ctx) =
    set t.1 True

fun collapse [ctx] (t : t ctx) =
    set t.1 False

fun render [ctx] [[Body] ~ ctx] (t : t ([Body] ++ ctx)) =
    <xml><dyn signal={b <- signal t.1;
                      return (if b then
                                  <xml>
                                    <button value="-" onclick={collapse t}/><br/>
                                    {t.2}
                                  </xml>
                              else
                                  <xml>
                                    <button value="+" onclick={expand t}/><br/>
                                  </xml>)}/></xml>