67 lines
1.4 KiB
JavaScript
67 lines
1.4 KiB
JavaScript
import React from 'react';
|
|
import CalendarDialog from './dialog';
|
|
import Input from '../input';
|
|
import events from '../utils/events';
|
|
import time from '../utils/time';
|
|
import style from './style';
|
|
|
|
class DatePicker extends React.Component {
|
|
static propTypes = {
|
|
className: React.PropTypes.string,
|
|
value: React.PropTypes.object
|
|
};
|
|
|
|
static defaultProps = {
|
|
className: ''
|
|
};
|
|
|
|
state = {
|
|
value: this.props.value
|
|
};
|
|
|
|
handleMouseDown = (event) => {
|
|
events.pauseEvent(event);
|
|
this.refs.dialog.show();
|
|
};
|
|
|
|
handleDateSelected = (value) => {
|
|
this.refs.input.setValue(this.formatDate(value));
|
|
this.setState({value: value});
|
|
};
|
|
|
|
formatDate (date) {
|
|
return `${date.getDate()} ${time.getFullMonth(date)} ${date.getFullYear()}`;
|
|
}
|
|
|
|
render () {
|
|
return (
|
|
<div data-toolbox='date-picker'>
|
|
<Input
|
|
ref='input'
|
|
type='text'
|
|
readOnly={true}
|
|
className={style.input}
|
|
onMouseDown={this.handleMouseDown}
|
|
placeholder='Pick up date'
|
|
value={this.state.value ? this.formatDate(this.state.value) : null}
|
|
/>
|
|
<CalendarDialog
|
|
ref='dialog'
|
|
initialDate={this.state.value}
|
|
onDateSelected={this.handleDateSelected}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
getValue () {
|
|
return this.state.value;
|
|
}
|
|
|
|
setValue (value) {
|
|
this.setState({value: value});
|
|
}
|
|
}
|
|
|
|
export default DatePicker;
|