@@ -14,7 +14,8 @@ import SlideTransition from './SlideTransition';
1414import dates from './util/dates' ;
1515import constants from './util/constants' ;
1616import _ from './util/_' ; //values, omit
17- import ifNotDisabled from './util/ifNotDisabled' ;
17+ import { instanceId , notify } from './util/widgetHelpers' ;
18+ import { widgetEditable , widgetEnabled } from './util/interaction' ;
1819
1920let dir = constants . directions
2021 , values = obj => Object . keys ( obj ) . map ( k => obj [ k ] )
@@ -56,6 +57,9 @@ let format = (props, f) => props[f + 'Format'] || localizers.date.formats[f]
5657
5758let propTypes = {
5859
60+ disabled : CustomPropTypes . disabled ,
61+ readOnly : CustomPropTypes . readOnly ,
62+
5963 onChange : React . PropTypes . func ,
6064 value : React . PropTypes . instanceOf ( Date ) ,
6165
@@ -73,16 +77,6 @@ let propTypes = {
7377 prop. This creates a range that cannot be rendered.` . replace ( / \n \t / g, '' ) )
7478 } ,
7579
76- disabled : React . PropTypes . oneOfType ( [
77- React . PropTypes . bool ,
78- React . PropTypes . oneOf ( [ 'disabled' ] )
79- ] ) ,
80-
81- readOnly : React . PropTypes . oneOfType ( [
82- React . PropTypes . bool ,
83- React . PropTypes . oneOf ( [ 'readOnly' ] )
84- ] ) ,
85-
8680 culture : React . PropTypes . string ,
8781
8882 footer : React . PropTypes . bool ,
@@ -109,7 +103,6 @@ var Calendar = React.createClass({
109103 displayName : 'Calendar' ,
110104
111105 mixins : [
112- require ( './mixins/WidgetMixin' ) ,
113106 require ( './mixins/TimeoutMixin' ) ,
114107 require ( './mixins/PureRenderMixin' ) ,
115108 require ( './mixins/RtlParentContextMixin' ) ,
@@ -181,8 +174,8 @@ var Calendar = React.createClass({
181174
182175 unit = unit === 'day' ? 'date' : unit
183176
184- let viewID = this . _id ( '_calendar' )
185- , labelID = this . _id ( '_calendar_label' )
177+ let viewID = instanceId ( this , '_calendar' )
178+ , labelID = instanceId ( this , '_calendar_label' )
186179 , key = view + '_' + dates [ view ] ( currentDate ) ;
187180
188181 let elementProps = _ . omit ( this . props , Object . keys ( propTypes ) )
@@ -250,7 +243,7 @@ var Calendar = React.createClass({
250243 )
251244 } ,
252245
253- @ifNotDisabled
246+ @widgetEditable
254247 navigate ( direction , date ) {
255248 var view = this . state . view
256249 , slideDir = ( direction === dir . LEFT || direction === dir . UP )
@@ -269,7 +262,7 @@ var Calendar = React.createClass({
269262 view = NEXT_VIEW [ view ] || view
270263
271264 if ( this . isValidView ( view ) && dates . inRange ( date , this . props . min , this . props . max , view ) ) {
272- this . notify ( ' onNavigate' , [ date , slideDir , view ] )
265+ notify ( this . props . onNavigate , [ date , slideDir , view ] )
273266 this . focus ( true ) ;
274267
275268 this . setState ( {
@@ -287,38 +280,38 @@ var Calendar = React.createClass({
287280 //console.log(document.activeElement)
288281 } ,
289282
290- @ifNotDisabled ( true )
283+ @widgetEnabled
291284 _focus ( focused , e ) {
292285 if ( + this . props . tabIndex === - 1 )
293286 return
294287
295288 this . setTimeout ( 'focus' , ( ) => {
296289 if ( focused !== this . state . focused ) {
297- this . notify ( focused ? 'onFocus' : 'onBlur' , e )
290+ notify ( this . props [ focused ? 'onFocus' : 'onBlur' ] , e )
298291 this . setState ( { focused } )
299292 }
300293 } )
301294 } ,
302295
303- @ifNotDisabled
296+ @widgetEditable
304297 change ( date ) {
305298 if ( this . state . view === this . props . initialView ) {
306- this . notify ( ' onChange' , date )
299+ notify ( this . props . onChange , date )
307300 this . focus ( ) ;
308301 return ;
309302 }
310303
311304 this . navigate ( dir . DOWN , date )
312305 } ,
313306
314- @ifNotDisabled
307+ @widgetEditable
315308 select ( date ) {
316309 var view = this . props . initialView
317310 , slideDir = view !== this . state . view || dates . gt ( date , this . state . currentDate )
318311 ? 'left' // move down to a the view
319312 : 'right' ;
320313
321- this . notify ( ' onChange' , date )
314+ notify ( this . props . onChange , date )
322315
323316 if ( this . isValidView ( view ) && dates . inRange ( date , this . props . min , this . props . max , view ) ) {
324317 this . focus ( ) ;
@@ -329,7 +322,6 @@ var Calendar = React.createClass({
329322 view : view
330323 } )
331324 }
332-
333325 } ,
334326
335327 nextDate ( direction ) {
@@ -341,7 +333,7 @@ var Calendar = React.createClass({
341333 return dates [ method ] ( this . state . currentDate , 1 * multi , unit )
342334 } ,
343335
344- @ifNotDisabled
336+ @widgetEditable
345337 _keyDown ( e ) {
346338 var ctrl = e . ctrlKey
347339 , key = e . key
@@ -382,7 +374,7 @@ var Calendar = React.createClass({
382374 }
383375 }
384376
385- this . notify ( ' onKeyDown' , [ e ] )
377+ notify ( this . props . onKeyDown , [ e ] )
386378 } ,
387379
388380 _label ( ) {
0 commit comments