react-day-picker 8.0.0-beta.32 → 8.0.0-beta.33

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.
Files changed (241) hide show
  1. package/CHANGELOG.md +12 -3
  2. package/build/DayPicker.d.ts +3 -2
  3. package/build/DayPicker.js +6 -5
  4. package/build/DayPicker.js.map +1 -1
  5. package/build/components/Button/Button.d.ts +1 -1
  6. package/build/components/Button/Button.js +1 -1
  7. package/build/components/Button/Button.js.map +1 -1
  8. package/build/components/Caption/Caption.d.ts +7 -0
  9. package/build/components/Caption/Caption.js +8 -8
  10. package/build/components/Caption/Caption.js.map +1 -1
  11. package/build/components/CaptionLabel/CaptionLabel.js +1 -1
  12. package/build/components/CaptionLabel/CaptionLabel.js.map +1 -1
  13. package/build/components/Day/Day.js +1 -1
  14. package/build/components/Day/Day.js.map +1 -1
  15. package/build/components/Day/hooks/useDay.d.ts +2 -2
  16. package/build/components/Day/hooks/useDay.js +5 -5
  17. package/build/components/Day/hooks/useDay.js.map +1 -1
  18. package/build/components/Day/hooks/useDayFocus.d.ts +1 -1
  19. package/build/components/Day/hooks/useDayFocus.js +1 -1
  20. package/build/components/Day/hooks/useDayFocus.js.map +1 -1
  21. package/build/components/DayContent/DayContent.js +1 -1
  22. package/build/components/DayContent/DayContent.js.map +1 -1
  23. package/build/components/Dropdown/Dropdown.d.ts +1 -1
  24. package/build/components/Dropdown/Dropdown.js +1 -1
  25. package/build/components/Dropdown/Dropdown.js.map +1 -1
  26. package/build/components/Footer/Footer.js +1 -1
  27. package/build/components/Footer/Footer.js.map +1 -1
  28. package/build/components/Head/Head.js +1 -1
  29. package/build/components/Head/Head.js.map +1 -1
  30. package/build/components/IconDropdown/IconDropdown.d.ts +2 -2
  31. package/build/components/IconDropdown/IconDropdown.js +1 -1
  32. package/build/components/IconDropdown/IconDropdown.js.map +1 -1
  33. package/build/components/IconLeft/IconLeft.d.ts +2 -2
  34. package/build/components/IconLeft/IconLeft.js +3 -3
  35. package/build/components/IconLeft/IconLeft.js.map +1 -1
  36. package/build/components/IconRight/IconRight.d.ts +2 -2
  37. package/build/components/IconRight/IconRight.js +3 -3
  38. package/build/components/IconRight/IconRight.js.map +1 -1
  39. package/build/components/MonthsDropdown/MonthsDropdown.d.ts +1 -1
  40. package/build/components/MonthsDropdown/MonthsDropdown.js +1 -1
  41. package/build/components/MonthsDropdown/MonthsDropdown.js.map +1 -1
  42. package/build/components/Navigation/Navigation.d.ts +1 -1
  43. package/build/components/Navigation/Navigation.js +1 -1
  44. package/build/components/Navigation/Navigation.js.map +1 -1
  45. package/build/components/Root/Root.js +1 -2
  46. package/build/components/Root/Root.js.map +1 -1
  47. package/build/components/Row/Row.js +1 -1
  48. package/build/components/Row/Row.js.map +1 -1
  49. package/build/components/Table/Table.js +1 -1
  50. package/build/components/Table/Table.js.map +1 -1
  51. package/build/components/WeekNumber/WeekNumber.js +1 -1
  52. package/build/components/WeekNumber/WeekNumber.js.map +1 -1
  53. package/build/components/YearsDropdown/YearsDropdown.d.ts +1 -1
  54. package/build/components/YearsDropdown/YearsDropdown.js +1 -1
  55. package/build/components/YearsDropdown/YearsDropdown.js.map +1 -1
  56. package/build/contexts/DayPicker/DayPickerContext.d.ts +3 -2
  57. package/build/contexts/DayPicker/DayPickerContext.js +1 -1
  58. package/build/contexts/DayPicker/DayPickerContext.js.map +1 -1
  59. package/build/contexts/DayPicker/DayPickerProvider.d.ts +1 -1
  60. package/build/contexts/DayPicker/DayPickerProvider.js +1 -1
  61. package/build/contexts/DayPicker/DayPickerProvider.js.map +1 -1
  62. package/build/contexts/DayPicker/defaultClassNames.js +1 -3
  63. package/build/contexts/DayPicker/defaultClassNames.js.map +1 -1
  64. package/build/contexts/DayPicker/labels/labelDay.d.ts +2 -2
  65. package/build/contexts/DayPicker/labels/labelDay.js +1 -1
  66. package/build/contexts/DayPicker/labels/labelDay.js.map +1 -1
  67. package/build/contexts/DayPicker/labels/labelNext.d.ts +2 -2
  68. package/build/contexts/DayPicker/labels/labelNext.js.map +1 -1
  69. package/build/contexts/DayPicker/labels/labelPrevious.d.ts +2 -2
  70. package/build/contexts/DayPicker/labels/labelPrevious.js.map +1 -1
  71. package/build/contexts/DayPicker/labels/labelWeekNumber.d.ts +2 -2
  72. package/build/contexts/DayPicker/labels/labelWeekNumber.js.map +1 -1
  73. package/build/contexts/DayPicker/labels/labelWeekday.d.ts +2 -2
  74. package/build/contexts/DayPicker/labels/labelWeekday.js.map +1 -1
  75. package/build/contexts/DayPicker/useDayPicker.js +1 -1
  76. package/build/contexts/DayPicker/useDayPicker.js.map +1 -1
  77. package/build/contexts/DayPicker/utils/parseModifierProps.js +1 -0
  78. package/build/contexts/DayPicker/utils/parseModifierProps.js.map +1 -1
  79. package/build/contexts/Focus/FocusContext.d.ts +5 -1
  80. package/build/contexts/Focus/FocusContext.js +63 -3
  81. package/build/contexts/Focus/FocusContext.js.map +1 -1
  82. package/build/contexts/Focus/index.d.ts +0 -1
  83. package/build/contexts/Focus/useFocus.js +1 -1
  84. package/build/contexts/Focus/useFocus.js.map +1 -1
  85. package/build/contexts/Navigation/NavigationContext.d.ts +5 -1
  86. package/build/contexts/Navigation/NavigationContext.js +23 -3
  87. package/build/contexts/Navigation/NavigationContext.js.map +1 -1
  88. package/build/contexts/Navigation/index.d.ts +0 -1
  89. package/build/contexts/Navigation/useNavigation.js +1 -1
  90. package/build/contexts/Navigation/useNavigation.js.map +1 -1
  91. package/build/contexts/RootProvider.d.ts +8 -0
  92. package/build/contexts/{ContextProvider.js → RootProvider.js} +9 -14
  93. package/build/contexts/RootProvider.js.map +1 -0
  94. package/build/contexts/SelectMultiple/SelectMultipleContext.d.ts +14 -2
  95. package/build/contexts/SelectMultiple/SelectMultipleContext.js +73 -3
  96. package/build/contexts/SelectMultiple/SelectMultipleContext.js.map +1 -1
  97. package/build/contexts/SelectMultiple/index.d.ts +0 -1
  98. package/build/contexts/SelectMultiple/useSelectMultiple.js +1 -1
  99. package/build/contexts/SelectMultiple/useSelectMultiple.js.map +1 -1
  100. package/build/contexts/SelectRange/SelectRangeContext.d.ts +14 -3
  101. package/build/contexts/SelectRange/SelectRangeContext.js +114 -3
  102. package/build/contexts/SelectRange/SelectRangeContext.js.map +1 -1
  103. package/build/contexts/SelectRange/index.d.ts +0 -1
  104. package/build/contexts/SelectRange/useSelectRange.js +1 -1
  105. package/build/contexts/SelectRange/useSelectRange.js.map +1 -1
  106. package/build/contexts/SelectSingle/SelectSingleContext.d.ts +17 -3
  107. package/build/contexts/SelectSingle/SelectSingleContext.js +36 -3
  108. package/build/contexts/SelectSingle/SelectSingleContext.js.map +1 -1
  109. package/build/contexts/SelectSingle/index.d.ts +0 -1
  110. package/build/contexts/SelectSingle/useSelectSingle.js +1 -1
  111. package/build/contexts/SelectSingle/useSelectSingle.js.map +1 -1
  112. package/build/contexts/index.d.ts +1 -1
  113. package/build/hooks/useControlledValue/useControlledValue.js +2 -2
  114. package/build/hooks/useControlledValue/useControlledValue.js.map +1 -1
  115. package/build/hooks/useInput/useInput.d.ts +11 -32
  116. package/build/hooks/useInput/useInput.js +2 -4
  117. package/build/hooks/useInput/useInput.js.map +1 -1
  118. package/build/hooks/useModifiers/useModifiers.js +3 -5
  119. package/build/hooks/useModifiers/useModifiers.js.map +1 -1
  120. package/build/hooks/useModifiers/utils/isDateInRange.d.ts +1 -1
  121. package/build/hooks/useModifiers/utils/isDateInRange.js.map +1 -1
  122. package/build/hooks/useModifiers/utils/isMatch.d.ts +1 -1
  123. package/build/hooks/useModifiers/utils/isMatch.js +10 -8
  124. package/build/hooks/useModifiers/utils/isMatch.js.map +1 -1
  125. package/build/main.js +11 -22
  126. package/build/main.js.map +1 -1
  127. package/build/types/{DayPickerProps.d.ts → DayPicker.d.ts} +35 -16
  128. package/build/types/DayPickerCustom.d.ts +11 -0
  129. package/build/types/{isDayPickerCustom.js → DayPickerCustom.js} +1 -1
  130. package/build/types/DayPickerCustom.js.map +1 -0
  131. package/build/types/{DayPickerMultipleProps.d.ts → DayPickerMultiple.d.ts} +5 -5
  132. package/build/types/{isDayPickerMultiple.js → DayPickerMultiple.js} +1 -1
  133. package/build/types/DayPickerMultiple.js.map +1 -0
  134. package/build/types/{DayPickerRangeProps.d.ts → DayPickerRange.d.ts} +6 -6
  135. package/build/types/{isDayPickerRange.js → DayPickerRange.js} +1 -1
  136. package/build/types/DayPickerRange.js.map +1 -0
  137. package/build/types/DayPickerSingle.d.ts +14 -0
  138. package/build/types/{isDayPickerSingle.js → DayPickerSingle.js} +1 -1
  139. package/build/types/DayPickerSingle.js.map +1 -0
  140. package/build/types/EventHandlers.d.ts +51 -0
  141. package/build/types/Formatters.d.ts +10 -5
  142. package/build/types/Labels.d.ts +24 -12
  143. package/build/types/Matchers.d.ts +34 -0
  144. package/build/types/Matchers.js +27 -0
  145. package/build/types/Matchers.js.map +1 -0
  146. package/build/types/Modifiers.d.ts +15 -4
  147. package/build/types/Styles.d.ts +83 -2
  148. package/build/types/index.d.ts +7 -50
  149. package/dist/main.js +555 -589
  150. package/dist/main.js.map +1 -1
  151. package/package.json +3 -2
  152. package/build/contexts/ContextProvider.d.ts +0 -8
  153. package/build/contexts/ContextProvider.js.map +0 -1
  154. package/build/contexts/Focus/FocusProvider.d.ts +0 -5
  155. package/build/contexts/Focus/FocusProvider.js +0 -66
  156. package/build/contexts/Focus/FocusProvider.js.map +0 -1
  157. package/build/contexts/Navigation/NavigationProvider.d.ts +0 -5
  158. package/build/contexts/Navigation/NavigationProvider.js +0 -26
  159. package/build/contexts/Navigation/NavigationProvider.js.map +0 -1
  160. package/build/contexts/SelectMultiple/SelectMultipleProvider.d.ts +0 -9
  161. package/build/contexts/SelectMultiple/SelectMultipleProvider.js +0 -23
  162. package/build/contexts/SelectMultiple/SelectMultipleProvider.js.map +0 -1
  163. package/build/contexts/SelectMultiple/SelectMultipleProviderInternal.d.ts +0 -8
  164. package/build/contexts/SelectMultiple/SelectMultipleProviderInternal.js +0 -61
  165. package/build/contexts/SelectMultiple/SelectMultipleProviderInternal.js.map +0 -1
  166. package/build/contexts/SelectRange/SelectRangeProvider.d.ts +0 -9
  167. package/build/contexts/SelectRange/SelectRangeProvider.js +0 -26
  168. package/build/contexts/SelectRange/SelectRangeProvider.js.map +0 -1
  169. package/build/contexts/SelectRange/SelectRangeProviderInternal.d.ts +0 -8
  170. package/build/contexts/SelectRange/SelectRangeProviderInternal.js +0 -99
  171. package/build/contexts/SelectRange/SelectRangeProviderInternal.js.map +0 -1
  172. package/build/contexts/SelectSingle/SelectSingleProvider.d.ts +0 -9
  173. package/build/contexts/SelectSingle/SelectSingleProvider.js +0 -20
  174. package/build/contexts/SelectSingle/SelectSingleProvider.js.map +0 -1
  175. package/build/contexts/SelectSingle/SelectSingleProviderInternal.d.ts +0 -8
  176. package/build/contexts/SelectSingle/SelectSingleProviderInternal.js +0 -27
  177. package/build/contexts/SelectSingle/SelectSingleProviderInternal.js.map +0 -1
  178. package/build/types/CaptionLayout.d.ts +0 -7
  179. package/build/types/ClassNames.d.ts +0 -3
  180. package/build/types/Components.d.ts +0 -39
  181. package/build/types/CustomModifiers.d.ts +0 -4
  182. package/build/types/DateAfter.d.ts +0 -7
  183. package/build/types/DateBefore.d.ts +0 -7
  184. package/build/types/DateFormatter.d.ts +0 -6
  185. package/build/types/DateInterval.d.ts +0 -8
  186. package/build/types/DateRange.d.ts +0 -8
  187. package/build/types/DayClickEventHandler.d.ts +0 -6
  188. package/build/types/DayFocusEventHandler.d.ts +0 -6
  189. package/build/types/DayKeyboardEventHandler.d.ts +0 -6
  190. package/build/types/DayLabelFormatter.d.ts +0 -7
  191. package/build/types/DayMouseEventHandler.d.ts +0 -6
  192. package/build/types/DayOfWeekMatcher.d.ts +0 -7
  193. package/build/types/DayPickerCustomProps.d.ts +0 -11
  194. package/build/types/DayPickerSingleProps.d.ts +0 -14
  195. package/build/types/DayTouchEventHandler.d.ts +0 -6
  196. package/build/types/InternalModifier.d.ts +0 -2
  197. package/build/types/Matcher.d.ts +0 -10
  198. package/build/types/Modifier.d.ts +0 -5
  199. package/build/types/ModifierClassNames.d.ts +0 -5
  200. package/build/types/ModifierStatus.d.ts +0 -5
  201. package/build/types/ModifierStyles.d.ts +0 -4
  202. package/build/types/MonthChangeEventHandler.d.ts +0 -4
  203. package/build/types/NavButtonLabelFormatter.d.ts +0 -7
  204. package/build/types/SelectMultipleEventHandler.d.ts +0 -12
  205. package/build/types/SelectRangeEventHandler.d.ts +0 -10
  206. package/build/types/SelectSingleEventHandler.d.ts +0 -12
  207. package/build/types/StyledComponentProps.d.ts +0 -10
  208. package/build/types/StyledElement.d.ts +0 -76
  209. package/build/types/WeekNumberClickEventHandler.d.ts +0 -9
  210. package/build/types/WeekNumberFormatter.d.ts +0 -6
  211. package/build/types/WeekNumberLabelFormatter.d.ts +0 -5
  212. package/build/types/WeekdayLabelFormatter.d.ts +0 -4
  213. package/build/types/isArrayOfDates.d.ts +0 -2
  214. package/build/types/isArrayOfDates.js +0 -9
  215. package/build/types/isArrayOfDates.js.map +0 -1
  216. package/build/types/isDateAfterType.d.ts +0 -3
  217. package/build/types/isDateAfterType.js +0 -7
  218. package/build/types/isDateAfterType.js.map +0 -1
  219. package/build/types/isDateBeforeType.d.ts +0 -3
  220. package/build/types/isDateBeforeType.js +0 -7
  221. package/build/types/isDateBeforeType.js.map +0 -1
  222. package/build/types/isDateInterval.d.ts +0 -3
  223. package/build/types/isDateInterval.js +0 -10
  224. package/build/types/isDateInterval.js.map +0 -1
  225. package/build/types/isDateRange.d.ts +0 -3
  226. package/build/types/isDateRange.js +0 -8
  227. package/build/types/isDateRange.js.map +0 -1
  228. package/build/types/isDateType.d.ts +0 -2
  229. package/build/types/isDateType.js +0 -9
  230. package/build/types/isDateType.js.map +0 -1
  231. package/build/types/isDayOfWeekType.d.ts +0 -3
  232. package/build/types/isDayOfWeekType.js +0 -7
  233. package/build/types/isDayOfWeekType.js.map +0 -1
  234. package/build/types/isDayPickerCustom.d.ts +0 -4
  235. package/build/types/isDayPickerCustom.js.map +0 -1
  236. package/build/types/isDayPickerMultiple.d.ts +0 -4
  237. package/build/types/isDayPickerMultiple.js.map +0 -1
  238. package/build/types/isDayPickerRange.d.ts +0 -4
  239. package/build/types/isDayPickerRange.js.map +0 -1
  240. package/build/types/isDayPickerSingle.d.ts +0 -4
  241. package/build/types/isDayPickerSingle.js.map +0 -1
