File tree Expand file tree Collapse file tree 4 files changed +103
-2
lines changed Expand file tree Collapse file tree 4 files changed +103
-2
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ module.exports = React.createClass
8
8
# -- States & Properties
9
9
propTypes :
10
10
className : React .PropTypes .string
11
+ onChange : React .PropTypes .func
11
12
selectedDate : React .PropTypes .object
12
13
viewDate : React .PropTypes .object
13
14
@@ -20,6 +21,9 @@ module.exports = React.createClass
20
21
selectedDate : @props .selectedDate
21
22
viewDate : @props .viewDate
22
23
24
+ componentDidUpdate : (prevProps , prevState ) ->
25
+ @props .onChange ? @ if prevState .selectedDate .getTime () != @state .selectedDate .getTime ()
26
+
23
27
# -- Events
24
28
onDayClick : (event ) ->
25
29
day = parseInt (event .target .textContent )
@@ -90,3 +94,6 @@ module.exports = React.createClass
90
94
</div >
91
95
</CTG >
92
96
</div >
97
+
98
+ getValue : ->
99
+ @state .selectedDate
Original file line number Diff line number Diff line change
1
+ css = require ' ./style'
2
+ Calendar = require ' ../calendar'
3
+ dateUtils = require ' ../date_utils'
4
+
5
+ module .exports = React .createClass
6
+
7
+ # -- States & Properties
8
+ propTypes :
9
+ className : React .PropTypes .string
10
+ initialDate : React .PropTypes .object
11
+
12
+ getDefaultProps : ->
13
+ className : ' '
14
+ initialDate : new Date ()
15
+
16
+ getInitialState : ->
17
+ date : @props .initialDate
18
+
19
+ # -- Events
20
+ onCalendarChange : (calendar ) ->
21
+ @setState
22
+ date : dateUtils .cloneDatetime (calendar .getValue ())
23
+
24
+ # -- Render
25
+ render : ->
26
+ <div className = {css .root }>
27
+ <header className = {css .header }>
28
+ <p className = {css .headerWeekday }>{dateUtils .weekDayInWords (@state .date .getDay ())}</p >
29
+ <p className = {css .headerMonth }>{dateUtils .monthInShortWords (@state .date )}</p >
30
+ <p className = {css .headerDay }>{@state .date .getDate ()}</p >
31
+ <p className = {css .headerYear }>{@state .date .getFullYear ()}</p >
32
+ </header >
33
+
34
+ <Calendar onChange = {@onCalendarChange } selectedDate = {@state .date } />
35
+ </div >
Original file line number Diff line number Diff line change
1
+ @import '../constants'
2
+
3
+ dayWidth = 38px
4
+ innerPadding = 10px
5
+ calendarWidth = dayWidth * 7
6
+ totalWidth = calendarWidth + innerPadding * 2
7
+
8
+ : local( .root )
9
+ text-align : center
10
+ width : totalWidth
11
+
12
+ : local( .header )
13
+ background-color : ACCENT
14
+ color : white
15
+
16
+ : local( .headerWeekday )
17
+ background-color : darken (ACCENT , 20% )
18
+ font-size : 14px
19
+ line-height : 1.8
20
+ width : 100%
21
+
22
+ : local( .headerMonth )
23
+ font-size : 18px
24
+ padding : 10px
25
+ text-transform : uppercase
26
+
27
+ : local( .headerDay )
28
+ font-size : 50px
29
+ line-height : 40px
30
+
31
+ : local( .headerYear )
32
+ font-size : 18px
33
+ opacity : .7
34
+ padding : 10px
Original file line number Diff line number Diff line change 1
1
module .exports =
2
2
daysInMonth : (date ) ->
3
- (new Date (date .getFullYear (), date .getMonth () + 1 , 0 )).getDate ()
3
+ (new Date (date .getFullYear (), date .getMonth (), 0 )).getDate ()
4
4
5
5
firstWeekDay : (date ) ->
6
- (new Date (date .getFullYear (), date .getMonth () + 1 , 1 )).getDay ()
6
+ (new Date (date .getFullYear (), date .getMonth (), 1 )).getDay ()
7
7
8
8
monthInWords : (date ) ->
9
9
switch (date .getMonth ())
@@ -20,6 +20,21 @@ module.exports =
20
20
when 10 then ' November'
21
21
when 11 then ' December'
22
22
23
+ monthInShortWords : (date ) ->
24
+ switch (date .getMonth ())
25
+ when 0 then ' Jan'
26
+ when 1 then ' Feb'
27
+ when 2 then ' Mar'
28
+ when 3 then ' Apr'
29
+ when 4 then ' May'
30
+ when 5 then ' Jun'
31
+ when 6 then ' Jul'
32
+ when 7 then ' Aug'
33
+ when 8 then ' Sep'
34
+ when 9 then ' Oct'
35
+ when 10 then ' Nov'
36
+ when 11 then ' Dec'
37
+
23
38
weekDayInWords : (day ) ->
24
39
switch (day)
25
40
when 0 then ' Sunday'
@@ -30,6 +45,16 @@ module.exports =
30
45
when 5 then ' Friday'
31
46
when 6 then ' Saturday'
32
47
48
+ weekDayInShortWords : (day ) ->
49
+ switch (day)
50
+ when 0 then ' Sun'
51
+ when 1 then ' Mon'
52
+ when 2 then ' Tue'
53
+ when 3 then ' Wed'
54
+ when 4 then ' Thu'
55
+ when 5 then ' Fri'
56
+ when 6 then ' Sat'
57
+
33
58
addDays : (date , days ) ->
34
59
newDate = @ cloneDatetime (date)
35
60
newDate .setDate (date .getDate () + days)
You can’t perform that action at this time.
0 commit comments