Permalink
Fetching contributors…
Cannot retrieve contributors at this time
32 lines (27 sloc) 810 Bytes
import React from 'react'
import { createField } from 'react-advanced-form'
import ReactDatepicker from 'react-datepicker'
import 'react-datepicker/dist/react-datepicker.css'
class Datepicker extends React.Component {
handleChange = (nextValue) => {
/* Dispatch "react-advanced-form" method to update the field state */
this.props.handleFieldChange({ nextValue })
}
render() {
const { fieldProps } = this.props
return (
<div className="form-group">
<ReactDatepicker
{...fieldProps}
className="form-control"
onChange={this.handleChange}
/>
</div>
)
}
}
export default createField({
/* "react-datepicker" uses "selected" prop instead of "value" */
valuePropName: 'selected',
initialValue: new Date(),
})(Datepicker)