@@ -1,11 +1,31 @@
1
- import * as React from 'react';
1
+ import React from 'react';
2
+ import { useDayPicker } from '../DayPicker/useDayPicker.js';
3
+ import { useNavigationState } from './useNavigationState.js';
4
+ import { getDisplayMonths } from './utils/getDisplayMonths.js';
5
+ import { getNextMonth } from './utils/getNextMonth.js';
6
+ import { getPreviousMonth } from './utils/getPreviousMonth.js';
2
7
 
3
8
  /**
4
9
  * The Navigation context shares details about the months being navigated in DayPicker.
5
10
  *
6
11
  * Access this context from the [[useNavigation]] hook.
7
12
  */
8
- var NavigationContext = React.createContext(undefined);
13
+ var NavigationContext = React.createContext(undefined);
14
+ /** Provides the values for the [[NavigationContext]]. */
15
+ function NavigationProvider(props) {
16
+ var context = useDayPicker();
17
+ var _a = useNavigationState(), month = _a[0], goToMonth = _a[1];
18
+ var displayMonths = getDisplayMonths(month, context);
19
+ var nextMonth = getNextMonth(month, context);
20
+ var previousMonth = getPreviousMonth(month, context);
21
+ return (React.createElement(NavigationContext.Provider, { value: {
22
+ month: month,
23
+ displayMonths: displayMonths,
24
+ goToMonth: goToMonth,
25
+ previousMonth: previousMonth,
26
+ nextMonth: nextMonth
27
+ } }, props.children));
28
+ }
9
29
 
