react-day-picker 8.8.0 → 8.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -7,6 +7,8 @@ interface CaptionProps {
7
7
  id?: string;
8
8
  /** The month where the caption is displayed. */
9
9
  displayMonth: Date;
10
+ /** The index of the month where the caption is displayed. Older custom components may miss this prop. */
11
+ displayIndex?: number | undefined;
10
12
  }
11
13
  /**
12
14
  * The layout of the caption:
@@ -28,6 +30,8 @@ interface CaptionLabelProps {
28
30
  id?: string;
29
31
  /** The month where the caption is displayed. */
30
32
  displayMonth: Date;
33
+ /** The index of the month where the caption is displayed. Older custom components may miss this prop. */
34
+ displayIndex?: number | undefined;
31
35
  }
32
36
  /** Render the caption for the displayed month. This component is used when `captionLayout="buttons"`. */
33
37
  declare function CaptionLabel(props: CaptionLabelProps): JSX.Element;
@@ -68,7 +72,7 @@ declare function Day(props: DayProps): JSX.Element;
68
72
  * // will match days after the 2nd of February 2019
69
73
  * const afterMatcher: DateAfter = { after: new Date(2019, 1, 2); };
70
74
  * // will match days before the 2nd of February 2019 }
71
- * const beforeMatcher: DateBefore = { before: : new Date(2019, 1, 2); };
75
+ * const beforeMatcher: DateBefore = { before: new Date(2019, 1, 2); };
72
76
  *
73
77
  * // will match Sundays
