Skip to content

Instantly share code, notes, and snippets.

@stuf
Created August 11, 2016 09:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stuf/69ea250606b3d754326106f5c42e9777 to your computer and use it in GitHub Desktop.
Save stuf/69ea250606b3d754326106f5c42e9777 to your computer and use it in GitHub Desktop.
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