10
- export { NavigationContext };
30
+ export { NavigationContext, NavigationProvider };
11
31
  //# sourceMappingURL=NavigationContext.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"NavigationContext.js","sources":["../../../src/contexts/Navigation/NavigationContext.ts"],"sourcesContent":["import * as React from 'react';\n\n/** Represents the value of the [[NavigationContext]]. */\nexport interface NavigationContextValue {\n /** The current month. Note that when `numberOfMonths > 1` represent the first month in the displayed months. */\n month: Date;\n /** The months to display, according to `numberOfMonths`. */\n displayMonths: Date[];\n /** Navigate to the specified month. */\n goToMonth: (month: Date) => void;\n /** The next month to display. `undefined` if no months left */\n nextMonth?: Date;\n /** The previous month to display. `undefined` if no months left */\n previousMonth?: Date;\n}\n\n/**\n * The Navigation context shares details about the months being navigated in DayPicker.\n *\n * Access this context from the [[useNavigation]] hook.\n */\nexport const NavigationContext = React.createContext<\n NavigationContextValue | undefined\n>(undefined);\n"],"names":[],"mappings":";;AAgBA;;;;;IAKa,iBAAiB,GAAG,KAAK,CAAC,aAAa,CAElD,SAAS;;;;"}
1
+ {"version":3,"file":"NavigationContext.js","sources":["../../../src/contexts/Navigation/NavigationContext.tsx"],"sourcesContent":["import React from 'react';\n\nimport { useDayPicker } from '../DayPicker';\nimport { useNavigationState } from './useNavigationState';\nimport { getDisplayMonths } from './utils/getDisplayMonths';\nimport { getNextMonth } from './utils/getNextMonth';\nimport { getPreviousMonth } from './utils/getPreviousMonth';\n\n/** Represents the value of the [[NavigationContext]]. */\nexport interface NavigationContextValue {\n /** The current month. Note that when `numberOfMonths > 1` represent the first month in the displayed months. */\n month: Date;\n /** The months to display, according to `numberOfMonths`. */\n displayMonths: Date[];\n /** Navigate to the specified month. */\n goToMonth: (month: Date) => void;\n /** The next month to display. `undefined` if no months left */\n nextMonth?: Date;\n /** The previous month to display. `undefined` if no months left */\n previousMonth?: Date;\n}\n\n/**\n * The Navigation context shares details about the months being navigated in DayPicker.\n *\n * Access this context from the [[useNavigation]] hook.\n */\nexport const NavigationContext = React.createContext<\n NavigationContextValue | undefined\n>(undefined);\n\n/** Provides the values for the [[NavigationContext]]. */\nexport function NavigationProvider(props: {\n children?: React.ReactNode;\n}): JSX.Element {\n const context = useDayPicker();\n const [month, goToMonth] = useNavigationState();\n\n const displayMonths = getDisplayMonths(month, context);\n const nextMonth = getNextMonth(month, context);\n const previousMonth = getPreviousMonth(month, context);\n\n return (\n <NavigationContext.Provider\n value={{\n month,\n displayMonths,\n goToMonth,\n previousMonth,\n nextMonth\n }}\n >\n {props.children}\n </NavigationContext.Provider>\n );\n}\n"],"names":[],"mappings":";;;;;;;AAsBA;;;;;IAKa,iBAAiB,GAAG,KAAK,CAAC,aAAa,CAElD,SAAS,EAAE;AAEb;SACgB,kBAAkB,CAAC,KAElC;IACC,IAAM,OAAO,GAAG,YAAY,EAAE,CAAC;IACzB,IAAA,KAAqB,kBAAkB,EAAE,EAAxC,KAAK,QAAA,EAAE,SAAS,QAAwB,CAAC;IAEhD,IAAM,aAAa,GAAG,gBAAgB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACvD,IAAM,SAAS,GAAG,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC/C,IAAM,aAAa,GAAG,gBAAgB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAEvD,QACE,oBAAC,iBAAiB,CAAC,QAAQ,IACzB,KAAK,EAAE;YACL,KAAK,OAAA;YACL,aAAa,eAAA;YACb,SAAS,WAAA;YACT,aAAa,eAAA;YACb,SAAS,WAAA;SACV,IAEA,KAAK,CAAC,QAAQ,CACY,EAC7B;AACJ;;;;"}
@@ -1,3 +1,2 @@
1
1
  export * from './NavigationContext';
2
- export * from './NavigationProvider';
3
2
  export * from './useNavigation';
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
1
+ import React from 'react';
2
2
  import { NavigationContext } from './NavigationContext.js';
3
3
 
4
4
  /** Hook to access the [[NavigationContext]]. */
@@ -1 +1 @@
1
- {"version":3,"file":"useNavigation.js","sources":["../../../src/contexts/Navigation/useNavigation.ts"],"sourcesContent":["import * as React from 'react';\n\nimport { NavigationContext, NavigationContextValue } from './NavigationContext';\n\n/** Hook to access the [[NavigationContext]]. */\nexport function useNavigation(): NavigationContextValue {\n const context = React.useContext(NavigationContext);\n if (!context) {\n throw new Error('useNavigation must be used within a NavigationProvider');\n }\n return context;\n}\n"],"names":[],"mappings":";;;AAIA;SACgB,aAAa;IAC3B,IAAM,OAAO,GAAG,KAAK,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC;IACpD,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;KAC3E;IACD,OAAO,OAAO,CAAC;AACjB;;;;"}
1
+ {"version":3,"file":"useNavigation.js","sources":["../../../src/contexts/Navigation/useNavigation.ts"],"sourcesContent":["import React from 'react';\n\nimport { NavigationContext, NavigationContextValue } from './NavigationContext';\n\n/** Hook to access the [[NavigationContext]]. */\nexport function useNavigation(): NavigationContextValue {\n const context = React.useContext(NavigationContext);\n if (!context) {\n throw new Error('useNavigation must be used within a NavigationProvider');\n }\n return context;\n}\n"],"names":[],"mappings":";;;AAIA;SACgB,aAAa;IAC3B,IAAM,OAAO,GAAG,KAAK,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC;IACpD,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;KAC3E;IACD,OAAO,OAAO,CAAC;AACjB;;;;"}
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ import { DayPickerProps } from '../types';
3
+ /** The props of [[RootProvider]]. */
4
+ export declare type RootContext = DayPickerProps & {
5
+ children: React.ReactNode;
6
+ };
7
+ /** Provide the value for all the context providers. */
8
+ export declare function RootProvider(props: RootContext): JSX.Element;
@@ -1,19 +1,14 @@
1
1
  import { __rest } from '../_virtual/_tslib.js';
2
- import * as React from 'react';
2
+ import React from 'react';
3
3
  import { DayPickerProvider } from './DayPicker/DayPickerProvider.js';
4
- import './Focus/FocusContext.js';
5
- import { FocusProvider } from './Focus/FocusProvider.js';
6
- import './Navigation/NavigationContext.js';
7
- import { NavigationProvider } from './Navigation/NavigationProvider.js';
8
- import './SelectMultiple/SelectMultipleContext.js';
9
- import { SelectMultipleProvider } from './SelectMultiple/SelectMultipleProvider.js';
10
- import './SelectRange/SelectRangeContext.js';
11
- import { SelectRangeProvider } from './SelectRange/SelectRangeProvider.js';
12
- import './SelectSingle/SelectSingleContext.js';
13
- import { SelectSingleProvider } from './SelectSingle/SelectSingleProvider.js';
4
+ import { FocusProvider } from './Focus/FocusContext.js';
5
+ import { NavigationProvider } from './Navigation/NavigationContext.js';
6
+ import { SelectMultipleProvider } from './SelectMultiple/SelectMultipleContext.js';
7
+ import { SelectRangeProvider } from './SelectRange/SelectRangeContext.js';
8
+ import { SelectSingleProvider } from './SelectSingle/SelectSingleContext.js';
14
9
 
15
10
  /** Provide the value for all the context providers. */
16
- function ContextProvider(props) {
11
+ function RootProvider(props) {
17
12
  var children = props.children, initialProps = __rest(props, ["children"]);
18
13
  return (React.createElement(DayPickerProvider, { initialProps: initialProps },
19
14
  React.createElement(NavigationProvider, null,
@@ -23,5 +18,5 @@ function ContextProvider(props) {
23
18
  React.createElement(FocusProvider, null, children)))))));
24
19
  }
25
20
 
