Skip to content

Instantly share code, notes, and snippets.

@b0urb4k1
Created October 6, 2016 05:43
Show Gist options
  • Save b0urb4k1/7a667d6520952988d3f824613a69da3a to your computer and use it in GitHub Desktop.
Save b0urb4k1/7a667d6520952988d3f824613a69da3a to your computer and use it in GitHub Desktop.
import Html exposing (div, button, text, span, table, tr, td, br, tbody, img)
import Html.App exposing (beginnerProgram)
import Html.Events exposing (onClick)
import Html.Attributes exposing (hidden, style, src)
import List exposing (member, filter, map, concat)
type alias Entry =
{ text : String
, errorText : String
, index : Int
, hidden : Bool
, error : Bool
}
errorStyle = style
[ ("background-color", "#aa7777")
, ("border-style", "solid")
, ("border-radius", "25px")
, ("border-color", "#ff0000")
]
normalStyle = style
[ ("background-color", "#77aa77")
, ("border-style", "solid")
, ("border-radius", "25px")
, ("border-color", "#00ff00")
]
tableStyle = style
[ ("width", "100%")
]
main = beginnerProgram
{ model =
[ { text = "foo"
, index = 1
, hidden = True
, error = False
, errorText = ""
}
, { text = "bar"
, index = 2
, hidden = True
, error = True
, errorText= "some error"
}
]
, view = view
, update = update
}
entryTemplate e =
[ table [tableStyle]
[ tbody []
[ tr []
[ td [] [img [hidden (not e.error),style [("width", "20px"), ("height", "20px")], src (if e.hidden then "closed.png" else "open.png"), onClick e.index] []]
, td [] [ div [ if e.error then errorStyle else normalStyle] [text e.text] ]
]
, tr [tableStyle]
[ td [] []
, td [tableStyle]
[ div
[ hidden e.hidden
, if e.error then errorStyle else normalStyle
] [text e.errorText]
]
]
]
]
]
view model =
div [style [("background-color", "#696660")]] (concat (map entryTemplate model))
update index model =
map (\e -> if e.index == index then {e | hidden = if e.error == False then True else not e.hidden} else e) model
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment