2015-10-11 20:07:09 +03:00
|
|
|
import React from 'react';
|
2015-10-20 21:10:47 +03:00
|
|
|
import Calendar from './calendar';
|
2015-09-09 23:34:56 +03:00
|
|
|
import Dialog from '../dialog';
|
2015-11-16 18:54:05 +03:00
|
|
|
import style from './style';
|
|
|
|
import time from '../utils/time';
|
2015-09-07 02:59:11 +03:00
|
|
|
|
2015-10-22 02:31:17 +03:00
|
|
|
class CalendarDialog extends React.Component {
|
2015-10-20 08:40:51 +03:00
|
|
|
static propTypes = {
|
2015-11-10 16:27:00 +03:00
|
|
|
active: React.PropTypes.bool,
|
2015-11-16 11:56:05 +03:00
|
|
|
maxDate: React.PropTypes.object,
|
|
|
|
minDate: React.PropTypes.object,
|
2015-11-11 22:34:19 +03:00
|
|
|
onDismiss: React.PropTypes.func,
|
|
|
|
onSelect: React.PropTypes.func,
|
|
|
|
value: React.PropTypes.object
|
2015-10-20 08:40:51 +03:00
|
|
|
};
|
2015-09-07 02:59:11 +03:00
|
|
|
|
2015-10-20 08:40:51 +03:00
|
|
|
static defaultProps = {
|
2015-11-10 16:27:00 +03:00
|
|
|
active: false,
|
2015-11-11 22:34:19 +03:00
|
|
|
value: new Date()
|
2015-10-20 08:40:51 +03:00
|
|
|
};
|
2015-09-07 02:59:11 +03:00
|
|
|
|
2015-10-20 08:40:51 +03:00
|
|
|
state = {
|
2015-11-11 22:34:19 +03:00
|
|
|
date: this.props.value,
|
2015-11-16 18:54:05 +03:00
|
|
|
display: 'months',
|
|
|
|
year: this.props.value.getFullYear()
|
2015-10-20 08:40:51 +03:00
|
|
|
};
|
2015-09-07 02:59:11 +03:00
|
|
|
|
2015-11-10 17:07:40 +03:00
|
|
|
handleCalendarChange = (value) => {
|
2015-11-16 18:54:05 +03:00
|
|
|
const state = {display: 'months', year: value.getFullYear()};
|
|
|
|
if (!time.dateOutOfRange(value, this.props.minDate, this.props.maxDate)) {
|
|
|
|
state.date = value;
|
|
|
|
}
|
|
|
|
this.setState(state);
|
2015-10-22 02:31:17 +03:00
|
|
|
};
|
|
|
|
|
2015-11-11 22:34:19 +03:00
|
|
|
handleSelect = () => {
|
|
|
|
if (this.props.onSelect) this.props.onSelect(this.state.date);
|
2015-10-22 02:31:17 +03:00
|
|
|
};
|
|
|
|
|
2015-11-11 22:34:19 +03:00
|
|
|
handleSwitchDisplay = (display) => {
|
|
|
|
this.setState({ display });
|
2015-10-22 02:31:17 +03:00
|
|
|
};
|
2015-09-07 02:59:11 +03:00
|
|
|
|
2015-11-11 22:34:19 +03:00
|
|
|
actions = [
|
|
|
|
{ label: 'Cancel', className: style.button, onClick: this.props.onDismiss },
|
|
|
|
{ label: 'Ok', className: style.button, onClick: this.handleSelect }
|
|
|
|
];
|
2015-09-07 02:59:11 +03:00
|
|
|
|
|
|
|
render () {
|
2015-10-10 21:06:16 +03:00
|
|
|
const display = `display-${this.state.display}`;
|
|
|
|
const headerClassName = `${style.header} ${style[display]}`;
|
2015-10-11 20:07:09 +03:00
|
|
|
|
2015-09-07 02:59:11 +03:00
|
|
|
return (
|
2015-11-11 22:34:19 +03:00
|
|
|
<Dialog active={this.props.active} type="custom" className={style.dialog} actions={this.actions}>
|
2015-10-10 21:06:16 +03:00
|
|
|
<header className={headerClassName}>
|
|
|
|
<span className={style.weekday}>
|
2015-09-07 02:59:11 +03:00
|
|
|
{time.getFullDayOfWeek(this.state.date.getDay())}
|
|
|
|
</span>
|
2015-11-11 22:34:19 +03:00
|
|
|
<div onClick={this.handleSwitchDisplay.bind(this, 'months')}>
|
2015-10-10 21:06:16 +03:00
|
|
|
<span className={style.month}>{time.getShortMonth(this.state.date)}</span>
|
|
|
|
<span className={style.day}>{this.state.date.getDate()}</span>
|
2015-09-07 02:59:11 +03:00
|
|
|
</div>
|
2015-11-11 22:34:19 +03:00
|
|
|
<span className={style.year} onClick={this.handleSwitchDisplay.bind(this, 'years')}>
|
2015-11-16 18:54:05 +03:00
|
|
|
{this.state.year}
|
2015-09-07 02:59:11 +03:00
|
|
|
</span>
|
|
|
|
</header>
|
|
|
|
|
2015-10-10 21:06:16 +03:00
|
|
|
<div className={style.wrapper}>
|
2015-09-07 02:59:11 +03:00
|
|
|
<Calendar
|
|
|
|
display={this.state.display}
|
2015-11-16 11:56:05 +03:00
|
|
|
maxDate={this.props.maxDate}
|
|
|
|
minDate={this.props.minDate}
|
2015-10-22 02:31:17 +03:00
|
|
|
onChange={this.handleCalendarChange}
|
2015-10-11 20:07:09 +03:00
|
|
|
selectedDate={this.state.date} />
|
2015-09-07 02:59:11 +03:00
|
|
|
</div>
|
|
|
|
</Dialog>
|
|
|
|
);
|
|
|
|
}
|
2015-10-21 13:25:07 +03:00
|
|
|
}
|
2015-10-22 02:31:17 +03:00
|
|
|
|
|
|
|
export default CalendarDialog;
|