26
- export { ContextProvider };
27
- //# sourceMappingURL=ContextProvider.js.map
21
+ export { RootProvider };
22
+ //# sourceMappingURL=RootProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RootProvider.js","sources":["../../src/contexts/RootProvider.tsx"],"sourcesContent":["import React from 'react';\n\nimport { DayPickerProps } from '../types';\n\nimport { DayPickerProvider } from './DayPicker/DayPickerProvider';\nimport { FocusProvider } from './Focus';\nimport { NavigationProvider } from './Navigation';\nimport { SelectMultipleProvider } from './SelectMultiple';\nimport { SelectRangeProvider } from './SelectRange';\nimport { SelectSingleProvider } from './SelectSingle';\n\n/** The props of [[RootProvider]]. */\nexport type RootContext = DayPickerProps & {\n children: React.ReactNode;\n};\n\n/** Provide the value for all the context providers. */\nexport function RootProvider(props: RootContext): JSX.Element {\n const { children, ...initialProps } = props;\n\n return (\n <DayPickerProvider initialProps={initialProps}>\n <NavigationProvider>\n <SelectSingleProvider initialProps={initialProps}>\n <SelectMultipleProvider initialProps={initialProps}>\n <SelectRangeProvider initialProps={initialProps}>\n <FocusProvider>{children}</FocusProvider>\n </SelectRangeProvider>\n </SelectMultipleProvider>\n </SelectSingleProvider>\n </NavigationProvider>\n </DayPickerProvider>\n );\n}\n"],"names":[],"mappings":";;;;;;;;;AAgBA;SACgB,YAAY,CAAC,KAAkB;IACrC,IAAA,QAAQ,GAAsB,KAAK,SAA3B,EAAK,YAAY,UAAK,KAAK,EAArC,YAA6B,CAAF,CAAW;IAE5C,QACE,oBAAC,iBAAiB,IAAC,YAAY,EAAE,YAAY;QAC3C,oBAAC,kBAAkB;YACjB,oBAAC,oBAAoB,IAAC,YAAY,EAAE,YAAY;gBAC9C,oBAAC,sBAAsB,IAAC,YAAY,EAAE,YAAY;oBAChD,oBAAC,mBAAmB,IAAC,YAAY,EAAE,YAAY;wBAC7C,oBAAC,aAAa,QAAE,QAAQ,CAAiB,CACrB,CACC,CACJ,CACJ,CACH,EACpB;AACJ;;;;"}
@@ -1,5 +1,5 @@
1
- import * as React from 'react';
2
- import { DayClickEventHandler, Modifiers } from '../../types';
1
+ import React from 'react';
2
+ import { DayClickEventHandler, DayPickerMultipleProps, DayPickerProps, Modifiers } from '../../types';
3
3
  /** Represent the modifiers that are changed by the multiple selection. */
4
4
  export declare type SelectMultipleModifiers = Pick<Modifiers, 'selected' | 'disabled'>;
5
5
  /** Represents the value of a [[SelectMultipleContext]]. */
