Skip to content

Instantly share code, notes, and snippets.

@eezis
Last active May 16, 2016 22:19
Show Gist options
  • Save eezis/b9a5dc64e7b5e62d930a221f4cf7f7d2 to your computer and use it in GitHub Desktop.
Save eezis/b9a5dc64e7b5e62d930a221f4cf7f7d2 to your computer and use it in GitHub Desktop.
elm button - 1
{-
Step 1, just trying to make the "-" button red. http://elm-lang.org/examples/buttons
-- import that Html.Attributes module
-- define the style
-- add the style attribute to the button
Step 2, How do I make the "-" button turn red on odd numbers, and green on even numbers?
-}
import Html exposing (..)
import Html.App exposing (beginnerProgram)
import Html.Events exposing (onClick)
import Html.Attributes exposing (..)
redStyle : Attribute msg
redStyle =
style
[ ("backgroundColor", "red")
]
greenStyle : Attribute msg
greenStyle =
style
[ ("backgroundColor", "green")
]
main =
beginnerProgram { model = 0, view = view, update = update }
view model =
div []
[ button [ Style, onClick Decrement ] [ text "-" ]
, div [] [ text (toString model) ]
, button [ onClick Increment ] [ text "+" ]
]
type Msg = Increment | Decrement
update msg model =
case msg of
Increment ->
model + 1
Style redStyle
Decrement ->
model - 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment