Created
August 26, 2015 06:28
-
-
Save proclamo-zz/92007e078c4cf757efa2 to your computer and use it in GitHub Desktop.
datepicker example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('rc-calendar/assets/bootstrap.css'); | |
var React = require('react'); | |
var Calendar = require('rc-calendar'); | |
var GregorianCalendar = require('gregorian-calendar'); | |
var DatetimeFormat = require('gregorian-calendar-format'); | |
var DatePicker = React.createClass({ | |
getDefaultProps: function() { | |
return { | |
formatter: new DatetimeFormat("dd/MM/yyyy HH:mm:ss") | |
}; | |
}, | |
getInitialState: function() { | |
var now = new GregorianCalendar(); | |
now.setTime(Date.now()); | |
return { | |
value: now | |
}; | |
}, | |
onOpenChange: function(e) { | |
this.setState({ | |
open: e.open | |
}); | |
}, | |
onCloseChange: function(e) { | |
this.setState({ | |
open: e.open | |
}); | |
}, | |
toggle: function() { | |
this.setState({ | |
open: !this.state.open | |
}); | |
}, | |
render: function() { | |
var calendar = <Calendar | |
style={{ zIndex: 2000 }} | |
orient={['bottom', 'right']} | |
showTime={this.props.showTime} | |
showOk={true} /> | |
return ( | |
<div ref="divContainer" style={{ | |
'boxSizing': 'border-box', | |
'position': 'relative', | |
'display': 'block', | |
'lineHeight': 1.5, | |
'marginBottom': 22 | |
}}> | |
<Calendar.Picker | |
rootNode={React.findDOMNode(this.refs.divContainer)} | |
adjustOrientOnCalendarOverflow={true} | |
calendar={calendar} | |
defaultOpen={false} | |
formatter={this.props.formatter} | |
onOpen={this.onOpenChange} | |
onClose={this.onCloseChange} | |
state={this.state.open} | |
> | |
<input style={{width: 200}} disabled={false} placeholder={this.props.placeholder} onClick={this.toggle}/> | |
</Calendar.Picker> | |
</div> | |
); | |
} | |
}); | |
module.exports = DatePicker; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment