Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add DatePicker #13

Closed
yiminghe opened this issue Jan 22, 2015 · 0 comments
Closed

add DatePicker #13

yiminghe opened this issue Jan 22, 2015 · 0 comments
Labels
Milestone

Comments

@yiminghe
Copy link
Member

<DatePicker ref='picker' formatter={this.props.formatter} calendar={calendar}  value={state.value}>
  <input type="text" className="form-control"/>
</DatePicker>
var React = require('react');
var Calendar = require('../');
var DatePicker = Calendar.Picker;
var zhCn = require('gregorian-calendar/lib/locale/zh-cn'); 
var DateTimeFormat = require('gregorian-calendar-format');
var GregorianCalendar = require('gregorian-calendar');
var CalendarLocale = require('../lib/locale/zh-cn');

var Test = React.createClass({
  open: function () {
    this.refs.picker.setState({
      open: true
    });
  },

  handleCalendarSelect: function (v) {
    //console.log('outer knows: ' + this.props.formatter.format(v));
    // sync status
    this.setState({
      value: v
    });
  },

  getDefaultProps: function () {
    return {
      formatter: new DateTimeFormat('yyyy-MM-dd HH:mm:ss', zhCn)
    }
  },

  getInitialState: function () {
    var value = new GregorianCalendar(zhCn);
    value.setTime(Date.now());
    return {
      showTime:true,
      value: value
    };
  },

  handleShowTimeChange:function(e){
    this.setState({
      showTime:e.target.checked
    });
  },

  render: function () {
    var state = this.state;
    var calendar = <Calendar locale={CalendarLocale}
    orient={['bottom','left']}
    showTime={this.state.showTime} onSelect={this.handleCalendarSelect}/>;
    return  <div className="form-group">
        <div className="input-group">
         <span><input type='checkbox' checked={this.state.showTime} onChange={this.handleShowTimeChange} /> showTime</span>
         </div>
        <div className="input-group">
          <DatePicker ref='picker' formatter={this.props.formatter} calendar={calendar}  value={state.value}>
            <input type="text" className="form-control" style={{background:'white',cursor:'pointer'}}/>
          </DatePicker>
          <span className="input-group-addon" onClick={this.open}>
            <span className="glyphicon glyphicon-calendar"></span>
          </span>
        </div>
      </div>;
  }
});
@yiminghe yiminghe added the new label Jan 22, 2015
@yiminghe yiminghe added this to the 1.5.0 milestone Jan 22, 2015
@yiminghe yiminghe changed the title add date-picker add DatePicker Jan 22, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant