-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRange.elm
93 lines (72 loc) · 2.19 KB
/
Range.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
module Range exposing (main)
import Browser
import Date exposing (Date)
import DatePicker
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
type alias Model =
{ calendar : DatePicker.DatePicker }
type Msg
= DatePickerMsg DatePicker.Msg
| PreviousMonth
| NextMonth
main : Program () Model Msg
main =
Browser.element
{ init = always init
, update = update
, subscriptions = always Sub.none
, view = view
}
init : ( Model, Cmd Msg )
init =
( { calendar = DatePicker.initCalendar DatePicker.Range }
, Cmd.map DatePickerMsg DatePicker.receiveDate
)
view : Model -> Html Msg
view model =
div []
[ h2 [ class "helvetica m0" ] [ text "Range DatePicker" ]
, button [ id "previous-month", class "bn pointer gray", onClick PreviousMonth ] [ text "<" ]
, DatePicker.showCalendar model.calendar config
|> Html.map DatePickerMsg
, button [ id "next-month", class "bn pointer gray", onClick NextMonth ] [ text ">" ]
]
config : DatePicker.Config
config =
let
config_ =
DatePicker.defaultConfig
in
{ config_
| rangeClass = "bg-dark-red white"
, rangeHoverClass = "bg-dark-red moon-gray"
, selectedClass = "bg-dark-red white selected"
, weekdayFormat = "ddd"
, validDate = validDate
}
validDate : Maybe Date -> Maybe Date -> Bool
validDate date currentDate =
case ( date, currentDate ) of
( _, Nothing ) ->
True
( Just date1, Just date2 ) ->
Date.toRataDie date1 > Date.toRataDie date2
( Nothing, Just _ ) ->
False
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
DatePickerMsg datePickerMsg ->
( { model | calendar = DatePicker.update datePickerMsg model.calendar }
, Cmd.none
)
PreviousMonth ->
( { model | calendar = DatePicker.previousMonth model.calendar }
, Cmd.none
)
NextMonth ->
( { model | calendar = DatePicker.nextMonth model.calendar }
, Cmd.none
)