Skip to content

Instantly share code, notes, and snippets.

@ts-ign0re
Last active March 2, 2018 13:22
Show Gist options
  • Save ts-ign0re/adc983800b587564398dd20ff90cfe56 to your computer and use it in GitHub Desktop.
Save ts-ign0re/adc983800b587564398dd20ff90cfe56 to your computer and use it in GitHub Desktop.
trying Elm
import Html exposing (Html, beginnerProgram, fieldset, input, label, text)
import Html.Attributes exposing (style, type_)
import Html.Events exposing (onClick)
main =
beginnerProgram { model = optOut, update = update, view = view }
-- MODEL
type alias Model =
{ notifications : Bool
, autoplay : Bool
, location : Bool
}
optOut : Model
optOut =
Model True True True
-- UPDATE
type Msg
= ToggleNotifications
| ToggleAutoplay
| ToggleLocation
update : Msg -> Model -> Model
update msg model =
case msg of
ToggleNotifications ->
{ model | notifications = not model.notifications }
ToggleAutoplay ->
{ model | autoplay = not model.autoplay }
ToggleLocation ->
{ model | location = not model.location }
-- VIEW
view : Model -> Html Msg
view model =
fieldset []
[ checkbox ToggleNotifications "Email Notifications"
, checkbox ToggleAutoplay "Video Autoplay"
, checkbox ToggleLocation "Use Location"
]
checkbox : msg -> String -> Html msg
checkbox msg name =
label
[ style [("padding", "20px")]
]
[ input [ type_ "checkbox", onClick msg ] []
, text name
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment