MonthPicker.js 1.2 KB
import React,{PropTypes} from 'react';
import ReactDOM from 'react-dom';  
import moment from 'moment';
import DateTimeField from './datetime/DateTimeField';
import cx from 'classnames';
import s from './Custom.scss';   


class MonthPicker extends React.Component {
    constructor(props) {
        super(props);  
        this.onChange=this.onChange.bind(this);
        this.state={
            today:new Date()
        }    
    }
    static propTypes = {    
        'onChange':PropTypes.func,
        'defaultValue':PropTypes.string
    } 
    static defaultProps={ 
        defaultValue:'',
        onChange: (x) => {
          console.log(x);
        }
    }  
    onChange(data){
        const {onChange}=this.props;
        onChange(data);
    }
    render(){
        const {today}=this.state;
        const {defaultValue}=this.props;
        const value=moment(defaultValue).isValid()?moment(defaultValue).format('x'):moment(today).format('x');
        return ( 
            <div className={cx(s.datetime_picker_wrap)}>
                <DateTimeField  dateTime={value} mode='month' onChange={this.onChange} />
            </div>) 
    }
}



export default MonthPicker;