Skip to content

Instantly share code, notes, and snippets.

@shamrin
Last active Jun 29, 2016
Embed
What would you like to do?
import Html exposing (Html, Attribute, text, div, input, button)
import Html.App exposing (beginnerProgram)
import Html.Attributes exposing (..)
import Html.Events exposing (onInput, onClick)
import String
main =
beginnerProgram { model = ["", "", ""], view = view, update = update }
-- UPDATE
type Msg
= NewContent Int String
| Click Int
update msg oldContent =
case msg of
NewContent i content ->
oldContent
|> List.indexedMap (\j t -> if j == i then content else t)
Click i ->
oldContent
|> List.indexedMap (,)
|> List.filter (\(j, t) -> j /= i)
|> List.map (\(j, t) -> t)
-- VIEW
view content =
div []
(List.indexedMap viewPair content)
viewPair i content =
div []
[ div []
[ input [ placeholder ("enter " ++ (toString (i+1)) ++ "")
, onInput (NewContent i), myStyle
] []
, button [ buttonStyle, onClick (Click i)] [ text "x" ]
]
, div [ myStyle ]
[ text (if String.isEmpty content then "" else "=> " ++ content) ]
]
myStyle =
style
[ ("width", "90%")
, ("height", "40px")
, ("padding", "10px 0")
, ("font-size", "2em")
, ("text-align", "center")
]
buttonStyle =
style
[ ("width", "9%")
, ("height", "40px")
, ("padding", "0")
, ("font-size", "2em")
, ("text-align", "center")
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment