Skip to content

Instantly share code, notes, and snippets.

@KTruong008
Created September 9, 2017 22:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KTruong008/416572ae6c47347abf130defcda1854b to your computer and use it in GitHub Desktop.
Save KTruong008/416572ae6c47347abf130defcda1854b to your computer and use it in GitHub Desktop.
import React from 'react';
import moment from 'moment';
import { SingleDatePicker } from 'react-dates';
import 'react-dates/lib/css/_datepicker.css';
export class Datepicker extends React.Component {
constructor(props) {
super(props);
this.state = {
date: moment(),
focused: false
};
}
changeActiveDateWidget = () => {
this.setState({
activeDateWidget: !this.state.activeDateWidget,
});
}
handleDateChange = (date) => {
this.setState({ date });
this.props.change(this.props.input.name, date)
}
render() {
return (
<div className="mv4 w-100">
<div className="b sans-serif pv2 w-100">{this.props.label}</div>
<SingleDatePicker
date={this.state.date} // momentPropTypes.momentObj or null
onDateChange={this.handleDateChange} // PropTypes.func.isRequired
focused={this.state.focused} // PropTypes.bool
onFocusChange={({ focused }) => this.setState({ focused })} // PropTypes.func.isRequired
showClearDate={true}
numberOfMonths={1}
/>
</div>
);
}
}
export default Datepicker;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment