react-toolbox/components/date_picker/CalendarDay.js

51 lines
1.3 KiB
JavaScript
Raw Normal View History

import React, { Component, PropTypes } from 'react';
2016-05-21 21:52:48 +03:00
import classnames from 'classnames';
import time from '../utils/time.js';
2015-09-09 23:34:56 +03:00
class Day extends Component {
static propTypes = {
day: PropTypes.number,
disabled: PropTypes.bool,
onClick: PropTypes.func,
selectedDate: PropTypes.object,
theme: PropTypes.shape({
active: PropTypes.string,
day: PropTypes.string,
disabled: PropTypes.string
2016-05-21 21:52:48 +03:00
}),
viewDate: PropTypes.object
};
2015-09-07 02:41:59 +03:00
2015-09-08 01:03:17 +03:00
dayStyle () {
2015-09-07 02:41:59 +03:00
if (this.props.day === 1) {
return {
marginLeft: `${time.getFirstWeekDay(this.props.viewDate) * 100 / 7}%`
};
}
}
2015-09-07 02:41:59 +03:00
2015-09-08 01:03:17 +03:00
isSelected () {
2015-09-07 02:41:59 +03:00
const sameYear = this.props.viewDate.getFullYear() === this.props.selectedDate.getFullYear();
const sameMonth = this.props.viewDate.getMonth() === this.props.selectedDate.getMonth();
const sameDay = this.props.day === this.props.selectedDate.getDate();
return sameYear && sameMonth && sameDay;
}
2015-09-07 02:41:59 +03:00
render () {
2016-05-21 21:52:48 +03:00
const className = classnames(this.props.theme.day, {
[this.props.theme.active]: this.isSelected(),
[this.props.theme.disabled]: this.props.disabled
2015-11-28 15:55:25 +03:00
});
2015-11-16 11:56:05 +03:00
2015-09-07 02:41:59 +03:00
return (
<div data-react-toolbox='day' className={className} style={this.dayStyle()}>
<span onClick={this.props.onClick}>
{this.props.day}
</span>
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 Day;