Skip to content

Commit 22067f5

Browse files
committed
Build lib
1 parent f828b8e commit 22067f5

10 files changed

+363
-211
lines changed

lib/daypicker.js

Lines changed: 75 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,8 @@
358358
exports.clone = clone;
359359
exports.addMonths = addMonths;
360360
exports.isSameDay = isSameDay;
361+
exports.isDayBefore = isDayBefore;
362+
exports.isDayAfter = isDayAfter;
361363
exports.isPastDay = isPastDay;
362364
exports.isFutureDay = isFutureDay;
363365
exports.isDayBetween = isDayBetween;
@@ -402,6 +404,34 @@
402404
);
403405
}
404406

407+
/**
408+
* Returns `true` if the first day is before the second day.
409+
*
410+
* @export
411+
* @param {Date} d1
412+
* @param {Date} d2
413+
* @returns {Boolean}
414+
*/
415+
function isDayBefore(d1, d2) {
416+
var day1 = clone(d1).setHours(0, 0, 0, 0);
417+
var day2 = clone(d2).setHours(0, 0, 0, 0);
418+
return day1 < day2;
419+
}
420+
421+
/**
422+
* Returns `true` if the first day is after the second day.
423+
*
424+
* @export
425+
* @param {Date} d1
426+
* @param {Date} d2
427+
* @returns {Boolean}
428+
*/
429+
function isDayAfter(d1, d2) {
430+
var day1 = clone(d1).setHours(0, 0, 0, 0);
431+
var day2 = clone(d2).setHours(0, 0, 0, 0);
432+
return day1 > day2;
433+
}
434+
405435
/**
406436
* Return `true` if a day is in the past, e.g. yesterday or any day
407437
* before yesterday.
@@ -412,7 +442,7 @@
412442
function isPastDay(d) {
413443
var today = new Date();
414444
today.setHours(0, 0, 0, 0);
415-
return d < today;
445+
return isDayBefore(d, today);
416446
}
417447

418448
/**
@@ -439,14 +469,10 @@
439469
*/
440470
function isDayBetween(d, d1, d2) {
441471
var date = clone(d);
442-
var date1 = clone(d1);
443-
var date2 = clone(d2);
444-
445472
date.setHours(0, 0, 0, 0);
446-
date1.setHours(0, 0, 0, 0);
447-
date2.setHours(0, 0, 0, 0);
448473
return (
449-
(date1 < date && date < date2) || (date2 < date && date < date1)
474+
(isDayAfter(date, d1) && isDayBefore(date, d2)) ||
475+
(isDayAfter(date, d2) && isDayBefore(date, d1))
450476
);
451477
}
452478