74
78
  * const dayOfWeekMatcher: DayOfWeek = {
@@ -632,7 +636,7 @@ interface DayPickerBase {
632
636
  ISOWeek?: boolean;
633
637
  /**
634
638
  * Map of components used to create the layout. Look at the [components
635
- * source](https://github.com/gpbl/react-day-picker/tree/master/packages/react-day-picker/src/components)
639
+ * source](https://github.com/gpbl/react-day-picker/tree/main/src/components)
636
640
  * to understand how internal components are built and provide your custom components.
637
641
  */
638
642
  components?: CustomComponents;
@@ -713,7 +717,7 @@ interface DayPickerBase {
713
717
  * Map of the components that can be changed using the `components` prop.
714
718
  *
715
719
  * Look at the [components
716
- * source](https://github.com/gpbl/react-day-picker/tree/master/packages/react-day-picker/src/components)
720
+ * source](https://github.com/gpbl/react-day-picker/tree/main/src/components)
717
721
  * to understand how internal components are built.
718
722
  */
719
723
  interface CustomComponents {
package/dist/index.esm.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import React__default, { createContext, useContext, useState, forwardRef, useEffect, useRef } from 'react';
3
- import { enUS } from 'date-fns/locale';
4
3
  import { format, startOfMonth, endOfMonth, startOfDay, isSameYear, setMonth, setYear, startOfYear, differenceInCalendarMonths, addMonths, isSameMonth, isBefore, startOfISOWeek, startOfWeek, addDays, isSameDay, isAfter, subDays, differenceInCalendarDays, isDate, max, min, addWeeks, addYears, endOfISOWeek, endOfWeek, getUnixTime, getISOWeek, getWeek, getWeeksInMonth, parse } from 'date-fns';
4
+ import { enUS } from 'date-fns/locale';
5
5
 
6
6
  /******************************************************************************
7
7
  Copyright (c) Microsoft Corporation.
@@ -49,7 +49,12 @@ function __spreadArray(to, from, pack) {
49
49
  }
50
50
  }
51
51
  return to.concat(ar || Array.prototype.slice.call(from));
52
- }
52
+ }
53
+
54
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
55
+ var e = new Error(message);
56
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
57
+ };
53
58
 
54
59
  /** Returns true when the props are of type {@link DayPickerMultipleProps}. */
55
60
  function isDayPickerMultiple(props) {
@@ -596,7 +601,7 @@ function CaptionDropdowns(props) {
596
601
  var _b = useDayPicker(), classNames = _b.classNames, styles = _b.styles, components = _b.components;
597
602
  var goToMonth = useNavigation().goToMonth;
598
603
  var handleMonthChange = function (newMonth) {
599
- goToMonth(newMonth);
604
+ goToMonth(addMonths(newMonth, props.displayIndex ? -props.displayIndex : 0));
600
605
  };
601
606
  var CaptionLabelComponent = (_a = components === null || components === void 0 ? void 0 : components.CaptionLabel) !== null && _a !== void 0 ? _a : CaptionLabel;
602
607
  var captionLabel = (React__default.createElement(CaptionLabelComponent, { id: props.id, displayMonth: props.displayMonth }));
@@ -704,12 +709,12 @@ function Caption(props) {
704
709
  }
705
710
  else if (captionLayout === 'dropdown-buttons') {
706
711
  caption = (React__default.createElement(React__default.Fragment, null,
707
- React__default.createElement(CaptionDropdowns, { displayMonth: props.displayMonth, id: props.id }),
708
- React__default.createElement(CaptionNavigation, { displayMonth: props.displayMonth, id: props.id })));
712
+ React__default.createElement(CaptionDropdowns, { displayMonth: props.displayMonth, displayIndex: props.displayIndex, id: props.id }),
713
+ React__default.createElement(CaptionNavigation, { displayMonth: props.displayMonth, displayIndex: props.displayIndex, id: props.id })));
709
714
  }
710
715
  else {
711
716
  caption = (React__default.createElement(React__default.Fragment, null,
712
- React__default.createElement(CaptionLabelComponent, { id: props.id, displayMonth: props.displayMonth }),
717
+ React__default.createElement(CaptionLabelComponent, { id: props.id, displayMonth: props.displayMonth, displayIndex: props.displayIndex }),
713
718
  React__default.createElement(CaptionNavigation, { displayMonth: props.displayMonth, id: props.id })));
714
719
  }
715
720
  return (React__default.createElement("div", { className: classNames.caption, style: styles.caption }, caption));
@@ -858,31 +863,34 @@ function useSelectMultiple() {
858
863
  */
859
864
  function addToRange(day, range) {
860
865
  var _a = range || {}, from = _a.from, to = _a.to;
861
- if (!from) {
862
- return { from: day, to: undefined };
863
- }
864
- if (!to && isSameDay(from, day)) {
866
+ if (from && to) {
867
+ if (isSameDay(to, day) && isSameDay(from, day)) {
868
+ return undefined;
869
+ }
870
+ if (isSameDay(to, day)) {
871
+ return { from: to, to: undefined };
872
+ }
873
+ if (isSameDay(from, day)) {
874
+ return undefined;
875
+ }
876
+ if (isAfter(from, day)) {
877
+ return { from: day, to: to };
878
+ }
865
879
  return { from: from, to: day };
866
880
  }
867
- if (!to && isBefore(day, from)) {
868
- return { from: day, to: from };
881
+ if (to) {
882
+ if (isAfter(day, to)) {
883
+ return { from: to, to: day };
884
+ }
885
+ return { from: day, to: to };
869
886
  }
870
- if (!to) {
887
+ if (from) {
888
+ if (isBefore(day, from)) {
889
+ return { from: day, to: from };
890
+ }
871
891
  return { from: from, to: day };
872
892
  }
873
- if (isSameDay(to, day) && isSameDay(from, day)) {
874
- return undefined;
875
- }
876
- if (isSameDay(to, day)) {
877
- return { from: to, to: undefined };
878
- }
879
- if (isSameDay(from, day)) {
880
- return undefined;
881
- }
882
- if (isAfter(from, day)) {
883
- return { from: day, to: to };
884
- }
885
- return { from: from, to: day };
893
+ return { from: day, to: undefined };
886
894
  }
887
895
 
888
896
  /**
@@ -943,6 +951,10 @@ function SelectRangeProviderInternal(_a) {
943
951
  }
944
952
  }
945
953
  }
954
+ else if (selectedTo) {
955
+ modifiers.range_start = [selectedTo];
956
+ modifiers.range_end = [selectedTo];
957
+ }
946
958
  if (min) {
947
959
  if (selectedFrom && !selectedTo) {
948
960
  modifiers.disabled.push({
@@ -956,6 +968,12 @@ function SelectRangeProviderInternal(_a) {
956
968
  before: addDays(selectedFrom, min - 1)
957
969
  });
958
970
  }
971
+ if (!selectedFrom && selectedTo) {
972
+ modifiers.disabled.push({
973
+ after: subDays(selectedTo, min - 1),
974
+ before: addDays(selectedTo, min - 1)
975
+ });
976
+ }
959
977
  }
960
978
  if (max) {
961
979
  if (selectedFrom && !selectedTo) {
@@ -976,6 +994,14 @@ function SelectRangeProviderInternal(_a) {
976
994
  after: addDays(selectedTo, offset)
977
995
  });
978
996
  }
997
+ if (!selectedFrom && selectedTo) {
998
+ modifiers.disabled.push({
999
+ before: addDays(selectedTo, -max + 1)
1000
+ });
1001
+ modifiers.disabled.push({
1002
+ after: addDays(selectedTo, max - 1)
1003
+ });
1004
+ }
979
1005
  }
980
1006
  return (React__default.createElement(SelectRangeContext.Provider, { value: { selected: selected, onDayClick: onDayClick, modifiers: modifiers } }, children));
981
1007
  }
@@ -1122,22 +1148,22 @@ function isDayOfWeekType(value) {
1122
1148
  function isDateInRange(date, range) {
1123
1149
  var _a;
1124
1150
  var from = range.from, to = range.to;
1125
- if (!from) {
1126
- return false;
1127
- }
1128
- if (!to && isSameDay(from, date)) {
1129
- return true;
1151
+ if (from && to) {
1152
+ var isRangeInverted = differenceInCalendarDays(to, from) < 0;
1153
+ if (isRangeInverted) {
1154
+ _a = [to, from], from = _a[0], to = _a[1];
1155
+ }
1156
+ var isInRange = differenceInCalendarDays(date, from) >= 0 &&
1157
+ differenceInCalendarDays(to, date) >= 0;
1158
+ return isInRange;
1130
1159
  }
1131
- if (!to) {
1132
- return false;
1160
+ if (to) {
1161
+ return isSameDay(to, date);
1133
1162
  }
1134
- var isRangeInverted = differenceInCalendarDays(to, from) < 0;
1135
- if (isRangeInverted) {
1136
- _a = [to, from], from = _a[0], to = _a[1];
1163
+ if (from) {
1164
+ return isSameDay(from, date);
1137
1165
  }
1138
- var isInRange = differenceInCalendarDays(date, from) >= 0 &&
1139
- differenceInCalendarDays(to, date) >= 0;
1140
- return isInRange;
1166
+ return false;
1141
1167
  }
1142
1168
 
1143
1169
  /** Returns true if `value` is a Date type. */
@@ -1853,7 +1879,7 @@ function Table(props) {
1853
1879
  var FooterComponent = (_c = components === null || components === void 0 ? void 0 : components.Footer) !== null && _c !== void 0 ? _c : Footer;
1854
1880
  return (React__default.createElement("table", { id: props.id, className: classNames.table, style: styles.table, role: "grid", "aria-labelledby": props['aria-labelledby'] },
1855
1881
  !hideHead && React__default.createElement(HeadComponent, null),
1856
- React__default.createElement("tbody", { className: classNames.tbody, style: styles.tbody, role: "rowgroup" }, weeks.map(function (week) { return (React__default.createElement(RowComponent, { displayMonth: props.displayMonth, key: week.weekNumber, dates: week.dates, weekNumber: week.weekNumber })); })),
1882
+ React__default.createElement("tbody", { className: classNames.tbody, style: styles.tbody }, weeks.map(function (week) { return (React__default.createElement(RowComponent, { displayMonth: props.displayMonth, key: week.weekNumber, dates: week.dates, weekNumber: week.weekNumber })); })),
1857
1883
  React__default.createElement(FooterComponent, { displayMonth: props.displayMonth })));
1858
1884
  }
1859
1885
 
@@ -1967,7 +1993,7 @@ function Month(props) {
1967
1993
  }
1968
1994
  var CaptionComponent = (_b = components === null || components === void 0 ? void 0 : components.Caption) !== null && _b !== void 0 ? _b : Caption;
1969
1995
  return (React__default.createElement("div", { key: props.displayIndex, className: className.join(' '), style: style },
1970
- React__default.createElement(CaptionComponent, { id: captionId, displayMonth: props.displayMonth }),
1996
+ React__default.createElement(CaptionComponent, { id: captionId, displayMonth: props.displayMonth, displayIndex: props.displayIndex }),
1971
1997
  React__default.createElement(Table, { id: tableId, "aria-labelledby": captionId, displayMonth: props.displayMonth })));
1972
1998
  }
1973
1999