view demo/more/expandable.ur @ 1291:be6e2cd8d9a9

Add 'title' attribute
author Adam Chlipala <adam@chlipala.net>
date Sat, 04 Sep 2010 14:12:02 -0400
parents 7facf72aaf0a
children
line wrap: on
line source
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>