Refactor
parent
b6e21ca848
commit
0683e7dc4b
|
@ -25,22 +25,23 @@ class Month extends Component {
|
|||
viewDate: PropTypes.object
|
||||
};
|
||||
|
||||
static defaultProps = {
|
||||
disabledDates: [],
|
||||
enabledDates: []
|
||||
};
|
||||
|
||||
handleDayClick = (day) => {
|
||||
if (this.props.onDayClick) this.props.onDayClick(day);
|
||||
};
|
||||
|
||||
isDayDisabled (date) {
|
||||
const {minDate, maxDate, enabledDates, disabledDates} = this.props;
|
||||
const compareDate = compDate => date.getTime() === compDate.getTime();
|
||||
const dateInDisabled = disabledDates.filter(compareDate).length > 0;
|
||||
const dateInEnabled = enabledDates.filter(compareDate).length > 0;
|
||||
return time.dateOutOfRange(date, minDate, maxDate)
|
||||
|| (enabledDates && enabledDates.length > 0 && !this.findDate(date, enabledDates))
|
||||
|| (disabledDates && disabledDates.length > 0 && this.findDate(date, disabledDates));
|
||||
}
|
||||
|
||||
findDate (comparisonDate, dates){
|
||||
for (const date of dates){
|
||||
if (comparisonDate.getTime() === date.getTime()) return true;
|
||||
}
|
||||
return false;
|
||||
|| (enabledDates.length > 0 && !dateInEnabled)
|
||||
|| dateInDisabled;
|
||||
}
|
||||
|
||||
renderWeeks () {
|
||||
|
@ -52,13 +53,11 @@ class Month extends Component {
|
|||
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 = this.isDayDisabled(date);
|
||||
|
||||
return (
|
||||
<CalendarDay
|
||||
key={i}
|
||||
day={i}
|
||||
disabled={disabled}
|
||||
disabled={this.isDayDisabled(date)}
|
||||
onClick={this.handleDayClick}
|
||||
selectedDate={this.props.selectedDate}
|
||||
theme={this.props.theme}
|
||||
|
|
|
@ -107,9 +107,9 @@ const factory = (Input, DatePickerDialog) => {
|
|||
|
||||
render () {
|
||||
const { active, onDismiss,// eslint-disable-line
|
||||
autoOk, cancelLabel, enabledDates, disabledDates, inputClassName, inputFormat, locale, maxDate, minDate,
|
||||
okLabel, onEscKeyDown, onOverlayClick, readonly, sundayFirstDayOfWeek, value,
|
||||
...others } = this.props;
|
||||
autoOk, cancelLabel, enabledDates, disabledDates, inputClassName, inputFormat,
|
||||
locale, maxDate, minDate, okLabel, onEscKeyDown, onOverlayClick, readonly,
|
||||
sundayFirstDayOfWeek, value, ...others } = this.props;
|
||||
const finalInputFormat = inputFormat || time.formatDate;
|
||||
const date = Object.prototype.toString.call(value) === '[object Date]' ? value : undefined;
|
||||
const formattedDate = date === undefined ? '' : finalInputFormat(value, locale);
|
||||
|
|
|
@ -131,7 +131,8 @@ const factory = (Dialog, Calendar) => {
|
|||
selectedDate={this.state.date}
|
||||
theme={this.props.theme}
|
||||
locale={this.props.locale}
|
||||
sundayFirstDayOfWeek={this.props.sundayFirstDayOfWeek}/>
|
||||
sundayFirstDayOfWeek={this.props.sundayFirstDayOfWeek}
|
||||
/>
|
||||
</div>
|
||||
</Dialog>
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue