Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
javivelasco committed Nov 22, 2016
1 parent b6e21ca commit 0683e7d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
23 changes: 11 additions & 12 deletions components/date_picker/CalendarMonth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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}
Expand Down
6 changes: 3 additions & 3 deletions components/date_picker/DatePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion components/date_picker/DatePickerDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -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>
);
Expand Down

0 comments on commit 0683e7d

Please sign in to comment.