-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathBasicCounter.elm
88 lines (65 loc) · 1.45 KB
/
BasicCounter.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
module Main exposing (..)
import Element
exposing
( Element
, Attribute
, column
, row
, button
, label
, map
, beginnerProgram
)
import Element.Attributes
exposing
( text
, textColor
, fontSize
, flexGrow
, justifyContent
, alignItems
, marginHorizontal
, marginBottom
)
import Element.Events exposing (onTouchUpInside)
import Color exposing (Color)
main : Program Never Model Msg
main =
beginnerProgram
{ model = 0
, view = view
, update = update
}
-- MODEL
type alias Model =
Int
-- UPDATE
type Msg
= Increment
| Decrement
update : Msg -> Model -> Model
update msg model =
case msg of
Increment ->
model + 1
Decrement ->
model - 1
-- VIEW
view : Model -> Element Msg
view model =
column [ flexGrow 1, justifyContent "center", alignItems "center" ]
[ label [ text <| toString model, fontSize 50, marginBottom 25 ]
, row []
[ viewButton "Decrement" Decrement Color.red
, viewButton "Increment" Increment Color.green
]
]
viewButton : String -> msg -> Color -> Element msg
viewButton label msg color =
button
[ text label
, textColor color
, fontSize 25
, onTouchUpInside msg
, marginHorizontal 20
]