11import React from 'react' ;
2- import style from './style' ;
3- import time from '../utils/time' ;
42import Calendar from './calendar' ;
53import Dialog from '../dialog' ;
4+ import style from './style' ;
5+ import time from '../utils/time' ;
66
77class CalendarDialog extends React . Component {
88 static propTypes = {
99 active : React . PropTypes . bool ,
10+ maxDate : React . PropTypes . object ,
11+ minDate : React . PropTypes . object ,
1012 onDismiss : React . PropTypes . func ,
1113 onSelect : React . PropTypes . func ,
1214 value : React . PropTypes . object
@@ -23,7 +25,11 @@ class CalendarDialog extends React.Component {
2325 } ;
2426
2527 handleCalendarChange = ( value ) => {
26- this . setState ( { date : value , display : 'months' } ) ;
28+ const state = { display : 'months' , date : value } ;
29+ if ( time . dateOutOfRange ( value , this . props . minDate , this . props . maxDate ) ) {
30+ state . date = this . props . maxDate || this . props . minDate ;
31+ }
32+ this . setState ( state ) ;
2733 } ;
2834
2935 handleSelect = ( ) => {
@@ -46,21 +52,19 @@ class CalendarDialog extends React.Component {
4652 return (
4753 < Dialog active = { this . props . active } type = "custom" className = { style . dialog } actions = { this . actions } >
4854 < header className = { headerClassName } >
49- < span className = { style . weekday } >
50- { time . getFullDayOfWeek ( this . state . date . getDay ( ) ) }
51- </ span >
52- < div onClick = { this . handleSwitchDisplay . bind ( this , 'months' ) } >
53- < span className = { style . month } > { time . getShortMonth ( this . state . date ) } </ span >
54- < span className = { style . day } > { this . state . date . getDate ( ) } </ span >
55- </ div >
5655 < span className = { style . year } onClick = { this . handleSwitchDisplay . bind ( this , 'years' ) } >
5756 { this . state . date . getFullYear ( ) }
5857 </ span >
58+ < h3 className = { style . date } onClick = { this . handleSwitchDisplay . bind ( this , 'months' ) } >
59+ { time . getShortDayOfWeek ( this . state . date . getDay ( ) ) } , { time . getShortMonth ( this . state . date ) } { this . state . date . getDate ( ) }
60+ </ h3 >
5961 </ header >
6062
6163 < div className = { style . wrapper } >
6264 < Calendar
6365 display = { this . state . display }
66+ maxDate = { this . props . maxDate }
67+ minDate = { this . props . minDate }
6468 onChange = { this . handleCalendarChange }
6569 selectedDate = { this . state . date } />
6670 </ div >
0 commit comments