Created
August 11, 2016 09:33
-
-
Save stuf/69ea250606b3d754326106f5c42e9777 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Collapse exposing (..) | |
import Html exposing (Html, text, div, button) | |
import Html.Attributes exposing (class, style) | |
import Html.Events exposing (onClick) | |
import Maybe exposing (withDefault) | |
-- MODEL | |
type alias Model = | |
{ collapsed : Bool } | |
init : Bool -> Model | |
init collapsed = | |
{ collapsed = collapsed } | |
-- UPDATE | |
type Msg | |
= Toggle | |
update : Msg -> Model -> Model | |
update msg model = | |
case msg of | |
Toggle -> | |
{ model | collapsed = not model.collapsed } | |
-- VIEW | |
view : Model -> Html Msg | |
view model = | |
div | |
[] | |
[ toggleButton | |
, withDefault (div [] []) (element model.collapsed) | |
] | |
toggleButton : Html Msg | |
toggleButton = | |
button | |
[ class "toggling-button" | |
, onClick Toggle | |
] | |
[ text "Toggle" ] | |
element : Bool -> Maybe (Html Msg) | |
element v = | |
case v of | |
True -> | |
Just (div [] [ text "I exist!" ]) | |
False -> | |
Nothing | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment