@@ -9,12 +9,6 @@ var assign = require('object-assign'),
99 moment = require ( 'moment' )
1010;
1111
12- var Constants = {
13- MODE_DATE : 'date' ,
14- MODE_DATETIME : 'datetime' ,
15- MODE_TIME : 'time'
16- } ;
17-
1812var Datetime = React . createClass ( {
1913 mixins : [
2014 require ( 'react-onclickoutside' )
@@ -26,43 +20,39 @@ var Datetime = React.createClass({
2620 time : TimeView
2721 } ,
2822 propTypes : {
29- date : React . PropTypes . string ,
23+ date : React . PropTypes . object ,
3024 onChange : React . PropTypes . func ,
25+ input : React . PropTypes . bool ,
3126 dateFormat : React . PropTypes . string ,
3227 timeFormat : React . PropTypes . string ,
3328 inputProps : React . PropTypes . object ,
34- defaultText : React . PropTypes . string ,
3529 viewMode : React . PropTypes . oneOf ( [ 'years' , 'months' , 'days' , 'time' ] ) ,
3630 minDate : React . PropTypes . object ,
3731 maxDate : React . PropTypes . object
3832 } ,
3933 getDefaultProps : function ( ) {
4034
4135 return {
42- date : false ,
36+ date : new Date ( ) ,
4337 viewMode : 'days' ,
4438 inputProps : { } ,
39+ input : true ,
4540 onChange : function ( x ) {
4641 console . log ( x ) ;
4742 }
4843 } ;
4944 } ,
5045 getInitialState : function ( ) {
5146 var formats = this . getFormats ( this . props ) ,
52- date = this . props . date || new Date ( )
47+ date = this . props . date
5348 ;
5449 return {
5550 currentView : this . props . viewMode ,
51+ open : ! this . props . input ,
5652 inputFormat : formats . datetime ,
57- widgetStyle : {
58- display : 'block' ,
59- position : 'absolute' ,
60- left : - 9999 ,
61- zIndex : '9999 !important'
62- } ,
6353 viewDate : moment ( date ) . startOf ( "month" ) ,
6454 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 )
6656 } ;
6757 } ,
6858
@@ -224,24 +214,12 @@ var Datetime = React.createClass({
224214 } ,
225215
226216 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 } ) ;
238218 } ,
239219
240220 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 } ) ;
245223 } ,
246224
247225 componentProps : {
@@ -252,8 +230,8 @@ var Datetime = React.createClass({
252230
253231 getComponentProps : function ( ) {
254232 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 }
257235 ;
258236
259237 this . componentProps . fromProps . forEach ( function ( name ) {
@@ -271,23 +249,34 @@ var Datetime = React.createClass({
271249
272250 render : function ( ) {
273251 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 ( {
275259 key : 'i' ,
276260 type :'text' ,
277261 className :'form-control' ,
278262 onFocus : this . openCalendar ,
279263 onChange : this . onChange ,
280264 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' ;
284273
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 ( ) )
289278 )
290- ] ) ;
279+ ) ) ;
291280 }
292281} ) ;
293282
0 commit comments