@@ -467,18 +493,21 @@
467493
if (!from) {
468494
from = day;
469495
} else if (
470-
from && to && isSameDay(from, to) && isSameDay(day, from)
496+
from &&
497+
to &&
498+
isSameDay(from, to) &&
499+
isSameDay(day, from)
471500
) {
472501
from = null;
473502
to = null;
474-
} else if (to && day < from) {
503+
} else if (to && isDayBefore(day, from)) {
475504
from = day;
476505
} else if (to && isSameDay(day, to)) {
477506
from = day;
478507
to = day;
479508
} else {
480509
to = day;
481-
if (to < from) {
510+
if (isDayBefore(to, from)) {
482511
to = from;
483512
from = day;
484513
}
@@ -1028,25 +1057,35 @@
10281057
return (0, _DateUtils.isDayInRange)(d, range);
10291058
}
10301059
if (day.after) {
1031-
return d > day.after;
1060+
return (0, _DateUtils.isDayAfter)(d, day.after);
10321061
}
10331062
if (day.before) {
1034-
return d < day.before;
1063+
return (0, _DateUtils.isDayBefore)(d, day.before);
1064+
}
1065+
if (typeof day === 'function' && day(d)) {
1066+
return true;
10351067
}
10361068
return false;
10371069
})
10381070
) {
10391071
modifiers.push(modifier);
10401072
}
10411073
} else if (
1042-
isRangeOfDates(value) && (0, _DateUtils.isDayInRange)(d, value)
1074+
isRangeOfDates(value) &&
1075+
(0, _DateUtils.isDayInRange)(d, value)
10431076
) {
10441077
// modifier's value is a range
10451078
modifiers.push(modifier);
1046-
} else if (value.after && d > value.after) {
1079+
} else if (
1080+
value.after &&
1081+
(0, _DateUtils.isDayAfter)(d, value.after)
1082+
) {
10471083
// modifier's value has an after date
10481084
modifiers.push(modifier);
1049-
} else if (value.before && d < value.before) {
1085+
} else if (
1086+
value.before &&
1087+
(0, _DateUtils.isDayBefore)(d, value.before)
1088+
) {
10501089
// modifier's value has an after date
10511090
modifiers.push(modifier);
10521091
} else if (typeof value === 'function' && value(d)) {
@@ -1886,6 +1925,7 @@
18861925
classNames: this.props.classNames,
18871926
day: day,
18881927
modifiers: modifiers,
1928+
modifiersStyles: this.props.modifiersStyles,
18891929
empty: isOutside &&
18901930
!this.props.enableOutsideDays &&
18911931
!this.props.fixedWeeks,
@@ -1990,7 +2030,7 @@
19902030
return DayPicker;
19912031
})(_react.Component);
19922032

1993-
DayPicker.VERSION = '5.2.3';
2033+
DayPicker.VERSION = '5.3.0';
19942034
DayPicker.propTypes = {
19952035
// Rendering months
19962036
initialMonth: _PropTypes2.default.instanceOf(Date),
@@ -2011,7 +2051,9 @@
20112051
_PropTypes.ModifierPropType,
20122052
_PropTypes2.default.arrayOf(_PropTypes.ModifierPropType),
20132053
]),
2054+
20142055
modifiers: _PropTypes2.default.object,
2056+
modifiersStyles: _PropTypes2.default.object,
20152057

20162058
// Localization
20172059
dir: _PropTypes2.default.string,
@@ -2258,6 +2300,7 @@
22582300

22592301
function Day(_ref) {
22602302
var classNames = _ref.classNames,
2303+
modifiersStyles = _ref.modifiersStyles,
22612304
day = _ref.day,
22622305
tabIndex = _ref.tabIndex,
22632306
empty = _ref.empty,
@@ -2285,18 +2328,33 @@
22852328
})
22862329
.join('');
22872330
}
2331+
2332+
var style = void 0;
2333+
if (modifiersStyles) {
2334+
Object.keys(modifiers)
2335+
.filter(function(modifier) {
2336+
return !!modifiersStyles[modifier];
2337+
})
2338+
.forEach(function(modifier) {
2339+
style = Object.assign({}, style, modifiersStyles[modifier]);
2340+
});
2341+
}
2342+
22882343
if (empty) {
22892344
return _react2.default.createElement('div', {
22902345
role: 'gridcell',
22912346
'aria-disabled': true,
22922347
className: className,
2348+
style: style,
22932349
});
22942350
}
2351+
22952352
return _react2.default.createElement(
22962353
'div',
22972354
{
22982355
className: className,
22992356
tabIndex: tabIndex,
2357+
style: style,
23002358
role: 'gridcell',
23012359
'aria-label': ariaLabel,
23022360
'aria-disabled': ariaDisabled.toString(),
@@ -2326,6 +2384,7 @@
23262384
ariaSelected: _PropTypes2.default.bool,
23272385
empty: _PropTypes2.default.bool,
23282386
modifiers: _PropTypes2.default.object,
2387+
modifiersStyles: _PropTypes2.default.object,
23292388
onClick: _PropTypes2.default.func,
23302389
onKeyDown: _PropTypes2.default.func,
23312390
onMouseEnter: _PropTypes2.default.func,

0 commit comments

Comments
 (0)