@@ -9,12 +9,6 @@ var assign = require('object-assign'),
9
9
moment = require ( 'moment' )
10
10
;
11
11
12
- var Constants = {
13
- MODE_DATE : 'date' ,
14
- MODE_DATETIME : 'datetime' ,
15
- MODE_TIME : 'time'
16
- } ;
17
-
18
12
var Datetime = React . createClass ( {
19
13
mixins : [
20
14
require ( 'react-onclickoutside' )
@@ -26,43 +20,39 @@ var Datetime = React.createClass({
26
20
time : TimeView
27
21
} ,
28
22
propTypes : {
29
- date : React . PropTypes . string ,
23
+ date : React . PropTypes . object ,
30
24
onChange : React . PropTypes . func ,
25
+ input : React . PropTypes . bool ,
31
26
dateFormat : React . PropTypes . string ,
32
27
timeFormat : React . PropTypes . string ,
33
28
inputProps : React . PropTypes . object ,
34
- defaultText : React . PropTypes . string ,
35
29
viewMode : React . PropTypes . oneOf ( [ 'years' , 'months' , 'days' , 'time' ] ) ,
36
30
minDate : React . PropTypes . object ,
37
31
maxDate : React . PropTypes . object
38
32
} ,
39
33
getDefaultProps : function ( ) {
40
34
41
35
return {
42
- date : false ,
36
+ date : new Date ( ) ,
43
37
viewMode : 'days' ,
44
38
inputProps : { } ,
39
+ input : true ,
45
40
onChange : function ( x ) {
46
41
console . log ( x ) ;
47
42
}
48
43
} ;
49
44
} ,
50
45
getInitialState : function ( ) {
51
46
var formats = this . getFormats ( this . props ) ,
52
- date = this . props . date || new Date ( )
47
+ date = this . props . date
53
48
;
54
49
return {
55
50
currentView : this . props . viewMode ,
51
+ open : ! this . props . input ,
56
52
inputFormat : formats . datetime ,
57
- widgetStyle : {
58
- display : 'block' ,
59
- position : 'absolute' ,
60
- left : - 9999 ,
61
- zIndex : '9999 !important'
62
- } ,
63
53
viewDate : moment ( date ) . startOf ( "month" ) ,
64
54
selectedDate : moment ( date ) ,
65
- inputValue : typeof this . props . defaultText != 'undefined' ? this . props . defaultText : moment ( date ) . format ( formats . datetime )
55
+ inputValue : moment ( date ) . format ( formats . datetime )
66
56
} ;
67
57
} ,
68
58
@@ -224,24 +214,12 @@ var Datetime = React.createClass({
224
214
} ,
225
215
226
216
openCalendar : function ( ) {
227
- var styles = {
228
- display : 'block' ,
229
- position : 'absolute'
230
- }
231
- ;
232
-
233
- this . setState ( {
234
- widgetStyle : styles ,
235
- widgetClasses : 'dropdown-menu bottom' ,
236
- showPicker : true
237
- } ) ;
217
+ this . setState ( { open : true } ) ;
238
218
} ,
239
219
240
220
handleClickOutside : function ( ) {
241
- this . setState ( {
242
- showPicker : false ,
243
- widgetStyle : { display : 'none' }
244
- } ) ;
221
+ if ( this . props . input && this . state . open )
222
+ this . setState ( { open : false } ) ;
245
223
} ,
246
224
247
225
componentProps : {
@@ -252,8 +230,8 @@ var Datetime = React.createClass({
252
230
253
231
getComponentProps : function ( ) {
254
232
var me = this ,
255
- formats = this . getFormats ( this . props ) ,
256
- props = { dateFormat : formats . date , timeFormat : formats . time }
233
+ formats = this . getFormats ( this . props ) ,
234
+ props = { dateFormat : formats . date , timeFormat : formats . time }
257
235
;
258
236
259
237
this . componentProps . fromProps . forEach ( function ( name ) {
@@ -271,23 +249,34 @@ var Datetime = React.createClass({
271
249
272
250
render : function ( ) {
273
251
var Component = this . viewComponents [ this . state . currentView ] ,
274
- inputProps = assign ( {
252
+ DOM = React . DOM ,
253
+ className = 'rdt' ,
254
+ children = [ ]
255
+ ;
256
+
257
+ if ( this . props . input ) {
258
+ children = [ DOM . input ( assign ( {
275
259
key : 'i' ,
276
260
type :'text' ,
277
261
className :'form-control' ,
278
262
onFocus : this . openCalendar ,
279
263
onChange : this . onChange ,
280
264
value : this . state . inputValue
281
- } , this . props . inputProps ) ,
282
- DOM = React . DOM
283
- ;
265
+ } , this . props . inputProps ) ) ] ;
266
+ }
267
+ else {
268
+ className += ' rdtStatic' ;
269
+ }
270
+
271
+ if ( this . state . open )
272
+ className += ' rdtOpen' ;
284
273
285
- return DOM . div ( { className : 'datetimePicker' } , [
286
- DOM . input ( inputProps ) ,
287
- DOM . div ( { key : 'dt' , className : this . state . widgetClasses , style : this . state . widgetStyle } ,
288
- React . createElement ( Component , this . getComponentProps ( ) )
274
+ return DOM . div ( { className : className } , children . concat (
275
+ DOM . div (
276
+ { key : 'dt' , className : 'rdtPicker' } ,
277
+ React . createElement ( Component , this . getComponentProps ( ) )
289
278
)
290
- ] ) ;
279
+ ) ) ;
291
280
}
292
281
} ) ;
293
282
0 commit comments