react-toolbox/components/date_picker/CalendarDay.js

52 lines
1.5 KiB
JavaScript
Raw Normal View History

import React from 'react';
2016-05-21 21:52:48 +03:00
import classnames from 'classnames';
import { themr } from 'react-css-themr';
2015-11-23 00:13:27 +03:00
import time from '../utils/time';
2015-09-09 23:34:56 +03:00
2015-10-22 02:31:17 +03:00
class Day extends React.Component {
static propTypes = {
2015-09-07 02:41:59 +03:00
day: React.PropTypes.number,
2015-11-16 11:56:05 +03:00
disabled: React.PropTypes.bool,
2015-09-07 02:41:59 +03:00
onClick: React.PropTypes.func,
selectedDate: React.PropTypes.object,
2016-05-21 21:52:48 +03:00
theme: React.PropTypes.shape({
active: React.PropTypes.string.isRequired,
day: React.PropTypes.string.isRequired,
disabled: React.PropTypes.string.isRequired
}),
2015-09-07 02:41:59 +03:00
viewDate: React.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
2016-05-21 21:52:48 +03:00
export default themr('ToolboxDatePicker')(Day);