2019-08-23 12:23:22 +00:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import styled, { css } from 'styled-components';
|
|
|
|
import ComboBox from '../combobox';
|
|
|
|
import moment from 'moment/min/moment-with-locales';
|
|
|
|
|
|
|
|
const HoverStyle = css`
|
|
|
|
&:hover {
|
|
|
|
background-color: #ECEEF1;
|
|
|
|
border-radius: 16px;
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2019-08-29 13:33:10 +00:00
|
|
|
const DisabledStyle = css`
|
|
|
|
-webkit-touch-callout: none;
|
|
|
|
-webkit-user-select: none;
|
|
|
|
-khtml-user-select: none;
|
|
|
|
-moz-user-select: none;
|
|
|
|
-ms-user-select: none;
|
|
|
|
user-select: none;
|
|
|
|
`;
|
|
|
|
|
2019-08-23 12:23:22 +00:00
|
|
|
const ComboBoxStyle = styled.div`
|
|
|
|
position: relative;
|
|
|
|
display: flex;
|
|
|
|
padding-bottom: 16px;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const ComboBoxDateStyle = styled.div`
|
|
|
|
min-width: 80px;
|
|
|
|
height: 32px;
|
|
|
|
margin-left: 8px;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const CalendarStyle = styled.div`
|
2019-08-28 12:53:38 +00:00
|
|
|
|
2019-08-29 13:33:10 +00:00
|
|
|
min-width: 280px;
|
|
|
|
width: ${props => props.scaled ? "100%;" : "325px;"}
|
2019-08-28 12:53:38 +00:00
|
|
|
|
2019-08-23 12:23:22 +00:00
|
|
|
border-radius: 6px;
|
|
|
|
-moz-border-radius: 6px;
|
|
|
|
-webkit-border-radius: 6px;
|
|
|
|
box-shadow: 0px 5px 20px rgba(0, 0, 0, 0.13);
|
|
|
|
-moz-box-shadow: 0px 5px 20px rgba(0, 0, 0, 0.13);
|
|
|
|
-webkit-box-shadow: 0px 5px 20px rgba(0, 0, 0, 0.13);
|
|
|
|
padding: 16px 16px 16px 17px;
|
|
|
|
box-sizing: content-box;
|
|
|
|
font-family: Open Sans;
|
|
|
|
font-style: normal;
|
|
|
|
font-weight: bold;
|
|
|
|
font-size: 13px;
|
|
|
|
text-align: center;
|
2019-08-29 13:33:10 +00:00
|
|
|
${props => props.disabled ?
|
|
|
|
`${DisabledStyle}
|
|
|
|
`
|
|
|
|
: "pointer-events: auto;"
|
|
|
|
}
|
2019-08-26 07:11:59 +00:00
|
|
|
|
2019-08-23 12:23:22 +00:00
|
|
|
.calendar-month {
|
|
|
|
${HoverStyle}
|
|
|
|
}
|
|
|
|
|
|
|
|
.calendar-month_neighboringMonth {
|
|
|
|
color: #ECEEF1;
|
2019-08-29 13:33:10 +00:00
|
|
|
|
2019-08-28 12:53:38 +00:00
|
|
|
${HoverStyle}
|
2019-08-28 13:58:14 +00:00
|
|
|
&:hover {color: #333;}
|
2019-08-23 12:23:22 +00:00
|
|
|
}
|
|
|
|
|
2019-08-29 13:33:10 +00:00
|
|
|
.calendar-month_disabled {
|
|
|
|
${DisabledStyle}
|
|
|
|
color: #ECEEF1;
|
|
|
|
pointer-events: none;
|
|
|
|
}
|
|
|
|
|
2019-08-23 12:23:22 +00:00
|
|
|
.calendar-month_weekend {
|
|
|
|
color: #A3A9AE;
|
|
|
|
${HoverStyle}
|
|
|
|
}
|
|
|
|
|
|
|
|
.calendar-month_weekdays_weekend {
|
|
|
|
color: #A3A9AE;
|
|
|
|
}
|
|
|
|
|
|
|
|
.calendar-month_selected-day {
|
|
|
|
background-color: ${props => props.color};
|
|
|
|
border-radius: 16px;
|
|
|
|
cursor: pointer;
|
|
|
|
color: #fff;
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const Weekday = styled.div`
|
2019-08-28 12:53:38 +00:00
|
|
|
display: flex;
|
2019-08-23 12:23:22 +00:00
|
|
|
overflow: hidden;
|
2019-08-28 12:53:38 +00:00
|
|
|
flex-basis: 14.2857%;
|
|
|
|
padding-left: 4px;
|
2019-08-23 12:23:22 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
const Weekdays = styled.div`
|
|
|
|
display: flex;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const Month = styled.div`
|
|
|
|
width: 100%;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const Days = styled.div`
|
|
|
|
display: flex;
|
|
|
|
flex-wrap: wrap;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const Day = styled.div`
|
|
|
|
display: flex;
|
|
|
|
flex-basis: 14.2857%;
|
|
|
|
padding: 4px;
|
|
|
|
text-align: center;
|
|
|
|
line-height: 2.5em;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const AbbrDay = styled.abbr`
|
|
|
|
width: 32px;
|
|
|
|
height: 32px;
|
|
|
|
`;
|
|
|
|
|
|
|
|
class Calendar extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
}
|
|
|
|
|
|
|
|
state = {
|
|
|
|
months: moment.months(),
|
|
|
|
openToDate: this.props.openToDate,
|
2019-08-29 13:33:10 +00:00
|
|
|
selectedDate: this.props.selectedDate
|
2019-08-23 12:23:22 +00:00
|
|
|
};
|
|
|
|
|
2019-08-28 12:53:38 +00:00
|
|
|
onSelectYear = (value) => {
|
2019-08-23 12:23:22 +00:00
|
|
|
this.setState({ openToDate: new Date(value.key, this.state.openToDate.getMonth()) });
|
|
|
|
}
|
|
|
|
|
2019-08-28 12:53:38 +00:00
|
|
|
onSelectMonth = (value) => {
|
2019-08-23 12:23:22 +00:00
|
|
|
this.setState({ openToDate: new Date(this.state.openToDate.getFullYear(), value.key) });
|
|
|
|
}
|
|
|
|
|
2019-08-28 12:53:38 +00:00
|
|
|
onDayClick = (day) => {
|
|
|
|
let month = this.state.openToDate.getMonth() + 1;
|
|
|
|
let year = this.state.openToDate.getFullYear();
|
|
|
|
const date = new Date(month + "/" + day + "/" + year);
|
|
|
|
const days = new Date(year, month, 0).getDate();
|
|
|
|
|
|
|
|
if (day < 0) {
|
|
|
|
if (month === 1) { month = 13, year -= 1 }
|
|
|
|
const prevDays = new Date(year, (month - 1), 0).getDate();
|
|
|
|
const prevDate = new Date((month - 1) + "/" + (prevDays + day + 1) + "/" + year);
|
|
|
|
this.setState({ selectedDate: prevDate, openToDate: prevDate });
|
|
|
|
}
|
|
|
|
else if (day > days) {
|
|
|
|
if (month === 12) { month = 0, year += 1 }
|
|
|
|
const nextDate = new Date(month + 1 + "/" + (day - days) + "/" + year);
|
|
|
|
this.setState({ selectedDate: nextDate, openToDate: nextDate });
|
|
|
|
}
|
|
|
|
else if (this.formatSelectedDate(date) != this.formatSelectedDate(this.state.selectedDate)) {
|
|
|
|
this.setState({ selectedDate: date });
|
|
|
|
this.props.onChange && this.props.onChange(date);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-29 13:33:10 +00:00
|
|
|
getListMonth = () => {
|
2019-08-28 11:03:55 +00:00
|
|
|
const minDate = this.props.minDate;
|
|
|
|
const maxDate = this.props.maxDate;
|
2019-08-29 13:33:10 +00:00
|
|
|
let disabled = false;
|
|
|
|
const monthList = [];
|
2019-08-30 07:46:51 +00:00
|
|
|
|
2019-08-29 13:33:10 +00:00
|
|
|
const month = this.state.months.map(item => item.charAt(0).toLocaleUpperCase() + item.slice(1));
|
|
|
|
//This function is not optimal for all languages. // It'is bad...
|
2019-08-30 07:46:51 +00:00
|
|
|
|
2019-08-29 13:33:10 +00:00
|
|
|
for (let i = 0; i <= 11; i++) {
|
|
|
|
monthList.push({ key: `${i}`, label: `${month[i]}`, disabled: disabled });
|
|
|
|
}
|
2019-08-30 07:46:51 +00:00
|
|
|
|
2019-08-29 13:33:10 +00:00
|
|
|
let i = 0;
|
2019-08-28 11:03:55 +00:00
|
|
|
if (this.state.openToDate.getFullYear() === minDate.getFullYear()) {
|
2019-08-29 13:33:10 +00:00
|
|
|
while (i != minDate.getMonth()) {
|
|
|
|
monthList[i].disabled = true;
|
|
|
|
i++;
|
|
|
|
}
|
2019-08-28 11:03:55 +00:00
|
|
|
}
|
|
|
|
|
2019-08-29 13:33:10 +00:00
|
|
|
i = 11;
|
|
|
|
if (this.state.openToDate.getFullYear() === maxDate.getFullYear()) {
|
|
|
|
while (i != maxDate.getMonth()) {
|
|
|
|
monthList[i].disabled = true;
|
|
|
|
i--;
|
|
|
|
}
|
2019-08-28 11:03:55 +00:00
|
|
|
}
|
|
|
|
|
2019-08-29 13:33:10 +00:00
|
|
|
return monthList;
|
2019-08-23 12:23:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getCurrentMonth = () => {
|
2019-08-28 13:58:14 +00:00
|
|
|
const openToDate = this.state.openToDate;
|
2019-08-29 13:33:10 +00:00
|
|
|
const month = this.getListMonth();
|
2019-08-30 07:46:51 +00:00
|
|
|
let selectedMonth = month.find(x => x.key == openToDate.getMonth());
|
|
|
|
|
|
|
|
if (selectedMonth.disabled === true) {
|
|
|
|
selectedMonth = month.find(x => x.disabled === false);
|
|
|
|
const key = selectedMonth.key;
|
|
|
|
const currentMonth = Number(key) + 1;
|
|
|
|
const date = new Date(openToDate.getFullYear() + "/" + currentMonth + "/" + "01");
|
|
|
|
this.state.openToDate = date;
|
|
|
|
}
|
2019-08-29 13:33:10 +00:00
|
|
|
return selectedMonth;
|
2019-08-23 12:23:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getArrayYears = () => {
|
2019-08-28 12:53:38 +00:00
|
|
|
const minDate = this.props.minDate.getFullYear();
|
|
|
|
const maxDate = this.props.maxDate.getFullYear();
|
2019-08-23 12:23:22 +00:00
|
|
|
const yearList = [];
|
2019-08-28 12:53:38 +00:00
|
|
|
for (let i = minDate; i <= maxDate; i++) {
|
2019-08-23 12:23:22 +00:00
|
|
|
let newDate = new Date(i, 0, 1);
|
|
|
|
yearList.push({ key: `${i}`, label: `${moment(newDate).format('YYYY')}` });
|
|
|
|
}
|
|
|
|
return yearList;
|
|
|
|
}
|
|
|
|
|
|
|
|
getCurrentYear = () => {
|
2019-08-28 12:53:38 +00:00
|
|
|
return this.getArrayYears().find(x => x.key == this.state.openToDate.getFullYear());
|
2019-08-23 12:23:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
formatSelectedDate = (date) => {
|
|
|
|
return (date.getMonth() + 1) + "/" + date.getDate() + "/" + date.getFullYear();
|
|
|
|
}
|
|
|
|
|
|
|
|
formatDate = (date) => {
|
|
|
|
return (date.getMonth() + 1) + "/" + 1 + "/" + date.getFullYear();
|
|
|
|
}
|
|
|
|
|
|
|
|
compareDays = () => {
|
2019-08-28 12:53:38 +00:00
|
|
|
const openDate = this.formatDate(this.state.openToDate);
|
|
|
|
const selectedDate = this.formatDate(this.state.selectedDate);
|
|
|
|
return (openDate === selectedDate) ? true : false;
|
2019-08-23 12:23:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
firstDayOfMonth = () => {
|
|
|
|
const selectedDate = this.state.openToDate;
|
|
|
|
const firstDay = moment(selectedDate).locale("en").startOf("month").format("d");
|
2019-08-28 12:53:38 +00:00
|
|
|
let day = firstDay - 1;
|
2019-08-26 07:11:59 +00:00
|
|
|
if (day < 0) { day = 6; }
|
|
|
|
return day;
|
2019-08-29 07:05:56 +00:00
|
|
|
}
|
2019-08-23 12:23:22 +00:00
|
|
|
|
|
|
|
getWeekDays = () => {
|
|
|
|
let arrayWeekDays = [];
|
2019-08-26 07:11:59 +00:00
|
|
|
const weekdays = moment.weekdaysMin();
|
2019-08-28 12:53:38 +00:00
|
|
|
weekdays.push(weekdays.shift());
|
2019-08-26 07:11:59 +00:00
|
|
|
let className = "";
|
2019-08-23 12:23:22 +00:00
|
|
|
for (let i = 0; i < weekdays.length; i++) {
|
2019-08-28 12:53:38 +00:00
|
|
|
(i >= 5) ? className = "calendar-month_weekdays_weekend" : className = "calendar-month_weekdays";
|
2019-08-29 13:33:10 +00:00
|
|
|
arrayWeekDays.push(<Weekday className={className} key={weekdays[i]}>
|
|
|
|
<AbbrDay>{(weekdays[i].charAt(0).toUpperCase() + weekdays[i].slice(1))}</AbbrDay></Weekday>)
|
|
|
|
//This function is not optimal for all languages. // It'is bad...
|
2019-08-23 12:23:22 +00:00
|
|
|
}
|
|
|
|
return arrayWeekDays;
|
|
|
|
}
|
|
|
|
|
|
|
|
getDays = () => {
|
|
|
|
let keys = 0;
|
|
|
|
let prevMonthDays = this.firstDayOfMonth();
|
|
|
|
const year = this.state.openToDate.getFullYear();
|
|
|
|
const month = this.state.openToDate.getMonth() + 1;
|
|
|
|
const days = new Date(year, month, 0).getDate();
|
|
|
|
let prevDays = new Date(year, month - 1, 0).getDate();
|
|
|
|
const arrayDays = [];
|
2019-08-28 12:53:38 +00:00
|
|
|
let className = "calendar-month_neighboringMonth";
|
|
|
|
|
2019-08-29 07:05:56 +00:00
|
|
|
const openToDate = this.state.openToDate;
|
|
|
|
const maxDate = this.props.maxDate;
|
|
|
|
const minDate = this.props.minDate;
|
2019-08-28 12:53:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
//Disable preview month
|
2019-08-29 07:05:56 +00:00
|
|
|
let disableClass = null;
|
|
|
|
if (openToDate.getFullYear() === minDate.getFullYear() && openToDate.getMonth() === minDate.getMonth()) {
|
|
|
|
disableClass = "calendar-month_disabled";
|
2019-08-28 12:53:38 +00:00
|
|
|
}
|
2019-08-23 12:23:22 +00:00
|
|
|
|
2019-08-30 07:46:51 +00:00
|
|
|
//prev month
|
|
|
|
let prevMonthDay = null;
|
|
|
|
if (openToDate.getFullYear() === minDate.getFullYear() && openToDate.getMonth() - 1 === minDate.getMonth()) {
|
|
|
|
prevMonthDay = minDate.getDate();
|
|
|
|
}
|
|
|
|
|
|
|
|
//prev month + year
|
|
|
|
let prevYearDay = null;
|
|
|
|
if (openToDate.getFullYear() === minDate.getFullYear() + 1 && openToDate.getMonth() === 0 && minDate.getMonth() === 11) {
|
|
|
|
prevYearDay = minDate.getDate();
|
|
|
|
}
|
|
|
|
|
2019-08-28 12:53:38 +00:00
|
|
|
// Show neighboring days in prev month
|
2019-08-26 07:11:59 +00:00
|
|
|
while (prevMonthDays != 0) {
|
2019-08-30 07:46:51 +00:00
|
|
|
if (prevDays + 1 === prevMonthDay) { disableClass = "calendar-month_disabled"; }
|
|
|
|
if (prevDays + 1 === prevYearDay) { disableClass = "calendar-month_disabled"; }
|
|
|
|
//console.log(prevDays);
|
2019-08-26 07:11:59 +00:00
|
|
|
arrayDays.unshift(
|
2019-08-29 07:05:56 +00:00
|
|
|
<Day key={--keys} className={disableClass} >
|
2019-08-28 12:53:38 +00:00
|
|
|
<AbbrDay
|
|
|
|
onClick={this.onDayClick.bind(this, keys)}
|
|
|
|
className={className} >
|
2019-08-26 07:11:59 +00:00
|
|
|
{prevDays--}
|
|
|
|
</AbbrDay>
|
|
|
|
</Day>
|
|
|
|
);
|
|
|
|
//console.log("loop");
|
2019-08-28 12:53:38 +00:00
|
|
|
prevMonthDays--;
|
2019-08-26 07:11:59 +00:00
|
|
|
}
|
2019-08-28 12:53:38 +00:00
|
|
|
keys = 0;
|
2019-08-26 07:11:59 +00:00
|
|
|
|
|
|
|
|
2019-08-28 12:53:38 +00:00
|
|
|
//Disable max days in month
|
2019-08-29 07:05:56 +00:00
|
|
|
let maxDay, minDay;
|
2019-08-29 13:33:10 +00:00
|
|
|
disableClass = null;
|
2019-08-29 07:05:56 +00:00
|
|
|
if (openToDate.getFullYear() === maxDate.getFullYear() && openToDate.getMonth() >= maxDate.getMonth()) {
|
|
|
|
if (openToDate.getMonth() === maxDate.getMonth()) { maxDay = maxDate.getDate(); }
|
2019-08-28 12:53:38 +00:00
|
|
|
else { maxDay = null; }
|
|
|
|
}
|
2019-08-26 07:11:59 +00:00
|
|
|
|
2019-08-28 12:53:38 +00:00
|
|
|
//Disable min days in month
|
2019-08-29 13:33:10 +00:00
|
|
|
if (openToDate.getFullYear() === minDate.getFullYear() && openToDate.getMonth() >= minDate.getMonth()) {
|
2019-08-29 07:05:56 +00:00
|
|
|
if (openToDate.getMonth() === minDate.getMonth()) { minDay = minDate.getDate(); }
|
2019-08-28 12:53:38 +00:00
|
|
|
else { minDay = null; }
|
|
|
|
}
|
2019-08-26 07:11:59 +00:00
|
|
|
|
2019-08-28 12:53:38 +00:00
|
|
|
// Show days in month and weekend days
|
2019-08-23 12:23:22 +00:00
|
|
|
let seven = 7;
|
|
|
|
const dateNow = this.state.selectedDate.getDate();
|
2019-08-28 12:53:38 +00:00
|
|
|
const temp = 1;
|
2019-08-26 07:11:59 +00:00
|
|
|
prevMonthDays = this.firstDayOfMonth();
|
|
|
|
|
2019-08-23 12:23:22 +00:00
|
|
|
for (let i = 1; i <= days; i++) {
|
2019-08-26 07:11:59 +00:00
|
|
|
if (i === (seven - prevMonthDays - temp)) { className = "calendar-month_weekend"; }
|
2019-08-23 12:23:22 +00:00
|
|
|
else if (i === (seven - prevMonthDays)) { seven += 7; className = "calendar-month_weekend"; }
|
|
|
|
else { className = "calendar-month"; }
|
2019-08-28 12:53:38 +00:00
|
|
|
if (i === dateNow && this.compareDays()) { className = "calendar-month_selected-day" }
|
2019-08-29 13:33:10 +00:00
|
|
|
if (i > maxDay || i < minDay) { disableClass = "calendar-month_disabled"; className = "calendar-month_disabled" }
|
2019-08-28 12:53:38 +00:00
|
|
|
else { disableClass = null; }
|
|
|
|
|
2019-08-23 12:23:22 +00:00
|
|
|
arrayDays.push(
|
2019-08-28 12:53:38 +00:00
|
|
|
<Day key={keys++} className={disableClass} >
|
2019-08-23 12:23:22 +00:00
|
|
|
<AbbrDay onClick={this.onDayClick.bind(this, i)} className={className}>{i}</AbbrDay>
|
|
|
|
</Day>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-08-28 12:53:38 +00:00
|
|
|
//Calculating neighboring days in next month
|
|
|
|
let maxDays = 42; // max days in month table
|
2019-08-23 12:23:22 +00:00
|
|
|
const firstDay = this.firstDayOfMonth();
|
|
|
|
if (firstDay > 5 && days >= 30) { maxDays += 7; }
|
2019-08-26 07:11:59 +00:00
|
|
|
else if (firstDay >= 5 && days > 30) { maxDays += 7; }
|
2019-08-28 12:53:38 +00:00
|
|
|
if (maxDays > 42) { maxDays -= 7; }
|
2019-08-23 12:23:22 +00:00
|
|
|
|
2019-08-28 12:53:38 +00:00
|
|
|
|
2019-08-30 07:46:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-08-28 12:53:38 +00:00
|
|
|
//Disable next month days
|
2019-08-29 07:05:56 +00:00
|
|
|
disableClass = null;
|
|
|
|
if (openToDate.getFullYear() === maxDate.getFullYear() && openToDate.getMonth() >= maxDate.getMonth()) {
|
|
|
|
disableClass = "calendar-month_disabled";
|
2019-08-28 12:53:38 +00:00
|
|
|
}
|
|
|
|
|
2019-08-30 07:46:51 +00:00
|
|
|
//next month + year
|
|
|
|
let nextYearDay = null;
|
|
|
|
if (openToDate.getFullYear() === maxDate.getFullYear() - 1 && openToDate.getMonth() === 11 && maxDate.getMonth() === 0) {
|
|
|
|
nextYearDay = maxDate.getDate();
|
|
|
|
}
|
|
|
|
|
|
|
|
//next month
|
|
|
|
let nextMonthDay = null;
|
|
|
|
if (openToDate.getFullYear() === maxDate.getFullYear() && openToDate.getMonth() === maxDate.getMonth() - 1) {
|
|
|
|
nextMonthDay = maxDate.getDate();
|
|
|
|
}
|
|
|
|
|
2019-08-28 12:53:38 +00:00
|
|
|
//Show neighboring days in next month
|
2019-08-23 12:23:22 +00:00
|
|
|
let nextDay = 1;
|
|
|
|
for (let i = days; i < maxDays - firstDay; i++) {
|
2019-08-30 07:46:51 +00:00
|
|
|
if (i - days === nextYearDay) { disableClass = "calendar-month_disabled" }
|
|
|
|
if (i - days === nextMonthDay) { disableClass = "calendar-month_disabled" }
|
2019-08-23 12:23:22 +00:00
|
|
|
arrayDays.push(
|
2019-08-29 07:05:56 +00:00
|
|
|
<Day key={keys++} className={disableClass} >
|
2019-08-28 12:53:38 +00:00
|
|
|
<AbbrDay
|
|
|
|
onClick={this.onDayClick.bind(this, i + 1)}
|
2019-08-30 07:46:51 +00:00
|
|
|
className={"calendar-month_neighboringMonth"} >
|
2019-08-23 12:23:22 +00:00
|
|
|
{nextDay++}
|
|
|
|
</AbbrDay>
|
|
|
|
</Day>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return arrayDays;
|
|
|
|
}
|
|
|
|
|
2019-08-29 13:33:10 +00:00
|
|
|
componentDidUpdate(prevProps) {
|
|
|
|
moment.locale(this.props.locale);
|
|
|
|
this.state.months = moment.months();
|
|
|
|
if (this.props.selectedDate !== prevProps.selectedDate ||
|
|
|
|
this.props.selectedDate !== prevProps.selectedDate) {
|
|
|
|
this.setState({
|
|
|
|
selectedDate: this.props.selectedDate,
|
|
|
|
openToDate: this.props.openToDate
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-23 12:23:22 +00:00
|
|
|
render() {
|
|
|
|
//console.log("render");
|
|
|
|
|
|
|
|
const disabled = this.props.disabled;
|
2019-08-29 13:33:10 +00:00
|
|
|
const scaled = this.props.scaled;
|
|
|
|
const dropDownSizeMonth = this.getListMonth().length > 4 ? 180 : undefined;
|
|
|
|
const dropDownSizeYear = this.getListMonth().length > 4 ? 180 : undefined;
|
2019-08-23 12:23:22 +00:00
|
|
|
|
|
|
|
return (
|
2019-08-29 13:33:10 +00:00
|
|
|
<CalendarStyle scaled={scaled} color={this.props.themeColor} disabled={disabled}>
|
2019-08-23 12:23:22 +00:00
|
|
|
<ComboBoxStyle>
|
|
|
|
<ComboBox
|
|
|
|
scaled={true}
|
2019-08-28 12:53:38 +00:00
|
|
|
dropDownMaxHeight={dropDownSizeMonth}
|
|
|
|
onSelect={this.onSelectMonth.bind(this)}
|
2019-08-23 12:23:22 +00:00
|
|
|
selectedOption={this.getCurrentMonth()}
|
2019-08-29 13:33:10 +00:00
|
|
|
options={this.getListMonth()}
|
2019-08-23 12:23:22 +00:00
|
|
|
isDisabled={disabled}
|
|
|
|
/>
|
|
|
|
<ComboBoxDateStyle>
|
|
|
|
<ComboBox
|
|
|
|
scaled={true}
|
2019-08-28 12:53:38 +00:00
|
|
|
dropDownMaxHeight={dropDownSizeYear}
|
|
|
|
onSelect={this.onSelectYear.bind(this)}
|
2019-08-23 12:23:22 +00:00
|
|
|
selectedOption={this.getCurrentYear()}
|
2019-08-29 13:33:10 +00:00
|
|
|
options={this.getArrayYears().reverse()}
|
2019-08-23 12:23:22 +00:00
|
|
|
isDisabled={disabled}
|
|
|
|
/>
|
|
|
|
</ComboBoxDateStyle>
|
|
|
|
</ComboBoxStyle>
|
|
|
|
<Month>
|
|
|
|
<Weekdays>
|
|
|
|
{this.getWeekDays()}
|
|
|
|
</Weekdays>
|
|
|
|
<Days>
|
|
|
|
{this.getDays()}
|
|
|
|
</Days>
|
|
|
|
</Month>
|
|
|
|
</CalendarStyle>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Calendar.propTypes = {
|
|
|
|
onChange: PropTypes.func,
|
|
|
|
themeColor: PropTypes.string,
|
|
|
|
selectedDate: PropTypes.instanceOf(Date),
|
|
|
|
openToDate: PropTypes.instanceOf(Date),
|
|
|
|
minDate: PropTypes.instanceOf(Date),
|
|
|
|
maxDate: PropTypes.instanceOf(Date),
|
2019-08-26 07:11:59 +00:00
|
|
|
locale: PropTypes.string,
|
|
|
|
disabled: PropTypes.bool,
|
2019-08-29 13:33:10 +00:00
|
|
|
scaled: PropTypes.bool
|
2019-08-23 12:23:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Calendar.defaultProps = {
|
|
|
|
selectedDate: new Date(),
|
|
|
|
openToDate: new Date(),
|
|
|
|
minDate: new Date("1970/01/01"),
|
|
|
|
maxDate: new Date("3000/01/01"),
|
|
|
|
themeColor: '#ED7309',
|
2019-08-26 07:11:59 +00:00
|
|
|
locale: moment.locale(),
|
2019-08-23 12:23:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default Calendar;
|