react-toolbox/components/date_picker/CalendarMonth.js

58 lines
1.6 KiB
JavaScript
Raw Normal View History

import React from 'react';
2015-11-23 00:13:27 +03:00
import CalendarDay from './CalendarDay';
import time from '../utils/time';
import utils from '../utils/utils';
import style from './style.calendar';
2015-09-07 02:41:59 +03:00
2015-10-22 02:31:17 +03:00
class Month extends React.Component {
static propTypes = {
2015-11-16 11:56:05 +03:00
maxDate: React.PropTypes.object,
minDate: React.PropTypes.object,
2015-09-07 02:41:59 +03:00
onDayClick: React.PropTypes.func,
selectedDate: React.PropTypes.object,
viewDate: React.PropTypes.object
};
2015-09-07 02:41:59 +03:00
2015-10-22 02:31:17 +03:00
handleDayClick = (day) => {
if (this.props.onDayClick) this.props.onDayClick(day);
2015-10-22 02:31:17 +03:00
};
2015-09-07 02:41:59 +03:00
renderWeeks () {
return utils.range(0, 7).map(i => {
return <span key={i}>{time.getFullDayOfWeek(i).charAt(0)}</span>;
2015-09-07 02:41:59 +03:00
});
}
2015-09-07 02:41:59 +03:00
renderDays () {
return utils.range(1, time.getDaysInMonth(this.props.viewDate) + 1).map(i => {
const date = new Date(this.props.viewDate.getFullYear(), this.props.viewDate.getMonth(), i);
const disabled = time.dateOutOfRange(date, this.props.minDate, this.props.maxDate);
2015-11-16 11:56:05 +03:00
2015-09-07 02:41:59 +03:00
return (
2015-11-23 00:13:27 +03:00
<CalendarDay
key={i}
2015-09-07 02:41:59 +03:00
day={i}
disabled={disabled}
onClick={!disabled ? this.handleDayClick.bind(this, i) : null}
2015-09-07 02:41:59 +03:00
selectedDate={this.props.selectedDate}
viewDate={this.props.viewDate}
/>
2015-09-07 02:41:59 +03:00
);
});
}
2015-09-07 02:41:59 +03:00
render () {
return (
<div data-react-toolbox='month' className={style.month}>
<span className={style.title}>
{time.getFullMonth(this.props.viewDate)} {this.props.viewDate.getFullYear()}
2015-09-07 02:41:59 +03:00
</span>
<div className={style.week}>{this.renderWeeks()}</div>
<div className={style.days}>{this.renderDays()}</div>
2015-09-07 02:41:59 +03:00
</div>
);
}
2015-10-21 13:25:07 +03:00
}
2015-10-22 02:31:17 +03:00
export default Month;