-
Notifications
You must be signed in to change notification settings - Fork 0
/
Header.elm
75 lines (63 loc) · 1.63 KB
/
Header.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
module Header (Action, Model(..), view, init, update) where
import Html exposing (a, h1, text, div)
import Html.Attributes exposing (..)
import Html.Events exposing (onClick)
type Model = Blog | About
init : Model
init = About
items : List (String, Model)
items =
[ ("About", About)
, ("Blog", Blog)
]
itemAsHtml : Signal.Address Action -> Model -> (String, Model) -> Html.Html
itemAsHtml address selected (value, option) =
let
style = if option == selected
then selectedItemStyle
else itemStyle
in
a [style, onClick address { selectedModel = option }]
[div
[]
[text value]]
selectedItemStyle : Html.Attribute
selectedItemStyle =
baseItemStyle
[
("text-decoration", "underline")
]
itemStyle : Html.Attribute
itemStyle =
baseItemStyle
[
]
baseItemStyle : List (String, String) -> Html.Attribute
baseItemStyle styles =
style
([
("height", "100%")
, ("color", "grey")
, ("display", "inline-block")
, ("font-size", "3em")
, ("padding-left", "0.75em")
, ("padding-right", "0.75em")
, ("text-decoration", "none")
, ("cursor", "pointer")
] ++ styles)
view : Signal.Address Action -> Model -> Html.Html
view address model =
div [headerStyle] <| List.map (itemAsHtml address model) items
headerStyle : Html.Attribute
headerStyle =
style
[
("text-align", "center")
, ("background", "black")
, ("height", "4em")
, ("width", "100%")
, ("border-radius", "5px")
]
type alias Action = { selectedModel : Model }
update : Action -> Model -> Model
update action _ = action.selectedModel