Created
November 14, 2019 21:45
-
-
Save chiroptical/dbf53f1deaaf1af1804b0289e5817760 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Main exposing (..) | |
| -- Input a user name and password. Make sure the password matches. | |
| -- | |
| -- Read how it works: | |
| -- https://guide.elm-lang.org/architecture/forms.html | |
| -- | |
| import Browser | |
| import Html exposing (..) | |
| import Html.Attributes exposing (..) | |
| import Html.Events exposing (onInput, onClick) | |
| -- MAIN | |
| main = | |
| Browser.sandbox { init = init, update = update, view = view } | |
| -- MODEL | |
| type alias Model = | |
| { ingredients : List String | |
| } | |
| init : Model | |
| init = | |
| Model [""] | |
| -- UPDATE | |
| type Msg | |
| = Name (List String) | |
| | Add | |
| update : Msg -> Model -> Model | |
| update msg model = | |
| case msg of | |
| Name xs -> | |
| { model | ingredients = xs } | |
| Add -> | |
| { model | ingredients = List.append model.ingredients [""] } | |
| -- VIEW | |
| view : Model -> Html Msg | |
| view model = | |
| div [] | |
| ( List.append | |
| ( List.map (\x -> viewInput "text" "Ingredient" x) model.ingredients ) | |
| ( List.singleton ( button [ onClick Add ] [ text "+" ] )) | |
| ) | |
| viewInput : String -> String -> String -> Html msg | |
| viewInput t p v = | |
| input [ type_ t, placeholder p, value v ] [] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment