-
Notifications
You must be signed in to change notification settings - Fork 40
/
SideMenu.elm
128 lines (107 loc) · 2.92 KB
/
SideMenu.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
module Main exposing (Model, Msg(..), Styles, init, main, styles, subscriptions, update, view)
import Animation exposing (px)
import Browser
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
type alias Model =
{ style : Animation.State
}
type Msg
= Show
| Hide
| Animate Animation.Msg
type alias Styles =
{ open : List Animation.Property
, closed : List Animation.Property
}
styles : Styles
styles =
{ open =
[ Animation.left (px 0.0)
, Animation.opacity 1.0
]
, closed =
[ Animation.left (px -200.0)
, Animation.opacity 0
]
}
update : Msg -> Model -> ( Model, Cmd Msg )
update action model =
case action of
Show ->
( { model
| style =
Animation.interrupt
[ Animation.to styles.open
]
model.style
}
, Cmd.none
)
Hide ->
( { model
| style =
Animation.interrupt
[ Animation.to styles.closed
]
model.style
}
, Cmd.none
)
Animate animMsg ->
( { model
| style = Animation.update animMsg model.style
}
, Cmd.none
)
view : Model -> Html Msg
view model =
div
[ onMouseEnter Show
, onMouseLeave Hide
, style "position" "absolute"
, style "left" "0px"
, style "top" "0px"
, style "width" "350px"
, style "height" "100%"
, style "border" "2px dashed #AAA"
]
[ h1 [ style "padding" "25px" ]
[ text "Hover here to see menu!" ]
, div
(Animation.render model.style
++ [ style "position" "absolute"
, style "top" "-2px"
, style "margin-left" "-2px"
, style "padding" "25px"
, style "width" "300px"
, style "height" "100%"
, style "background-color" "rgb(58,40,69)"
, style "color" "white"
, style "border" "2px solid rgb(58,40,69)"
]
)
[ h1 [] [ text "Hidden Menu" ]
, ul []
[ li [] [ text "Some things" ]
, li [] [ text "in a list" ]
]
]
]
subscriptions : Model -> Sub Msg
subscriptions model =
Animation.subscription Animate [ model.style ]
init : ( Model, Cmd Msg )
init =
( { style = Animation.style styles.closed }
, Cmd.none
)
main : Program () Model Msg
main =
Browser.element
{ init = always init
, view = view
, update = update
, subscriptions = subscriptions
}