@@ -18,3 +18,15 @@ export interface SelectMultipleContextValue {
18
18
  * Access this context from the [[useSelectMultiple]] hook.
19
19
  */
20
20
  export declare const SelectMultipleContext: React.Context<SelectMultipleContextValue | undefined>;
21
+ export declare type SelectMultipleProviderProps = {
22
+ initialProps: DayPickerProps;
23
+ children: React.ReactNode;
24
+ };
25
+ /** Provides the values for the [[SelectMultipleContext]]. */
26
+ export declare function SelectMultipleProvider(props: SelectMultipleProviderProps): JSX.Element;
27
+ declare type SelectMultipleProviderInternalProps = {
28
+ initialProps: DayPickerMultipleProps;
29
+ children: React.ReactNode;
30
+ };
31
+ export declare function SelectMultipleProviderInternal({ initialProps, children }: SelectMultipleProviderInternalProps): JSX.Element;
32
+ export {};
@@ -1,4 +1,7 @@
1
- import * as React from 'react';
1
+ import { __spreadArray } from '../../_virtual/_tslib.js';
2
+ import React from 'react';
3
+ import { isSameDay } from 'date-fns';
4
+ import { isDayPickerMultiple } from '../../types/DayPickerMultiple.js';
2
5
 
3
6
  /**
4
7
  * The SelectMultiple context shares details about the selected days when in
@@ -6,7 +9,74 @@ import * as React from 'react';
6
9
  *
7
10
  * Access this context from the [[useSelectMultiple]] hook.
8
11
  */
9
- var SelectMultipleContext = React.createContext(undefined);
12
+ var SelectMultipleContext = React.createContext(undefined);
13
+ /** Provides the values for the [[SelectMultipleContext]]. */
14
+ function SelectMultipleProvider(props) {
15
+ if (!isDayPickerMultiple(props.initialProps)) {
16
+ var emptyContextValue = {
17
+ selected: undefined,
18
+ modifiers: {
19
+ selected: [],
20
+ disabled: []
21
+ }
22
+ };
23
+ return (React.createElement(SelectMultipleContext.Provider, { value: emptyContextValue }, props.children));
24
+ }
25
+ return (React.createElement(SelectMultipleProviderInternal, { initialProps: props.initialProps, children: props.children }));
26
+ }
27
+ function SelectMultipleProviderInternal(_a) {
28
+ var initialProps = _a.initialProps, children = _a.children;
29
+ var selected = initialProps.selected;
30
+ var handleDayClick = function (day, modifiers, e) {
31
+ var _a, _b;
32
+ (_a = initialProps.onDayClick) === null || _a === void 0 ? void 0 : _a.call(initialProps, day, modifiers, e);
33
+ var isMinSelected = Boolean(initialProps.min &&
34
+ modifiers.selected &&
35
+ selected &&
36
+ selected.length === initialProps.min);
37
+ if (isMinSelected) {
38
+ return;
39
+ }
40
+ var isMaxSelected = Boolean(initialProps.max &&
41
+ !modifiers.selected &&
42
+ selected &&
43
+ selected.length === initialProps.max);
44
+ if (isMaxSelected) {
45
+ return;
46
+ }
47
+ var days = selected ? __spreadArray([], selected, true) : [];
48
+ if (modifiers.selected) {
49
+ var index = days.findIndex(function (selectedDay) {
50
+ return isSameDay(day, selectedDay);
51
+ });
52
+ days.splice(index, 1);
53
+ }
54
+ else {
55
+ days.push(day);
56
+ }
57
+ (_b = initialProps.onSelect) === null || _b === void 0 ? void 0 : _b.call(initialProps, days, day, modifiers, e);
58
+ };
59
+ var modifiers = {
60
+ selected: [],
61
+ disabled: []
62
+ };
63
+ if (selected) {
64
+ modifiers.selected = selected;
65
+ modifiers.disabled = [
66
+ function disableDay(day) {
67
+ var isMaxSelected = initialProps.max &&
68
+ selected &&
69
+ selected.length > initialProps.max - 1;
70
+ var isSelected = selected === null || selected === void 0 ? void 0 : selected.some(function (selectedDay) {
71
+ return isSameDay(selectedDay, day);
72
+ });
73
+ return Boolean(isMaxSelected && !isSelected);
74
+ }
75
+ ];
76
+ }
77
+ var contextValue = { selected: selected, handleDayClick: handleDayClick, modifiers: modifiers };
78
+ return (React.createElement(SelectMultipleContext.Provider, { value: contextValue }, children));
79
+ }
10
80
 
11
- export { SelectMultipleContext };
81
+ export { SelectMultipleContext, SelectMultipleProvider, SelectMultipleProviderInternal };
12
82
  //# sourceMappingURL=SelectMultipleContext.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SelectMultipleContext.js","sources":["../../../src/contexts/SelectMultiple/SelectMultipleContext.ts"],"sourcesContent":["import * as React from 'react';\n\nimport { DayClickEventHandler, Modifiers } from '../../types';\n\n/** Represent the modifiers that are changed by the multiple selection. */\nexport type SelectMultipleModifiers = Pick<Modifiers, 'selected' | 'disabled'>;\n\n/** Represents the value of a [[SelectMultipleContext]]. */\nexport interface SelectMultipleContextValue {\n /** The days that have been selected. */\n selected: Date[] | undefined;\n /** The modifiers for the corresponding selection. */\n modifiers: SelectMultipleModifiers;\n /** Event handler to attach to the day button to enable the multiple select. */\n handleDayClick?: DayClickEventHandler;\n}\n\n/**\n * The SelectMultiple context shares details about the selected days when in\n * multiple selection mode.\n *\n * Access this context from the [[useSelectMultiple]] hook.\n */\nexport const SelectMultipleContext = React.createContext<\n SelectMultipleContextValue | undefined\n>(undefined);\n"],"names":[],"mappings":";;AAiBA;;;;;;IAMa,qBAAqB,GAAG,KAAK,CAAC,aAAa,CAEtD,SAAS;;;;"}
1
+ {"version":3,"file":"SelectMultipleContext.js","sources":["../../../src/contexts/SelectMultiple/SelectMultipleContext.tsx"],"sourcesContent":["import React from 'react';\n\nimport { isSameDay } from 'date-fns';\n\nimport {\n DayClickEventHandler,\n DayPickerMultipleProps,\n DayPickerProps,\n isDayPickerMultiple,\n Modifiers\n} from '../../types';\n\n/** Represent the modifiers that are changed by the multiple selection. */\nexport type SelectMultipleModifiers = Pick<Modifiers, 'selected' | 'disabled'>;\n\n/** Represents the value of a [[SelectMultipleContext]]. */\nexport interface SelectMultipleContextValue {\n /** The days that have been selected. */\n selected: Date[] | undefined;\n /** The modifiers for the corresponding selection. */\n modifiers: SelectMultipleModifiers;\n /** Event handler to attach to the day button to enable the multiple select. */\n handleDayClick?: DayClickEventHandler;\n}\n\n/**\n * The SelectMultiple context shares details about the selected days when in\n * multiple selection mode.\n *\n * Access this context from the [[useSelectMultiple]] hook.\n */\nexport const SelectMultipleContext = React.createContext<\n SelectMultipleContextValue | undefined\n>(undefined);\n\nexport type SelectMultipleProviderProps = {\n initialProps: DayPickerProps;\n children: React.ReactNode;\n};\n\n/** Provides the values for the [[SelectMultipleContext]]. */\nexport function SelectMultipleProvider(\n props: SelectMultipleProviderProps\n): JSX.Element {\n if (!isDayPickerMultiple(props.initialProps)) {\n const emptyContextValue: SelectMultipleContextValue = {\n selected: undefined,\n modifiers: {\n selected: [],\n disabled: []\n }\n };\n return (\n <SelectMultipleContext.Provider value={emptyContextValue}>\n {props.children}\n </SelectMultipleContext.Provider>\n );\n }\n return (\n <SelectMultipleProviderInternal\n initialProps={props.initialProps}\n children={props.children}\n />\n );\n}\n\ntype SelectMultipleProviderInternalProps = {\n initialProps: DayPickerMultipleProps;\n children: React.ReactNode;\n};\n\nexport function SelectMultipleProviderInternal({\n initialProps,\n children\n}: SelectMultipleProviderInternalProps): JSX.Element {\n const { selected } = initialProps;\n const handleDayClick: DayClickEventHandler = (day, modifiers, e) => {\n initialProps.onDayClick?.(day, modifiers, e);\n\n const isMinSelected = Boolean(\n initialProps.min &&\n modifiers.selected &&\n selected &&\n selected.length === initialProps.min\n );\n if (isMinSelected) {\n return;\n }\n const isMaxSelected = Boolean(\n initialProps.max &&\n !modifiers.selected &&\n selected &&\n selected.length === initialProps.max\n );\n if (isMaxSelected) {\n return;\n }\n\n const days = selected ? [...selected] : [];\n if (modifiers.selected) {\n const index = days.findIndex((selectedDay) =>\n isSameDay(day, selectedDay)\n );\n days.splice(index, 1);\n } else {\n days.push(day);\n }\n initialProps.onSelect?.(days, day, modifiers, e);\n };\n\n const modifiers: SelectMultipleModifiers = {\n selected: [],\n disabled: []\n };\n\n if (selected) {\n modifiers.selected = selected;\n modifiers.disabled = [\n function disableDay(day: Date) {\n const isMaxSelected =\n initialProps.max &&\n selected &&\n selected.length > initialProps.max - 1;\n const isSelected = selected?.some((selectedDay) =>\n isSameDay(selectedDay, day)\n );\n return Boolean(isMaxSelected && !isSelected);\n }\n ];\n }\n\n const contextValue = { selected, handleDayClick, modifiers };\n\n return (\n <SelectMultipleContext.Provider value={contextValue}>\n {children}\n </SelectMultipleContext.Provider>\n );\n}\n"],"names":[],"mappings":";;;;;AAyBA;;;;;;IAMa,qBAAqB,GAAG,KAAK,CAAC,aAAa,CAEtD,SAAS,EAAE;AAOb;SACgB,sBAAsB,CACpC,KAAkC;IAElC,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE;QAC5C,IAAM,iBAAiB,GAA+B;YACpD,QAAQ,EAAE,SAAS;YACnB,SAAS,EAAE;gBACT,QAAQ,EAAE,EAAE;gBACZ,QAAQ,EAAE,EAAE;aACb;SACF,CAAC;QACF,QACE,oBAAC,qBAAqB,CAAC,QAAQ,IAAC,KAAK,EAAE,iBAAiB,IACrD,KAAK,CAAC,QAAQ,CACgB,EACjC;KACH;IACD,QACE,oBAAC,8BAA8B,IAC7B,YAAY,EAAE,KAAK,CAAC,YAAY,EAChC,QAAQ,EAAE,KAAK,CAAC,QAAQ,GACxB,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IAEF,IAAI,QAAQ,EAAE;QACZ,SAAS,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAC9B,SAAS,CAAC,QAAQ,GAAG;YACnB,SAAS,UAAU,CAAC,GAAS;gBAC3B,IAAM,aAAa,GACjB,YAAY,CAAC,GAAG;oBAChB,QAAQ;oBACR,QAAQ,CAAC,MAAM,GAAG,YAAY,CAAC,GAAG,GAAG,CAAC,CAAC;gBACzC,IAAM,UAAU,GAAG,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,IAAI,CAAC,UAAC,WAAW;oBAC5C,OAAA,SAAS,CAAC,WAAW,EAAE,GAAG,CAAC;iBAAA,CAC5B,CAAC;gBACF,OAAO,OAAO,CAAC,aAAa,IAAI,CAAC,UAAU,CAAC,CAAC;aAC9C;SACF,CAAC;KACH;IAED,IAAM,YAAY,GAAG,EAAE,QAAQ,UAAA,EAAE,cAAc,gBAAA,EAAE,SAAS,WAAA,EAAE,CAAC;IAE7D,QACE,oBAAC,qBAAqB,CAAC,QAAQ,IAAC,KAAK,EAAE,YAAY,IAChD,QAAQ,CACsB,EACjC;AACJ;;;;"}
@@ -1,3 +1,2 @@
1
1
  export * from './SelectMultipleContext';
2
- export * from './SelectMultipleProvider';
3
2
  export * from './useSelectMultiple';
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
1
+ import React from 'react';
2
2
  import { SelectMultipleContext } from './SelectMultipleContext.js';
3
3
 
4
4
  /** Hook to access the [[SelectMultipleContext]]. */
@@ -1 +1 @@
1
- {"version":3,"file":"useSelectMultiple.js","sources":["../../../src/contexts/SelectMultiple/useSelectMultiple.ts"],"sourcesContent":["import * as React from 'react';\n\nimport {\n SelectMultipleContext,\n SelectMultipleContextValue\n} from './SelectMultipleContext';\n\n/** Hook to access the [[SelectMultipleContext]]. */\nexport function useSelectMultiple(): SelectMultipleContextValue {\n const context = React.useContext(SelectMultipleContext);\n if (!context) {\n throw new Error(\n 'useSelectMultiple must be used within a SelectMultipleProvider'\n );\n }\n return context;\n}\n"],"names":[],"mappings":";;;AAOA;SACgB,iBAAiB;IAC/B,IAAM,OAAO,GAAG,KAAK,CAAC,UAAU,CAAC,qBAAqB,CAAC,CAAC;IACxD,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CACb,gEAAgE,CACjE,CAAC;KACH;IACD,OAAO,OAAO,CAAC;AACjB;;;;"}
1
+ {"version":3,"file":"useSelectMultiple.js","sources":["../../../src/contexts/SelectMultiple/useSelectMultiple.ts"],"sourcesContent":["import React from 'react';\n\nimport {\n SelectMultipleContext,\n SelectMultipleContextValue\n} from './SelectMultipleContext';\n\n/** Hook to access the [[SelectMultipleContext]]. */\nexport function useSelectMultiple(): SelectMultipleContextValue {\n const context = React.useContext(SelectMultipleContext);\n if (!context) {\n throw new Error(\n 'useSelectMultiple must be used within a SelectMultipleProvider'\n );\n }\n return context;\n}\n"],"names":[],"mappings":";;;AAOA;SACgB,iBAAiB;IAC/B,IAAM,OAAO,GAAG,KAAK,CAAC,UAAU,CAAC,qBAAqB,CAAC,CAAC;IACxD,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CACb,gEAAgE,CACjE,CAAC;KACH;IACD,OAAO,OAAO,CAAC;AACjB;;;;"}
@@ -1,6 +1,5 @@
1
- import * as React from 'react';
2
- import { DateRange, DayClickEventHandler } from '../../types';
3
- import { Modifiers } from '../../types';
1
+ import React from 'react';
2
+ import { DateRange, DayClickEventHandler, DayPickerProps, DayPickerRangeProps, Modifiers } from '../../types';
4
3
  /** Represent the modifiers that are changed by the range selection. */
5
4
  export declare type SelectRangeModifiers = Pick<Modifiers, 'selected' | 'range_start' | 'range_end' | 'range_middle' | 'disabled'>;
6
5
  /** Represents the value of a [[SelectRangeContext]]. */
@@ -19,3 +18,15 @@ export interface SelectRangeContextValue {
19
18
  * Access this context from the [[useSelectRange]] hook.
20
19
  */
21
20
  export declare const SelectRangeContext: React.Context<SelectRangeContextValue | undefined>;
21
+ declare type SelectRangeProviderProps = {
22
+ initialProps: DayPickerProps;
23
+ children: React.ReactNode;
24
+ };
25
+ /** Provides the values for the [[SelectRangeProvider]]. */
26
+ export declare function SelectRangeProvider(props: SelectRangeProviderProps): JSX.Element;
27
+ declare type SelectRangeProviderInternalProps = {
28
+ initialProps: DayPickerRangeProps;
29
+ children: React.ReactNode;
30
+ };
31
+ export declare function SelectRangeProviderInternal({ initialProps, children }: SelectRangeProviderInternalProps): JSX.Element;
32
+ export {};
@@ -1,4 +1,7 @@
1
- import * as React from 'react';
1
+ import React from 'react';
2
+ import { differenceInCalendarDays, isBefore, isAfter } from 'date-fns';
3
+ import { isDayPickerRange } from '../../types/DayPickerRange.js';
4
+ import { addToRange } from './utils/addToRange.js';
2
5
 
3
6
  /**
4
7
  * The SelectRange context shares details about the selected days when in
@@ -6,7 +9,115 @@ import * as React from 'react';
6
9
  *
7
10
  * Access this context from the [[useSelectRange]] hook.
8
11
  */
9
- var SelectRangeContext = React.createContext(undefined);
12
+ var SelectRangeContext = React.createContext(undefined);
13
+ /** Provides the values for the [[SelectRangeProvider]]. */
14
+ function SelectRangeProvider(props) {
15
+ if (!isDayPickerRange(props.initialProps)) {
16
+ var emptyContextValue = {
17
+ selected: undefined,
18
+ modifiers: {
19
+ selected: [],
20
+ range_start: [],
21
+ range_end: [],
22
+ range_middle: [],
23
+ disabled: []
24
+ }
25
+ };
26
+ return (React.createElement(SelectRangeContext.Provider, { value: emptyContextValue }, props.children));
27
+ }
28
+ return (React.createElement(SelectRangeProviderInternal, { initialProps: props.initialProps, children: props.children }));
29
+ }
30
+ function SelectRangeProviderInternal(_a) {
31
+ var initialProps = _a.initialProps, children = _a.children;
32
+ var selected = initialProps.selected;
33
+ var min = initialProps.min;
34
+ var max = initialProps.max;
35
+ var handleDayClick = function (day, modifiers, e) {
36
+ var _a, _b;
37
+ (_a = initialProps.onDayClick) === null || _a === void 0 ? void 0 : _a.call(initialProps, day, modifiers, e);
38
+ var newValue = addToRange(day, selected);
39
+ if ((min || max) &&
40
+ selected &&
41
+ (newValue === null || newValue === void 0 ? void 0 : newValue.to) &&
42
+ newValue.from &&
43
+ newValue.from !== newValue.to) {
44
+ var diff = Math.abs(differenceInCalendarDays(newValue === null || newValue === void 0 ? void 0 : newValue.to, newValue === null || newValue === void 0 ? void 0 : newValue.from));
45
+ if (min && diff < min) {
46
+ return;
47
+ }
48
+ if (max && diff >= max) {
49
+ return;
50
+ }
51
+ }
52
+ (_b = initialProps.onSelect) === null || _b === void 0 ? void 0 : _b.call(initialProps, newValue, day, modifiers, e);
53
+ };
54
+ var modifiers = {
55
+ selected: [],
56
+ range_start: [],
57
+ range_end: [],
58
+ range_middle: [],
59
+ disabled: []
60
+ };
61
+ if (selected) {
62
+ modifiers.selected = [selected];
63
+ if (selected.from) {
64
+ modifiers.range_start = [selected.from];
65
+ if (selected.to) {
66
+ modifiers.range_middle = [
67
+ {
68
+ after: selected.from,
69
+ before: selected.to
70
+ }
71
+ ];
72
+ if (max || min) {
73
+ modifiers.disabled = [
74
+ function (date) {
75
+ if (max &&
76
+ selected.to &&
77
+ selected.from &&
78
+ isBefore(date, selected.from)) {
79
+ var diff = differenceInCalendarDays(selected.to, date);
80
+ if (diff >= max) {
81
+ return true;
82
+ }
83
+ }
84
+ if (max &&
85
+ selected.to &&
86
+ selected.from &&
87
+ isAfter(date, selected.to)) {
88
+ var diff = differenceInCalendarDays(date, selected.from);
89
+ if (diff >= max) {
90
+ return true;
91
+ }
92
+ }
93
+ if (min && selected.from && isBefore(date, selected.from)) {
94
+ var diff = differenceInCalendarDays(selected.from, date);
95
+ if (diff < min) {
96
+ return true;
97
+ }
98
+ }
99
+ if (min &&
100
+ selected.to &&
101
+ selected.from &&
102
+ isAfter(date, selected.to)) {
103
+ var diff = differenceInCalendarDays(date, selected.from);
104
+ if (diff < min) {
105
+ return true;
106
+ }
107
+ }
108
+ return false;
109
+ }
110
+ ];
111
+ }
112
+ modifiers.range_end = [selected.to];
113
+ }
114
+ else {
115
+ modifiers.range_end = [selected.from];
116
+ }
117
+ }
118
+ }
119
+ return (React.createElement(SelectRangeContext.Provider, { value: { selected: selected, handleDayClick: handleDayClick, modifiers: modifiers } }, children));
120
+ }
10
121
 
11
- export { SelectRangeContext };
122
+ export { SelectRangeContext, SelectRangeProvider, SelectRangeProviderInternal };
12
123
  //# sourceMappingURL=SelectRangeContext.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SelectRangeContext.js","sources":["../../../src/contexts/SelectRange/SelectRangeContext.ts"],"sourcesContent":["import * as React from 'react';\n\nimport { DateRange, DayClickEventHandler } from '../../types';\n\nimport { Modifiers } from '../../types';\n\n/** Represent the modifiers that are changed by the range selection. */\nexport type SelectRangeModifiers = Pick<\n Modifiers,\n 'selected' | 'range_start' | 'range_end' | 'range_middle' | 'disabled'\n>;\n\n/** Represents the value of a [[SelectRangeContext]]. */\nexport interface SelectRangeContextValue {\n /** The range of days that has been selected. */\n selected: DateRange | undefined;\n /** The modifiers for the corresponding selection. */\n modifiers: SelectRangeModifiers;\n /** Event handler to attach to the day button to enable the range select. */\n handleDayClick?: DayClickEventHandler;\n}\n\n/**\n * The SelectRange context shares details about the selected days when in\n * range selection mode.\n *\n * Access this context from the [[useSelectRange]] hook.\n */\nexport const SelectRangeContext = React.createContext<\n SelectRangeContextValue | undefined\n>(undefined);\n"],"names":[],"mappings":";;AAsBA;;;;;;IAMa,kBAAkB,GAAG,KAAK,CAAC,aAAa,CAEnD,SAAS;;;;"}
1
+ {"version":3,"file":"SelectRangeContext.js","sources":["../../../src/contexts/SelectRange/SelectRangeContext.tsx"],"sourcesContent":["import React from 'react';\n\nimport { differenceInCalendarDays, isAfter, isBefore } from 'date-fns';\n\nimport {\n DateRange,\n DayClickEventHandler,\n DayPickerProps,\n DayPickerRangeProps,\n isDayPickerRange,\n Modifiers\n} from '../../types';\nimport { addToRange } from './utils/addToRange';\n\n/** Represent the modifiers that are changed by the range selection. */\nexport type SelectRangeModifiers = Pick<\n Modifiers,\n 'selected' | 'range_start' | 'range_end' | 'range_middle' | 'disabled'\n>;\n\n/** Represents the value of a [[SelectRangeContext]]. */\nexport interface SelectRangeContextValue {\n /** The range of days that has been selected. */\n selected: DateRange | undefined;\n /** The modifiers for the corresponding selection. */\n modifiers: SelectRangeModifiers;\n /** Event handler to attach to the day button to enable the range select. */\n handleDayClick?: DayClickEventHandler;\n}\n\n/**\n * The SelectRange context shares details about the selected days when in\n * range selection mode.\n *\n * Access this context from the [[useSelectRange]] hook.\n */\nexport const SelectRangeContext = React.createContext<\n SelectRangeContextValue | undefined\n>(undefined);\n\ntype SelectRangeProviderProps = {\n initialProps: DayPickerProps;\n children: React.ReactNode;\n};\n\n/** Provides the values for the [[SelectRangeProvider]]. */\nexport function SelectRangeProvider(\n props: SelectRangeProviderProps\n): JSX.Element {\n if (!isDayPickerRange(props.initialProps)) {\n const emptyContextValue: SelectRangeContextValue = {\n selected: undefined,\n modifiers: {\n selected: [],\n range_start: [],\n range_end: [],\n range_middle: [],\n disabled: []\n }\n };\n return (\n <SelectRangeContext.Provider value={emptyContextValue}>\n {props.children}\n </SelectRangeContext.Provider>\n );\n }\n return (\n <SelectRangeProviderInternal\n initialProps={props.initialProps}\n children={props.children}\n />\n );\n}\n\ntype SelectRangeProviderInternalProps = {\n initialProps: DayPickerRangeProps;\n children: React.ReactNode;\n};\n\nexport function SelectRangeProviderInternal({\n initialProps,\n children\n}: SelectRangeProviderInternalProps): JSX.Element {\n const { selected } = initialProps;\n const min = initialProps.min;\n const max = initialProps.max;\n\n const handleDayClick: DayClickEventHandler = (day, modifiers, e) => {\n initialProps.onDayClick?.(day, modifiers, e);\n const newValue = addToRange(day, selected);\n if (\n (min || max) &&\n selected &&\n newValue?.to &&\n newValue.from &&\n newValue.from !== newValue.to\n ) {\n const diff = Math.abs(\n differenceInCalendarDays(newValue?.to, newValue?.from)\n );\n if (min && diff < min) {\n return;\n }\n if (max && diff >= max) {\n return;\n }\n }\n initialProps.onSelect?.(newValue, day, modifiers, e);\n };\n\n const modifiers: SelectRangeModifiers = {\n selected: [],\n range_start: [],\n range_end: [],\n range_middle: [],\n disabled: []\n };\n\n if (selected) {\n modifiers.selected = [selected];\n if (selected.from) {\n modifiers.range_start = [selected.from];\n if (selected.to) {\n modifiers.range_middle = [\n {\n after: selected.from,\n before: selected.to\n }\n ];\n if (max || min) {\n modifiers.disabled = [\n (date: Date) => {\n if (\n max &&\n selected.to &&\n selected.from &&\n isBefore(date, selected.from)\n ) {\n const diff = differenceInCalendarDays(selected.to, date);\n if (diff >= max) {\n return true;\n }\n }\n if (\n max &&\n selected.to &&\n selected.from &&\n isAfter(date, selected.to)\n ) {\n const diff = differenceInCalendarDays(date, selected.from);\n if (diff >= max) {\n return true;\n }\n }\n if (min && selected.from && isBefore(date, selected.from)) {\n const diff = differenceInCalendarDays(selected.from, date);\n if (diff < min) {\n return true;\n }\n }\n if (\n min &&\n selected.to &&\n selected.from &&\n isAfter(date, selected.to)\n ) {\n const diff = differenceInCalendarDays(date, selected.from);\n if (diff < min) {\n return true;\n }\n }\n return false;\n }\n ];\n }\n modifiers.range_end = [selected.to];\n } else {\n modifiers.range_end = [selected.from];\n }\n }\n }\n return (\n <SelectRangeContext.Provider\n value={{ selected, handleDayClick, modifiers }}\n >\n {children}\n </SelectRangeContext.Provider>\n );\n}\n"],"names":[],"mappings":";;;;;AA8BA;;;;;;IAMa,kBAAkB,GAAG,KAAK,CAAC,aAAa,CAEnD,SAAS,EAAE;AAOb;SACgB,mBAAmB,CACjC,KAA+B;IAE/B,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE;QACzC,IAAM,iBAAiB,GAA4B;YACjD,QAAQ,EAAE,SAAS;YACnB,SAAS,EAAE;gBACT,QAAQ,EAAE,EAAE;gBACZ,WAAW,EAAE,EAAE;gBACf,SAAS,EAAE,EAAE;gBACb,YAAY,EAAE,EAAE;gBAChB,QAAQ,EAAE,EAAE;aACb;SACF,CAAC;QACF,QACE,oBAAC,kBAAkB,CAAC,Q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AAI,IAAI,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE;gCACzD,IAAM,IAAI,GAAG,wBAAwB,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;gCAC3D,IAAI,IAAI,GAAG,GAAG,EAAE;oCACd,OAAO,IAAI,CAAC;iCACb;6BACF;4BACD,IACE,GAAG;gCACH,QAAQ,CAAC,EAAE;gCACX,QAAQ,CAAC,IAAI;gCACb,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,EAAE,CAAC,EAC1B;gCACA,IAAM,IAAI,GAAG,wBAAwB,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;gCAC3D,IAAI,IAAI,GAAG,GAAG,EAAE;oCACd,OAAO,IAAI,CAAC;iCACb;6BACF;4BACD,OAAO,KAAK,CAAC;yBACd;qBACF,CAAC;iBACH;gBACD,SAAS,CAAC,SAAS,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;aACrC;iBAAM;gBACL,SAAS,CAAC,SAAS,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;aACvC;SACF;KACF;IACD,QACE,oBAAC,kBAAkB,CAAC,QAAQ,IAC1B,KAAK,EAAE,EAAE,QAAQ,UAAA,EAAE,cAAc,gBAAA,EAAE,SAAS,WAAA,EAAE,IAE7C,QAAQ,CACmB,EAC9B;AACJ;;;;"}
@@ -1,3 +1,2 @@
1
1
  export * from './SelectRangeContext';
2
- export * from './SelectRangeProvider';
3
2
  export * from './useSelectRange';
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
1
+ import React from 'react';
2
2
  import { SelectRangeContext } from './SelectRangeContext.js';
3
3
 
4
4
  /** Hook to access the [[SelectRangeContext]]. */
@@ -1 +1 @@
1
- {"version":3,"file":"useSelectRange.js","sources":["../../../src/contexts/SelectRange/useSelectRange.ts"],"sourcesContent":["import * as React from 'react';\n\nimport {\n SelectRangeContext,\n SelectRangeContextValue\n} from './SelectRangeContext';\n\n/** Hook to access the [[SelectRangeContext]]. */\nexport function useSelectRange(): SelectRangeContextValue {\n const context = React.useContext(SelectRangeContext);\n if (!context) {\n throw new Error('useSelectRange must be used within a SelectRangeProvider');\n }\n return context;\n}\n"],"names":[],"mappings":";;;AAOA;SACgB,cAAc;IAC5B,IAAM,OAAO,GAAG,KAAK,CAAC,UAAU,CAAC,kBAAkB,CAAC,CAAC;IACrD,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;KAC7E;IACD,OAAO,OAAO,CAAC;AACjB;;;;"}
1
+ {"version":3,"file":"useSelectRange.js","sources":["../../../src/contexts/SelectRange/useSelectRange.ts"],"sourcesContent":["import React from 'react';\n\nimport {\n SelectRangeContext,\n SelectRangeContextValue\n} from './SelectRangeContext';\n\n/** Hook to access the [[SelectRangeContext]]. */\nexport function useSelectRange(): SelectRangeContextValue {\n const context = React.useContext(SelectRangeContext);\n if (!context) {\n throw new Error('useSelectRange must be used within a SelectRangeProvider');\n }\n return context;\n}\n"],"names":[],"mappings":";;;AAOA;SACgB,cAAc;IAC5B,IAAM,OAAO,GAAG,KAAK,CAAC,UAAU,CAAC,kBAAkB,CAAC,CAAC;IACrD,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;KAC7E;IACD,OAAO,OAAO,CAAC;AACjB;;;;"}
@@ -1,6 +1,8 @@
1
- import * as React from 'react';
2
- import { DayClickEventHandler } from '../../types';
3
- import { Modifiers } from '../../types';
1
+ import React from 'react';
2
+ import { DayPickerProps } from '../../types/DayPicker';
3
+ import { DayPickerSingleProps } from '../../types/DayPickerSingle';
4
+ import { DayClickEventHandler } from '../../types/EventHandlers';
5
+ import { Modifiers } from '../../types/Modifiers';
4
6
  /** Represent the modifiers that are changed by the single selection. */
5
7
  export declare type SelectSingleModifiers = Pick<Modifiers, 'selected'>;
6
8
  /** Represents the value of a [[SelectSingleContext]]. */
@@ -19,3 +21,15 @@ export interface SelectSingleContextValue {
19
21
  * Access this context from the [[useSelectSingle]] hook.
20
22
  */
21
23
  export declare const SelectSingleContext: React.Context<SelectSingleContextValue | undefined>;
24
+ declare type SelectSingleProviderProps = {
25
+ initialProps: DayPickerProps;
26
+ children: React.ReactNode;
27
+ };
28
+ /** Provides the values for the [[SelectSingleProvider]]. */
29
+ export declare function SelectSingleProvider(props: SelectSingleProviderProps): JSX.Element;
30
+ declare type SelectSingleProviderInternal = {
31
+ initialProps: DayPickerSingleProps;
32
+ children: React.ReactNode;
33
+ };
34
+ export declare function SelectSingleProviderInternal({ initialProps, children }: SelectSingleProviderInternal): JSX.Element;
35
+ export {};
@@ -1,4 +1,5 @@
1
- import * as React from 'react';
1
+ import React from 'react';
2
+ import { isDayPickerSingle } from '../../types/DayPickerSingle.js';
2
3
 
3
4
  /**
4
5
  * The SelectSingle context shares details about the selected days when in
@@ -6,7 +7,39 @@ import * as React from 'react';
6
7
  *
7
8
  * Access this context from the [[useSelectSingle]] hook.
8
9
  */
9
- var SelectSingleContext = React.createContext(undefined);
10
+ var SelectSingleContext = React.createContext(undefined);
11
+ /** Provides the values for the [[SelectSingleProvider]]. */
12
+ function SelectSingleProvider(props) {
13
+ if (!isDayPickerSingle(props.initialProps)) {
14
+ var emptyContextValue = {
15
+ selected: undefined,
16
+ modifiers: { selected: [] }
17
+ };
18
+ return (React.createElement(SelectSingleContext.Provider, { value: emptyContextValue }, props.children));
19
+ }
20
+ return (React.createElement(SelectSingleProviderInternal, { initialProps: props.initialProps, children: props.children }));
21
+ }
22
+ function SelectSingleProviderInternal(_a) {
23
+ var initialProps = _a.initialProps, children = _a.children;
24
+ var handleDayClick = function (day, dayModifiers, e) {
25
+ var _a, _b;
26
+ if (dayModifiers.selected && !initialProps.required) {
27
+ (_a = initialProps.onSelect) === null || _a === void 0 ? void 0 : _a.call(initialProps, undefined, day, dayModifiers, e);
28
+ return;
29
+ }
30
+ (_b = initialProps.onSelect) === null || _b === void 0 ? void 0 : _b.call(initialProps, day, day, dayModifiers, e);
31
+ };
32
+ var modifiers = { selected: [] };
33
+ if (initialProps.selected) {
34
+ modifiers.selected = [initialProps.selected];
35
+ }
36
+ var contextValue = {
37
+ selected: initialProps.selected,
38
+ handleDayClick: handleDayClick,
39
+ modifiers: modifiers
40
+ };
41
+ return (React.createElement(SelectSingleContext.Provider, { value: contextValue }, children));
42
+ }
10
43
 
11
- export { SelectSingleContext };
44
+ export { SelectSingleContext, SelectSingleProvider, SelectSingleProviderInternal };
12
45
  //# sourceMappingURL=SelectSingleContext.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SelectSingleContext.js","sources":["../../../src/contexts/SelectSingle/SelectSingleContext.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { DayClickEventHandler } from '../../types';\n\nimport { Modifiers } from '../../types';\n\n/** Represent the modifiers that are changed by the single selection. */\n\nexport type SelectSingleModifiers = Pick<Modifiers, 'selected'>;\n\n/** Represents the value of a [[SelectSingleContext]]. */\nexport interface SelectSingleContextValue {\n /** The day that has been selected. */\n selected: Date | undefined;\n /** The modifiers for the corresponding selection. */\n modifiers: SelectSingleModifiers;\n /** Event handler to attach to the day button to enable the single select. */\n handleDayClick?: DayClickEventHandler;\n}\n\n/**\n * The SelectSingle context shares details about the selected days when in\n * single selection mode.\n *\n * Access this context from the [[useSelectSingle]] hook.\n */\nexport const SelectSingleContext = React.createContext<\n SelectSingleContextValue | undefined\n>(undefined);\n"],"names":[],"mappings":";;AAoBA;;;;;;IAMa,mBAAmB,GAAG,KAAK,CAAC,aAAa,CAEpD,SAAS;;;;"}
1
+ {"version":3,"file":"SelectSingleContext.js","sources":["../../../src/contexts/SelectSingle/SelectSingleContext.tsx"],"sourcesContent":["import React from 'react';\n\nimport { DayPickerProps } from '../../types/DayPicker';\nimport {\n DayPickerSingleProps,\n isDayPickerSingle\n} from '../../types/DayPickerSingle';\nimport { DayClickEventHandler } from '../../types/EventHandlers';\nimport { Modifiers } from '../../types/Modifiers';\n\n/** Represent the modifiers that are changed by the single selection. */\nexport type SelectSingleModifiers = Pick<Modifiers, 'selected'>;\n\n/** Represents the value of a [[SelectSingleContext]]. */\nexport interface SelectSingleContextValue {\n /** The day that has been selected. */\n selected: Date | undefined;\n /** The modifiers for the corresponding selection. */\n modifiers: SelectSingleModifiers;\n /** Event handler to attach to the day button to enable the single select. */\n handleDayClick?: DayClickEventHandler;\n}\n\n/**\n * The SelectSingle context shares details about the selected days when in\n * single selection mode.\n *\n * Access this context from the [[useSelectSingle]] hook.\n */\nexport const SelectSingleContext = React.createContext<\n SelectSingleContextValue | undefined\n>(undefined);\n\ntype SelectSingleProviderProps = {\n initialProps: DayPickerProps;\n children: React.ReactNode;\n};\n\n/** Provides the values for the [[SelectSingleProvider]]. */\nexport function SelectSingleProvider(\n props: SelectSingleProviderProps\n): JSX.Element {\n if (!isDayPickerSingle(props.initialProps)) {\n const emptyContextValue: SelectSingleContextValue = {\n selected: undefined,\n modifiers: { selected: [] }\n };\n return (\n <SelectSingleContext.Provider value={emptyContextValue}>\n {props.children}\n </SelectSingleContext.Provider>\n );\n }\n return (\n <SelectSingleProviderInternal\n initialProps={props.initialProps}\n children={props.children}\n />\n );\n}\n\ntype SelectSingleProviderInternal = {\n initialProps: DayPickerSingleProps;\n children: React.ReactNode;\n};\n\nexport function SelectSingleProviderInternal({\n initialProps,\n children\n}: SelectSingleProviderInternal): JSX.Element {\n const handleDayClick: DayClickEventHandler = (day, dayModifiers, e) => {\n if (dayModifiers.selected && !initialProps.required) {\n initialProps.onSelect?.(undefined, day, dayModifiers, e);\n return;\n }\n initialProps.onSelect?.(day, day, dayModifiers, e);\n };\n\n const modifiers: SelectSingleModifiers = { selected: [] };\n\n if (initialProps.selected) {\n modifiers.selected = [initialProps.selected];\n }\n\n const contextValue: SelectSingleContextValue = {\n selected: initialProps.selected,\n handleDayClick,\n modifiers\n };\n return (\n <SelectSingleContext.Provider value={contextValue}>\n {children}\n </SelectSing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B,cAAc,gBAAA;QACd,SAAS,WAAA;KACV,CAAC;IACF,QACE,oBAAC,mBAAmB,CAAC,QAAQ,IAAC,KAAK,EAAE,YAAY,IAC9C,QAAQ,CACoB,EAC/B;AACJ;;;;"}
@@ -1,3 +1,2 @@
1
1
  export * from './SelectSingleContext';
2
- export * from './SelectSingleProvider';
3
2
  export * from './useSelectSingle';
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
1
+ import React from 'react';
2
2
  import { SelectSingleContext } from './SelectSingleContext.js';
3
3
 
4
4
  /** Hook to access the [[SelectSingleContext]]. */
@@ -1 +1 @@
1
- {"version":3,"file":"useSelectSingle.js","sources":["../../../src/contexts/SelectSingle/useSelectSingle.ts"],"sourcesContent":["import * as React from 'react';\n\nimport {\n SelectSingleContext,\n SelectSingleContextValue\n} from './SelectSingleContext';\n\n/** Hook to access the [[SelectSingleContext]]. */\nexport function useSelectSingle(): SelectSingleContextValue {\n const context = React.useContext(SelectSingleContext);\n if (!context) {\n throw new Error(\n 'useSelectSingle must be used within a SelectSingleProvider'\n );\n }\n return context;\n}\n"],"names":[],"mappings":";;;AAOA;SACgB,eAAe;IAC7B,IAAM,OAAO,GAAG,KAAK,CAAC,UAAU,CAAC,mBAAmB,CAAC,CAAC;IACtD,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CACb,4DAA4D,CAC7D,CAAC;KACH;IACD,OAAO,OAAO,CAAC;AACjB;;;;"}
1
+ {"version":3,"file":"useSelectSingle.js","sources":["../../../src/contexts/SelectSingle/useSelectSingle.ts"],"sourcesContent":["import React from 'react';\n\nimport {\n SelectSingleContext,\n SelectSingleContextValue\n} from './SelectSingleContext';\n\n/** Hook to access the [[SelectSingleContext]]. */\nexport function useSelectSingle(): SelectSingleContextValue {\n const context = React.useContext(SelectSingleContext);\n if (!context) {\n throw new Error(\n 'useSelectSingle must be used within a SelectSingleProvider'\n );\n }\n return context;\n}\n"],"names":[],"mappings":";;;AAOA;SACgB,eAAe;IAC7B,IAAM,OAAO,GAAG,KAAK,CAAC,UAAU,CAAC,mBAAmB,CAAC,CAAC;IACtD,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CACb,4DAA4D,CAC7D,CAAC;KACH;IACD,OAAO,OAAO,CAAC;AACjB;;;;"}
@@ -1,4 +1,4 @@
1
- export * from './ContextProvider';
1
+ export * from './RootProvider';
2
2
  export * from './DayPicker';
3
3
  export * from './Focus';
4
4
  export * from './Navigation';
@@ -1,4 +1,4 @@
1
- import React__default from 'react';
1
+ import React from 'react';
2
2
 
3
3
  /**
4
4
  * Helper hook for using controlled/uncontrolled values from a component props.
@@ -10,7 +10,7 @@ import React__default from 'react';
10
10
  * argument, which will be always returned as `value`.
11
11
  */
12
12
  function useControlledValue(defaultValue, controlledValue) {
13
- var _a = React__default.useState(defaultValue), uncontrolledValue = _a[0], setValue = _a[1];
13
+ var _a = React.useState(defaultValue), uncontrolledValue = _a[0], setValue = _a[1];
14
14
  var value = controlledValue === undefined ? uncontrolledValue : controlledValue;
15
15
  return [value, setValue];
16
16
  }
@@ -1 +1 @@
1
- {"version":3,"file":"useControlledValue.js","sources":["../../../src/hooks/useControlledValue/useControlledValue.ts"],"sourcesContent":["import React from 'react';\n\nexport type DispatchStateAction<T> = React.Dispatch<React.SetStateAction<T>>;\n\n/**\n * Helper hook for using controlled/uncontrolled values from a component props.\n *\n * When the value is not controlled, pass `undefined` as `controlledValue` and\n * use the returned setter to update it.\n *\n * When the value is controlled, pass the controlled value as second\n * argument, which will be always returned as `value`.\n */\nexport function useControlledValue<T>(\n defaultValue: T,\n controlledValue: T | undefined\n): [T, DispatchStateAction<T>] {\n const [uncontrolledValue, setValue] = React.useState(defaultValue);\n\n const value =\n controlledValue === undefined ? uncontrolledValue : controlledValue;\n\n return [value, setValue] as [T, DispatchStateAction<T>];\n}\n"],"names":["React"],"mappings":";;AAIA;;;;;;;;;SASgB,kBAAkB,CAChC,YAAe,EACf,eAA8B;IAExB,IAAA,KAAgCA,cAAK,CAAC,QAAQ,CAAC,YAAY,CAAC,EAA3D,iBAAiB,QAAA,EAAE,QAAQ,QAAgC,CAAC;IAEnE,IAAM,KAAK,GACT,eAAe,KAAK,SAAS,GAAG,iBAAiB,GAAG,eAAe,CAAC;IAEtE,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAgC,CAAC;AAC1D;;;;"}
1
+ {"version":3,"file":"useControlledValue.js","sources":["../../../src/hooks/useControlledValue/useControlledValue.ts"],"sourcesContent":["import React from 'react';\n\nexport type DispatchStateAction<T> = React.Dispatch<React.SetStateAction<T>>;\n\n/**\n * Helper hook for using controlled/uncontrolled values from a component props.\n *\n * When the value is not controlled, pass `undefined` as `controlledValue` and\n * use the returned setter to update it.\n *\n * When the value is controlled, pass the controlled value as second\n * argument, which will be always returned as `value`.\n */\nexport function useControlledValue<T>(\n defaultValue: T,\n controlledValue: T | undefined\n): [T, DispatchStateAction<T>] {\n const [uncontrolledValue, setValue] = React.useState(defaultValue);\n\n const value =\n controlledValue === undefined ? uncontrolledValue : controlledValue;\n\n return [value, setValue] as [T, DispatchStateAction<T>];\n}\n"],"names":[],"mappings":";;AAIA;;;;;;;;;SASgB,kBAAkB,CAChC,YAAe,EACf,eAA8B;IAExB,IAAA,KAAgC,KAAK,CAAC,QAAQ,CAAC,YAAY,CAAC,EAA3D,iBAAiB,QAAA,EAAE,QAAQ,QAAgC,CAAC;IAEnE,IAAM,KAAK,GACT,eAAe,KAAK,SAAS,GAAG,iBAAiB,GAAG,eAAe,CAAC;IAEtE,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAgC,CAAC;AAC1D;;;;"}