Created
April 21, 2016 23:33
-
-
Save chuck0523/c4dcad94473cfc5f5000c2492eebb815 to your computer and use it in GitHub Desktop.
This file contains 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
-- view | |
view : Signal.Address Action -> Model -> Html | |
view address model = | |
let | |
todos = List.map (viewTodos address) model.todos | |
addButton = getAddButton address model.addText | |
in | |
div [ todosStyle ] | |
[ input | |
[ placeholder "enter todo" | |
, value model.addText | |
, on "input" targetValue ( Signal.message address << InputText) | |
] | |
[] | |
, addButton | |
, div | |
[] (todos) | |
] | |
viewTodos : Signal.Address Action -> (ID, Todo.Model) -> Html | |
viewTodos address (id, model) = | |
Todo.view (Signal.forwardTo address (Modify id)) model | |
getAddButton : Signal.Address Action -> String -> Html | |
getAddButton address addText = | |
if addText == "" | |
then | |
button | |
[ isDisbledButton ] | |
[ text "Add" ] | |
else | |
button | |
[ onClick address Add ] | |
[ text "Add" ] | |
todosStyle : Attribute | |
todosStyle = | |
style | |
[ ("margin", "10px") | |
] | |
textareaStyle : Attribute | |
textareaStyle = | |
style | |
[ ("margin-right", "5px") | |
, ("height", "20px") | |
] | |
isDisbledButton : Attribute | |
isDisbledButton = | |
style | |
[ ("color", "#999") | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment