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

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 (318) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/{build → dist}/DayPicker.d.ts +93 -89
  3. package/dist/components/Button/Button.d.ts +7 -0
  4. package/{build → dist}/components/Button/index.d.ts +1 -1
  5. package/{build → dist}/components/Caption/Caption.d.ts +20 -18
  6. package/{build → dist}/components/Caption/index.d.ts +1 -1
  7. package/{build → dist}/components/CaptionLabel/CaptionLabel.d.ts +10 -8
  8. package/{build → dist}/components/CaptionLabel/index.d.ts +1 -1
  9. package/{build → dist}/components/Day/Day.d.ts +13 -13
  10. package/dist/components/Day/index.d.ts +1 -0
  11. package/{build → dist}/components/DayContent/DayContent.d.ts +15 -15
  12. package/{build → dist}/components/DayContent/index.d.ts +1 -1
  13. package/{build → dist}/components/Dropdown/Dropdown.d.ts +16 -16
  14. package/{build → dist}/components/Dropdown/index.d.ts +1 -1
  15. package/{build → dist}/components/Footer/Footer.d.ts +3 -3
  16. package/{build → dist}/components/Footer/index.d.ts +1 -1
  17. package/{build → dist}/components/Head/Head.d.ts +5 -5
  18. package/{build → dist}/components/Head/index.d.ts +1 -1
  19. package/{build → dist}/components/Head/utils/getWeekdays.d.ts +6 -6
  20. package/{build → dist}/components/Head/utils/index.d.ts +1 -1
  21. package/{build → dist}/components/IconDropdown/IconDropdown.d.ts +6 -6
  22. package/{build → dist}/components/IconDropdown/index.d.ts +1 -1
  23. package/{build → dist}/components/IconLeft/IconLeft.d.ts +6 -6
  24. package/{build → dist}/components/IconLeft/index.d.ts +1 -1
  25. package/{build → dist}/components/IconRight/IconRight.d.ts +6 -6
  26. package/{build → dist}/components/IconRight/index.d.ts +1 -1
  27. package/dist/components/Month/Month.d.ts +8 -0
  28. package/dist/components/Month/index.d.ts +1 -0
  29. package/{build → dist}/components/MonthsDropdown/MonthsDropdown.d.ts +10 -12
  30. package/{build → dist}/components/MonthsDropdown/index.d.ts +1 -1
  31. package/{build → dist}/components/Navigation/Navigation.d.ts +20 -20
  32. package/{build → dist}/components/Navigation/index.d.ts +1 -1
  33. package/dist/components/Root/Root.d.ts +3 -0
  34. package/{build → dist}/components/Root/index.d.ts +1 -1
  35. package/{build → dist}/components/Row/Row.d.ts +14 -16
  36. package/{build → dist}/components/Row/index.d.ts +1 -1
  37. package/{build → dist}/components/Table/Table.d.ts +10 -12
  38. package/{build → dist}/components/Table/index.d.ts +1 -1
  39. package/{build → dist}/components/Table/utils/getOutsideEndDays.d.ts +3 -3
  40. package/{build → dist}/components/Table/utils/getOutsideStartDays.d.ts +4 -4
  41. package/{build → dist}/components/Table/utils/getWeeks.d.ts +17 -17
  42. package/{build → dist}/components/WeekNumber/WeekNumber.d.ts +15 -15
  43. package/{build → dist}/components/WeekNumber/index.d.ts +1 -1
  44. package/{build → dist}/components/YearsDropdown/YearsDropdown.d.ts +16 -16
  45. package/{build → dist}/components/YearsDropdown/index.d.ts +1 -1
  46. package/dist/contexts/DayPicker/DayPickerContext.d.ts +45 -0
  47. package/{build → dist}/contexts/DayPicker/defaultClassNames.d.ts +5 -5
  48. package/dist/contexts/DayPicker/defaultContextValue.d.ts +6 -0
  49. package/{build → dist}/contexts/DayPicker/formatters/formatCaption.d.ts +7 -7
  50. package/{build → dist}/contexts/DayPicker/formatters/formatDay.d.ts +7 -7
  51. package/{build → dist}/contexts/DayPicker/formatters/formatMonthCaption.d.ts +7 -7
  52. package/{build → dist}/contexts/DayPicker/formatters/formatWeekNumber.d.ts +4 -4
  53. package/{build → dist}/contexts/DayPicker/formatters/formatWeekdayName.d.ts +7 -7
  54. package/{build → dist}/contexts/DayPicker/formatters/formatYearCaption.d.ts +6 -6
  55. package/{build → dist}/contexts/DayPicker/formatters/index.d.ts +6 -6
  56. package/dist/contexts/DayPicker/index.d.ts +2 -0
  57. package/{build → dist}/contexts/DayPicker/labels/index.d.ts +7 -7
  58. package/{build → dist}/contexts/DayPicker/labels/labelDay.d.ts +5 -5
  59. package/{build → dist}/contexts/DayPicker/labels/labelMonthDropdown.d.ts +4 -4
  60. package/{build → dist}/contexts/DayPicker/labels/labelNext.d.ts +5 -5
  61. package/{build → dist}/contexts/DayPicker/labels/labelPrevious.d.ts +5 -5
  62. package/{build → dist}/contexts/DayPicker/labels/labelWeekNumber.d.ts +5 -5
  63. package/{build → dist}/contexts/DayPicker/labels/labelWeekday.d.ts +5 -5
  64. package/{build → dist}/contexts/DayPicker/labels/labelYearDropdown.d.ts +4 -4
  65. package/{build → dist}/contexts/DayPicker/useDayPicker.d.ts +8 -8
  66. package/dist/contexts/DayPicker/utils/index.d.ts +1 -0
  67. package/{build → dist}/contexts/DayPicker/utils/parseFromToProps.d.ts +6 -9
  68. package/dist/contexts/Focus/FocusContext.d.ts +36 -0
  69. package/dist/contexts/Focus/index.d.ts +2 -0
  70. package/{build/contexts/Focus/useFocus.d.ts → dist/contexts/Focus/useFocusContext.d.ts} +3 -3
  71. package/dist/contexts/Focus/utils/getInitialFocusTarget.d.ts +3 -0
  72. package/dist/contexts/Modifiers/ModifiersContext.d.ts +9 -0
  73. package/dist/contexts/Modifiers/index.d.ts +2 -0
  74. package/dist/contexts/Modifiers/useModifiers.d.ts +6 -0
  75. package/dist/contexts/Modifiers/utils/getActiveModifiers.d.ts +7 -0
  76. package/dist/contexts/Modifiers/utils/getCustomModifiers.d.ts +3 -0
  77. package/dist/contexts/Modifiers/utils/getInternalModifiers.d.ts +6 -0
  78. package/{build/hooks/useModifiers → dist/contexts/Modifiers}/utils/isDateInRange.d.ts +3 -3
  79. package/{build/hooks/useModifiers → dist/contexts/Modifiers}/utils/isMatch.d.ts +3 -5
  80. package/dist/contexts/Modifiers/utils/matcherToArray.d.ts +3 -0
  81. package/{build → dist}/contexts/Navigation/NavigationContext.d.ts +28 -24
  82. package/{build → dist}/contexts/Navigation/index.d.ts +2 -2
  83. package/{build → dist}/contexts/Navigation/useNavigation.d.ts +3 -3
  84. package/{build → dist}/contexts/Navigation/useNavigationState.d.ts +7 -7
  85. package/{build → dist}/contexts/Navigation/utils/getDisplayMonths.d.ts +8 -8
  86. package/{build → dist}/contexts/Navigation/utils/getInitialMonth.d.ts +3 -3
  87. package/{build → dist}/contexts/Navigation/utils/getNextMonth.d.ts +18 -18
  88. package/{build → dist}/contexts/Navigation/utils/getPreviousMonth.d.ts +19 -19
  89. package/{build → dist}/contexts/RootProvider.d.ts +8 -8
  90. package/{build → dist}/contexts/SelectMultiple/SelectMultipleContext.d.ts +35 -32
  91. package/{build → dist}/contexts/SelectMultiple/index.d.ts +2 -2
  92. package/{build → dist}/contexts/SelectMultiple/useSelectMultiple.d.ts +3 -3
  93. package/{build → dist}/contexts/SelectRange/SelectRangeContext.d.ts +36 -32
  94. package/{build → dist}/contexts/SelectRange/index.d.ts +2 -2
  95. package/{build → dist}/contexts/SelectRange/useSelectRange.d.ts +3 -3
  96. package/{build → dist}/contexts/SelectRange/utils/addToRange.d.ts +8 -8
  97. package/{build → dist}/contexts/SelectSingle/SelectSingleContext.d.ts +30 -35
  98. package/{build → dist}/contexts/SelectSingle/index.d.ts +2 -2
  99. package/{build → dist}/contexts/SelectSingle/useSelectSingle.d.ts +3 -3
  100. package/dist/hooks/useActiveModifiers/index.d.ts +1 -0
  101. package/dist/hooks/useActiveModifiers/useActiveModifiers.d.ts +9 -0
  102. package/{build → dist}/hooks/useControlledValue/index.d.ts +1 -1
  103. package/{build → dist}/hooks/useControlledValue/useControlledValue.d.ts +12 -12
  104. package/dist/hooks/useDayEventHandlers/index.d.ts +1 -0
  105. package/dist/hooks/useDayEventHandlers/useDayEventHandlers.d.ts +28 -0
  106. package/dist/hooks/useDayRender/index.d.ts +1 -0
  107. package/dist/hooks/useDayRender/useDayRender.d.ts +39 -0
  108. package/dist/hooks/useDayRender/utils/getDayClassNames.d.ts +4 -0
  109. package/dist/hooks/useDayRender/utils/getDayStyle.d.ts +5 -0
  110. package/{build → dist}/hooks/useInput/index.d.ts +1 -1
  111. package/{build → dist}/hooks/useInput/useInput.d.ts +28 -28
  112. package/{build → dist}/hooks/useInput/utils/isValidDate.d.ts +2 -2
  113. package/dist/hooks/useSelectedDays/index.d.ts +1 -0
  114. package/dist/hooks/useSelectedDays/useSelectedDays.d.ts +8 -0
  115. package/dist/index.d.ts +35 -0
  116. package/dist/index.esm.js +2213 -0
  117. package/dist/index.esm.js.map +1 -0
  118. package/dist/{main.js → index.js} +2116 -1744
  119. package/dist/index.js.map +1 -0
  120. package/dist/react-day-picker.min.js +1 -0
  121. package/{style.css → dist/style.css} +21 -10
  122. package/{style.css.d.ts → dist/style.css.d.ts} +2 -2
  123. package/{build → dist}/types/DayPicker.d.ts +249 -228
  124. package/{build → dist}/types/DayPickerCustom.d.ts +9 -11
  125. package/{build → dist}/types/DayPickerMultiple.d.ts +16 -16
  126. package/{build → dist}/types/DayPickerRange.d.ts +17 -17
  127. package/{build → dist}/types/DayPickerSingle.d.ts +14 -14
  128. package/{build → dist}/types/EventHandlers.d.ts +51 -51
  129. package/{build → dist}/types/Formatters.d.ts +24 -24
  130. package/{build → dist}/types/Labels.d.ts +28 -28
  131. package/{build → dist}/types/Matchers.d.ts +34 -34
  132. package/dist/types/Modifiers.d.ts +51 -0
  133. package/{build → dist}/types/Styles.d.ts +82 -85
  134. package/package.json +42 -29
  135. package/build/DayPicker.js +0 -98
  136. package/build/DayPicker.js.map +0 -1
  137. package/build/_virtual/_tslib.js +0 -50
  138. package/build/_virtual/_tslib.js.map +0 -1
  139. package/build/components/Button/Button.d.ts +0 -7
  140. package/build/components/Button/Button.js +0 -23
  141. package/build/components/Button/Button.js.map +0 -1
  142. package/build/components/Caption/Caption.js +0 -57
  143. package/build/components/Caption/Caption.js.map +0 -1
  144. package/build/components/CaptionLabel/CaptionLabel.js +0 -11
  145. package/build/components/CaptionLabel/CaptionLabel.js.map +0 -1
  146. package/build/components/Day/Day.js +0 -24
  147. package/build/components/Day/Day.js.map +0 -1
  148. package/build/components/Day/hooks/index.d.ts +0 -1
  149. package/build/components/Day/hooks/useDay.d.ts +0 -58
  150. package/build/components/Day/hooks/useDay.js +0 -176
  151. package/build/components/Day/hooks/useDay.js.map +0 -1
  152. package/build/components/Day/hooks/useDayFocus.d.ts +0 -8
  153. package/build/components/Day/hooks/useDayFocus.js +0 -56
  154. package/build/components/Day/hooks/useDayFocus.js.map +0 -1
  155. package/build/components/Day/index.d.ts +0 -2
  156. package/build/components/DayContent/DayContent.js +0 -15
  157. package/build/components/DayContent/DayContent.js.map +0 -1
  158. package/build/components/Dropdown/Dropdown.js +0 -20
  159. package/build/components/Dropdown/Dropdown.js.map +0 -1
  160. package/build/components/Footer/Footer.js +0 -15
  161. package/build/components/Footer/Footer.js.map +0 -1
  162. package/build/components/Head/Head.js +0 -20
  163. package/build/components/Head/Head.js.map +0 -1
  164. package/build/components/Head/utils/getWeekdays.js +0 -18
  165. package/build/components/Head/utils/getWeekdays.js.map +0 -1
  166. package/build/components/IconDropdown/IconDropdown.js +0 -13
  167. package/build/components/IconDropdown/IconDropdown.js.map +0 -1
  168. package/build/components/IconLeft/IconLeft.js +0 -13
  169. package/build/components/IconLeft/IconLeft.js.map +0 -1
  170. package/build/components/IconRight/IconRight.js +0 -13
  171. package/build/components/IconRight/IconRight.js.map +0 -1
  172. package/build/components/MonthsDropdown/MonthsDropdown.js +0 -39
  173. package/build/components/MonthsDropdown/MonthsDropdown.js.map +0 -1
  174. package/build/components/Navigation/Navigation.js +0 -33
  175. package/build/components/Navigation/Navigation.js.map +0 -1
  176. package/build/components/Root/Root.d.ts +0 -6
  177. package/build/components/Root/Root.js +0 -49
  178. package/build/components/Root/Root.js.map +0 -1
  179. package/build/components/Row/Row.js +0 -22
  180. package/build/components/Row/Row.js.map +0 -1
  181. package/build/components/Table/Table.js +0 -18
  182. package/build/components/Table/Table.js.map +0 -1
  183. package/build/components/Table/utils/getOutsideEndDays.js +0 -15
  184. package/build/components/Table/utils/getOutsideEndDays.js.map +0 -1
  185. package/build/components/Table/utils/getOutsideStartDays.js +0 -15
  186. package/build/components/Table/utils/getOutsideStartDays.js.map +0 -1
  187. package/build/components/Table/utils/getWeeks.js +0 -50
  188. package/build/components/Table/utils/getWeeks.js.map +0 -1
  189. package/build/components/WeekNumber/WeekNumber.js +0 -24
  190. package/build/components/WeekNumber/WeekNumber.js.map +0 -1
  191. package/build/components/YearsDropdown/YearsDropdown.js +0 -28
  192. package/build/components/YearsDropdown/YearsDropdown.js.map +0 -1
  193. package/build/components/index.d.ts +0 -18
  194. package/build/contexts/DayPicker/DayPickerContext.d.ts +0 -31
  195. package/build/contexts/DayPicker/DayPickerContext.js +0 -14
  196. package/build/contexts/DayPicker/DayPickerContext.js.map +0 -1
  197. package/build/contexts/DayPicker/DayPickerProvider.d.ts +0 -12
  198. package/build/contexts/DayPicker/DayPickerProvider.js +0 -59
  199. package/build/contexts/DayPicker/DayPickerProvider.js.map +0 -1
  200. package/build/contexts/DayPicker/defaultClassNames.js +0 -42
  201. package/build/contexts/DayPicker/defaultClassNames.js.map +0 -1
  202. package/build/contexts/DayPicker/formatters/formatCaption.js +0 -11
  203. package/build/contexts/DayPicker/formatters/formatCaption.js.map +0 -1
  204. package/build/contexts/DayPicker/formatters/formatDay.js +0 -11
  205. package/build/contexts/DayPicker/formatters/formatDay.js.map +0 -1
  206. package/build/contexts/DayPicker/formatters/formatMonthCaption.js +0 -11
  207. package/build/contexts/DayPicker/formatters/formatMonthCaption.js.map +0 -1
  208. package/build/contexts/DayPicker/formatters/formatWeekNumber.js +0 -9
  209. package/build/contexts/DayPicker/formatters/formatWeekNumber.js.map +0 -1
  210. package/build/contexts/DayPicker/formatters/formatWeekdayName.js +0 -11
  211. package/build/contexts/DayPicker/formatters/formatWeekdayName.js.map +0 -1
  212. package/build/contexts/DayPicker/formatters/formatYearCaption.js +0 -11
  213. package/build/contexts/DayPicker/formatters/formatYearCaption.js.map +0 -1
  214. package/build/contexts/DayPicker/formatters/index.js +0 -7
  215. package/build/contexts/DayPicker/formatters/index.js.map +0 -1
  216. package/build/contexts/DayPicker/index.d.ts +0 -1
  217. package/build/contexts/DayPicker/labels/index.js +0 -8
  218. package/build/contexts/DayPicker/labels/index.js.map +0 -1
  219. package/build/contexts/DayPicker/labels/labelDay.js +0 -11
  220. package/build/contexts/DayPicker/labels/labelDay.js.map +0 -1
  221. package/build/contexts/DayPicker/labels/labelMonthDropdown.js +0 -9
  222. package/build/contexts/DayPicker/labels/labelMonthDropdown.js.map +0 -1
  223. package/build/contexts/DayPicker/labels/labelNext.js +0 -9
  224. package/build/contexts/DayPicker/labels/labelNext.js.map +0 -1
  225. package/build/contexts/DayPicker/labels/labelPrevious.js +0 -9
  226. package/build/contexts/DayPicker/labels/labelPrevious.js.map +0 -1
  227. package/build/contexts/DayPicker/labels/labelWeekNumber.js +0 -9
  228. package/build/contexts/DayPicker/labels/labelWeekNumber.js.map +0 -1
  229. package/build/contexts/DayPicker/labels/labelWeekday.js +0 -11
  230. package/build/contexts/DayPicker/labels/labelWeekday.js.map +0 -1
  231. package/build/contexts/DayPicker/labels/labelYearDropdown.js +0 -9
  232. package/build/contexts/DayPicker/labels/labelYearDropdown.js.map +0 -1
  233. package/build/contexts/DayPicker/useDayPicker.js +0 -19
  234. package/build/contexts/DayPicker/useDayPicker.js.map +0 -1
  235. package/build/contexts/DayPicker/utils/index.d.ts +0 -2
  236. package/build/contexts/DayPicker/utils/parseFromToProps.js +0 -29
  237. package/build/contexts/DayPicker/utils/parseFromToProps.js.map +0 -1
  238. package/build/contexts/DayPicker/utils/parseModifierProps.d.ts +0 -9
  239. package/build/contexts/DayPicker/utils/parseModifierProps.js +0 -54
  240. package/build/contexts/DayPicker/utils/parseModifierProps.js.map +0 -1
  241. package/build/contexts/Focus/FocusContext.d.ts +0 -30
  242. package/build/contexts/Focus/FocusContext.js +0 -71
  243. package/build/contexts/Focus/FocusContext.js.map +0 -1
  244. package/build/contexts/Focus/index.d.ts +0 -2
  245. package/build/contexts/Focus/useFocus.js +0 -14
  246. package/build/contexts/Focus/useFocus.js.map +0 -1
  247. package/build/contexts/Navigation/NavigationContext.js +0 -31
  248. package/build/contexts/Navigation/NavigationContext.js.map +0 -1
  249. package/build/contexts/Navigation/useNavigation.js +0 -14
  250. package/build/contexts/Navigation/useNavigation.js.map +0 -1
  251. package/build/contexts/Navigation/useNavigationState.js +0 -19
  252. package/build/contexts/Navigation/useNavigationState.js.map +0 -1
  253. package/build/contexts/Navigation/utils/getDisplayMonths.js +0 -23
  254. package/build/contexts/Navigation/utils/getDisplayMonths.js.map +0 -1
  255. package/build/contexts/Navigation/utils/getInitialMonth.js +0 -21
  256. package/build/contexts/Navigation/utils/getInitialMonth.js.map +0 -1
  257. package/build/contexts/Navigation/utils/getNextMonth.js +0 -32
  258. package/build/contexts/Navigation/utils/getNextMonth.js.map +0 -1
  259. package/build/contexts/Navigation/utils/getPreviousMonth.js +0 -33
  260. package/build/contexts/Navigation/utils/getPreviousMonth.js.map +0 -1
  261. package/build/contexts/RootProvider.js +0 -22
  262. package/build/contexts/RootProvider.js.map +0 -1
  263. package/build/contexts/SelectMultiple/SelectMultipleContext.js +0 -82
  264. package/build/contexts/SelectMultiple/SelectMultipleContext.js.map +0 -1
  265. package/build/contexts/SelectMultiple/useSelectMultiple.js +0 -14
  266. package/build/contexts/SelectMultiple/useSelectMultiple.js.map +0 -1
  267. package/build/contexts/SelectRange/SelectRangeContext.js +0 -123
  268. package/build/contexts/SelectRange/SelectRangeContext.js.map +0 -1
  269. package/build/contexts/SelectRange/useSelectRange.js +0 -14
  270. package/build/contexts/SelectRange/useSelectRange.js.map +0 -1
  271. package/build/contexts/SelectRange/utils/addToRange.js +0 -39
  272. package/build/contexts/SelectRange/utils/addToRange.js.map +0 -1
  273. package/build/contexts/SelectSingle/SelectSingleContext.js +0 -45
  274. package/build/contexts/SelectSingle/SelectSingleContext.js.map +0 -1
  275. package/build/contexts/SelectSingle/useSelectSingle.js +0 -14
  276. package/build/contexts/SelectSingle/useSelectSingle.js.map +0 -1
  277. package/build/contexts/index.d.ts +0 -7
  278. package/build/hooks/index.d.ts +0 -2
  279. package/build/hooks/useControlledValue/useControlledValue.js +0 -19
  280. package/build/hooks/useControlledValue/useControlledValue.js.map +0 -1
  281. package/build/hooks/useInput/useInput.js +0 -101
  282. package/build/hooks/useInput/useInput.js.map +0 -1
  283. package/build/hooks/useInput/utils/isValidDate.js +0 -7
  284. package/build/hooks/useInput/utils/isValidDate.js.map +0 -1
  285. package/build/hooks/useModifiers/index.d.ts +0 -1
  286. package/build/hooks/useModifiers/types/UseModifiers.d.ts +0 -10
  287. package/build/hooks/useModifiers/types/index.d.ts +0 -1
  288. package/build/hooks/useModifiers/useModifiers.d.ts +0 -3
  289. package/build/hooks/useModifiers/useModifiers.js +0 -65
  290. package/build/hooks/useModifiers/useModifiers.js.map +0 -1
  291. package/build/hooks/useModifiers/utils/getModifierStatus.d.ts +0 -7
  292. package/build/hooks/useModifiers/utils/getModifierStatus.js +0 -22
  293. package/build/hooks/useModifiers/utils/getModifierStatus.js.map +0 -1
  294. package/build/hooks/useModifiers/utils/isDateInRange.js +0 -25
  295. package/build/hooks/useModifiers/utils/isDateInRange.js.map +0 -1
  296. package/build/hooks/useModifiers/utils/isMatch.js +0 -52
  297. package/build/hooks/useModifiers/utils/isMatch.js.map +0 -1
  298. package/build/main.d.ts +0 -5
  299. package/build/main.js +0 -40
  300. package/build/main.js.map +0 -1
  301. package/build/test/PageObjects.d.ts +0 -40
  302. package/build/test/customRender.d.ts +0 -4
  303. package/build/test/customRenderHook.d.ts +0 -3
  304. package/build/test/index.d.ts +0 -3
  305. package/build/test/setup.d.ts +0 -2
  306. package/build/types/DayPickerCustom.js +0 -7
  307. package/build/types/DayPickerCustom.js.map +0 -1
  308. package/build/types/DayPickerMultiple.js +0 -7
  309. package/build/types/DayPickerMultiple.js.map +0 -1
  310. package/build/types/DayPickerRange.js +0 -7
  311. package/build/types/DayPickerRange.js.map +0 -1
  312. package/build/types/DayPickerSingle.js +0 -7
  313. package/build/types/DayPickerSingle.js.map +0 -1
  314. package/build/types/Matchers.js +0 -27
  315. package/build/types/Matchers.js.map +0 -1
  316. package/build/types/Modifiers.d.ts +0 -16
  317. package/build/types/index.d.ts +0 -11
  318. package/dist/main.js.map +0 -1
@@ -59,1487 +59,230 @@ function __spreadArray(to, from, pack) {
59
59
  return to.concat(ar || Array.prototype.slice.call(from));
60
60
  }
61
61
 
62
- /**
63
- * The DayPicker context shares the props passed to DayPicker within the
64
- * internal components. It is used to set the default values and perform
65
- * one-time calculations required to render the days.
66
- *
67
- * Access this context from the [[useDayPicker]] hook when using custom
68
- * components.
69
- */
70
- var DayPickerContext = React__default["default"].createContext(undefined);
71
-
72
- /**
73
- * Hook to access the [[DayPickerContext]].
74
- *
75
- * To use this hook make sure to wrap the components with a one
76
- * [[DayPickerProvider]].
77
- * */
78
- function useDayPicker() {
79
- var context = React__default["default"].useContext(DayPickerContext);
80
- if (!context) {
81
- throw new Error("Context is not defined. useDayPicker must be used within a DayPickerProvider with a valid values.");
82
- }
83
- return context;
84
- }
85
-
86
- function getOutsideEndDays(month, options) {
87
- var days = [];
88
- var lastDayOfWeek = dateFns.endOfWeek(month, options);
89
- var endDiff = dateFns.differenceInCalendarDays(lastDayOfWeek, month);
90
- for (var i = 1; i <= endDiff; i++) {
91
- var dayDate = dateFns.addDays(month, i);
92
- days.push(dayDate);
93
- }
94
- return days;
95
- }
96
-
97
- function getOutsideStartDays(month, options) {
98
- var days = [];
99
- var firstDayOfWeek = dateFns.startOfWeek(month, options);
100
- var startDiff = dateFns.differenceInCalendarDays(month, firstDayOfWeek);
101
- for (var i = 0; i < startDiff; i++) {
102
- var newDay = dateFns.addDays(firstDayOfWeek, i);
103
- days.push(newDay);
104
- }
105
- return days;
106
- }
107
-
108
- /**
109
- * Return the weeks belonging to the given month.
110
- */
111
- function getWeeks(month, _a) {
112
- var locale = _a.locale, fixedWeeks = _a.fixedWeeks;
113
- var monthStart = dateFns.startOfMonth(month);
114
- var monthEnd = dateFns.endOfMonth(month);
115
- var diff = dateFns.differenceInCalendarDays(monthEnd, monthStart);
116
- var weeks = [];
117
- var lastWeek = { weekNumber: 0, dates: [] };
118
- for (var i = 0; i <= diff; i++) {
119
- var date = dateFns.addDays(monthStart, i);
120
- var week = dateFns.getWeek(date, { locale: locale });
121
- if (lastWeek.weekNumber !== week) {
122
- // Create a new week by adding outside start days
123
- var startDays = getOutsideStartDays(date, { locale: locale });
124
- lastWeek = { weekNumber: week, dates: startDays };
125
- weeks.push(lastWeek);
126
- }
127
- lastWeek.dates.push(date);
128
- }
129
- var lastDay = lastWeek.dates[lastWeek.dates.length - 1];
130
- var endDays = getOutsideEndDays(lastDay, { locale: locale });
131
- lastWeek.dates = lastWeek.dates.concat(endDays);
132
- // Add extra weeks to the month, up to 6 weeks
133
- if (fixedWeeks) {
134
- var lastWeekDate = lastWeek.dates[lastWeek.dates.length - 1];
135
- var weeksInMonth = dateFns.getWeeksInMonth(month, { locale: locale });
136
- if (weeksInMonth < 6) {
137
- var diffDays = dateFns.differenceInCalendarDays(dateFns.addWeeks(lastWeekDate, 6 - weeksInMonth), lastWeekDate);
138
- for (var i = 0; i < diffDays; i++) {
139
- var date = dateFns.addDays(lastWeekDate, i + 1);
140
- var week = dateFns.getWeek(date, { locale: locale });
141
- if (lastWeek.weekNumber !== week) {
142
- lastWeek = { weekNumber: week, dates: [] };
143
- weeks.push(lastWeek);
144
- }
145
- lastWeek.dates.push(date);
146
- }
147
- }
148
- }
149
- return weeks;
150
- }
151
-
152
- /**
153
- * Render the table with the calendar.
154
- */
155
- function Table(props) {
156
- var _a = useDayPicker(), locale = _a.locale, classNames = _a.classNames, styles = _a.styles, hideHead = _a.hideHead, fixedWeeks = _a.fixedWeeks, _b = _a.components, Head = _b.Head, Row = _b.Row, Footer = _b.Footer;
157
- var weeks = getWeeks(props.displayMonth, { locale: locale, fixedWeeks: fixedWeeks });
158
- return (React__default["default"].createElement("table", { className: classNames.table, style: styles.table },
159
- !hideHead && React__default["default"].createElement(Head, null),
160
- React__default["default"].createElement("tbody", { className: classNames.tbody, style: styles.tbody }, weeks.map(function (week) { return (React__default["default"].createElement(Row, { displayMonth: props.displayMonth, key: week.weekNumber, dates: week.dates, weekNumber: week.weekNumber })); })),
161
- React__default["default"].createElement(Footer, null)));
162
- }
163
-
164
- /** Return the initial month according to the given options. */
165
- function getInitialMonth(context) {
166
- var month = context.month, defaultMonth = context.defaultMonth, today = context.today;
167
- var initialMonth = month || defaultMonth || today || new Date();
168
- var toDate = context.toDate, fromDate = context.fromDate, _a = context.numberOfMonths, numberOfMonths = _a === void 0 ? 1 : _a;
169
- // Fix the initialMonth if is after the to-date
170
- if (toDate && dateFns.differenceInCalendarMonths(toDate, initialMonth) < 0) {
171
- var offset = -1 * (numberOfMonths - 1);
172
- initialMonth = dateFns.addMonths(toDate, offset);
173
- }
174
- // Fix the initialMonth if is before the from-date
175
- if (fromDate && dateFns.differenceInCalendarMonths(initialMonth, fromDate) < 0) {
176
- initialMonth = fromDate;
177
- }
178
- return dateFns.startOfMonth(initialMonth);
179
- }
180
-
181
- /**
182
- * Helper hook for using controlled/uncontrolled values from a component props.
183
- *
184
- * When the value is not controlled, pass `undefined` as `controlledValue` and
185
- * use the returned setter to update it.
186
- *
187
- * When the value is controlled, pass the controlled value as second
188
- * argument, which will be always returned as `value`.
189
- */
190
- function useControlledValue(defaultValue, controlledValue) {
191
- var _a = React__default["default"].useState(defaultValue), uncontrolledValue = _a[0], setValue = _a[1];
192
- var value = controlledValue === undefined ? uncontrolledValue : controlledValue;
193
- return [value, setValue];
194
- }
195
-
196
- /** Controls the navigation state. */
197
- function useNavigationState() {
198
- var context = useDayPicker();
199
- var initialMonth = getInitialMonth(context);
200
- var _a = useControlledValue(initialMonth, context.month), month = _a[0], setMonth = _a[1];
201
- var goToMonth = function (date) {
202
- if (context.disableNavigation)
203
- return;
204
- setMonth(date);
205
- };
206
- return [month, goToMonth];
207
- }
208
-
209
- /**
210
- * Return the months to display in the component according to the number of
211
- * months and the from/to date.
212
- */
213
- function getDisplayMonths(month, _a) {
214
- var reverseMonths = _a.reverseMonths, numberOfMonths = _a.numberOfMonths;
215
- var start = dateFns.startOfMonth(month);
216
- var end = dateFns.startOfMonth(dateFns.addMonths(start, numberOfMonths));
217
- var monthsDiff = dateFns.differenceInCalendarMonths(end, start);
218
- var months = [];
219
- for (var i = 0; i < monthsDiff; i++) {
220
- var nextMonth = dateFns.addMonths(start, i);
221
- months.push(nextMonth);
222
- }
223
- if (reverseMonths)
224
- months = months.reverse();
225
- return months;
226
- }
227
-
228
- /**
229
- * Returns the next month the user can navigate to according to the given
230
- * options.
231
- *
232
- * Please note that the next month is not always the next calendar month:
233
- *
234
- * - if after the `toDate` range, is undefined;
235
- * - if the navigation is paged, is the number of months displayed ahead.
236
- *
237
- */
238
- function getNextMonth(startingMonth, options) {
239
- if (options.disableNavigation) {
240
- return undefined;
241
- }
242
- var toDate = options.toDate, pagedNavigation = options.pagedNavigation, _a = options.numberOfMonths, numberOfMonths = _a === void 0 ? 1 : _a;
243
- var offset = pagedNavigation ? numberOfMonths : 1;
244
- var month = dateFns.startOfMonth(startingMonth);
245
- if (!toDate) {
246
- return dateFns.addMonths(month, offset);
247
- }
248
- var monthsDiff = dateFns.differenceInCalendarMonths(toDate, startingMonth);
249
- if (monthsDiff < numberOfMonths) {
250
- return undefined;
251
- }
252
- // Jump forward as the number of months when paged navigation
253
- return dateFns.addMonths(month, offset);
254
- }
255
-
256
- /**
257
- * Returns the next previous the user can navigate to, according to the given
258
- * options.
259
- *
260
- * Please note that the previous month is not always the previous calendar
261
- * month:
262
- *
263
- * - if before the `fromDate` date, is `undefined`;
264
- * - if the navigation is paged, is the number of months displayed before.
265
- *
266
- */
267
- function getPreviousMonth(startingMonth, options) {
268
- if (options.disableNavigation) {
269
- return undefined;
270
- }
271
- var fromDate = options.fromDate, pagedNavigation = options.pagedNavigation, _a = options.numberOfMonths, numberOfMonths = _a === void 0 ? 1 : _a;
272
- var offset = pagedNavigation ? numberOfMonths : 1;
273
- var month = dateFns.startOfMonth(startingMonth);
274
- if (!fromDate) {
275
- return dateFns.addMonths(month, -offset);
276
- }
277
- var monthsDiff = dateFns.differenceInCalendarMonths(month, fromDate);
278
- if (monthsDiff <= 0) {
279
- return undefined;
280
- }
281
- // Jump back as the number of months when paged navigation
282
- return dateFns.addMonths(month, -offset);
283
- }
284
-
285
- /**
286
- * The Navigation context shares details about the months being navigated in DayPicker.
287
- *
288
- * Access this context from the [[useNavigation]] hook.
289
- */
290
- var NavigationContext = React__default["default"].createContext(undefined);
291
- /** Provides the values for the [[NavigationContext]]. */
292
- function NavigationProvider(props) {
293
- var context = useDayPicker();
294
- var _a = useNavigationState(), month = _a[0], goToMonth = _a[1];
295
- var displayMonths = getDisplayMonths(month, context);
296
- var nextMonth = getNextMonth(month, context);
297
- var previousMonth = getPreviousMonth(month, context);
298
- return (React__default["default"].createElement(NavigationContext.Provider, { value: {
299
- month: month,
300
- displayMonths: displayMonths,
301
- goToMonth: goToMonth,
302
- previousMonth: previousMonth,
303
- nextMonth: nextMonth
304
- } }, props.children));
305
- }
306
-
307
- /** Hook to access the [[NavigationContext]]. */
308
- function useNavigation() {
309
- var context = React__default["default"].useContext(NavigationContext);
310
- if (!context) {
311
- throw new Error('useNavigation must be used within a NavigationProvider');
312
- }
313
- return context;
314
- }
315
-
316
- /**
317
- * Render the container with the months and their captions. The number of months
318
- * rendered depends by the `numberOfMonths` prop.
319
- */
320
- function Root() {
321
- var _a = useDayPicker(), dir = _a.dir, className = _a.className, classNames = _a.classNames, style = _a.style, styles = _a.styles, numberOfMonths = _a.numberOfMonths, showWeekNumber = _a.showWeekNumber, Caption = _a.components.Caption;
322
- var displayMonths = useNavigation().displayMonths;
323
- var rootClassNames = [className !== null && className !== void 0 ? className : classNames.root];
324
- if (numberOfMonths > 1) {
325
- rootClassNames.push(classNames.multiple_month);
326
- }
327
- if (showWeekNumber) {
328
- rootClassNames.push(classNames.with_weeknumber);
329
- }
330
- if (className)
331
- rootClassNames.concat(className.split(' '));
332
- var renderMonth = function (displayMonth, displayIndex) {
333
- var _a;
334
- var className = [classNames.month];
335
- var style = __assign({}, styles.month);
336
- var isFirst = displayIndex === 0;
337
- var isLast = displayIndex === displayMonths.length - 1;
338
- if (dir === 'rtl')
339
- _a = [isFirst, isLast], isLast = _a[0], isFirst = _a[1];
340
- if (isFirst) {
341
- className.push(classNames.caption_first);
342
- Object.assign(style, styles.caption_first);
343
- }
344
- if (isLast)
345
- className.push(classNames.caption_last);
346
- if (!isFirst && !isLast)
347
- className.push(classNames.caption_middle);
348
- return (React__default["default"].createElement("div", { key: displayIndex, className: className.join(' '), style: style },
349
- React__default["default"].createElement(Caption, { displayMonth: displayMonth }),
350
- React__default["default"].createElement(Table, { displayMonth: displayMonth })));
351
- };
352
- return (React__default["default"].createElement("div", { className: rootClassNames.join(' '), style: __assign(__assign({}, styles.root), style), dir: dir },
353
- React__default["default"].createElement("div", { className: classNames.months, style: styles.months }, displayMonths.map(renderMonth))));
354
- }
355
-
356
- /**
357
- * Render the dropdown to navigate between months.
358
- */
359
- function MonthsDropdown(props) {
360
- var displayMonth = props.displayMonth;
361
- var _a = useDayPicker(), fromDate = _a.fromDate, toDate = _a.toDate, styles = _a.styles, locale = _a.locale, formatMonthCaption = _a.formatters.formatMonthCaption, classNames = _a.classNames, Dropdown = _a.components.Dropdown, labelMonthDropdown = _a.labels.labelMonthDropdown;
362
- if (!fromDate && !toDate) {
363
- // TODO: use type guards
364
- return React__default["default"].createElement(React__default["default"].Fragment, null);
365
- }
366
- var dropdownMonths = [];
367
- if (fromDate && toDate) {
368
- if (dateFns.isSameYear(fromDate, toDate)) {
369
- // only display the months included in the range
370
- for (var month = fromDate.getMonth(); month <= toDate.getMonth(); month++) {
371
- dropdownMonths.push(dateFns.setMonth(dateFns.startOfMonth(fromDate), month));
372
- }
373
- }
374
- else {
375
- // display all the 12 months
376
- for (var month = 0; month <= 11; month++) {
377
- var anyDate = new Date(); // any date is OK, we just need the year
378
- dropdownMonths.push(dateFns.setMonth(dateFns.startOfMonth(anyDate), month));
379
- }
380
- }
381
- }
382
- var handleChange = function (e) {
383
- var newMonth = dateFns.setMonth(new Date(displayMonth), Number(e.target.value));
384
- props.onChange(newMonth);
385
- };
386
- return (React__default["default"].createElement(Dropdown, { "aria-label": labelMonthDropdown(), className: classNames.dropdown_month, style: styles.dropdown_month, onChange: handleChange, value: displayMonth.getMonth(), caption: formatMonthCaption(displayMonth, { locale: locale }) }, dropdownMonths.map(function (m) { return (React__default["default"].createElement("option", { key: m.getMonth(), value: m.getMonth() }, formatMonthCaption(m, { locale: locale }))); })));
387
- }
388
-
389
- /**
390
- * Render a button HTML element applying the reset class name.
391
- */
392
- var Button = React__default["default"].forwardRef(function (props, ref) {
393
- var _a = useDayPicker(), classNames = _a.classNames, styles = _a.styles;
394
- var classNamesArr = [classNames.button_reset, classNames.button];
395
- if (props.className) {
396
- classNamesArr.push(props.className);
397
- }
398
- var className = classNamesArr.join(' ');
399
- var style = __assign(__assign({}, styles.button_reset), styles.button);
400
- if (props.style) {
401
- Object.assign(style, props.style);
402
- }
403
- return (React__default["default"].createElement("button", __assign({}, props, { ref: ref, type: "button", className: className, style: style })));
404
- });
405
-
406
- /** A component rendering the navigation buttons or the drop-downs. */
407
- function Navigation(props) {
408
- var _a;
409
- var _b = useDayPicker(), dir = _b.dir, locale = _b.locale, classNames = _b.classNames, styles = _b.styles, _c = _b.labels, labelPrevious = _c.labelPrevious, labelNext = _c.labelNext, _d = _b.components, IconRight = _d.IconRight, IconLeft = _d.IconLeft;
410
- var onPreviousClick = props.onPreviousClick, onNextClick = props.onNextClick;
411
- if (dir === 'rtl') {
412
- _a = [onPreviousClick, onNextClick], onNextClick = _a[0], onPreviousClick = _a[1];
413
- }
414
- var previousMonth = props.previousMonth, nextMonth = props.nextMonth;
415
- var previousLabel = labelPrevious(previousMonth, { locale: locale });
416
- var previousClassName = [
417
- classNames.nav_button,
418
- classNames.nav_button_previous
419
- ].join(' ');
420
- var nextLabel = labelNext(nextMonth, { locale: locale });
421
- var nextClassName = [
422
- classNames.nav_button,
423
- classNames.nav_button_next
424
- ].join(' ');
425
- if (!nextMonth && !previousMonth) {
426
- return React__default["default"].createElement(React__default["default"].Fragment, null);
427
- }
428
- return (React__default["default"].createElement("div", { className: classNames.nav, style: styles.nav },
429
- !props.hidePrevious && (React__default["default"].createElement(Button, { "aria-label": previousLabel, className: previousClassName, style: styles.nav_button_next, disabled: !previousMonth, onClick: dir === 'rtl' ? onNextClick : onPreviousClick }, dir === 'rtl' ? (React__default["default"].createElement(IconRight, { className: classNames.nav_icon, style: styles.nav_icon })) : (React__default["default"].createElement(IconLeft, { className: classNames.nav_icon, style: styles.nav_icon })))),
430
- !props.hideNext && (React__default["default"].createElement(Button, { "aria-label": nextLabel, className: nextClassName, style: styles.nav_button_next, disabled: !nextMonth, onClick: dir === 'rtl' ? onPreviousClick : onNextClick }, dir === 'rtl' ? (React__default["default"].createElement(IconLeft, { className: classNames.nav_icon, style: styles.nav_icon })) : (React__default["default"].createElement(IconRight, { className: classNames.nav_icon, style: styles.nav_icon }))))));
431
- }
432
-
433
- /**
434
- * Render a dropdown to change the year. Take in account the `nav.fromDate` and
435
- * `toDate` from context.
436
- */
437
- function YearsDropdown(props) {
438
- var displayMonth = props.displayMonth;
439
- var _a = useDayPicker(), fromDate = _a.fromDate, toDate = _a.toDate, locale = _a.locale, styles = _a.styles, classNames = _a.classNames, Dropdown = _a.components.Dropdown, formatYearCaption = _a.formatters.formatYearCaption, labelYearDropdown = _a.labels.labelYearDropdown;
440
- var years = [];
441
- if (fromDate && toDate) {
442
- var fromYear = fromDate.getFullYear();
443
- var toYear = toDate.getFullYear();
444
- for (var year = fromYear; year <= toYear; year++) {
445
- years.push(dateFns.setYear(dateFns.startOfYear(new Date()), year));
446
- }
447
- }
448
- var handleChange = function (e) {
449
- var newMonth = dateFns.setYear(new Date(displayMonth), Number(e.target.value));
450
- props.onChange(newMonth);
451
- };
452
- return (React__default["default"].createElement(Dropdown, { "aria-label": labelYearDropdown(), className: classNames.dropdown_month, style: styles.dropdown_month, onChange: handleChange, value: displayMonth.getFullYear(), caption: formatYearCaption(displayMonth, { locale: locale }) }, years.map(function (year) { return (React__default["default"].createElement("option", { key: year.getFullYear(), value: year.getFullYear() }, formatYearCaption(year, { locale: locale }))); })));
453
- }
454
-
455
- /**
456
- * Render the caption of a month, which includes title and navigation buttons.
457
- * The caption has a different layout when setting the `numberOfMonths` prop.
458
- */
459
- function Caption(props) {
460
- var _a;
461
- var displayMonth = props.displayMonth;
462
- var context = useDayPicker();
463
- var classNames = context.classNames, numberOfMonths = context.numberOfMonths, disableNavigation = context.disableNavigation, styles = context.styles, captionLayout = context.captionLayout, onMonthChange = context.onMonthChange, dir = context.dir, CaptionLabel = context.components.CaptionLabel;
464
- var _b = useNavigation(), previousMonth = _b.previousMonth, nextMonth = _b.nextMonth, goToMonth = _b.goToMonth, displayMonths = _b.displayMonths;
465
- var handlePreviousClick = function (e) {
466
- if (!previousMonth)
467
- return;
468
- goToMonth(previousMonth);
469
- onMonthChange === null || onMonthChange === void 0 ? void 0 : onMonthChange(previousMonth);
470
- };
471
- var handleNextClick = function (e) {
472
- if (!nextMonth)
473
- return;
474
- goToMonth(nextMonth);
475
- onMonthChange === null || onMonthChange === void 0 ? void 0 : onMonthChange(nextMonth);
476
- };
477
- var handleMonthChange = function (newMonth) {
478
- goToMonth(newMonth);
479
- onMonthChange === null || onMonthChange === void 0 ? void 0 : onMonthChange(newMonth);
480
- };
481
- var displayIndex = displayMonths.findIndex(function (month) {
482
- return dateFns.isSameMonth(displayMonth, month);
483
- });
484
- var isFirst = displayIndex === 0;
485
- var isLast = displayIndex === displayMonths.length - 1;
486
- if (dir === 'rtl') {
487
- _a = [isFirst, isLast], isLast = _a[0], isFirst = _a[1];
488
- }
489
- var captionLabel = React__default["default"].createElement(CaptionLabel, { displayMonth: displayMonth });
490
- var hideNext = numberOfMonths > 1 && (isFirst || !isLast);
491
- var hidePrevious = numberOfMonths > 1 && (isLast || !isFirst);
492
- return (React__default["default"].createElement("div", { className: classNames.caption, style: styles.caption },
493
- disableNavigation && captionLabel,
494
- !disableNavigation && (React__default["default"].createElement(React__default["default"].Fragment, null, captionLayout === 'dropdown' ? (React__default["default"].createElement("div", { className: classNames.caption_dropdowns, style: styles.caption_dropdowns },
495
- React__default["default"].createElement(MonthsDropdown, { onChange: handleMonthChange, displayMonth: displayMonth }),
496
- React__default["default"].createElement(YearsDropdown, { onChange: handleMonthChange, displayMonth: displayMonth }))) : (React__default["default"].createElement(React__default["default"].Fragment, null,
497
- React__default["default"].createElement(CaptionLabel, { displayMonth: displayMonth }),
498
- React__default["default"].createElement(Navigation, { displayMonth: displayMonth, hideNext: hideNext, hidePrevious: hidePrevious, nextMonth: nextMonth, previousMonth: previousMonth, onPreviousClick: handlePreviousClick, onNextClick: handleNextClick })))))));
499
- }
500
-
501
- /** Render the caption for the displayed month. This component is used when `captionLayout="buttons"`. */
502
- function CaptionLabel(props) {
503
- var _a = useDayPicker(), locale = _a.locale, classNames = _a.classNames, styles = _a.styles, formatCaption = _a.formatters.formatCaption;
504
- return (React__default["default"].createElement("div", { key: "caption", className: classNames.caption_label, style: styles.caption_label, "aria-live": "polite", "aria-atomic": "true" }, formatCaption(props.displayMonth, { locale: locale })));
505
- }
506
-
507
- /** Returns true when the props are of type [[DayPickerMultiple]]. */
508
- function isDayPickerMultiple(props) {
509
- return props.mode === 'multiple';
510
- }
511
-
512
- /** Returns true when the props are of type [[DayPickerRange]]. */
513
- function isDayPickerRange(props) {
514
- return props.mode === 'range';
515
- }
516
-
517
- /** Returns true when the props are of type [[DayPickerSingle]]. */
518
- function isDayPickerSingle(props) {
519
- return props.mode === 'single';
520
- }
521
-
522
- /**
523
- * The SelectMultiple context shares details about the selected days when in
524
- * multiple selection mode.
525
- *
526
- * Access this context from the [[useSelectMultiple]] hook.
527
- */
528
- var SelectMultipleContext = React__default["default"].createContext(undefined);
529
- /** Provides the values for the [[SelectMultipleContext]]. */
530
- function SelectMultipleProvider(props) {
531
- if (!isDayPickerMultiple(props.initialProps)) {
532
- var emptyContextValue = {
533
- selected: undefined,
534
- modifiers: {
535
- selected: [],
536
- disabled: []
537
- }
538
- };
539
- return (React__default["default"].createElement(SelectMultipleContext.Provider, { value: emptyContextValue }, props.children));
540
- }
541
- return (React__default["default"].createElement(SelectMultipleProviderInternal, { initialProps: props.initialProps, children: props.children }));
542
- }
543
- function SelectMultipleProviderInternal(_a) {
544
- var initialProps = _a.initialProps, children = _a.children;
545
- var selected = initialProps.selected;
546
- var handleDayClick = function (day, modifiers, e) {
547
- var _a, _b;
548
- (_a = initialProps.onDayClick) === null || _a === void 0 ? void 0 : _a.call(initialProps, day, modifiers, e);
549
- var isMinSelected = Boolean(initialProps.min &&
550
- modifiers.selected &&
551
- selected &&
552
- selected.length === initialProps.min);
553
- if (isMinSelected) {
554
- return;
555
- }
556
- var isMaxSelected = Boolean(initialProps.max &&
557
- !modifiers.selected &&
558
- selected &&
559
- selected.length === initialProps.max);
560
- if (isMaxSelected) {
561
- return;
562
- }
563
- var days = selected ? __spreadArray([], selected, true) : [];
564
- if (modifiers.selected) {
565
- var index = days.findIndex(function (selectedDay) {
566
- return dateFns.isSameDay(day, selectedDay);
567
- });
568
- days.splice(index, 1);
569
- }
570
- else {
571
- days.push(day);
572
- }
573
- (_b = initialProps.onSelect) === null || _b === void 0 ? void 0 : _b.call(initialProps, days, day, modifiers, e);
574
- };
575
- var modifiers = {
576
- selected: [],
577
- disabled: []
578
- };
579
- if (selected) {
580
- modifiers.selected = selected;
581
- modifiers.disabled = [
582
- function disableDay(day) {
583
- var isMaxSelected = initialProps.max &&
584
- selected &&
585
- selected.length > initialProps.max - 1;
586
- var isSelected = selected === null || selected === void 0 ? void 0 : selected.some(function (selectedDay) {
587
- return dateFns.isSameDay(selectedDay, day);
588
- });
589
- return Boolean(isMaxSelected && !isSelected);
590
- }
591
- ];
592
- }
593
- var contextValue = { selected: selected, handleDayClick: handleDayClick, modifiers: modifiers };
594
- return (React__default["default"].createElement(SelectMultipleContext.Provider, { value: contextValue }, children));
595
- }
596
-
597
- /** Hook to access the [[SelectMultipleContext]]. */
598
- function useSelectMultiple() {
599
- var context = React__default["default"].useContext(SelectMultipleContext);
600
- if (!context) {
601
- throw new Error('useSelectMultiple must be used within a SelectMultipleProvider');
602
- }
603
- return context;
604
- }
605
-
606
- /**
607
- * Add a day to an existing range.
608
- *
609
- * The returned range takes in account the `undefined` values and if the added
610
- * day is already present in the range.
611
- */
612
- function addToRange(day, range) {
613
- var _a = range || {}, from = _a.from, to = _a.to;
614
- if (!from) {
615
- return { from: day, to: day };
616
- }
617
- if (!to && dateFns.isSameDay(from, day)) {
618
- return undefined;
619
- }
620
- if (!to && dateFns.isBefore(day, from)) {
621
- return { from: day, to: from };
622
- }
623
- if (!to) {
624
- return { from: from, to: day };
625
- }
626
- if (dateFns.isSameDay(to, day) && dateFns.isSameDay(from, day)) {
627
- return undefined;
628
- }
629
- if (dateFns.isSameDay(to, day)) {
630
- return { from: to, to: to };
631
- }
632
- if (dateFns.isSameDay(from, day)) {
633
- return undefined;
634
- }
635
- if (dateFns.isAfter(from, day)) {
636
- return { from: day, to: to };
637
- }
638
- return { from: from, to: day };
639
- }
640
-
641
- /**
642
- * The SelectRange context shares details about the selected days when in
643
- * range selection mode.
644
- *
645
- * Access this context from the [[useSelectRange]] hook.
646
- */
647
- var SelectRangeContext = React__default["default"].createContext(undefined);
648
- /** Provides the values for the [[SelectRangeProvider]]. */
649
- function SelectRangeProvider(props) {
650
- if (!isDayPickerRange(props.initialProps)) {
651
- var emptyContextValue = {
652
- selected: undefined,
653
- modifiers: {
654
- selected: [],
655
- range_start: [],
656
- range_end: [],
657
- range_middle: [],
658
- disabled: []
659
- }
660
- };
661
- return (React__default["default"].createElement(SelectRangeContext.Provider, { value: emptyContextValue }, props.children));
662
- }
663
- return (React__default["default"].createElement(SelectRangeProviderInternal, { initialProps: props.initialProps, children: props.children }));
664
- }
665
- function SelectRangeProviderInternal(_a) {
666
- var initialProps = _a.initialProps, children = _a.children;
667
- var selected = initialProps.selected;
668
- var min = initialProps.min;
669
- var max = initialProps.max;
670
- var handleDayClick = function (day, modifiers, e) {
671
- var _a, _b;
672
- (_a = initialProps.onDayClick) === null || _a === void 0 ? void 0 : _a.call(initialProps, day, modifiers, e);
673
- var newValue = addToRange(day, selected);
674
- if ((min || max) &&
675
- selected &&
676
- (newValue === null || newValue === void 0 ? void 0 : newValue.to) &&
677
- newValue.from &&
678
- newValue.from !== newValue.to) {
679
- var diff = Math.abs(dateFns.differenceInCalendarDays(newValue === null || newValue === void 0 ? void 0 : newValue.to, newValue === null || newValue === void 0 ? void 0 : newValue.from));
680
- if (min && diff < min) {
681
- return;
682
- }
683
- if (max && diff >= max) {
684
- return;
685
- }
686
- }
687
- (_b = initialProps.onSelect) === null || _b === void 0 ? void 0 : _b.call(initialProps, newValue, day, modifiers, e);
688
- };
689
- var modifiers = {
690
- selected: [],
691
- range_start: [],
692
- range_end: [],
693
- range_middle: [],
694
- disabled: []
695
- };
696
- if (selected) {
697
- modifiers.selected = [selected];
698
- if (selected.from) {
699
- modifiers.range_start = [selected.from];
700
- if (selected.to) {
701
- modifiers.range_middle = [
702
- {
703
- after: selected.from,
704
- before: selected.to
705
- }
706
- ];
707
- if (max || min) {
708
- modifiers.disabled = [
709
- function (date) {
710
- if (max &&
711
- selected.to &&
712
- selected.from &&
713
- dateFns.isBefore(date, selected.from)) {
714
- var diff = dateFns.differenceInCalendarDays(selected.to, date);
715
- if (diff >= max) {
716
- return true;
717
- }
718
- }
719
- if (max &&
720
- selected.to &&
721
- selected.from &&
722
- dateFns.isAfter(date, selected.to)) {
723
- var diff = dateFns.differenceInCalendarDays(date, selected.from);
724
- if (diff >= max) {
725
- return true;
726
- }
727
- }
728
- if (min && selected.from && dateFns.isBefore(date, selected.from)) {
729
- var diff = dateFns.differenceInCalendarDays(selected.from, date);
730
- if (diff < min) {
731
- return true;
732
- }
733
- }
734
- if (min &&
735
- selected.to &&
736
- selected.from &&
737
- dateFns.isAfter(date, selected.to)) {
738
- var diff = dateFns.differenceInCalendarDays(date, selected.from);
739
- if (diff < min) {
740
- return true;
741
- }
742
- }
743
- return false;
744
- }
745
- ];
746
- }
747
- modifiers.range_end = [selected.to];
748
- }
749
- else {
750
- modifiers.range_end = [selected.from];
751
- }
752
- }
753
- }
754
- return (React__default["default"].createElement(SelectRangeContext.Provider, { value: { selected: selected, handleDayClick: handleDayClick, modifiers: modifiers } }, children));
755
- }
756
-
757
- /** Hook to access the [[SelectRangeContext]]. */
758
- function useSelectRange() {
759
- var context = React__default["default"].useContext(SelectRangeContext);
760
- if (!context) {
761
- throw new Error('useSelectRange must be used within a SelectRangeProvider');
762
- }
763
- return context;
764
- }
765
-
766
- /**
767
- * The SelectSingle context shares details about the selected days when in
768
- * single selection mode.
769
- *
770
- * Access this context from the [[useSelectSingle]] hook.
771
- */
772
- var SelectSingleContext = React__default["default"].createContext(undefined);
773
- /** Provides the values for the [[SelectSingleProvider]]. */
774
- function SelectSingleProvider(props) {
775
- if (!isDayPickerSingle(props.initialProps)) {
776
- var emptyContextValue = {
777
- selected: undefined,
778
- modifiers: { selected: [] }
779
- };
780
- return (React__default["default"].createElement(SelectSingleContext.Provider, { value: emptyContextValue }, props.children));
781
- }
782
- return (React__default["default"].createElement(SelectSingleProviderInternal, { initialProps: props.initialProps, children: props.children }));
783
- }
784
- function SelectSingleProviderInternal(_a) {
785
- var initialProps = _a.initialProps, children = _a.children;
786
- var handleDayClick = function (day, dayModifiers, e) {
787
- var _a, _b;
788
- if (dayModifiers.selected && !initialProps.required) {
789
- (_a = initialProps.onSelect) === null || _a === void 0 ? void 0 : _a.call(initialProps, undefined, day, dayModifiers, e);
790
- return;
791
- }
792
- (_b = initialProps.onSelect) === null || _b === void 0 ? void 0 : _b.call(initialProps, day, day, dayModifiers, e);
793
- };
794
- var modifiers = { selected: [] };
795
- if (initialProps.selected) {
796
- modifiers.selected = [initialProps.selected];
797
- }
798
- var contextValue = {
799
- selected: initialProps.selected,
800
- handleDayClick: handleDayClick,
801
- modifiers: modifiers
802
- };
803
- return (React__default["default"].createElement(SelectSingleContext.Provider, { value: contextValue }, children));
804
- }
805
-
806
- /** Hook to access the [[SelectSingleContext]]. */
807
- function useSelectSingle() {
808
- var context = React__default["default"].useContext(SelectSingleContext);
809
- if (!context) {
810
- throw new Error('useSelectSingle must be used within a SelectSingleProvider');
811
- }
812
- return context;
813
- }
814
-
815
- /** Returns true if `matcher` is of type [[DateInterval]]. */
816
- function isDateInterval(matcher) {
817
- return Boolean(matcher &&
818
- typeof matcher === 'object' &&
819
- 'before' in matcher &&
820
- 'after' in matcher);
821
- }
822
- /** Returns true if `value` is a [[DateRange]] type. */
823
- function isDateRange(value) {
824
- // TODO: Check if dates?!
825
- return Boolean(value && typeof value === 'object' && 'from' in value);
826
- }
827
- /** Returns true if `value` is of type [[DateAfter]]. */
828
- function isDateAfterType(value) {
829
- return Boolean(value && typeof value === 'object' && 'after' in value);
830
- }
831
- /** Returns true if `value` is of type [[DateBefore]]. */
832
- function isDateBeforeType(value) {
833
- return Boolean(value && typeof value === 'object' && 'before' in value);
834
- }
835
- /** Returns true if `value` is a [[DayOfWeek]] type. */
836
- function isDayOfWeekType(value) {
837
- return Boolean(value && typeof value === 'object' && 'dayOfWeek' in value);
838
- }
839
-
840
- /** Return `true` whether the given date is inside the range. */
841
- function isDateInRange(date, range) {
842
- var _a;
843
- var from = range.from, to = range.to;
844
- if (!from) {
845
- return false;
846
- }
847
- if (!to && dateFns.isSameDay(from, date)) {
848
- return true;
849
- }
850
- if (!to) {
851
- return false;
852
- }
853
- var isToBeforeFrom = dateFns.differenceInCalendarDays(to, from) < 0;
854
- if (to && isToBeforeFrom) {
855
- _a = [to, from], from = _a[0], to = _a[1];
856
- }
857
- return (dateFns.differenceInCalendarDays(date, from) >= 0 &&
858
- dateFns.differenceInCalendarDays(to, date) >= 0);
859
- }
860
-
861
- /** Returns true if `value` is a Date type. */
862
- function isDateType(value) {
863
- return dateFns.isDate(value);
864
- }
865
- /** Returns true if `value` is an array of valid dates. */
866
- function isArrayOfDates(value) {
867
- return Array.isArray(value) && value.every(dateFns.isDate);
868
- }
869
- /**
870
- * Returns `true` whether the day matches against the given matchers.
871
- */
872
- function isMatch(day, matchers) {
873
- return matchers.some(function (matcher) {
874
- if (typeof matcher === 'boolean') {
875
- return matcher;
876
- }
877
- if (isDateType(matcher)) {
878
- return dateFns.isSameDay(day, matcher);
879
- }
880
- if (isArrayOfDates(matcher)) {
881
- return matcher.includes(day);
882
- }
883
- if (isDateRange(matcher)) {
884
- return isDateInRange(day, matcher);
885
- }
886
- if (isDayOfWeekType(matcher)) {
887
- return matcher.dayOfWeek.includes(day.getDay());
888
- }
889
- if (isDateInterval(matcher)) {
890
- var isBefore = dateFns.differenceInCalendarDays(matcher.before, day) > 0;
891
- var isAfter = dateFns.differenceInCalendarDays(day, matcher.after) > 0;
892
- return isBefore && isAfter;
893
- }
894
- if (isDateAfterType(matcher)) {
895
- return dateFns.differenceInCalendarDays(day, matcher.after) > 0;
896
- }
897
- if (isDateBeforeType(matcher)) {
898
- return dateFns.differenceInCalendarDays(matcher.before, day) > 0;
899
- }
900
- if (typeof matcher === 'function') {
901
- return matcher(day);
902
- }
903
- return false;
904
- });
905
- }
906
-
907
- /**
908
- * Return the status of the modifiers that matches the given date.
909
- */
910
- function getModifierStatus(date,
911
- /** The modifiers to match for the given date. */
912
- modifiers) {
913
- var modifiersList = Object.keys(modifiers).reduce(function (previousValue, key) {
914
- var modifier = modifiers[key];
915
- if (isMatch(date, modifier)) {
916
- previousValue.push(key);
917
- }
918
- return previousValue;
919
- }, []);
920
- var modifiersStatus = {};
921
- modifiersList.forEach(function (modifier) { return (modifiersStatus[modifier] = true); });
922
- return modifiersStatus;
923
- }
924
-
925
- /** Return the modifiers and its styles for the specified date. */
926
- function useModifiers(date) {
927
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
928
- var context = useDayPicker();
929
- var singleSelect = useSelectSingle();
930
- var multipleSelect = useSelectMultiple();
931
- var rangeSelect = useSelectRange();
932
- // TODO: modifiers from context should not be overridden
933
- var modifiers = __assign(__assign({}, context.modifiers), { today: (_a = context.modifiers.today) !== null && _a !== void 0 ? _a : [context.today], disabled: context.modifiers.disabled });
934
- if (isDayPickerSingle(context)) {
935
- modifiers.selected = modifiers.selected.concat((_b = singleSelect.modifiers.selected) !== null && _b !== void 0 ? _b : []);
936
- }
937
- else if (isDayPickerMultiple(context)) {
938
- modifiers.selected = modifiers.selected.concat((_c = multipleSelect.modifiers.selected) !== null && _c !== void 0 ? _c : []);
939
- modifiers.disabled = modifiers.disabled.concat((_d = multipleSelect.modifiers.disabled) !== null && _d !== void 0 ? _d : []);
940
- }
941
- else if (isDayPickerRange(context)) {
942
- modifiers.selected = modifiers.selected.concat((_e = rangeSelect.modifiers.selected) !== null && _e !== void 0 ? _e : []);
943
- modifiers.disabled = modifiers.disabled.concat((_f = rangeSelect.modifiers.disabled) !== null && _f !== void 0 ? _f : []);
944
- modifiers.range_start = (_g = rangeSelect.modifiers.range_start) !== null && _g !== void 0 ? _g : [];
945
- modifiers.range_middle = (_h = rangeSelect.modifiers.range_middle) !== null && _h !== void 0 ? _h : [];
946
- modifiers.range_end = (_j = rangeSelect.modifiers.range_end) !== null && _j !== void 0 ? _j : [];
947
- }
948
- var status = getModifierStatus(date, modifiers);
949
- var modifierClassNames = [];
950
- Object.keys(status)
951
- .filter(function (modifier) { return Boolean(status[modifier]); })
952
- .forEach(function (modifier) {
953
- var customClassName = context.modifierClassNames[modifier];
954
- if (customClassName) {
955
- modifierClassNames.push(customClassName);
956
- }
957
- else {
958
- modifierClassNames.push("" + context.modifierPrefix + modifier);
959
- }
960
- });
961
- var modifierStyle = {};
962
- if (context.modifierStyles) {
963
- Object.keys(status).forEach(function (modifier) {
964
- var _a;
965
- modifierStyle = __assign(__assign({}, modifierStyle), (_a = context.modifierStyles) === null || _a === void 0 ? void 0 : _a[modifier]);
966
- });
967
- }
968
- return {
969
- modifiers: status,
970
- modifierClassNames: modifierClassNames,
971
- modifierStyle: modifierStyle
972
- };
973
- }
974
-
975
- /**
976
- * The Focus context shares details about the focused day for the keyboard navigation.
977
- *
978
- * Access this context from the [[useFocus]] hook.
979
- */
980
- var FocusContext = React__default["default"].createContext(undefined);
981
- /** The provider for the [[FocusContext]]. */
982
- function FocusProvider(_a) {
983
- var children = _a.children;
984
- var _b = React__default["default"].useState(), focusedDay = _b[0], setDay = _b[1];
985
- var _c = useNavigation(), goToMonth = _c.goToMonth, displayMonths = _c.displayMonths;
986
- var numberOfMonths = useDayPicker().numberOfMonths;
987
- var blur = function () { return setDay(undefined); };
988
- var focus = function (date) { return setDay(date); };
989
- var switchMonth = function (date, offset) {
990
- if (displayMonths.some(function (m) { return dateFns.isSameMonth(date, m); }))
991
- return;
992
- if (offset < 0) {
993
- goToMonth(dateFns.addMonths(date, 1 + offset));
994
- }
995
- else {
996
- goToMonth(date);
997
- }
998
- };
999
- var focusDayBefore = function () {
1000
- if (!focusedDay)
1001
- return;
1002
- var before = dateFns.addDays(focusedDay, -1);
1003
- setDay(before);
1004
- switchMonth(before, numberOfMonths * -1);
1005
- };
1006
- var focusDayAfter = function () {
1007
- if (!focusedDay)
1008
- return;
1009
- var after = dateFns.addDays(focusedDay, 1);
1010
- setDay(after);
1011
- switchMonth(after, numberOfMonths);
1012
- };
1013
- var focusWeekBeforeDay = function () {
1014
- if (!focusedDay)
1015
- return;
1016
- var up = dateFns.addWeeks(focusedDay, -1);
1017
- setDay(up);
1018
- switchMonth(up, numberOfMonths * -1);
1019
- };
1020
- var focusWeekAfterDay = function () {
1021
- if (!focusedDay)
1022
- return;
1023
- var down = dateFns.addWeeks(focusedDay, 1);
1024
- setDay(down);
1025
- switchMonth(down, numberOfMonths);
1026
- };
1027
- var setters = {
1028
- blur: blur,
1029
- focus: focus,
1030
- focusDayAfter: focusDayAfter,
1031
- focusDayBefore: focusDayBefore,
1032
- focusWeekAfterDay: focusWeekAfterDay,
1033
- focusWeekBeforeDay: focusWeekBeforeDay
1034
- };
1035
- return (React__default["default"].createElement(FocusContext.Provider, { value: [focusedDay, setters] }, children));
1036
- }
1037
-
1038
- /** Hook to access the [[FocusContext]]. */
1039
- function useFocus() {
1040
- var context = React__default["default"].useContext(FocusContext);
1041
- if (!context) {
1042
- throw new Error('useFocus must be used within a FocusProvider');
1043
- }
1044
- return context;
1045
- }
1046
-
1047
- /** Handle the focus for the day element. */
1048
- function useDayFocus(date, buttonRef) {
1049
- var _a = useFocus(), focusedDay = _a[0], _b = _a[1], focusDayAfter = _b.focusDayAfter, focusDayBefore = _b.focusDayBefore, focusWeekAfterDay = _b.focusWeekAfterDay, focusWeekBeforeDay = _b.focusWeekBeforeDay, blur = _b.blur, focus = _b.focus;
1050
- var dir = useDayPicker().dir;
1051
- // Focus the HTML element if this is the focused day.
1052
- React__default["default"].useEffect(function () {
1053
- var _a;
1054
- if (!focusedDay)
1055
- return;
1056
- if (dateFns.isSameDay(focusedDay, date)) {
1057
- (_a = buttonRef.current) === null || _a === void 0 ? void 0 : _a.focus();
1058
- }
1059
- }, [focusedDay, date, buttonRef]);
1060
- var focusOnKeyDown = function (e) {
1061
- switch (e.key) {
1062
- case 'ArrowLeft':
1063
- e.preventDefault();
1064
- e.stopPropagation();
1065
- dir === 'rtl' ? focusDayAfter() : focusDayBefore();
1066
- break;
1067
- case 'ArrowRight':
1068
- e.preventDefault();
1069
- e.stopPropagation();
1070
- dir === 'rtl' ? focusDayBefore() : focusDayAfter();
1071
- break;
1072
- case 'ArrowDown':
1073
- e.preventDefault();
1074
- e.stopPropagation();
1075
- focusWeekAfterDay();
1076
- break;
1077
- case 'ArrowUp':
1078
- e.preventDefault();
1079
- e.stopPropagation();
1080
- focusWeekBeforeDay();
1081
- break;
1082
- }
1083
- };
1084
- var isFocused = Boolean(focusedDay && !dateFns.isSameDay(focusedDay, date));
1085
- return { focus: focus, blur: blur, focusOnKeyDown: focusOnKeyDown, isFocused: isFocused };
1086
- }
1087
-
1088
- /**
1089
- * This hook returns details about the content to render in the day cell.
1090
- *
1091
- *
1092
- * When a day cell is rendered in the table, DayPicker can either:
1093
- *
1094
- * - render nothing: when the day is outside the month or has matched the
1095
- * "hidden" modifier.
1096
- * - render a button. When a selection mode is set, DayPicker renders a button
1097
- * to allow the focus and the selection. In case of `custom` selection
1098
- * mode, DayPicker expects a `onDayClick` prop to render a button.
1099
- * - render a non-interactive element: when no selection mode is set, the day
1100
- * cell shouldn’t respond to any interaction. DayPicker should render a `div`
1101
- * or a `span`.
1102
- *
1103
- * ### Usage
1104
- *
1105
- * Use this hook to customize the behavior of the [[Day]] component. Create a
1106
- * new `Day` component using this hook and pass it to the `components` prop.
1107
- * The source of [[Day]] can be a good starting point.
1108
- *
1109
- * */
1110
- function useDay(
1111
- /** The day rendered in the month. */
1112
- date,
1113
- /** The month where the date is displayed. DayPicker renders days outside the display month when `showOutsideDays` is true. */
1114
- displayMonth,
1115
- /** A ref to the button element. */
1116
- buttonRef) {
1117
- var context = useDayPicker();
1118
- var single = useSelectSingle();
1119
- var multiple = useSelectMultiple();
1120
- var range = useSelectRange();
1121
- var _a = useDayFocus(date, buttonRef), focus = _a.focus, blur = _a.blur, focusOnKeyDown = _a.focusOnKeyDown, isFocused = _a.isFocused;
1122
- var _b = useModifiers(date), modifiers = _b.modifiers, modifierClassNames = _b.modifierClassNames, modifierStyle = _b.modifierStyle;
1123
- var isOutside = !dateFns.isSameMonth(date, displayMonth);
1124
- var returnValue = {
1125
- isOutside: isOutside,
1126
- modifiers: modifiers,
1127
- selected: isDayPickerSingle(context)
1128
- ? single.selected
1129
- : isDayPickerMultiple(context)
1130
- ? multiple.selected
1131
- : isDayPickerRange(context)
1132
- ? range.selected
1133
- : undefined,
1134
- single: single,
1135
- multiple: multiple,
1136
- range: range
1137
- };
1138
- if (isOutside && !context.showOutsideDays) {
1139
- return returnValue;
1140
- }
1141
- if (modifiers.hidden) {
1142
- return returnValue;
1143
- }
1144
- var classNames = [context.classNames.day].concat(modifierClassNames);
1145
- var style = __assign(__assign({}, context.styles.day), modifierStyle);
1146
- if (isOutside) {
1147
- classNames.push(context.classNames.day_outside);
1148
- style = __assign(__assign({}, context.styles), context.styles.day_outside);
1149
- }
1150
- var DayContent = context.components.DayContent;
1151
- var children = (React__default["default"].createElement(DayContent, { date: date, displayMonth: displayMonth, modifiers: modifiers }));
1152
- var className = classNames.join(' ');
1153
- if (!context.mode && !context.onDayClick) {
1154
- return __assign(__assign({}, returnValue), { nonInteractiveProps: {
1155
- style: style,
1156
- className: className,
1157
- children: children
1158
- } });
1159
- }
1160
- // #region Event handlers
1161
- var handleClick = function (e) {
1162
- var _a, _b, _c, _d;
1163
- if (isDayPickerSingle(context)) {
1164
- (_a = single.handleDayClick) === null || _a === void 0 ? void 0 : _a.call(single, date, modifiers, e);
1165
- }
1166
- else if (isDayPickerMultiple(context)) {
1167
- (_b = multiple.handleDayClick) === null || _b === void 0 ? void 0 : _b.call(multiple, date, modifiers, e);
1168
- }
1169
- else if (isDayPickerRange(context)) {
1170
- (_c = range.handleDayClick) === null || _c === void 0 ? void 0 : _c.call(range, date, modifiers, e);
1171
- }
1172
- (_d = context.onDayClick) === null || _d === void 0 ? void 0 : _d.call(context, date, modifiers, e);
1173
- };
1174
- var handleFocus = function (e) {
1175
- var _a;
1176
- focus(date);
1177
- (_a = context.onDayFocus) === null || _a === void 0 ? void 0 : _a.call(context, date, modifiers, e);
1178
- };
1179
- var handleBlur = function (e) {
1180
- var _a;
1181
- blur();
1182
- (_a = context.onDayBlur) === null || _a === void 0 ? void 0 : _a.call(context, date, modifiers, e);
1183
- };
1184
- var handleKeyDown = function (e) {
1185
- var _a;
1186
- focusOnKeyDown(e);
1187
- (_a = context.onDayKeyDown) === null || _a === void 0 ? void 0 : _a.call(context, date, modifiers, e);
1188
- };
1189
- var handleKeyUp = function (e) {
1190
- var _a;
1191
- (_a = context.onDayKeyUp) === null || _a === void 0 ? void 0 : _a.call(context, date, modifiers, e);
1192
- };
1193
- var handleMouseEnter = function (e) {
1194
- var _a;
1195
- (_a = context.onDayMouseEnter) === null || _a === void 0 ? void 0 : _a.call(context, date, modifiers, e);
1196
- };
1197
- var handleMouseLeave = function (e) {
1198
- var _a;
1199
- (_a = context.onDayMouseLeave) === null || _a === void 0 ? void 0 : _a.call(context, date, modifiers, e);
1200
- };
1201
- var handleTouchCancel = function (e) {
1202
- var _a;
1203
- (_a = context.onDayTouchCancel) === null || _a === void 0 ? void 0 : _a.call(context, date, modifiers, e);
1204
- };
1205
- var handleTouchEnd = function (e) {
1206
- var _a;
1207
- (_a = context.onDayTouchEnd) === null || _a === void 0 ? void 0 : _a.call(context, date, modifiers, e);
1208
- };
1209
- var handleTouchMove = function (e) {
1210
- var _a;
1211
- (_a = context.onDayTouchMove) === null || _a === void 0 ? void 0 : _a.call(context, date, modifiers, e);
1212
- };
1213
- var handleTouchStart = function (e) {
1214
- var _a;
1215
- (_a = context.onDayTouchStart) === null || _a === void 0 ? void 0 : _a.call(context, date, modifiers, e);
1216
- };
1217
- if (isOutside) {
1218
- classNames.push(context.classNames.day_outside);
1219
- style = __assign(__assign({}, context.styles), context.styles.day_outside);
1220
- }
1221
- className = classNames.join(' ');
1222
- var selected = modifiers.selected, disabled = modifiers.disabled;
1223
- var tabIndex = disabled || isFocused ? -1 : 0;
1224
- return __assign(__assign({}, returnValue), { buttonProps: {
1225
- children: children,
1226
- 'aria-pressed': selected,
1227
- style: style,
1228
- disabled: disabled,
1229
- className: className,
1230
- tabIndex: tabIndex,
1231
- onClick: handleClick,
1232
- onFocus: handleFocus,
1233
- onBlur: handleBlur,
1234
- onKeyDown: handleKeyDown,
1235
- onKeyUp: handleKeyUp,
1236
- onMouseEnter: handleMouseEnter,
1237
- onMouseLeave: handleMouseLeave,
1238
- onTouchCancel: handleTouchCancel,
1239
- onTouchEnd: handleTouchEnd,
1240
- onTouchMove: handleTouchMove,
1241
- onTouchStart: handleTouchStart
1242
- } });
1243
- }
1244
-
1245
- /**
1246
- * The content of a day cell – as a button or span element according to its
1247
- * modifiers.
1248
- */
1249
- function Day(props) {
1250
- var buttonRef = React__default["default"].useRef(null);
1251
- var day = useDay(props.date, props.displayMonth, buttonRef);
1252
- var buttonProps = day.buttonProps, nonInteractiveProps = day.nonInteractiveProps;
1253
- if (!buttonProps && !nonInteractiveProps) {
1254
- return React__default["default"].createElement(React__default["default"].Fragment, null);
1255
- }
1256
- if (nonInteractiveProps) {
1257
- return React__default["default"].createElement("div", __assign({}, nonInteractiveProps));
1258
- }
1259
- return React__default["default"].createElement(Button, __assign({ ref: buttonRef }, buttonProps));
1260
- }
1261
-
1262
- /**
1263
- * Build the `fromDate` and `toDate` values, given the fromMonth/toMonth
1264
- * or fromYear/toYear props.
1265
- */
1266
- function parseFromToProps(props) {
1267
- var fromYear = props.fromYear, toYear = props.toYear, fromMonth = props.fromMonth, toMonth = props.toMonth;
1268
- var fromDate = props.fromDate, toDate = props.toDate;
1269
- if (fromMonth) {
1270
- fromDate = dateFns.startOfMonth(fromMonth);
1271
- }
1272
- else if (fromYear) {
1273
- fromDate = new Date(fromYear, 0, 1);
1274
- }
1275
- if (toMonth) {
1276
- toDate = dateFns.startOfMonth(toMonth);
1277
- }
1278
- else if (toYear) {
1279
- toDate = new Date(toYear, 11, 31);
1280
- }
1281
- return {
1282
- fromDate: fromDate ? dateFns.startOfDay(fromDate) : undefined,
1283
- toDate: toDate ? dateFns.startOfDay(toDate) : undefined
1284
- };
1285
- }
1286
-
1287
- /** Props that will merge into the modifiers. */
1288
- var modifierShortcuts = [
1289
- 'selected',
1290
- 'hidden',
1291
- 'disabled'
1292
- ];
1293
- /**
1294
- * Parse the modifiers from the props and return them as a map of array of
1295
- * matcher.
1296
- *
1297
- * Internally we want modifiers as an array of matchers – as opposite of the
1298
- * props which can accept also a matcher.
1299
- */
1300
- function parseModifierProps(initialProps) {
1301
- var initialModifiers = initialProps.modifiers || {};
1302
- var modifiers = {
1303
- selected: [],
1304
- disabled: [],
1305
- hidden: [],
1306
- today: [],
1307
- range_end: [],
1308
- range_middle: [],
1309
- range_start: []
1310
- };
1311
- Object.entries(initialModifiers).forEach(function (_a) {
1312
- var modifier = _a[0], matcher = _a[1];
1313
- if (Array.isArray(matcher)) {
1314
- modifiers[modifier] = matcher;
1315
- }
1316
- else if (matcher) {
1317
- modifiers[modifier] = [matcher];
1318
- }
1319
- else {
1320
- modifiers[modifier] = [];
1321
- }
1322
- });
1323
- modifierShortcuts.forEach(function (modifier) {
1324
- // @ts-expect-error TOFIX: initial props do not have some modifiers
1325
- var modifierFromProp = initialProps[modifier];
1326
- if (Array.isArray(modifierFromProp)) {
1327
- modifiers[modifier] = modifierFromProp;
1328
- }
1329
- else if (modifierFromProp !== undefined) {
1330
- modifiers[modifier] = [modifierFromProp];
1331
- }
1332
- else {
1333
- modifiers[modifier] = [];
1334
- }
1335
- });
1336
- return modifiers;
1337
- }
1338
-
1339
- /**
1340
- * Render the content of the day cell.
1341
- */
1342
- function DayContent(props) {
1343
- var _a = useDayPicker(), locale = _a.locale, classNames = _a.classNames, styles = _a.styles, labelDay = _a.labels.labelDay, formatDay = _a.formatters.formatDay;
1344
- return (React__default["default"].createElement(React__default["default"].Fragment, null,
1345
- React__default["default"].createElement("span", { "aria-hidden": "true" }, formatDay(props.date, { locale: locale })),
1346
- React__default["default"].createElement("span", { className: classNames.vhidden, style: styles.vhidden }, labelDay(props.date, props.modifiers, { locale: locale }))));
1347
- }
1348
-
1349
- /**
1350
- * Render a styled select component – displaying a caption and a custom
1351
- * drop-down icon.
1352
- */
1353
- function Dropdown(props) {
1354
- var onChange = props.onChange, value = props.value, children = props.children, caption = props.caption, className = props.className, style = props.style;
1355
- var _a = useDayPicker(), classNames = _a.classNames, styles = _a.styles, IconDropdown = _a.components.IconDropdown;
1356
- return (React__default["default"].createElement("div", { className: className, style: style },
1357
- React__default["default"].createElement("span", { className: classNames.vhidden }, props['aria-label']),
1358
- React__default["default"].createElement("select", { "aria-label": props['aria-label'], className: classNames.dropdown, style: styles.dropdown, value: value, onChange: onChange }, children),
1359
- React__default["default"].createElement("div", { className: classNames.caption_label, style: styles.caption_label, "aria-hidden": "true" },
1360
- caption,
1361
- React__default["default"].createElement(IconDropdown, { className: classNames.dropdown_icon, style: styles.dropdown_icon }))));
1362
- }
1363
-
1364
- /** Render the Footer component (empty as default).*/
1365
- function Footer() {
1366
- var _a = useDayPicker(), footer = _a.footer, styles = _a.styles, tfoot = _a.classNames.tfoot;
1367
- if (!footer)
1368
- return React__default["default"].createElement(React__default["default"].Fragment, null);
1369
- return (React__default["default"].createElement("tfoot", { className: tfoot, style: styles.tfoot },
1370
- React__default["default"].createElement("tr", null,
1371
- React__default["default"].createElement("td", { colSpan: 8 }, footer))));
1372
- }
1373
-
1374
- /**
1375
- * Generate a series of 7 days, starting from the week, to use for formatting
1376
- * the weekday names (Monday, Tuesday, etc.).
1377
- */
1378
- function getWeekdays(locale) {
1379
- var start = dateFns.startOfWeek(new Date(), { locale: locale });
1380
- var days = [];
1381
- for (var i = 0; i < 7; i++) {
1382
- var day = dateFns.addDays(start, i);
1383
- days.push(day);
1384
- }
1385
- return days;
1386
- }
1387
-
1388
- /**
1389
- * Render the Head component - i.e. the table head with the weekday names.
1390
- */
1391
- function Head() {
1392
- var _a = useDayPicker(), classNames = _a.classNames, styles = _a.styles, showWeekNumber = _a.showWeekNumber, locale = _a.locale, formatWeekdayName = _a.formatters.formatWeekdayName, labelWeekday = _a.labels.labelWeekday;
1393
- var weekdays = getWeekdays(locale);
1394
- return (React__default["default"].createElement("thead", { style: styles.head, className: classNames.head },
1395
- React__default["default"].createElement("tr", { style: styles.head_row, className: classNames.head_row },
1396
- showWeekNumber && (React__default["default"].createElement("th", { scope: "col", style: styles.head_cell, className: classNames.head_cell })),
1397
- weekdays.map(function (weekday, i) { return (React__default["default"].createElement("th", { key: i, scope: "col", className: classNames.head_cell, style: styles.head_cell },
1398
- React__default["default"].createElement("span", { className: classNames.vhidden, "aria-label": "" }, labelWeekday(weekday, { locale: locale })),
1399
- React__default["default"].createElement("span", { "aria-hidden": true }, formatWeekdayName(weekday, { locale: locale })))); }))));
1400
- }
1401
-
1402
- /**
1403
- * Render the icon in the styled drop-down.
1404
- */
1405
- function IconDropdown(props) {
1406
- return (React__default["default"].createElement("svg", __assign({ width: "8px", height: "8px", viewBox: "0 0 120 120", "data-testid": "iconDropdown" }, props),
1407
- React__default["default"].createElement("path", { d: "M4.22182541,48.2218254 C8.44222828,44.0014225 15.2388494,43.9273804 19.5496459,47.9996989 L19.7781746,48.2218254 L60,88.443 L100.221825,48.2218254 C104.442228,44.0014225 111.238849,43.9273804 115.549646,47.9996989 L115.778175,48.2218254 C119.998577,52.4422283 120.07262,59.2388494 116.000301,63.5496459 L115.778175,63.7781746 L67.7781746,111.778175 C63.5577717,115.998577 56.7611506,116.07262 52.4503541,112.000301 L52.2218254,111.778175 L4.22182541,63.7781746 C-0.0739418023,59.4824074 -0.0739418023,52.5175926 4.22182541,48.2218254 Z", fill: "currentColor", fillRule: "nonzero" })));
1408
- }
1409
-
1410
- /**
1411
- * Render the "previous month" button in the navigation.
1412
- */
1413
- function IconLeft(props) {
1414
- return (React__default["default"].createElement("svg", __assign({ width: "16px", height: "16px", viewBox: "0 0 120 120", "data-testid": "iconLeft" }, props),
1415
- React__default["default"].createElement("path", { d: "M69.490332,3.34314575 C72.6145263,0.218951416 77.6798462,0.218951416 80.8040405,3.34314575 C83.8617626,6.40086786 83.9268205,11.3179931 80.9992143,14.4548388 L80.8040405,14.6568542 L35.461,60 L80.8040405,105.343146 C83.8617626,108.400868 83.9268205,113.317993 80.9992143,116.454839 L80.8040405,116.656854 C77.7463184,119.714576 72.8291931,119.779634 69.6923475,116.852028 L69.490332,116.656854 L18.490332,65.6568542 C15.4326099,62.5991321 15.367552,57.6820069 18.2951583,54.5451612 L18.490332,54.3431458 L69.490332,3.34314575 Z", fill: "currentColor", fillRule: "nonzero" })));
1416
- }
1417
-
1418
- /**
1419
- * Render the "next month" button in the navigation.
1420
- */
1421
- function IconRight(props) {
1422
- return (React__default["default"].createElement("svg", __assign({ width: "16px", height: "16px", viewBox: "0 0 120 120" }, props, { "data-testid": "iconRight" }),
1423
- React__default["default"].createElement("path", { d: "M49.8040405,3.34314575 C46.6798462,0.218951416 41.6145263,0.218951416 38.490332,3.34314575 C35.4326099,6.40086786 35.367552,11.3179931 38.2951583,14.4548388 L38.490332,14.6568542 L83.8333725,60 L38.490332,105.343146 C35.4326099,108.400868 35.367552,113.317993 38.2951583,116.454839 L38.490332,116.656854 C41.5480541,119.714576 46.4651794,119.779634 49.602025,116.852028 L49.8040405,116.656854 L100.804041,65.6568542 C103.861763,62.5991321 103.926821,57.6820069 100.999214,54.5451612 L100.804041,54.3431458 L49.8040405,3.34314575 Z", fill: "currentColor" })));
1424
- }
1425
-
1426
- /**
1427
- * Render a row in the calendar, with the days and optionally the week number.
1428
- */
1429
- function Row(props) {
1430
- var _a = useDayPicker(), styles = _a.styles, classNames = _a.classNames, showWeekNumber = _a.showWeekNumber, _b = _a.components, Day = _b.Day, WeekNumber = _b.WeekNumber;
1431
- var weekNumberCell;
1432
- if (showWeekNumber) {
1433
- weekNumberCell = (React__default["default"].createElement("td", { className: classNames.cell, style: styles.cell },
1434
- React__default["default"].createElement(WeekNumber, { number: props.weekNumber, dates: props.dates })));
1435
- }
1436
- return (React__default["default"].createElement("tr", { className: classNames.row, style: styles.row },
1437
- weekNumberCell,
1438
- props.dates.map(function (date) { return (React__default["default"].createElement("td", { className: classNames.cell, style: styles.cell, key: dateFns.getUnixTime(date) },
1439
- React__default["default"].createElement(Day, { displayMonth: props.displayMonth, date: date }))); })));
1440
- }
1441
-
1442
- /**
1443
- * Render the week number element. If `onWeekNumberClick` is passed to DayPicker, it
1444
- * renders a button, otherwise a span element.
1445
- */
1446
- function WeekNumber(props) {
1447
- var weekNumber = props.number, dates = props.dates;
1448
- var _a = useDayPicker(), onWeekNumberClick = _a.onWeekNumberClick, styles = _a.styles, classNames = _a.classNames, locale = _a.locale, labelWeekNumber = _a.labels.labelWeekNumber, formatWeekNumber = _a.formatters.formatWeekNumber;
1449
- var handleClick = function (e) {
1450
- onWeekNumberClick === null || onWeekNumberClick === void 0 ? void 0 : onWeekNumberClick(weekNumber, dates, e);
1451
- };
1452
- var content = formatWeekNumber(Number(weekNumber), { locale: locale });
1453
- if (!onWeekNumberClick) {
1454
- return (React__default["default"].createElement("span", { className: classNames.weeknumber, style: styles.weeknumber }, content));
1455
- }
1456
- var label = labelWeekNumber(Number(weekNumber), { locale: locale });
1457
- return (React__default["default"].createElement(Button, { "aria-label": label, className: classNames.weeknumber, style: styles.weeknumber, onClick: handleClick }, content));
1458
- }
1459
-
1460
- /**
1461
- * The name of the default CSS classes.
1462
- */
1463
- var defaultClassNames = {
1464
- root: 'rdp',
1465
- multiple_month: 'rdp-multiple_months',
1466
- with_weeknumber: 'rdp-with_weeknumber',
1467
- vhidden: 'rdp-vhidden',
1468
- button_reset: 'rdp-button_reset',
1469
- button: 'rdp-button',
1470
- caption: 'rdp-caption',
1471
- caption_first: 'rdp-caption_first',
1472
- caption_last: 'rdp-caption_last',
1473
- caption_middle: 'rdp-caption_middle',
1474
- caption_label: 'rdp-caption_label',
1475
- caption_dropdowns: 'rdp-caption_dropdowns',
1476
- dropdown: 'rdp-dropdown',
1477
- dropdown_month: 'rdp-dropdown_month',
1478
- dropdown_year: 'rdp-dropdown_year',
1479
- dropdown_icon: 'rdp-dropdown_icon',
1480
- months: 'rdp-months',
1481
- month: 'rdp-month',
1482
- table: 'rdp-table',
1483
- tbody: 'rdp-tbody',
1484
- tfoot: 'rdp-tfoot',
1485
- head: 'rdp-head',
1486
- head_row: 'rdp-head_row',
1487
- head_cell: 'rdp-head_cell',
1488
- nav: 'rdp-nav',
1489
- nav_button: 'rdp-nav_button',
1490
- nav_button_previous: 'rdp-nav_button_previous',
1491
- nav_button_next: 'rdp-nav_button_next',
1492
- nav_icon: 'rdp-nav_icon',
1493
- row: 'rdp-row',
1494
- weeknumber: 'rdp-weeknumber',
1495
- cell: 'rdp-cell',
1496
- day: 'rdp-day',
1497
- day_outside: 'rdp-day_outside'
62
+ function canUseDOM() {
63
+ return !!(typeof window !== "undefined" && window.document && window.document.createElement);
64
+ }
65
+
66
+ /**
67
+ * React currently throws a warning when using useLayoutEffect on the server. To
68
+ * get around it, we can conditionally useEffect on the server (no-op) and
69
+ * useLayoutEffect in the browser. We occasionally need useLayoutEffect to
70
+ * ensure we don't get a render flash for certain operations, but we may also
71
+ * need affected components to render on the server. One example is when setting
72
+ * a component's descendants to retrieve their index values.
73
+ *
74
+ * Important to note that using this hook as an escape hatch will break the
75
+ * eslint dependency warnings unless you rename the import to `useLayoutEffect`.
76
+ * Use sparingly only when the effect won't effect the rendered HTML to avoid
77
+ * any server/client mismatch.
78
+ *
79
+ * If a useLayoutEffect is needed and the result would create a mismatch, it's
80
+ * likely that the component in question shouldn't be rendered on the server at
81
+ * all, so a better approach would be to lazily render those in a parent
82
+ * component after client-side hydration.
83
+ *
84
+ * https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85
85
+ * https://github.com/reduxjs/react-redux/blob/master/src/utils/useIsomorphicLayoutEffect.js
86
+ *
87
+ * @param effect
88
+ * @param deps
89
+ */
90
+
91
+ var useIsomorphicLayoutEffect = /*#__PURE__*/canUseDOM() ? React.useLayoutEffect : React.useEffect;
92
+
93
+ /*
94
+ * Welcome to @reach/auto-id!
95
+
96
+ * Let's see if we can make sense of why this hook exists and its
97
+ * implementation.
98
+ *
99
+ * Some background:
100
+ * 1. Accessibility APIs rely heavily on element IDs
101
+ * 2. Requiring developers to put IDs on every element in Reach UI is both
102
+ * cumbersome and error-prone
103
+ * 3. With a component model, we can generate IDs for them!
104
+ *
105
+ * Solution 1: Generate random IDs.
106
+ *
107
+ * This works great as long as you don't server render your app. When React (in
108
+ * the client) tries to reuse the markup from the server, the IDs won't match
109
+ * and React will then recreate the entire DOM tree.
110
+ *
111
+ * Solution 2: Increment an integer
112
+ *
113
+ * This sounds great. Since we're rendering the exact same tree on the server
114
+ * and client, we can increment a counter and get a deterministic result between
115
+ * client and server. Also, JS integers can go up to nine-quadrillion. I'm
116
+ * pretty sure the tab will be closed before an app never needs
117
+ * 10 quadrillion IDs!
118
+ *
119
+ * Problem solved, right?
120
+ *
121
+ * Ah, but there's a catch! React's concurrent rendering makes this approach
122
+ * non-deterministic. While the client and server will end up with the same
123
+ * elements in the end, depending on suspense boundaries (and possibly some user
124
+ * input during the initial render) the incrementing integers won't always match
125
+ * up.
126
+ *
127
+ * Solution 3: Don't use IDs at all on the server; patch after first render.
128
+ *
129
+ * What we've done here is solution 2 with some tricks. With this approach, the
130
+ * ID returned is an empty string on the first render. This way the server and
131
+ * client have the same markup no matter how wild the concurrent rendering may
132
+ * have gotten.
133
+ *
134
+ * After the render, we patch up the components with an incremented ID. This
135
+ * causes a double render on any components with `useId`. Shouldn't be a problem
136
+ * since the components using this hook should be small, and we're only updating
137
+ * the ID attribute on the DOM, nothing big is happening.
138
+ *
139
+ * It doesn't have to be an incremented number, though--we could do generate
140
+ * random strings instead, but incrementing a number is probably the cheapest
141
+ * thing we can do.
142
+ *
143
+ * Additionally, we only do this patchup on the very first client render ever.
144
+ * Any calls to `useId` that happen dynamically in the client will be
145
+ * populated immediately with a value. So, we only get the double render after
146
+ * server hydration and never again, SO BACK OFF ALRIGHT?
147
+ */
148
+ var serverHandoffComplete = false;
149
+ var id = 0;
150
+
151
+ var genId = function genId() {
152
+ return ++id;
153
+ };
154
+ /**
155
+ * useId
156
+ *
157
+ * Autogenerate IDs to facilitate WAI-ARIA and server rendering.
158
+ *
159
+ * Note: The returned ID will initially be `null` and will update after a
160
+ * component mounts. Users may need to supply their own ID if they need
161
+ * consistent values for SSR.
162
+ *
163
+ * @see Docs https://reach.tech/auto-id
164
+ */
165
+
166
+
167
+ function useId(idFromProps) {
168
+ /*
169
+ * If this instance isn't part of the initial render, we don't have to do the
170
+ * double render/patch-up dance. We can just generate the ID and return it.
171
+ */
172
+ var initialId = idFromProps || (serverHandoffComplete ? genId() : null);
173
+
174
+ var _React$useState = React.useState(initialId),
175
+ id = _React$useState[0],
176
+ setId = _React$useState[1];
177
+
178
+ useIsomorphicLayoutEffect(function () {
179
+ if (id === null) {
180
+ /*
181
+ * Patch the ID after render. We do this in `useLayoutEffect` to avoid any
182
+ * rendering flicker, though it'll make the first render slower (unlikely
183
+ * to matter, but you're welcome to measure your app and let us know if
184
+ * it's a problem).
185
+ */
186
+ setId(genId());
187
+ } // eslint-disable-next-line react-hooks/exhaustive-deps
188
+
189
+ }, []);
190
+ React.useEffect(function () {
191
+ if (serverHandoffComplete === false) {
192
+ /*
193
+ * Flag all future uses of `useId` to skip the update dance. This is in
194
+ * `useEffect` because it goes after `useLayoutEffect`, ensuring we don't
195
+ * accidentally bail out of the patch-up dance prematurely.
196
+ */
197
+ serverHandoffComplete = true;
198
+ }
199
+ }, []);
200
+ return id != null ? String(id) : undefined;
201
+ }
202
+
203
+ /**
204
+ * The name of the default CSS classes.
205
+ */
206
+ var defaultClassNames = {
207
+ root: 'rdp',
208
+ multiple_months: 'rdp-multiple_months',
209
+ with_weeknumber: 'rdp-with_weeknumber',
210
+ vhidden: 'rdp-vhidden',
211
+ button_reset: 'rdp-button_reset',
212
+ button: 'rdp-button',
213
+ caption: 'rdp-caption',
214
+ caption_start: 'rdp-caption_start',
215
+ caption_end: 'rdp-caption_end',
216
+ caption_between: 'rdp-caption_between',
217
+ caption_label: 'rdp-caption_label',
218
+ caption_dropdowns: 'rdp-caption_dropdowns',
219
+ dropdown: 'rdp-dropdown',
220
+ dropdown_month: 'rdp-dropdown_month',
221
+ dropdown_year: 'rdp-dropdown_year',
222
+ dropdown_icon: 'rdp-dropdown_icon',
223
+ months: 'rdp-months',
224
+ month: 'rdp-month',
225
+ table: 'rdp-table',
226
+ tbody: 'rdp-tbody',
227
+ tfoot: 'rdp-tfoot',
228
+ head: 'rdp-head',
229
+ head_row: 'rdp-head_row',
230
+ head_cell: 'rdp-head_cell',
231
+ nav: 'rdp-nav',
232
+ nav_button: 'rdp-nav_button',
233
+ nav_button_previous: 'rdp-nav_button_previous',
234
+ nav_button_next: 'rdp-nav_button_next',
235
+ nav_icon: 'rdp-nav_icon',
236
+ row: 'rdp-row',
237
+ weeknumber: 'rdp-weeknumber',
238
+ cell: 'rdp-cell',
239
+ day: 'rdp-day',
240
+ day_outside: 'rdp-day_outside'
1498
241
  };
1499
242
 
1500
- /**
1501
- * The default formatter for the caption.
1502
- */
1503
- function formatCaption(month, options) {
1504
- return dateFns.format(month, 'LLLL y', options);
243
+ /**
244
+ * The default formatter for the caption.
245
+ */
246
+ function formatCaption(month, options) {
247
+ return dateFns.format(month, 'LLLL y', options);
1505
248
  }
1506
249
 
1507
- /**
1508
- * The default formatter for the Day button.
1509
- */
1510
- function formatDay(day, options) {
1511
- return dateFns.format(day, 'd', options);
250
+ /**
251
+ * The default formatter for the Day button.
252
+ */
253
+ function formatDay(day, options) {
254
+ return dateFns.format(day, 'd', options);
1512
255
  }
1513
256
 
1514
- /**
1515
- * The default formatter for the Month caption.
1516
- */
1517
- function formatMonthCaption(month, options) {
1518
- return dateFns.format(month, 'LLLL', options);
257
+ /**
258
+ * The default formatter for the Month caption.
259
+ */
260
+ function formatMonthCaption(month, options) {
261
+ return dateFns.format(month, 'LLLL', options);
1519
262
  }
1520
263
 
1521
- /**
1522
- * The default formatter for the week number.
1523
- */
1524
- function formatWeekNumber(weekNumber) {
1525
- return "" + weekNumber;
264
+ /**
265
+ * The default formatter for the week number.
266
+ */
267
+ function formatWeekNumber(weekNumber) {
268
+ return "".concat(weekNumber);
1526
269
  }
1527
270
 
1528
- /**
1529
- * The default formatter for the name of the weekday.
1530
- */
1531
- function formatWeekdayName(weekday, options) {
1532
- return dateFns.format(weekday, 'cccccc', options);
271
+ /**
272
+ * The default formatter for the name of the weekday.
273
+ */
274
+ function formatWeekdayName(weekday, options) {
275
+ return dateFns.format(weekday, 'cccccc', options);
1533
276
  }
1534
277
 
1535
- /**
1536
- * The default formatter for the Year caption.
1537
- */
1538
- function formatYearCaption(year, options) {
1539
- return dateFns.format(year, 'yyyy', options);
278
+ /**
279
+ * The default formatter for the Year caption.
280
+ */
281
+ function formatYearCaption(year, options) {
282
+ return dateFns.format(year, 'yyyy', options);
1540
283
  }
1541
284
 
1542
- var index = /*#__PURE__*/Object.freeze({
285
+ var formatters = /*#__PURE__*/Object.freeze({
1543
286
  __proto__: null,
1544
287
  formatCaption: formatCaption,
1545
288
  formatDay: formatDay,
@@ -1549,56 +292,56 @@ var index = /*#__PURE__*/Object.freeze({
1549
292
  formatYearCaption: formatYearCaption
1550
293
  });
1551
294
 
1552
- /**
1553
- * The default ARIA label for the day button.
1554
- */
1555
- var labelDay = function (day, modifers, options) {
1556
- return dateFns.format(day, 'do MMMM (EEEE)', options);
295
+ /**
296
+ * The default ARIA label for the day button.
297
+ */
298
+ var labelDay = function (day, activeModifiers, options) {
299
+ return dateFns.format(day, 'do MMMM (EEEE)', options);
1557
300
  };
1558
301
 
1559
- /**
1560
- * The default ARIA label for the WeekNumber element.
1561
- */
1562
- var labelMonthDropdown = function () {
1563
- return 'Month: ';
302
+ /**
303
+ * The default ARIA label for the WeekNumber element.
304
+ */
305
+ var labelMonthDropdown = function () {
306
+ return 'Month: ';
1564
307
  };
1565
308
 
1566
- /**
1567
- * The default ARIA label for next month button in navigation
1568
- */
1569
- var labelNext = function () {
1570
- return 'Go to next month';
309
+ /**
310
+ * The default ARIA label for next month button in navigation
311
+ */
312
+ var labelNext = function () {
313
+ return 'Go to next month';
1571
314
  };
1572
315
 
1573
- /**
1574
- * The default ARIA label for previous month button in navigation
1575
- */
1576
- var labelPrevious = function () {
1577
- return 'Go to previous month';
316
+ /**
317
+ * The default ARIA label for previous month button in navigation
318
+ */
319
+ var labelPrevious = function () {
320
+ return 'Go to previous month';
1578
321
  };
1579
322
 
1580
- /**
1581
- * The default ARIA label for the Weekday element.
1582
- */
1583
- var labelWeekday = function (day, options) {
1584
- return dateFns.format(day, 'cccc.', options);
323
+ /**
324
+ * The default ARIA label for the Weekday element.
325
+ */
326
+ var labelWeekday = function (day, options) {
327
+ return dateFns.format(day, 'cccc', options);
1585
328
  };
1586
329
 
1587
- /**
1588
- * The default ARIA label for the WeekNumber element.
1589
- */
1590
- var labelWeekNumber = function (n) {
1591
- return "Week n. " + n;
330
+ /**
331
+ * The default ARIA label for the WeekNumber element.
332
+ */
333
+ var labelWeekNumber = function (n) {
334
+ return "Week n. ".concat(n);
1592
335
  };
1593
336
 
1594
- /**
1595
- * The default ARIA label for the WeekNumber element.
1596
- */
1597
- var labelYearDropdown = function () {
1598
- return 'Year: ';
337
+ /**
338
+ * The default ARIA label for the WeekNumber element.
339
+ */
340
+ var labelYearDropdown = function () {
341
+ return 'Year: ';
1599
342
  };
1600
343
 
1601
- var index$1 = /*#__PURE__*/Object.freeze({
344
+ var labels = /*#__PURE__*/Object.freeze({
1602
345
  __proto__: null,
1603
346
  labelDay: labelDay,
1604
347
  labelMonthDropdown: labelMonthDropdown,
@@ -1609,238 +352,1870 @@ var index$1 = /*#__PURE__*/Object.freeze({
1609
352
  labelYearDropdown: labelYearDropdown
1610
353
  });
1611
354
 
1612
- /**
1613
- * The provider for the [[DayPickerContext]].
1614
- */
1615
- function DayPickerProvider(props) {
1616
- var _a, _b, _c, _d, _e, _f;
1617
- var children = props.children, initialProps = props.initialProps;
1618
- var locale = (_a = initialProps.locale) !== null && _a !== void 0 ? _a : enUS__default["default"];
1619
- var numberOfMonths = (_b = initialProps.numberOfMonths) !== null && _b !== void 0 ? _b : 1;
1620
- var today = (_c = initialProps.today) !== null && _c !== void 0 ? _c : new Date();
1621
- // Limit navigation
1622
- var _g = parseFromToProps(initialProps), fromDate = _g.fromDate, toDate = _g.toDate;
1623
- // Default caption layout. If calendar navigation is unlimited, it must be
1624
- // always `buttons` – as we cannot display infinite options in the dropdown.
1625
- var captionLayout = (_d = initialProps.captionLayout) !== null && _d !== void 0 ? _d : 'buttons';
1626
- if (!fromDate && !toDate)
1627
- captionLayout = 'buttons';
1628
- var modifiers = parseModifierProps(initialProps);
1629
- // Disable days before/after from/toDate
1630
- if (fromDate) {
1631
- modifiers.disabled.push({ before: fromDate });
1632
- }
1633
- if (toDate) {
1634
- modifiers.disabled.push({ after: toDate });
1635
- }
1636
- initialProps.toYear; initialProps.fromYear; initialProps.toMonth; initialProps.fromMonth; var contextProps = __rest(initialProps, ["toYear", "fromYear", "toMonth", "fromMonth"]);
1637
- var context = __assign(__assign({}, contextProps), { captionLayout: captionLayout, fromDate: fromDate, toDate: toDate, today: today, locale: locale, modifierClassNames: (_e = initialProps.modifierClassNames) !== null && _e !== void 0 ? _e : {}, modifierPrefix: 'rdp-day_', modifiers: modifiers, numberOfMonths: numberOfMonths, styles: (_f = initialProps.styles) !== null && _f !== void 0 ? _f : {}, classNames: __assign(__assign({}, defaultClassNames), initialProps.classNames), formatters: __assign(__assign({}, index), initialProps.formatters), labels: __assign(__assign({}, index$1), initialProps.labels), components: __assign({ Caption: Caption, CaptionLabel: CaptionLabel, Day: Day, DayContent: DayContent, Dropdown: Dropdown, Footer: Footer, Head: Head, IconDropdown: IconDropdown, IconRight: IconRight, IconLeft: IconLeft, Row: Row, WeekNumber: WeekNumber }, initialProps.components) });
1638
- return (React__default["default"].createElement(DayPickerContext.Provider, { value: context }, children));
1639
- }
1640
-
1641
- /** Provide the value for all the context providers. */
1642
- function RootProvider(props) {
1643
- var children = props.children, initialProps = __rest(props, ["children"]);
1644
- return (React__default["default"].createElement(DayPickerProvider, { initialProps: initialProps },
1645
- React__default["default"].createElement(NavigationProvider, null,
1646
- React__default["default"].createElement(SelectSingleProvider, { initialProps: initialProps },
1647
- React__default["default"].createElement(SelectMultipleProvider, { initialProps: initialProps },
1648
- React__default["default"].createElement(SelectRangeProvider, { initialProps: initialProps },
1649
- React__default["default"].createElement(FocusProvider, null, children)))))));
1650
- }
1651
-
1652
- /**
1653
- * DayPicker render a date picker component to let users pick dates from a
1654
- * calendar. See http://react-day-picker.js.org for updated documentation and
1655
- * examples.
1656
- *
1657
- * ### Customization
1658
- *
1659
- * DayPicker offers different customization props. For example,
1660
- *
1661
- * - show multiple months using `numberOfMonths`
1662
- * - display a dropdown to navigate the months via `captionLayout`
1663
- * - display the week numbers with `showWeekNumbers`
1664
- * - disable or hide days with `disabled` or `hidden`
1665
- *
1666
- * ### Controlling the months
1667
- *
1668
- * Change the initially displayed month using the `defaultMonth` prop. The
1669
- * displayed months are controlled by DayPicker and stored in its internal
1670
- * state. To control the months yourself, use `month` instead of `defaultMonth`
1671
- * and use the `onMonthChange` event to set it.
1672
- *
1673
- * To limit the months the user can navigate to, use
1674
- * `fromDate`/`fromMonth`/`fromYear` or `toDate`/`toMonth`/`toYear`.
1675
- *
1676
- * ### Selection modes
1677
- *
1678
- * DayPicker supports different selection mode that can be toggled using the
1679
- * `mode` prop:
1680
- *
1681
- * - `mode="single"`: only one day can be selected. Use `required` to make the
1682
- * selection required. Use the `onSelect` event handler to get the selected
1683
- * days.
1684
- * - `mode="multiple"`: users can select one or more days. Limit the amount of
1685
- * days that can be selected with the `min` or the `max` props.
1686
- * - `mode="range"`: users can select a range of days. Limit the amount of days
1687
- * in the range with the `min` or the `max` props.
1688
- * - `mode="custom"`: implement your own selection mode with `onDayClick`.
1689
- *
1690
- * These selection modes should cover the most common use cases. In case you
1691
- * need a more refined way of selecting days, use `mode="custom"`. Use the
1692
- * `selected` props and add the day event handlers to add/remove days from the
1693
- * selection.
1694
- *
1695
- * ### Modifiers
1696
- *
1697
- * A _modifier_ represents different styles or states for the days displayed in
1698
- * the calendar (like "selected" or "disabled"). Define custom modifiers using
1699
- * the `modifiers` prop.
1700
- *
1701
- * ### Formatters and custom component
1702
- *
1703
- * You can customize how the content is displayed in the date picker by using
1704
- * either the formatters or replacing the internal components.
1705
- *
1706
- * For the most common cases you want to use the `formatters` prop to change how
1707
- * the content is formatted in the calendar. Use the `components` prop to
1708
- * replace the internal components, like the navigation icons.
1709
- *
1710
- * ### Styling
1711
- *
1712
- * DayPicker comes with a default, basic style in `react-day-picker/style` – use
1713
- * it as template for your own style.
1714
- *
1715
- * If you are using CSS modules, pass the imported styles object the
1716
- * `classNames` props.
1717
- *
1718
- * You can also style the elements via inline-styles using the `styles` prop.
1719
- *
1720
- * ### Form fields
1721
- *
1722
- * If you need to bind the date picker to a form field, you can use the
1723
- * `useInput` hooks for a basic behavior. See the `useInput` source as an
1724
- * example to bind the date picker with form fields.
1725
- *
1726
- * ### Localization
1727
- *
1728
- * To localize DayPicker, import the locale from `date-fns` package and use the
1729
- * `locale` prop.
1730
- *
1731
- * For example, to use Spanish locale:
1732
- *
1733
- * ```
1734
- * import es from 'date-fns/locale/es';
1735
- * <DayPicker locale={es} />
1736
- * ```
1737
- */
1738
- function DayPicker(props) {
1739
- return (React__default["default"].createElement(RootProvider, __assign({}, props),
1740
- React__default["default"].createElement(Root, null)));
1741
- }
1742
-
1743
- /** Returns true when the props are of type [[DayPickerCustom]]. */
1744
- function isDayPickerCustom(props) {
1745
- return props.mode === 'custom';
1746
- }
1747
-
1748
- /** @private */
1749
- function isValidDate(day) {
1750
- return !isNaN(day.getTime());
1751
- }
1752
-
1753
- /** Return props and setters for binding an input field to DayPicker. */
1754
- function useInput(options) {
1755
- if (options === void 0) { options = {}; }
1756
- var _a = options.locale, locale = _a === void 0 ? enUS__default["default"] : _a, required = options.required, _b = options.format, format$1 = _b === void 0 ? 'PP' : _b, defaultSelected = options.defaultSelected, _c = options.today, today = _c === void 0 ? new Date() : _c;
1757
- var _d = parseFromToProps(options), fromDate = _d.fromDate, toDate = _d.toDate;
1758
- // Shortcut to the DateFns functions
1759
- var parseValue = function (value) { return dateFns.parse(value, format$1, today, { locale: locale }); };
1760
- // Initialize states
1761
- var _e = React__default["default"].useState(defaultSelected !== null && defaultSelected !== void 0 ? defaultSelected : today), month = _e[0], setMonth = _e[1];
1762
- var _f = React__default["default"].useState(defaultSelected), selectedDay = _f[0], setSelectedDay = _f[1];
1763
- var defaultInputValue = defaultSelected
1764
- ? dateFns.format(defaultSelected, format$1, { locale: locale })
1765
- : '';
1766
- var _g = React__default["default"].useState(defaultInputValue), inputValue = _g[0], setInputValue = _g[1];
1767
- var reset = function () {
1768
- setSelectedDay(defaultSelected);
1769
- setMonth(defaultSelected !== null && defaultSelected !== void 0 ? defaultSelected : today);
1770
- setInputValue(defaultInputValue !== null && defaultInputValue !== void 0 ? defaultInputValue : '');
1771
- };
1772
- var setSelected = function (date) {
1773
- setSelectedDay(date);
1774
- setMonth(date !== null && date !== void 0 ? date : today);
1775
- setInputValue(date ? dateFns.format(date, format$1, { locale: locale }) : '');
1776
- };
1777
- var handleDayClick = function (day, _a) {
1778
- var selected = _a.selected;
1779
- if (!required && selected) {
1780
- setSelectedDay(undefined);
1781
- setInputValue('');
1782
- return;
1783
- }
1784
- setSelectedDay(day);
1785
- setInputValue(day ? dateFns.format(day, format$1, { locale: locale }) : '');
1786
- };
1787
- var handleMonthChange = function (month) {
1788
- setMonth(month);
1789
- };
1790
- // When changing the input field, save its value in state and check if the
1791
- // string is a valid date. If it is a valid day, set it as selected and update
1792
- // the calendar’s month.
1793
- var handleChange = function (e) {
1794
- setInputValue(e.target.value);
1795
- var day = parseValue(e.target.value);
1796
- var isBefore = fromDate && dateFns.differenceInCalendarDays(fromDate, day) > 0;
1797
- var isAfter = toDate && dateFns.differenceInCalendarDays(day, toDate) > 0;
1798
- if (!isValidDate(day) || isBefore || isAfter) {
1799
- setSelectedDay(undefined);
1800
- return;
1801
- }
1802
- setSelectedDay(day);
1803
- setMonth(day);
1804
- };
1805
- // Special case for _required_ fields: on blur, if the value of the input is not
1806
- // a valid date, reset the calendar and the input value.
1807
- var handleBlur = function (e) {
1808
- var day = parseValue(e.target.value);
1809
- if (!isValidDate(day)) {
1810
- reset();
1811
- }
1812
- };
1813
- // When focusing, make sure DayPicker visualizes the month of the date in the
1814
- // input field.
1815
- var handleFocus = function (e) {
1816
- if (!e.target.value) {
1817
- reset();
1818
- return;
1819
- }
1820
- var day = parseValue(e.target.value);
1821
- if (isValidDate(day)) {
1822
- setMonth(day);
1823
- }
1824
- };
1825
- var dayPickerProps = {
1826
- mode: 'custom',
1827
- month: month,
1828
- onDayClick: handleDayClick,
1829
- onMonthChange: handleMonthChange,
1830
- selected: selectedDay,
1831
- locale: locale,
1832
- fromDate: options === null || options === void 0 ? void 0 : options.fromDate,
1833
- toDate: options === null || options === void 0 ? void 0 : options.toDate,
1834
- today: today
1835
- };
1836
- var inputProps = {
1837
- onBlur: handleBlur,
1838
- onChange: handleChange,
1839
- onFocus: handleFocus,
1840
- value: inputValue,
1841
- placeholder: dateFns.format(new Date(), format$1, { locale: locale })
1842
- };
1843
- return { dayPickerProps: dayPickerProps, inputProps: inputProps, reset: reset, setSelected: setSelected };
355
+ /**
356
+ * Returns the default values to use in the DayPickerContext, in case they are
357
+ * not passed down with the DayPicker initial props.
358
+ */
359
+ function getDefaultContextValue() {
360
+ var captionLayout = 'buttons';
361
+ var classNames = defaultClassNames;
362
+ var locale = enUS__default["default"];
363
+ var modifiersClassNames = {};
364
+ var modifierPrefix = 'rdp-day_';
365
+ var modifiers = {};
366
+ var numberOfMonths = 1;
367
+ var styles = {};
368
+ var today = new Date();
369
+ return {
370
+ captionLayout: captionLayout,
371
+ classNames: classNames,
372
+ formatters: formatters,
373
+ labels: labels,
374
+ locale: locale,
375
+ modifiersClassNames: modifiersClassNames,
376
+ modifierPrefix: modifierPrefix,
377
+ modifiers: modifiers,
378
+ numberOfMonths: numberOfMonths,
379
+ styles: styles,
380
+ today: today
381
+ };
382
+ }
383
+
384
+ /** Return the `fromDate` and `toDate` prop values values parsing the DayPicker props. */
385
+ function parseFromToProps(props) {
386
+ var fromYear = props.fromYear, toYear = props.toYear, fromMonth = props.fromMonth, toMonth = props.toMonth;
387
+ var fromDate = props.fromDate, toDate = props.toDate;
388
+ if (fromMonth) {
389
+ fromDate = dateFns.startOfMonth(fromMonth);
390
+ }
391
+ else if (fromYear) {
392
+ fromDate = new Date(fromYear, 0, 1);
393
+ }
394
+ if (toMonth) {
395
+ toDate = dateFns.startOfMonth(toMonth);
396
+ }
397
+ else if (toYear) {
398
+ toDate = new Date(toYear, 11, 31);
399
+ }
400
+ return {
401
+ fromDate: fromDate ? dateFns.startOfDay(fromDate) : undefined,
402
+ toDate: toDate ? dateFns.startOfDay(toDate) : undefined
403
+ };
404
+ }
405
+
406
+ /**
407
+ * The DayPicker Context shares the props passed to DayPicker within internal
408
+ * and custom components. It is used to set the default values and perform
409
+ * one-time calculations required to render the days.
410
+ *
411
+ * Developers may access this context from the [[useDayPicker]] hook when
412
+ * using custom components.
413
+ */
414
+ var DayPickerContext = React.createContext(undefined);
415
+ /**
416
+ * The provider for the [[DayPickerContext]], assigning the defaults from the
417
+ * initial DayPicker props.
418
+ */
419
+ function DayPickerProvider(props) {
420
+ var _a, _b, _c, _d, _e;
421
+ var initialProps = props.initialProps;
422
+ var defaults = getDefaultContextValue();
423
+ var locale = (_a = initialProps.locale) !== null && _a !== void 0 ? _a : defaults.locale;
424
+ var numberOfMonths = (_b = initialProps.numberOfMonths) !== null && _b !== void 0 ? _b : defaults.numberOfMonths;
425
+ var today = (_c = initialProps.today) !== null && _c !== void 0 ? _c : defaults.today;
426
+ var _f = parseFromToProps(initialProps), fromDate = _f.fromDate, toDate = _f.toDate;
427
+ var captionLayout = (_d = initialProps.captionLayout) !== null && _d !== void 0 ? _d : defaults.captionLayout;
428
+ if (captionLayout !== 'buttons' && (!fromDate || !toDate)) {
429
+ captionLayout = 'buttons';
430
+ }
431
+ // TODO: remove eslint disable, move to external utils
432
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
433
+ initialProps.toYear; initialProps.fromYear; initialProps.toMonth; initialProps.fromMonth; var contextProps = __rest(initialProps, ["toYear", "fromYear", "toMonth", "fromMonth"]);
434
+ var modifierPrefix = (_e = initialProps.modifierPrefix) !== null && _e !== void 0 ? _e : defaults.modifierPrefix;
435
+ var modifiers = __assign(__assign({}, defaults.modifiers), initialProps.modifiers);
436
+ var modifiersClassNames = __assign(__assign({}, defaults.modifiersClassNames), initialProps.modifiersClassNames);
437
+ var styles = __assign(__assign({}, defaults.styles), initialProps.styles);
438
+ var classNames = __assign(__assign({}, defaults.classNames), initialProps.classNames);
439
+ var formatters = __assign(__assign({}, defaults.formatters), initialProps.formatters);
440
+ var labels = __assign(__assign({}, defaults.labels), initialProps.labels);
441
+ var components = __assign(__assign({}, defaults.components), initialProps.components);
442
+ var context = __assign(__assign({}, contextProps), { captionLayout: captionLayout, fromDate: fromDate, toDate: toDate, today: today, locale: locale, modifiersClassNames: modifiersClassNames, modifierPrefix: modifierPrefix, modifiers: modifiers, numberOfMonths: numberOfMonths, styles: styles, classNames: classNames, formatters: formatters, labels: labels, components: components });
443
+ return (React__default["default"].createElement(DayPickerContext.Provider, { value: context }, props.children));
444
+ }
445
+
446
+ /**
447
+ * Hook to access the [[DayPickerContext]].
448
+ *
449
+ * To use this hook make sure to wrap the components with a one
450
+ * [[DayPickerProvider]].
451
+ */
452
+ function useDayPicker() {
453
+ var context = React.useContext(DayPickerContext);
454
+ if (!context) {
455
+ throw new Error("useDayPicker must be used within a DayPickerProvider.");
456
+ }
457
+ return context;
458
+ }
459
+
460
+ /** Render the caption for the displayed month. This component is used when `captionLayout="buttons"`. */
461
+ function CaptionLabel(props) {
462
+ var _a = useDayPicker(), locale = _a.locale, classNames = _a.classNames, styles = _a.styles, formatCaption = _a.formatters.formatCaption;
463
+ return (React__default["default"].createElement("h2", { className: classNames.caption_label, style: styles.caption_label, "aria-live": "polite", "aria-atomic": "true", id: props.id }, formatCaption(props.displayMonth, { locale: locale })));
464
+ }
465
+
466
+ /**
467
+ * Render the icon in the styled drop-down.
468
+ */
469
+ function IconDropdown(props) {
470
+ return (React__default["default"].createElement("svg", __assign({ width: "8px", height: "8px", viewBox: "0 0 120 120", "data-testid": "iconDropdown" }, props),
471
+ React__default["default"].createElement("path", { d: "M4.22182541,48.2218254 C8.44222828,44.0014225 15.2388494,43.9273804 19.5496459,47.9996989 L19.7781746,48.2218254 L60,88.443 L100.221825,48.2218254 C104.442228,44.0014225 111.238849,43.9273804 115.549646,47.9996989 L115.778175,48.2218254 C119.998577,52.4422283 120.07262,59.2388494 116.000301,63.5496459 L115.778175,63.7781746 L67.7781746,111.778175 C63.5577717,115.998577 56.7611506,116.07262 52.4503541,112.000301 L52.2218254,111.778175 L4.22182541,63.7781746 C-0.0739418023,59.4824074 -0.0739418023,52.5175926 4.22182541,48.2218254 Z", fill: "currentColor", fillRule: "nonzero" })));
472
+ }
473
+
474
+ /**
475
+ * Render a styled select component – displaying a caption and a custom
476
+ * drop-down icon.
477
+ */
478
+ function Dropdown(props) {
479
+ var _a, _b;
480
+ var onChange = props.onChange, value = props.value, children = props.children, caption = props.caption, className = props.className, style = props.style;
481
+ var dayPicker = useDayPicker();
482
+ var IconDropdownComponent = (_b = (_a = dayPicker.components) === null || _a === void 0 ? void 0 : _a.IconDropdown) !== null && _b !== void 0 ? _b : IconDropdown;
483
+ return (React__default["default"].createElement("div", { className: className, style: style },
484
+ React__default["default"].createElement("span", { className: dayPicker.classNames.vhidden }, props['aria-label']),
485
+ React__default["default"].createElement("select", { "aria-label": props['aria-label'], className: dayPicker.classNames.dropdown, style: dayPicker.styles.dropdown, value: value, onChange: onChange }, children),
486
+ React__default["default"].createElement("div", { className: dayPicker.classNames.caption_label, style: dayPicker.styles.caption_label, "aria-hidden": "true" },
487
+ caption,
488
+ React__default["default"].createElement(IconDropdownComponent, { className: dayPicker.classNames.dropdown_icon, style: dayPicker.styles.dropdown_icon }))));
489
+ }
490
+
491
+ /** Render the dropdown to navigate between months. */
492
+ function MonthsDropdown(props) {
493
+ var _a;
494
+ var _b = useDayPicker(), fromDate = _b.fromDate, toDate = _b.toDate, styles = _b.styles, locale = _b.locale, formatMonthCaption = _b.formatters.formatMonthCaption, classNames = _b.classNames, components = _b.components, labelMonthDropdown = _b.labels.labelMonthDropdown;
495
+ // Dropdown should appear only when both from/toDate is set
496
+ if (!fromDate)
497
+ return React__default["default"].createElement(React__default["default"].Fragment, null);
498
+ if (!toDate)
499
+ return React__default["default"].createElement(React__default["default"].Fragment, null);
500
+ var dropdownMonths = [];
501
+ if (dateFns.isSameYear(fromDate, toDate)) {
502
+ // only display the months included in the range
503
+ var date = dateFns.startOfMonth(fromDate);
504
+ for (var month = fromDate.getMonth(); month <= toDate.getMonth(); month++) {
505
+ dropdownMonths.push(dateFns.setMonth(date, month));
506
+ }
507
+ }
508
+ else {
509
+ // display all the 12 months
510
+ var date = dateFns.startOfMonth(new Date()); // Any date should be OK, as we just need the year
511
+ for (var month = 0; month <= 11; month++) {
512
+ dropdownMonths.push(dateFns.setMonth(date, month));
513
+ }
514
+ }
515
+ var handleChange = function (e) {
516
+ var selectedMonth = Number(e.target.value);
517
+ var newMonth = dateFns.setMonth(dateFns.startOfMonth(props.displayMonth), selectedMonth);
518
+ props.onChange(newMonth);
519
+ };
520
+ var DropdownComponent = (_a = components === null || components === void 0 ? void 0 : components.Dropdown) !== null && _a !== void 0 ? _a : Dropdown;
521
+ return (React__default["default"].createElement(DropdownComponent, { "aria-label": labelMonthDropdown(), className: classNames.dropdown_month, style: styles.dropdown_month, onChange: handleChange, value: props.displayMonth.getMonth(), caption: formatMonthCaption(props.displayMonth, { locale: locale }) }, dropdownMonths.map(function (m) { return (React__default["default"].createElement("option", { key: m.getMonth(), value: m.getMonth() }, formatMonthCaption(m, { locale: locale }))); })));
522
+ }
523
+
524
+ /**
525
+ * Render the "previous month" button in the navigation.
526
+ */
527
+ function IconLeft(props) {
528
+ return (React__default["default"].createElement("svg", __assign({ width: "16px", height: "16px", viewBox: "0 0 120 120", "data-testid": "iconLeft" }, props),
529
+ React__default["default"].createElement("path", { d: "M69.490332,3.34314575 C72.6145263,0.218951416 77.6798462,0.218951416 80.8040405,3.34314575 C83.8617626,6.40086786 83.9268205,11.3179931 80.9992143,14.4548388 L80.8040405,14.6568542 L35.461,60 L80.8040405,105.343146 C83.8617626,108.400868 83.9268205,113.317993 80.9992143,116.454839 L80.8040405,116.656854 C77.7463184,119.714576 72.8291931,119.779634 69.6923475,116.852028 L69.490332,116.656854 L18.490332,65.6568542 C15.4326099,62.5991321 15.367552,57.6820069 18.2951583,54.5451612 L18.490332,54.3431458 L69.490332,3.34314575 Z", fill: "currentColor", fillRule: "nonzero" })));
530
+ }
531
+
532
+ /**
533
+ * Render the "next month" button in the navigation.
534
+ */
535
+ function IconRight(props) {
536
+ return (React__default["default"].createElement("svg", __assign({ width: "16px", height: "16px", viewBox: "0 0 120 120" }, props, { "data-testid": "iconRight" }),
537
+ React__default["default"].createElement("path", { d: "M49.8040405,3.34314575 C46.6798462,0.218951416 41.6145263,0.218951416 38.490332,3.34314575 C35.4326099,6.40086786 35.367552,11.3179931 38.2951583,14.4548388 L38.490332,14.6568542 L83.8333725,60 L38.490332,105.343146 C35.4326099,108.400868 35.367552,113.317993 38.2951583,116.454839 L38.490332,116.656854 C41.5480541,119.714576 46.4651794,119.779634 49.602025,116.852028 L49.8040405,116.656854 L100.804041,65.6568542 C103.861763,62.5991321 103.926821,57.6820069 100.999214,54.5451612 L100.804041,54.3431458 L49.8040405,3.34314575 Z", fill: "currentColor" })));
538
+ }
539
+
540
+ /**
541
+ * Render a button HTML element applying the reset class name.
542
+ */
543
+ var Button = React.forwardRef(function (props, ref) {
544
+ var _a = useDayPicker(), classNames = _a.classNames, styles = _a.styles;
545
+ var classNamesArr = [classNames.button_reset, classNames.button];
546
+ if (props.className) {
547
+ classNamesArr.push(props.className);
548
+ }
549
+ var className = classNamesArr.join(' ');
550
+ var style = __assign(__assign({}, styles.button_reset), styles.button);
551
+ if (props.style) {
552
+ Object.assign(style, props.style);
553
+ }
554
+ return (React__default["default"].createElement("button", __assign({}, props, { ref: ref, type: "button", className: className, style: style })));
555
+ });
556
+
557
+ /** A component rendering the navigation buttons or the drop-downs. */
558
+ function Navigation(props) {
559
+ var _a;
560
+ var _b, _c;
561
+ var _d = useDayPicker(), dir = _d.dir, locale = _d.locale, classNames = _d.classNames, styles = _d.styles, _e = _d.labels, labelPrevious = _e.labelPrevious, labelNext = _e.labelNext, components = _d.components;
562
+ var onPreviousClick = props.onPreviousClick, onNextClick = props.onNextClick;
563
+ if (dir === 'rtl') {
564
+ _a = [onPreviousClick, onNextClick], onNextClick = _a[0], onPreviousClick = _a[1];
565
+ }
566
+ var previousMonth = props.previousMonth, nextMonth = props.nextMonth;
567
+ var previousLabel = labelPrevious(previousMonth, { locale: locale });
568
+ var previousClassName = [
569
+ classNames.nav_button,
570
+ classNames.nav_button_previous
571
+ ].join(' ');
572
+ var nextLabel = labelNext(nextMonth, { locale: locale });
573
+ var nextClassName = [
574
+ classNames.nav_button,
575
+ classNames.nav_button_next
576
+ ].join(' ');
577
+ if (!nextMonth && !previousMonth) {
578
+ return React__default["default"].createElement(React__default["default"].Fragment, null);
579
+ }
580
+ var IconRightComponent = (_b = components === null || components === void 0 ? void 0 : components.IconRight) !== null && _b !== void 0 ? _b : IconRight;
581
+ var IconLeftComponent = (_c = components === null || components === void 0 ? void 0 : components.IconLeft) !== null && _c !== void 0 ? _c : IconLeft;
582
+ return (React__default["default"].createElement("div", { className: classNames.nav, style: styles.nav },
583
+ !props.hidePrevious && (React__default["default"].createElement(Button, { "aria-label": previousLabel, className: previousClassName, style: styles.nav_button_next, disabled: !previousMonth, onClick: dir === 'rtl' ? onNextClick : onPreviousClick }, dir === 'rtl' ? (React__default["default"].createElement(IconRightComponent, { className: classNames.nav_icon, style: styles.nav_icon })) : (React__default["default"].createElement(IconLeftComponent, { className: classNames.nav_icon, style: styles.nav_icon })))),
584
+ !props.hideNext && (React__default["default"].createElement(Button, { "aria-label": nextLabel, className: nextClassName, style: styles.nav_button_next, disabled: !nextMonth, onClick: dir === 'rtl' ? onPreviousClick : onNextClick }, dir === 'rtl' ? (React__default["default"].createElement(IconLeftComponent, { className: classNames.nav_icon, style: styles.nav_icon })) : (React__default["default"].createElement(IconRightComponent, { className: classNames.nav_icon, style: styles.nav_icon }))))));
585
+ }
586
+
587
+ /**
588
+ * Render a dropdown to change the year. Take in account the `nav.fromDate` and
589
+ * `toDate` from context.
590
+ */
591
+ function YearsDropdown(props) {
592
+ var _a;
593
+ var displayMonth = props.displayMonth;
594
+ var _b = useDayPicker(), fromDate = _b.fromDate, toDate = _b.toDate, locale = _b.locale, styles = _b.styles, classNames = _b.classNames, components = _b.components, formatYearCaption = _b.formatters.formatYearCaption, labelYearDropdown = _b.labels.labelYearDropdown;
595
+ var years = [];
596
+ // Dropdown should appear only when both from/toDate is set
597
+ if (!fromDate)
598
+ return React__default["default"].createElement(React__default["default"].Fragment, null);
599
+ if (!toDate)
600
+ return React__default["default"].createElement(React__default["default"].Fragment, null);
601
+ var fromYear = fromDate.getFullYear();
602
+ var toYear = toDate.getFullYear();
603
+ for (var year = fromYear; year <= toYear; year++) {
604
+ years.push(dateFns.setYear(dateFns.startOfYear(new Date()), year));
605
+ }
606
+ var handleChange = function (e) {
607
+ var newMonth = dateFns.setYear(dateFns.startOfMonth(displayMonth), Number(e.target.value));
608
+ props.onChange(newMonth);
609
+ };
610
+ var DropdownComponent = (_a = components === null || components === void 0 ? void 0 : components.Dropdown) !== null && _a !== void 0 ? _a : Dropdown;
611
+ return (React__default["default"].createElement(DropdownComponent, { "aria-label": labelYearDropdown(), className: classNames.dropdown_month, style: styles.dropdown_month, onChange: handleChange, value: displayMonth.getFullYear(), caption: formatYearCaption(displayMonth, { locale: locale }) }, years.map(function (year) { return (React__default["default"].createElement("option", { key: year.getFullYear(), value: year.getFullYear() }, formatYearCaption(year, { locale: locale }))); })));
612
+ }
613
+
614
+ /**
615
+ * Helper hook for using controlled/uncontrolled values from a component props.
616
+ *
617
+ * When the value is not controlled, pass `undefined` as `controlledValue` and
618
+ * use the returned setter to update it.
619
+ *
620
+ * When the value is controlled, pass the controlled value as second
621
+ * argument, which will be always returned as `value`.
622
+ */
623
+ function useControlledValue(defaultValue, controlledValue) {
624
+ var _a = React.useState(defaultValue), uncontrolledValue = _a[0], setValue = _a[1];
625
+ var value = controlledValue === undefined ? uncontrolledValue : controlledValue;
626
+ return [value, setValue];
627
+ }
628
+
629
+ /** Return the initial month according to the given options. */
630
+ function getInitialMonth(context) {
631
+ var month = context.month, defaultMonth = context.defaultMonth, today = context.today;
632
+ var initialMonth = month || defaultMonth || today || new Date();
633
+ var toDate = context.toDate, fromDate = context.fromDate, _a = context.numberOfMonths, numberOfMonths = _a === void 0 ? 1 : _a;
634
+ // Fix the initialMonth if is after the to-date
635
+ if (toDate && dateFns.differenceInCalendarMonths(toDate, initialMonth) < 0) {
636
+ var offset = -1 * (numberOfMonths - 1);
637
+ initialMonth = dateFns.addMonths(toDate, offset);
638
+ }
639
+ // Fix the initialMonth if is before the from-date
640
+ if (fromDate && dateFns.differenceInCalendarMonths(initialMonth, fromDate) < 0) {
641
+ initialMonth = fromDate;
642
+ }
643
+ return dateFns.startOfMonth(initialMonth);
644
+ }
645
+
646
+ /** Controls the navigation state. */
647
+ function useNavigationState() {
648
+ var context = useDayPicker();
649
+ var initialMonth = getInitialMonth(context);
650
+ var _a = useControlledValue(initialMonth, context.month), month = _a[0], setMonth = _a[1];
651
+ var goToMonth = function (date) {
652
+ if (context.disableNavigation)
653
+ return;
654
+ setMonth(date);
655
+ };
656
+ return [month, goToMonth];
657
+ }
658
+
659
+ /**
660
+ * Return the months to display in the component according to the number of
661
+ * months and the from/to date.
662
+ */
663
+ function getDisplayMonths(month, _a) {
664
+ var reverseMonths = _a.reverseMonths, numberOfMonths = _a.numberOfMonths;
665
+ var start = dateFns.startOfMonth(month);
666
+ var end = dateFns.startOfMonth(dateFns.addMonths(start, numberOfMonths));
667
+ var monthsDiff = dateFns.differenceInCalendarMonths(end, start);
668
+ var months = [];
669
+ for (var i = 0; i < monthsDiff; i++) {
670
+ var nextMonth = dateFns.addMonths(start, i);
671
+ months.push(nextMonth);
672
+ }
673
+ if (reverseMonths)
674
+ months = months.reverse();
675
+ return months;
676
+ }
677
+
678
+ /**
679
+ * Returns the next month the user can navigate to according to the given
680
+ * options.
681
+ *
682
+ * Please note that the next month is not always the next calendar month:
683
+ *
684
+ * - if after the `toDate` range, is undefined;
685
+ * - if the navigation is paged, is the number of months displayed ahead.
686
+ *
687
+ */
688
+ function getNextMonth(startingMonth, options) {
689
+ if (options.disableNavigation) {
690
+ return undefined;
691
+ }
692
+ var toDate = options.toDate, pagedNavigation = options.pagedNavigation, _a = options.numberOfMonths, numberOfMonths = _a === void 0 ? 1 : _a;
693
+ var offset = pagedNavigation ? numberOfMonths : 1;
694
+ var month = dateFns.startOfMonth(startingMonth);
695
+ if (!toDate) {
696
+ return dateFns.addMonths(month, offset);
697
+ }
698
+ var monthsDiff = dateFns.differenceInCalendarMonths(toDate, startingMonth);
699
+ if (monthsDiff < numberOfMonths) {
700
+ return undefined;
701
+ }
702
+ // Jump forward as the number of months when paged navigation
703
+ return dateFns.addMonths(month, offset);
704
+ }
705
+
706
+ /**
707
+ * Returns the next previous the user can navigate to, according to the given
708
+ * options.
709
+ *
710
+ * Please note that the previous month is not always the previous calendar
711
+ * month:
712
+ *
713
+ * - if before the `fromDate` date, is `undefined`;
714
+ * - if the navigation is paged, is the number of months displayed before.
715
+ *
716
+ */
717
+ function getPreviousMonth(startingMonth, options) {
718
+ if (options.disableNavigation) {
719
+ return undefined;
720
+ }
721
+ var fromDate = options.fromDate, pagedNavigation = options.pagedNavigation, _a = options.numberOfMonths, numberOfMonths = _a === void 0 ? 1 : _a;
722
+ var offset = pagedNavigation ? numberOfMonths : 1;
723
+ var month = dateFns.startOfMonth(startingMonth);
724
+ if (!fromDate) {
725
+ return dateFns.addMonths(month, -offset);
726
+ }
727
+ var monthsDiff = dateFns.differenceInCalendarMonths(month, fromDate);
728
+ if (monthsDiff <= 0) {
729
+ return undefined;
730
+ }
731
+ // Jump back as the number of months when paged navigation
732
+ return dateFns.addMonths(month, -offset);
733
+ }
734
+
735
+ /**
736
+ * The Navigation context shares details about the months being navigated in DayPicker.
737
+ *
738
+ * Access this context from the [[useNavigation]] hook.
739
+ */
740
+ var NavigationContext = React.createContext(undefined);
741
+ /** Provides the values for the [[NavigationContext]]. */
742
+ function NavigationProvider(props) {
743
+ var dayPicker = useDayPicker();
744
+ var _a = useNavigationState(), month = _a[0], goToMonth = _a[1];
745
+ var displayMonths = getDisplayMonths(month, dayPicker);
746
+ var nextMonth = getNextMonth(month, dayPicker);
747
+ var previousMonth = getPreviousMonth(month, dayPicker);
748
+ var isDateDisplayed = function (date) {
749
+ return displayMonths.some(function (displayMonth) {
750
+ return dateFns.isSameMonth(date, displayMonth);
751
+ });
752
+ };
753
+ var goToDate = function (date, refDate) {
754
+ if (isDateDisplayed(date)) {
755
+ return;
756
+ }
757
+ if (refDate && dateFns.isBefore(date, refDate)) {
758
+ goToMonth(dateFns.addMonths(date, 1 + dayPicker.numberOfMonths * -1));
759
+ }
760
+ else {
761
+ goToMonth(date);
762
+ }
763
+ };
764
+ var value = {
765
+ month: month,
766
+ displayMonths: displayMonths,
767
+ goToMonth: goToMonth,
768
+ goToDate: goToDate,
769
+ previousMonth: previousMonth,
770
+ nextMonth: nextMonth,
771
+ isDateDisplayed: isDateDisplayed
772
+ };
773
+ return (React__default["default"].createElement(NavigationContext.Provider, { value: value }, props.children));
774
+ }
775
+
776
+ /** Hook to access the [[NavigationContext]]. */
777
+ function useNavigation() {
778
+ var context = React.useContext(NavigationContext);
779
+ if (!context) {
780
+ throw new Error('useNavigation must be used within a NavigationProvider');
781
+ }
782
+ return context;
783
+ }
784
+
785
+ /**
786
+ * Render the caption of a month, which includes title and navigation buttons.
787
+ * The caption has a different layout when setting the [[DayPickerProps.captionLayout]] prop.
788
+ */
789
+ function Caption(props) {
790
+ var _a;
791
+ var _b;
792
+ var _c = useDayPicker(), classNames = _c.classNames, numberOfMonths = _c.numberOfMonths, disableNavigation = _c.disableNavigation, styles = _c.styles, captionLayout = _c.captionLayout, onMonthChange = _c.onMonthChange, dir = _c.dir, components = _c.components;
793
+ var _d = useNavigation(), previousMonth = _d.previousMonth, nextMonth = _d.nextMonth, goToMonth = _d.goToMonth, displayMonths = _d.displayMonths;
794
+ var handlePreviousClick = function () {
795
+ if (!previousMonth)
796
+ return;
797
+ goToMonth(previousMonth);
798
+ onMonthChange === null || onMonthChange === void 0 ? void 0 : onMonthChange(previousMonth);
799
+ };
800
+ var handleNextClick = function () {
801
+ if (!nextMonth)
802
+ return;
803
+ goToMonth(nextMonth);
804
+ onMonthChange === null || onMonthChange === void 0 ? void 0 : onMonthChange(nextMonth);
805
+ };
806
+ var handleMonthChange = function (newMonth) {
807
+ goToMonth(newMonth);
808
+ onMonthChange === null || onMonthChange === void 0 ? void 0 : onMonthChange(newMonth);
809
+ };
810
+ var displayIndex = displayMonths.findIndex(function (month) {
811
+ return dateFns.isSameMonth(props.displayMonth, month);
812
+ });
813
+ var isFirst = displayIndex === 0;
814
+ var isLast = displayIndex === displayMonths.length - 1;
815
+ if (dir === 'rtl') {
816
+ _a = [isFirst, isLast], isLast = _a[0], isFirst = _a[1];
817
+ }
818
+ var hideNext = numberOfMonths > 1 && (isFirst || !isLast);
819
+ var hidePrevious = numberOfMonths > 1 && (isLast || !isFirst);
820
+ var CaptionLabelComponent = (_b = components === null || components === void 0 ? void 0 : components.CaptionLabel) !== null && _b !== void 0 ? _b : CaptionLabel;
821
+ var captionLabel = (React__default["default"].createElement(CaptionLabelComponent, { id: props.id, displayMonth: props.displayMonth }));
822
+ var captionContent;
823
+ if (disableNavigation) {
824
+ captionContent = captionLabel;
825
+ }
826
+ else if (captionLayout === 'dropdown') {
827
+ captionContent = (React__default["default"].createElement("div", { className: classNames.caption_dropdowns, style: styles.caption_dropdowns },
828
+ React__default["default"].createElement("div", { className: classNames.vhidden }, captionLabel),
829
+ React__default["default"].createElement(MonthsDropdown, { onChange: handleMonthChange, displayMonth: props.displayMonth }),
830
+ React__default["default"].createElement(YearsDropdown, { onChange: handleMonthChange, displayMonth: props.displayMonth })));
831
+ }
832
+ else {
833
+ captionContent = (React__default["default"].createElement(React__default["default"].Fragment, null,
834
+ captionLabel,
835
+ React__default["default"].createElement(Navigation, { displayMonth: props.displayMonth, hideNext: hideNext, hidePrevious: hidePrevious, nextMonth: nextMonth, previousMonth: previousMonth, onPreviousClick: handlePreviousClick, onNextClick: handleNextClick })));
836
+ }
837
+ return (React__default["default"].createElement("div", { className: classNames.caption, style: styles.caption }, captionContent));
838
+ }
839
+
840
+ /** Render the Footer component (empty as default).*/
841
+ function Footer() {
842
+ var _a = useDayPicker(), footer = _a.footer, styles = _a.styles, tfoot = _a.classNames.tfoot;
843
+ if (!footer)
844
+ return React__default["default"].createElement(React__default["default"].Fragment, null);
845
+ return (React__default["default"].createElement("tfoot", { className: tfoot, style: styles.tfoot },
846
+ React__default["default"].createElement("tr", null,
847
+ React__default["default"].createElement("td", { colSpan: 8 }, footer))));
848
+ }
849
+
850
+ /**
851
+ * Generate a series of 7 days, starting from the week, to use for formatting
852
+ * the weekday names (Monday, Tuesday, etc.).
853
+ */
854
+ function getWeekdays(locale) {
855
+ var start = dateFns.startOfWeek(new Date(), { locale: locale });
856
+ var days = [];
857
+ for (var i = 0; i < 7; i++) {
858
+ var day = dateFns.addDays(start, i);
859
+ days.push(day);
860
+ }
861
+ return days;
862
+ }
863
+
864
+ /**
865
+ * Render the Head component - i.e. the table head with the weekday names.
866
+ */
867
+ function Head() {
868
+ var _a = useDayPicker(), classNames = _a.classNames, styles = _a.styles, showWeekNumber = _a.showWeekNumber, locale = _a.locale, formatWeekdayName = _a.formatters.formatWeekdayName, labelWeekday = _a.labels.labelWeekday;
869
+ var weekdays = getWeekdays(locale);
870
+ return (React__default["default"].createElement("thead", { style: styles.head, className: classNames.head },
871
+ React__default["default"].createElement("tr", { style: styles.head_row, className: classNames.head_row },
872
+ showWeekNumber && (React__default["default"].createElement("th", { scope: "col", style: styles.head_cell, className: classNames.head_cell })),
873
+ weekdays.map(function (weekday, i) { return (React__default["default"].createElement("th", { key: i, scope: "col", className: classNames.head_cell, style: styles.head_cell },
874
+ React__default["default"].createElement("span", { "aria-hidden": true }, formatWeekdayName(weekday, { locale: locale })),
875
+ React__default["default"].createElement("span", { className: classNames.vhidden }, labelWeekday(weekday, { locale: locale })))); }))));
876
+ }
877
+
878
+ /**
879
+ * Render the content of the day cell.
880
+ */
881
+ function DayContent(props) {
882
+ var _a = useDayPicker(), locale = _a.locale, classNames = _a.classNames, styles = _a.styles, labelDay = _a.labels.labelDay, formatDay = _a.formatters.formatDay;
883
+ return (React__default["default"].createElement(React__default["default"].Fragment, null,
884
+ React__default["default"].createElement("span", { "aria-hidden": "true" }, formatDay(props.date, { locale: locale })),
885
+ React__default["default"].createElement("span", { className: classNames.vhidden, style: styles.vhidden }, labelDay(props.date, props.activeModifiers, { locale: locale }))));
886
+ }
887
+
888
+ /** Returns true when the props are of type [[DayPickerMultiple]]. */
889
+ function isDayPickerMultiple(props) {
890
+ return props.mode === 'multiple';
891
+ }
892
+
893
+ /**
894
+ * The SelectMultiple context shares details about the selected days when in
895
+ * multiple selection mode.
896
+ *
897
+ * Access this context from the [[useSelectMultiple]] hook.
898
+ */
899
+ var SelectMultipleContext = React.createContext(undefined);
900
+ /** Provides the values for the [[SelectMultipleContext]]. */
901
+ function SelectMultipleProvider(props) {
902
+ if (!isDayPickerMultiple(props.initialProps)) {
903
+ var emptyContextValue = {
904
+ selected: undefined,
905
+ modifiers: {
906
+ disabled: []
907
+ }
908
+ };
909
+ return (React__default["default"].createElement(SelectMultipleContext.Provider, { value: emptyContextValue }, props.children));
910
+ }
911
+ return (React__default["default"].createElement(SelectMultipleProviderInternal, { initialProps: props.initialProps, children: props.children }));
912
+ }
913
+ function SelectMultipleProviderInternal(_a) {
914
+ var initialProps = _a.initialProps, children = _a.children;
915
+ var selected = initialProps.selected;
916
+ var onDayClick = function (day, modifiers, e) {
917
+ var _a, _b;
918
+ (_a = initialProps.onDayClick) === null || _a === void 0 ? void 0 : _a.call(initialProps, day, modifiers, e);
919
+ var isMinSelected = Boolean(initialProps.min &&
920
+ modifiers.selected &&
921
+ selected &&
922
+ selected.length === initialProps.min);
923
+ if (isMinSelected) {
924
+ return;
925
+ }
926
+ var isMaxSelected = Boolean(initialProps.max &&
927
+ !modifiers.selected &&
928
+ selected &&
929
+ selected.length === initialProps.max);
930
+ if (isMaxSelected) {
931
+ return;
932
+ }
933
+ var days = selected ? __spreadArray([], selected, true) : [];
934
+ if (modifiers.selected) {
935
+ var index = days.findIndex(function (selectedDay) {
936
+ return dateFns.isSameDay(day, selectedDay);
937
+ });
938
+ days.splice(index, 1);
939
+ }
940
+ else {
941
+ days.push(day);
942
+ }
943
+ (_b = initialProps.onSelect) === null || _b === void 0 ? void 0 : _b.call(initialProps, days, day, modifiers, e);
944
+ };
945
+ var modifiers = {
946
+ disabled: []
947
+ };
948
+ if (selected) {
949
+ modifiers.disabled = [
950
+ function disableDay(day) {
951
+ var isMaxSelected = initialProps.max &&
952
+ selected &&
953
+ selected.length > initialProps.max - 1;
954
+ var isSelected = selected === null || selected === void 0 ? void 0 : selected.some(function (selectedDay) {
955
+ return dateFns.isSameDay(selectedDay, day);
956
+ });
957
+ return Boolean(isMaxSelected && !isSelected);
958
+ }
959
+ ];
960
+ }
961
+ var contextValue = { selected: selected, onDayClick: onDayClick, modifiers: modifiers };
962
+ return (React__default["default"].createElement(SelectMultipleContext.Provider, { value: contextValue }, children));
963
+ }
964
+
965
+ /** Hook to access the [[SelectMultipleContext]]. */
966
+ function useSelectMultiple() {
967
+ var context = React.useContext(SelectMultipleContext);
968
+ if (!context) {
969
+ throw new Error('useSelectMultiple must be used within a SelectMultipleProvider');
970
+ }
971
+ return context;
972
+ }
973
+
974
+ /** Returns true when the props are of type [[DayPickerRange]]. */
975
+ function isDayPickerRange(props) {
976
+ return props.mode === 'range';
977
+ }
978
+
979
+ /**
980
+ * Add a day to an existing range.
981
+ *
982
+ * The returned range takes in account the `undefined` values and if the added
983
+ * day is already present in the range.
984
+ */
985
+ function addToRange(day, range) {
986
+ var _a = range || {}, from = _a.from, to = _a.to;
987
+ if (!from) {
988
+ return { from: day, to: day };
989
+ }
990
+ if (!to && dateFns.isSameDay(from, day)) {
991
+ return undefined;
992
+ }
993
+ if (!to && dateFns.isBefore(day, from)) {
994
+ return { from: day, to: from };
995
+ }
996
+ if (!to) {
997
+ return { from: from, to: day };
998
+ }
999
+ if (dateFns.isSameDay(to, day) && dateFns.isSameDay(from, day)) {
1000
+ return undefined;
1001
+ }
1002
+ if (dateFns.isSameDay(to, day)) {
1003
+ return { from: to, to: to };
1004
+ }
1005
+ if (dateFns.isSameDay(from, day)) {
1006
+ return undefined;
1007
+ }
1008
+ if (dateFns.isAfter(from, day)) {
1009
+ return { from: day, to: to };
1010
+ }
1011
+ return { from: from, to: day };
1012
+ }
1013
+
1014
+ /**
1015
+ * The SelectRange context shares details about the selected days when in
1016
+ * range selection mode.
1017
+ *
1018
+ * Access this context from the [[useSelectRange]] hook.
1019
+ */
1020
+ var SelectRangeContext = React.createContext(undefined);
1021
+ /** Provides the values for the [[SelectRangeProvider]]. */
1022
+ function SelectRangeProvider(props) {
1023
+ if (!isDayPickerRange(props.initialProps)) {
1024
+ var emptyContextValue = {
1025
+ selected: undefined,
1026
+ modifiers: {
1027
+ range_start: [],
1028
+ range_end: [],
1029
+ range_middle: [],
1030
+ disabled: []
1031
+ }
1032
+ };
1033
+ return (React__default["default"].createElement(SelectRangeContext.Provider, { value: emptyContextValue }, props.children));
1034
+ }
1035
+ return (React__default["default"].createElement(SelectRangeProviderInternal, { initialProps: props.initialProps, children: props.children }));
1036
+ }
1037
+ function SelectRangeProviderInternal(_a) {
1038
+ var initialProps = _a.initialProps, children = _a.children;
1039
+ var selected = initialProps.selected;
1040
+ var min = initialProps.min;
1041
+ var max = initialProps.max;
1042
+ var onDayClick = function (day, modifiers, e) {
1043
+ var _a, _b;
1044
+ (_a = initialProps.onDayClick) === null || _a === void 0 ? void 0 : _a.call(initialProps, day, modifiers, e);
1045
+ var newValue = addToRange(day, selected);
1046
+ if ((min || max) &&
1047
+ selected &&
1048
+ (newValue === null || newValue === void 0 ? void 0 : newValue.to) &&
1049
+ newValue.from &&
1050
+ newValue.from !== newValue.to) {
1051
+ var diff = Math.abs(dateFns.differenceInCalendarDays(newValue === null || newValue === void 0 ? void 0 : newValue.to, newValue === null || newValue === void 0 ? void 0 : newValue.from));
1052
+ if (min && diff < min) {
1053
+ return;
1054
+ }
1055
+ if (max && diff >= max) {
1056
+ return;
1057
+ }
1058
+ }
1059
+ (_b = initialProps.onSelect) === null || _b === void 0 ? void 0 : _b.call(initialProps, newValue, day, modifiers, e);
1060
+ };
1061
+ var modifiers = {
1062
+ range_start: [],
1063
+ range_end: [],
1064
+ range_middle: [],
1065
+ disabled: []
1066
+ };
1067
+ if (selected) {
1068
+ if (selected.from) {
1069
+ modifiers.range_start = [selected.from];
1070
+ if (selected.to) {
1071
+ modifiers.range_middle = [
1072
+ {
1073
+ after: selected.from,
1074
+ before: selected.to
1075
+ }
1076
+ ];
1077
+ if (max || min) {
1078
+ modifiers.disabled = [
1079
+ function (date) {
1080
+ if (max &&
1081
+ selected.to &&
1082
+ selected.from &&
1083
+ dateFns.isBefore(date, selected.from)) {
1084
+ var diff = dateFns.differenceInCalendarDays(selected.to, date);
1085
+ if (diff >= max) {
1086
+ return true;
1087
+ }
1088
+ }
1089
+ if (max &&
1090
+ selected.to &&
1091
+ selected.from &&
1092
+ dateFns.isAfter(date, selected.to)) {
1093
+ var diff = dateFns.differenceInCalendarDays(date, selected.from);
1094
+ if (diff >= max) {
1095
+ return true;
1096
+ }
1097
+ }
1098
+ if (min && selected.from && dateFns.isBefore(date, selected.from)) {
1099
+ var diff = dateFns.differenceInCalendarDays(selected.from, date);
1100
+ if (diff < min) {
1101
+ return true;
1102
+ }
1103
+ }
1104
+ if (min &&
1105
+ selected.to &&
1106
+ selected.from &&
1107
+ dateFns.isAfter(date, selected.to)) {
1108
+ var diff = dateFns.differenceInCalendarDays(date, selected.from);
1109
+ if (diff < min) {
1110
+ return true;
1111
+ }
1112
+ }
1113
+ return false;
1114
+ }
1115
+ ];
1116
+ }
1117
+ modifiers.range_end = [selected.to];
1118
+ }
1119
+ else {
1120
+ modifiers.range_end = [selected.from];
1121
+ }
1122
+ }
1123
+ }
1124
+ return (React__default["default"].createElement(SelectRangeContext.Provider, { value: { selected: selected, onDayClick: onDayClick, modifiers: modifiers } }, children));
1125
+ }
1126
+
1127
+ /** Hook to access the [[SelectRangeContext]]. */
1128
+ function useSelectRange() {
1129
+ var context = React.useContext(SelectRangeContext);
1130
+ if (!context) {
1131
+ throw new Error('useSelectRange must be used within a SelectRangeProvider');
1132
+ }
1133
+ return context;
1134
+ }
1135
+
1136
+ /** Normalize to array a matcher input. */
1137
+ function matcherToArray(matcher) {
1138
+ if (Array.isArray(matcher)) {
1139
+ return matcher;
1140
+ }
1141
+ else if (matcher !== undefined) {
1142
+ return [matcher];
1143
+ }
1144
+ else {
1145
+ return [];
1146
+ }
1147
+ }
1148
+
1149
+ /** Create CustomModifiers from dayModifiers */
1150
+ function getCustomModifiers(dayModifiers) {
1151
+ var customModifiers = {};
1152
+ Object.entries(dayModifiers).forEach(function (_a) {
1153
+ var modifier = _a[0], matcher = _a[1];
1154
+ customModifiers[modifier] = matcherToArray(matcher);
1155
+ });
1156
+ return customModifiers;
1157
+ }
1158
+
1159
+ /** The name of the modifiers that are used internally by DayPicker. */
1160
+ exports.InternalModifier = void 0;
1161
+ (function (InternalModifier) {
1162
+ InternalModifier["Outside"] = "outside";
1163
+ /** Name of the modifier applied to the disabled days, using the `disabled` prop. */
1164
+ InternalModifier["Disabled"] = "disabled";
1165
+ /** Name of the modifier applied to the selected days using the `selected` prop). */
1166
+ InternalModifier["Selected"] = "selected";
1167
+ /** Name of the modifier applied to the hidden days using the `hidden` prop). */
1168
+ InternalModifier["Hidden"] = "hidden";
1169
+ /** Name of the modifier applied to the day specified using the `today` prop). */
1170
+ InternalModifier["Today"] = "today";
1171
+ /** The modifier applied to the day starting a selected range, when in range selection mode. */
1172
+ InternalModifier["RangeStart"] = "range_start";
1173
+ /** The modifier applied to the day ending a selected range, when in range selection mode. */
1174
+ InternalModifier["RangeEnd"] = "range_end";
1175
+ /** The modifier applied to the days between the start and the end of a selected range, when in range selection mode. */
1176
+ InternalModifier["RangeMiddle"] = "range_middle";
1177
+ })(exports.InternalModifier || (exports.InternalModifier = {}));
1178
+
1179
+ var Selected = exports.InternalModifier.Selected, Disabled = exports.InternalModifier.Disabled, Hidden = exports.InternalModifier.Hidden, Today = exports.InternalModifier.Today, RangeEnd = exports.InternalModifier.RangeEnd, RangeMiddle = exports.InternalModifier.RangeMiddle, RangeStart = exports.InternalModifier.RangeStart, Outside = exports.InternalModifier.Outside;
1180
+ /** Return the [[InternalModifiers]] from the DayPicker and select contexts. */
1181
+ function getInternalModifiers(dayPicker, selectMultiple, selectRange) {
1182
+ var _a;
1183
+ var internalModifiers = (_a = {},
1184
+ _a[Selected] = matcherToArray(dayPicker.selected),
1185
+ _a[Disabled] = matcherToArray(dayPicker.disabled),
1186
+ _a[Hidden] = matcherToArray(dayPicker.hidden),
1187
+ _a[Today] = [dayPicker.today],
1188
+ _a[RangeEnd] = [],
1189
+ _a[RangeMiddle] = [],
1190
+ _a[RangeStart] = [],
1191
+ _a[Outside] = [],
1192
+ _a);
1193
+ if (dayPicker.fromDate) {
1194
+ internalModifiers[Disabled].push({ before: dayPicker.fromDate });
1195
+ }
1196
+ if (dayPicker.toDate) {
1197
+ internalModifiers[Disabled].push({ after: dayPicker.toDate });
1198
+ }
1199
+ if (isDayPickerMultiple(dayPicker)) {
1200
+ internalModifiers[Disabled] = internalModifiers[Disabled].concat(selectMultiple.modifiers[Disabled]);
1201
+ }
1202
+ else if (isDayPickerRange(dayPicker)) {
1203
+ internalModifiers[Disabled] = internalModifiers[Disabled].concat(selectRange.modifiers[Disabled]);
1204
+ internalModifiers[RangeStart] = selectRange.modifiers[RangeStart];
1205
+ internalModifiers[RangeMiddle] = selectRange.modifiers[RangeMiddle];
1206
+ internalModifiers[RangeEnd] = selectRange.modifiers[RangeEnd];
1207
+ }
1208
+ return internalModifiers;
1209
+ }
1210
+
1211
+ /** The Modifiers context store the modifiers used in DayPicker. To access the value of this context, use [[useModifiers]]. */
1212
+ var ModifiersContext = React.createContext(undefined);
1213
+ /** Provide the value for the [[ModifiersContext]]. */
1214
+ function ModifiersProvider(props) {
1215
+ var dayPicker = useDayPicker();
1216
+ var selectMultiple = useSelectMultiple();
1217
+ var selectRange = useSelectRange();
1218
+ var internalModifiers = getInternalModifiers(dayPicker, selectMultiple, selectRange);
1219
+ var customModifiers = getCustomModifiers(dayPicker.modifiers);
1220
+ var modifiers = __assign(__assign({}, internalModifiers), customModifiers);
1221
+ return (React__default["default"].createElement(ModifiersContext.Provider, { value: modifiers }, props.children));
1222
+ }
1223
+
1224
+ /**
1225
+ * Return the modifiers used by DayPicker.
1226
+ *
1227
+ * Requires to be wrapped into [[ModifiersProvider]]. */
1228
+ function useModifiers() {
1229
+ var context = React.useContext(ModifiersContext);
1230
+ if (!context) {
1231
+ throw new Error('useModifiers must be used within a ModifiersProvider');
1232
+ }
1233
+ return context;
1234
+ }
1235
+
1236
+ /** Returns true if `matcher` is of type [[DateInterval]]. */
1237
+ function isDateInterval(matcher) {
1238
+ return Boolean(matcher &&
1239
+ typeof matcher === 'object' &&
1240
+ 'before' in matcher &&
1241
+ 'after' in matcher);
1242
+ }
1243
+ /** Returns true if `value` is a [[DateRange]] type. */
1244
+ function isDateRange(value) {
1245
+ // TODO: Check if dates?!
1246
+ return Boolean(value && typeof value === 'object' && 'from' in value);
1247
+ }
1248
+ /** Returns true if `value` is of type [[DateAfter]]. */
1249
+ function isDateAfterType(value) {
1250
+ return Boolean(value && typeof value === 'object' && 'after' in value);
1251
+ }
1252
+ /** Returns true if `value` is of type [[DateBefore]]. */
1253
+ function isDateBeforeType(value) {
1254
+ return Boolean(value && typeof value === 'object' && 'before' in value);
1255
+ }
1256
+ /** Returns true if `value` is a [[DayOfWeek]] type. */
1257
+ function isDayOfWeekType(value) {
1258
+ return Boolean(value && typeof value === 'object' && 'dayOfWeek' in value);
1259
+ }
1260
+
1261
+ /** Return `true` whether `date` is inside `range`. */
1262
+ function isDateInRange(date, range) {
1263
+ var _a;
1264
+ var from = range.from, to = range.to;
1265
+ if (!from) {
1266
+ return false;
1267
+ }
1268
+ if (!to && dateFns.isSameDay(from, date)) {
1269
+ return true;
1270
+ }
1271
+ if (!to) {
1272
+ return false;
1273
+ }
1274
+ var isToBeforeFrom = dateFns.differenceInCalendarDays(to, from) < 0;
1275
+ if (to && isToBeforeFrom) {
1276
+ _a = [to, from], from = _a[0], to = _a[1];
1277
+ }
1278
+ return (dateFns.differenceInCalendarDays(date, from) >= 0 &&
1279
+ dateFns.differenceInCalendarDays(to, date) >= 0);
1280
+ }
1281
+
1282
+ /** Returns true if `value` is a Date type. */
1283
+ function isDateType(value) {
1284
+ return dateFns.isDate(value);
1285
+ }
1286
+ /** Returns true if `value` is an array of valid dates. */
1287
+ function isArrayOfDates(value) {
1288
+ return Array.isArray(value) && value.every(dateFns.isDate);
1289
+ }
1290
+ /** Returns `true` whether the day matches against the given matchers. */
1291
+ function isMatch(day, matchers) {
1292
+ return matchers.some(function (matcher) {
1293
+ if (typeof matcher === 'boolean') {
1294
+ return matcher;
1295
+ }
1296
+ if (isDateType(matcher)) {
1297
+ return dateFns.isSameDay(day, matcher);
1298
+ }
1299
+ if (isArrayOfDates(matcher)) {
1300
+ return matcher.includes(day);
1301
+ }
1302
+ if (isDateRange(matcher)) {
1303
+ return isDateInRange(day, matcher);
1304
+ }
1305
+ if (isDayOfWeekType(matcher)) {
1306
+ return matcher.dayOfWeek.includes(day.getDay());
1307
+ }
1308
+ if (isDateInterval(matcher)) {
1309
+ var isBefore = dateFns.differenceInCalendarDays(matcher.before, day) > 0;
1310
+ var isAfter = dateFns.differenceInCalendarDays(day, matcher.after) > 0;
1311
+ return isBefore && isAfter;
1312
+ }
1313
+ if (isDateAfterType(matcher)) {
1314
+ return dateFns.differenceInCalendarDays(day, matcher.after) > 0;
1315
+ }
1316
+ if (isDateBeforeType(matcher)) {
1317
+ return dateFns.differenceInCalendarDays(matcher.before, day) > 0;
1318
+ }
1319
+ if (typeof matcher === 'function') {
1320
+ return matcher(day);
1321
+ }
1322
+ return false;
1323
+ });
1324
+ }
1325
+
1326
+ /** Return the active modifiers for the given day. */
1327
+ function getActiveModifiers(day,
1328
+ /** The modifiers to match for the given date. */
1329
+ modifiers,
1330
+ /** The month where the day is displayed, to add the "outside" modifiers. */
1331
+ displayMonth) {
1332
+ var matchedModifiers = Object.keys(modifiers).reduce(function (result, key) {
1333
+ var modifier = modifiers[key];
1334
+ if (isMatch(day, modifier)) {
1335
+ result.push(key);
1336
+ }
1337
+ return result;
1338
+ }, []);
1339
+ var activeModifiers = {};
1340
+ matchedModifiers.forEach(function (modifier) { return (activeModifiers[modifier] = true); });
1341
+ if (displayMonth && !dateFns.isSameMonth(day, displayMonth)) {
1342
+ activeModifiers.outside = true;
1343
+ }
1344
+ return activeModifiers;
1345
+ }
1346
+
1347
+ /** Returns the day that should be the target of the focus when DayPicker is rendered the first time. */
1348
+ function getInitialFocusTarget(displayMonths, modifiers) {
1349
+ var firstDayInMonth = dateFns.startOfMonth(displayMonths[0]);
1350
+ var lastDayInMonth = dateFns.endOfMonth(displayMonths[displayMonths.length - 1]);
1351
+ // TODO: cleanup code
1352
+ var firstFocusableDay;
1353
+ var today;
1354
+ var date = firstDayInMonth;
1355
+ while (date <= lastDayInMonth) {
1356
+ var activeModifiers = getActiveModifiers(date, modifiers);
1357
+ var isFocusable = !activeModifiers.disabled && !activeModifiers.hidden;
1358
+ if (!isFocusable) {
1359
+ date = dateFns.addDays(date, 1);
1360
+ continue;
1361
+ }
1362
+ if (activeModifiers.selected) {
1363
+ return date;
1364
+ }
1365
+ if (activeModifiers.today && !today) {
1366
+ today = date;
1367
+ }
1368
+ if (!firstFocusableDay) {
1369
+ firstFocusableDay = date;
1370
+ }
1371
+ date = dateFns.addDays(date, 1);
1372
+ }
1373
+ if (today) {
1374
+ return today;
1375
+ }
1376
+ else {
1377
+ return firstFocusableDay;
1378
+ }
1379
+ }
1380
+
1381
+ /**
1382
+ * The Focus context shares details about the focused day for the keyboard
1383
+ *
1384
+ * Access this context from the [[useFocus]] hook.
1385
+ */
1386
+ var FocusContext = React.createContext(undefined);
1387
+ /** The provider for the [[FocusContext]]. */
1388
+ function FocusProvider(props) {
1389
+ var navigation = useNavigation();
1390
+ var modifiers = useModifiers();
1391
+ var _a = React.useState(), focusedDay = _a[0], setFocusedDay = _a[1];
1392
+ var _b = React.useState(), lastFocused = _b[0], setLastFocused = _b[1];
1393
+ var initialFocusTarget = getInitialFocusTarget(navigation.displayMonths, modifiers);
1394
+ // TODO: cleanup and test obscure code below
1395
+ var focusTarget = (focusedDay !== null && focusedDay !== void 0 ? focusedDay : (lastFocused && navigation.isDateDisplayed(lastFocused)))
1396
+ ? lastFocused
1397
+ : initialFocusTarget;
1398
+ var blur = function () {
1399
+ setLastFocused(focusedDay);
1400
+ setFocusedDay(undefined);
1401
+ };
1402
+ var focus = function (date) {
1403
+ setFocusedDay(date);
1404
+ };
1405
+ var focusDayBefore = function () {
1406
+ if (!focusedDay)
1407
+ return;
1408
+ var before = dateFns.addDays(focusedDay, -1);
1409
+ focus(before);
1410
+ navigation.goToDate(before, focusedDay);
1411
+ };
1412
+ var focusDayAfter = function () {
1413
+ if (!focusedDay)
1414
+ return;
1415
+ var after = dateFns.addDays(focusedDay, 1);
1416
+ focus(after);
1417
+ navigation.goToDate(after, focusedDay);
1418
+ };
1419
+ var focusWeekBefore = function () {
1420
+ if (!focusedDay)
1421
+ return;
1422
+ var up = dateFns.addWeeks(focusedDay, -1);
1423
+ focus(up);
1424
+ navigation.goToDate(up, focusedDay);
1425
+ };
1426
+ var focusWeekAfter = function () {
1427
+ if (!focusedDay)
1428
+ return;
1429
+ var down = dateFns.addWeeks(focusedDay, 1);
1430
+ focus(down);
1431
+ navigation.goToDate(down, focusedDay);
1432
+ };
1433
+ var focusStartOfWeek = function () {
1434
+ if (!focusedDay)
1435
+ return;
1436
+ var dayToFocus = dateFns.startOfWeek(focusedDay);
1437
+ navigation.goToDate(dayToFocus, focusedDay);
1438
+ focus(dayToFocus);
1439
+ };
1440
+ var focusEndOfWeek = function () {
1441
+ if (!focusedDay)
1442
+ return;
1443
+ var dayToFocus = dateFns.endOfWeek(focusedDay);
1444
+ navigation.goToDate(dayToFocus, focusedDay);
1445
+ focus(dayToFocus);
1446
+ };
1447
+ var focusMonthBefore = function () {
1448
+ if (!focusedDay)
1449
+ return;
1450
+ var monthBefore = dateFns.addMonths(focusedDay, -1);
1451
+ navigation.goToDate(monthBefore, focusedDay);
1452
+ focus(monthBefore);
1453
+ };
1454
+ var focusMonthAfter = function () {
1455
+ if (!focusedDay)
1456
+ return;
1457
+ var monthAfter = dateFns.addMonths(focusedDay, 1);
1458
+ navigation.goToDate(monthAfter, focusedDay);
1459
+ focus(monthAfter);
1460
+ };
1461
+ var focusYearBefore = function () {
1462
+ if (!focusedDay)
1463
+ return;
1464
+ var yearBefore = dateFns.addYears(focusedDay, -1);
1465
+ navigation.goToDate(yearBefore, focusedDay);
1466
+ focus(yearBefore);
1467
+ };
1468
+ var focusYearAfter = function () {
1469
+ if (!focusedDay)
1470
+ return;
1471
+ var yearAfter = dateFns.addYears(focusedDay, 1);
1472
+ navigation.goToDate(yearAfter, focusedDay);
1473
+ focus(yearAfter);
1474
+ };
1475
+ var value = {
1476
+ focusedDay: focusedDay,
1477
+ focusTarget: focusTarget,
1478
+ blur: blur,
1479
+ focus: focus,
1480
+ focusDayAfter: focusDayAfter,
1481
+ focusDayBefore: focusDayBefore,
1482
+ focusWeekAfter: focusWeekAfter,
1483
+ focusWeekBefore: focusWeekBefore,
1484
+ focusMonthBefore: focusMonthBefore,
1485
+ focusMonthAfter: focusMonthAfter,
1486
+ focusYearBefore: focusYearBefore,
1487
+ focusYearAfter: focusYearAfter,
1488
+ focusStartOfWeek: focusStartOfWeek,
1489
+ focusEndOfWeek: focusEndOfWeek
1490
+ };
1491
+ return (React__default["default"].createElement(FocusContext.Provider, { value: value }, props.children));
1492
+ }
1493
+
1494
+ /** Hook to access the [[FocusContext]]. */
1495
+ function useFocusContext() {
1496
+ var context = React.useContext(FocusContext);
1497
+ if (!context) {
1498
+ throw new Error('useFocusContext must be used within a FocusProvider');
1499
+ }
1500
+ return context;
1501
+ }
1502
+
1503
+ /**
1504
+ * Return the active modifiers for the specified day.
1505
+ *
1506
+ * @param day
1507
+ * @param displayMonth The month where the date is displayed. If not the same as
1508
+ * `date`, the day is an "outside day".
1509
+ */
1510
+ function useActiveModifiers(day, displayMonth) {
1511
+ var modifiers = useModifiers();
1512
+ var activeModifiers = getActiveModifiers(day, modifiers, displayMonth);
1513
+ return activeModifiers;
1514
+ }
1515
+
1516
+ /** Returns true when the props are of type [[DayPickerSingle]]. */
1517
+ function isDayPickerSingle(props) {
1518
+ return props.mode === 'single';
1519
+ }
1520
+
1521
+ /**
1522
+ * The SelectSingle context shares details about the selected days when in
1523
+ * single selection mode.
1524
+ *
1525
+ * Access this context from the [[useSelectSingle]] hook.
1526
+ */
1527
+ var SelectSingleContext = React.createContext(undefined);
1528
+ /** Provides the values for the [[SelectSingleProvider]]. */
1529
+ function SelectSingleProvider(props) {
1530
+ if (!isDayPickerSingle(props.initialProps)) {
1531
+ var emptyContextValue = {
1532
+ selected: undefined
1533
+ };
1534
+ return (React__default["default"].createElement(SelectSingleContext.Provider, { value: emptyContextValue }, props.children));
1535
+ }
1536
+ return (React__default["default"].createElement(SelectSingleProviderInternal, { initialProps: props.initialProps, children: props.children }));
1537
+ }
1538
+ function SelectSingleProviderInternal(_a) {
1539
+ var initialProps = _a.initialProps, children = _a.children;
1540
+ var onDayClick = function (day, dayModifiers, e) {
1541
+ var _a, _b;
1542
+ if (dayModifiers.selected && !initialProps.required) {
1543
+ (_a = initialProps.onSelect) === null || _a === void 0 ? void 0 : _a.call(initialProps, undefined, day, dayModifiers, e);
1544
+ return;
1545
+ }
1546
+ (_b = initialProps.onSelect) === null || _b === void 0 ? void 0 : _b.call(initialProps, day, day, dayModifiers, e);
1547
+ };
1548
+ var contextValue = {
1549
+ selected: initialProps.selected,
1550
+ onDayClick: onDayClick
1551
+ };
1552
+ return (React__default["default"].createElement(SelectSingleContext.Provider, { value: contextValue }, children));
1553
+ }
1554
+
1555
+ /** Hook to access the [[SelectSingleContext]]. */
1556
+ function useSelectSingle() {
1557
+ var context = React.useContext(SelectSingleContext);
1558
+ if (!context) {
1559
+ throw new Error('useSelectSingle must be used within a SelectSingleProvider');
1560
+ }
1561
+ return context;
1562
+ }
1563
+
1564
+ /**
1565
+ * This hook returns details about the content to render in the day cell.
1566
+ *
1567
+ *
1568
+ * When a day cell is rendered in the table, DayPicker can either:
1569
+ *
1570
+ * - render nothing: when the day is outside the month or has matched the
1571
+ * "hidden" modifier.
1572
+ * - render a button. When a selection mode is set, DayPicker renders a button
1573
+ * to allow the focus and the selection. In case of `custom` selection
1574
+ * mode, DayPicker expects a `onDayClick` prop to render a button.
1575
+ * - render a non-interactive element: when no selection mode is set, the day
1576
+ * cell shouldn’t respond to any interaction. DayPicker should render a `div`
1577
+ * or a `span`.
1578
+ *
1579
+ * ### Usage
1580
+ *
1581
+ * Use this hook to customize the behavior of the [[Day]] component. Create a
1582
+ * new `Day` component using this hook and pass it to the `components` prop.
1583
+ * The source of [[Day]] can be a good starting point.
1584
+ *
1585
+ */
1586
+ function useDayEventHandlers(date, activeModifiers) {
1587
+ var dayPicker = useDayPicker();
1588
+ var single = useSelectSingle();
1589
+ var multiple = useSelectMultiple();
1590
+ var range = useSelectRange();
1591
+ var _a = useFocusContext(), focusDayAfter = _a.focusDayAfter, focusDayBefore = _a.focusDayBefore, focusWeekAfter = _a.focusWeekAfter, focusWeekBefore = _a.focusWeekBefore, blur = _a.blur, focus = _a.focus, focusMonthBefore = _a.focusMonthBefore, focusMonthAfter = _a.focusMonthAfter, focusYearBefore = _a.focusYearBefore, focusYearAfter = _a.focusYearAfter, focusStartOfWeek = _a.focusStartOfWeek, focusEndOfWeek = _a.focusEndOfWeek;
1592
+ var onClick = function (e) {
1593
+ var _a, _b, _c, _d;
1594
+ if (isDayPickerSingle(dayPicker)) {
1595
+ (_a = single.onDayClick) === null || _a === void 0 ? void 0 : _a.call(single, date, activeModifiers, e);
1596
+ }
1597
+ else if (isDayPickerMultiple(dayPicker)) {
1598
+ (_b = multiple.onDayClick) === null || _b === void 0 ? void 0 : _b.call(multiple, date, activeModifiers, e);
1599
+ }
1600
+ else if (isDayPickerRange(dayPicker)) {
1601
+ (_c = range.onDayClick) === null || _c === void 0 ? void 0 : _c.call(range, date, activeModifiers, e);
1602
+ }
1603
+ (_d = dayPicker.onDayClick) === null || _d === void 0 ? void 0 : _d.call(dayPicker, date, activeModifiers, e);
1604
+ };
1605
+ var onFocus = function (e) {
1606
+ var _a;
1607
+ focus(date);
1608
+ (_a = dayPicker.onDayFocus) === null || _a === void 0 ? void 0 : _a.call(dayPicker, date, activeModifiers, e);
1609
+ };
1610
+ var onBlur = function (e) {
1611
+ var _a;
1612
+ blur();
1613
+ (_a = dayPicker.onDayBlur) === null || _a === void 0 ? void 0 : _a.call(dayPicker, date, activeModifiers, e);
1614
+ };
1615
+ var onMouseEnter = function (e) {
1616
+ var _a;
1617
+ (_a = dayPicker.onDayMouseEnter) === null || _a === void 0 ? void 0 : _a.call(dayPicker, date, activeModifiers, e);
1618
+ };
1619
+ var onMouseLeave = function (e) {
1620
+ var _a;
1621
+ (_a = dayPicker.onDayMouseLeave) === null || _a === void 0 ? void 0 : _a.call(dayPicker, date, activeModifiers, e);
1622
+ };
1623
+ var onTouchCancel = function (e) {
1624
+ var _a;
1625
+ (_a = dayPicker.onDayTouchCancel) === null || _a === void 0 ? void 0 : _a.call(dayPicker, date, activeModifiers, e);
1626
+ };
1627
+ var onTouchEnd = function (e) {
1628
+ var _a;
1629
+ (_a = dayPicker.onDayTouchEnd) === null || _a === void 0 ? void 0 : _a.call(dayPicker, date, activeModifiers, e);
1630
+ };
1631
+ var onTouchMove = function (e) {
1632
+ var _a;
1633
+ (_a = dayPicker.onDayTouchMove) === null || _a === void 0 ? void 0 : _a.call(dayPicker, date, activeModifiers, e);
1634
+ };
1635
+ var onTouchStart = function (e) {
1636
+ var _a;
1637
+ (_a = dayPicker.onDayTouchStart) === null || _a === void 0 ? void 0 : _a.call(dayPicker, date, activeModifiers, e);
1638
+ };
1639
+ var onKeyUp = function (e) {
1640
+ var _a;
1641
+ (_a = dayPicker.onDayKeyUp) === null || _a === void 0 ? void 0 : _a.call(dayPicker, date, activeModifiers, e);
1642
+ };
1643
+ var onKeyDown = function (e) {
1644
+ var _a;
1645
+ switch (e.key) {
1646
+ case 'ArrowLeft':
1647
+ e.preventDefault();
1648
+ e.stopPropagation();
1649
+ dayPicker.dir === 'rtl' ? focusDayAfter() : focusDayBefore();
1650
+ break;
1651
+ case 'ArrowRight':
1652
+ e.preventDefault();
1653
+ e.stopPropagation();
1654
+ dayPicker.dir === 'rtl' ? focusDayBefore() : focusDayAfter();
1655
+ break;
1656
+ case 'ArrowDown':
1657
+ e.preventDefault();
1658
+ e.stopPropagation();
1659
+ focusWeekAfter();
1660
+ break;
1661
+ case 'ArrowUp':
1662
+ e.preventDefault();
1663
+ e.stopPropagation();
1664
+ focusWeekBefore();
1665
+ break;
1666
+ case 'PageUp':
1667
+ e.preventDefault();
1668
+ e.stopPropagation();
1669
+ e.shiftKey ? focusYearBefore() : focusMonthBefore();
1670
+ break;
1671
+ case 'PageDown':
1672
+ e.preventDefault();
1673
+ e.stopPropagation();
1674
+ e.shiftKey ? focusYearAfter() : focusMonthAfter();
1675
+ break;
1676
+ case 'Home':
1677
+ e.preventDefault();
1678
+ e.stopPropagation();
1679
+ focusStartOfWeek();
1680
+ break;
1681
+ case 'End':
1682
+ e.preventDefault();
1683
+ e.stopPropagation();
1684
+ focusEndOfWeek();
1685
+ break;
1686
+ }
1687
+ (_a = dayPicker.onDayKeyDown) === null || _a === void 0 ? void 0 : _a.call(dayPicker, date, activeModifiers, e);
1688
+ };
1689
+ var eventHandlers = {
1690
+ onClick: onClick,
1691
+ onFocus: onFocus,
1692
+ onBlur: onBlur,
1693
+ onKeyDown: onKeyDown,
1694
+ onKeyUp: onKeyUp,
1695
+ onMouseEnter: onMouseEnter,
1696
+ onMouseLeave: onMouseLeave,
1697
+ onTouchCancel: onTouchCancel,
1698
+ onTouchEnd: onTouchEnd,
1699
+ onTouchMove: onTouchMove,
1700
+ onTouchStart: onTouchStart
1701
+ };
1702
+ return eventHandlers;
1703
+ }
1704
+
1705
+ /**
1706
+ * Return the current selected days when DayPicker is in selection mode.
1707
+ *
1708
+ * Days selected by the custom selection mode are not returned.
1709
+ */
1710
+ function useSelectedDays() {
1711
+ var dayPicker = useDayPicker();
1712
+ var single = useSelectSingle();
1713
+ var multiple = useSelectMultiple();
1714
+ var range = useSelectRange();
1715
+ var selectedDays = isDayPickerSingle(dayPicker)
1716
+ ? single.selected
1717
+ : isDayPickerMultiple(dayPicker)
1718
+ ? multiple.selected
1719
+ : isDayPickerRange(dayPicker)
1720
+ ? range.selected
1721
+ : undefined;
1722
+ return selectedDays;
1723
+ }
1724
+
1725
+ /** Return the class names for the Day element, according to the given active modifiers. */
1726
+ function getDayClassNames(dayPicker, activeModifiers) {
1727
+ var classNames = [dayPicker.classNames.day];
1728
+ Object.keys(activeModifiers).forEach(function (modifier) {
1729
+ var customClassName = dayPicker.modifiersClassNames[modifier];
1730
+ if (customClassName) {
1731
+ classNames.push(customClassName);
1732
+ }
1733
+ else {
1734
+ classNames.push("".concat(dayPicker.modifierPrefix).concat(modifier));
1735
+ }
1736
+ });
1737
+ return classNames;
1738
+ }
1739
+
1740
+ /** Return the style for the Day element, according to the given active modifiers. */
1741
+ function getDayStyle(dayPicker, activeModifiers) {
1742
+ var style = __assign({}, dayPicker.styles.day);
1743
+ Object.keys(activeModifiers).forEach(function (modifier) {
1744
+ var _a;
1745
+ style = __assign(__assign({}, style), (_a = dayPicker.modifiersStyles) === null || _a === void 0 ? void 0 : _a[modifier]);
1746
+ });
1747
+ return style;
1748
+ }
1749
+
1750
+ /**
1751
+ * Return props and data used to render the [[Day]] component.
1752
+ *
1753
+ * Use this hook when creating a component to replace the built-in `Day`
1754
+ * component.
1755
+ *
1756
+ * Each Day in DayPicker should render one of the following, according to the return
1757
+ * value:
1758
+ *
1759
+ * - an empty `React.Fragment`, to render if `isHidden` is true
1760
+ * - a `button` element, when the day is interactive, e.g. is selectable
1761
+ * - a `div` element, whe the day is not interactive
1762
+ *
1763
+ * @param day The date to render
1764
+ * @param displayMonth The month where the date is displayed (if not the same as
1765
+ * `date`, it means it is an "outside" day)
1766
+ * @param buttonRef A ref to the button element that will be target of focus
1767
+ * when rendered (if required).
1768
+ */
1769
+ function useDayRender(day, displayMonth, buttonRef) {
1770
+ var _a;
1771
+ var _b, _c;
1772
+ var dayPicker = useDayPicker();
1773
+ var focusContext = useFocusContext();
1774
+ var activeModifiers = useActiveModifiers(day, displayMonth);
1775
+ var eventHandlers = useDayEventHandlers(day, activeModifiers);
1776
+ var selectedDays = useSelectedDays();
1777
+ var isButton = Boolean(dayPicker.mode || dayPicker.onDayClick);
1778
+ // Focus the button if the day is focused according to the focus context
1779
+ React.useEffect(function () {
1780
+ var _a;
1781
+ if (!focusContext.focusedDay)
1782
+ return;
1783
+ if (!isButton)
1784
+ return;
1785
+ if (dateFns.isSameDay(focusContext.focusedDay, day)) {
1786
+ (_a = buttonRef.current) === null || _a === void 0 ? void 0 : _a.focus();
1787
+ }
1788
+ }, [focusContext.focusedDay, day, buttonRef, isButton]);
1789
+ var className = getDayClassNames(dayPicker, activeModifiers).join(' ');
1790
+ var style = getDayStyle(dayPicker, activeModifiers);
1791
+ var isHidden = Boolean((activeModifiers.outside && !dayPicker.showOutsideDays) ||
1792
+ activeModifiers.hidden);
1793
+ var DayContentComponent = (_c = (_b = dayPicker.components) === null || _b === void 0 ? void 0 : _b.DayContent) !== null && _c !== void 0 ? _c : DayContent;
1794
+ var children = (React__default["default"].createElement(DayContentComponent, { date: day, displayMonth: displayMonth, activeModifiers: activeModifiers }));
1795
+ var divProps = {
1796
+ style: style,
1797
+ className: className,
1798
+ children: children
1799
+ };
1800
+ var isFocusTarget = Boolean(focusContext.focusTarget && dateFns.isSameDay(focusContext.focusTarget, day));
1801
+ var buttonProps = __assign(__assign(__assign({}, divProps), (_a = { disabled: activeModifiers.disabled }, _a['aria-pressed'] = activeModifiers.selected, _a.tabIndex = isFocusTarget ? 0 : -1, _a)), eventHandlers);
1802
+ var dayRender = {
1803
+ isButton: isButton,
1804
+ isHidden: isHidden,
1805
+ activeModifiers: activeModifiers,
1806
+ selectedDays: selectedDays,
1807
+ buttonProps: buttonProps,
1808
+ divProps: divProps
1809
+ };
1810
+ return dayRender;
1811
+ }
1812
+
1813
+ /**
1814
+ * The content of a day cell – as a button or span element according to its
1815
+ * modifiers.
1816
+ */
1817
+ function Day(props) {
1818
+ var buttonRef = React.useRef(null);
1819
+ var dayRender = useDayRender(props.date, props.displayMonth, buttonRef);
1820
+ if (dayRender.isHidden) {
1821
+ return React__default["default"].createElement(React__default["default"].Fragment, null);
1822
+ }
1823
+ if (!dayRender.isButton) {
1824
+ return React__default["default"].createElement("div", __assign({}, dayRender.divProps));
1825
+ }
1826
+ return React__default["default"].createElement(Button, __assign({ ref: buttonRef }, dayRender.buttonProps));
1827
+ }
1828
+
1829
+ /**
1830
+ * Render the week number element. If `onWeekNumberClick` is passed to DayPicker, it
1831
+ * renders a button, otherwise a span element.
1832
+ */
1833
+ function WeekNumber(props) {
1834
+ var weekNumber = props.number, dates = props.dates;
1835
+ var _a = useDayPicker(), onWeekNumberClick = _a.onWeekNumberClick, styles = _a.styles, classNames = _a.classNames, locale = _a.locale, labelWeekNumber = _a.labels.labelWeekNumber, formatWeekNumber = _a.formatters.formatWeekNumber;
1836
+ var handleClick = function (e) {
1837
+ onWeekNumberClick === null || onWeekNumberClick === void 0 ? void 0 : onWeekNumberClick(weekNumber, dates, e);
1838
+ };
1839
+ var content = formatWeekNumber(Number(weekNumber), { locale: locale });
1840
+ if (!onWeekNumberClick) {
1841
+ return (React__default["default"].createElement("span", { className: classNames.weeknumber, style: styles.weeknumber }, content));
1842
+ }
1843
+ var label = labelWeekNumber(Number(weekNumber), { locale: locale });
1844
+ return (React__default["default"].createElement(Button, { "aria-label": label, className: classNames.weeknumber, style: styles.weeknumber, onClick: handleClick }, content));
1845
+ }
1846
+
1847
+ /** Render a row in the calendar, with the days and the week number. */
1848
+ function Row(props) {
1849
+ var _a, _b;
1850
+ var _c = useDayPicker(), styles = _c.styles, classNames = _c.classNames, showWeekNumber = _c.showWeekNumber, components = _c.components;
1851
+ var DayComponent = (_a = components === null || components === void 0 ? void 0 : components.Day) !== null && _a !== void 0 ? _a : Day;
1852
+ var WeeknumberComponent = (_b = components === null || components === void 0 ? void 0 : components.WeekNumber) !== null && _b !== void 0 ? _b : WeekNumber;
1853
+ var weekNumberCell;
1854
+ if (showWeekNumber) {
1855
+ weekNumberCell = (React__default["default"].createElement("td", { className: classNames.cell, style: styles.cell },
1856
+ React__default["default"].createElement(WeeknumberComponent, { number: props.weekNumber, dates: props.dates })));
1857
+ }
1858
+ return (React__default["default"].createElement("tr", { className: classNames.row, style: styles.row },
1859
+ weekNumberCell,
1860
+ props.dates.map(function (date) { return (React__default["default"].createElement("td", { className: classNames.cell, style: styles.cell, key: dateFns.getUnixTime(date) },
1861
+ React__default["default"].createElement(DayComponent, { displayMonth: props.displayMonth, date: date }))); })));
1862
+ }
1863
+
1864
+ function getOutsideEndDays(month, options) {
1865
+ var days = [];
1866
+ var lastDayOfWeek = dateFns.endOfWeek(month, options);
1867
+ var endDiff = dateFns.differenceInCalendarDays(lastDayOfWeek, month);
1868
+ for (var i = 1; i <= endDiff; i++) {
1869
+ var dayDate = dateFns.addDays(month, i);
1870
+ days.push(dayDate);
1871
+ }
1872
+ return days;
1873
+ }
1874
+
1875
+ function getOutsideStartDays(month, options) {
1876
+ var days = [];
1877
+ var firstDayOfWeek = dateFns.startOfWeek(month, options);
1878
+ var startDiff = dateFns.differenceInCalendarDays(month, firstDayOfWeek);
1879
+ for (var i = 0; i < startDiff; i++) {
1880
+ var newDay = dateFns.addDays(firstDayOfWeek, i);
1881
+ days.push(newDay);
1882
+ }
1883
+ return days;
1884
+ }
1885
+
1886
+ /**
1887
+ * Return the weeks belonging to the given month.
1888
+ */
1889
+ function getWeeks(month, _a) {
1890
+ var locale = _a.locale, fixedWeeks = _a.fixedWeeks;
1891
+ var monthStart = dateFns.startOfMonth(month);
1892
+ var monthEnd = dateFns.endOfMonth(month);
1893
+ var diff = dateFns.differenceInCalendarDays(monthEnd, monthStart);
1894
+ var weeks = [];
1895
+ var lastWeek = { weekNumber: 0, dates: [] };
1896
+ for (var i = 0; i <= diff; i++) {
1897
+ var date = dateFns.addDays(monthStart, i);
1898
+ var week = dateFns.getWeek(date, { locale: locale });
1899
+ if (lastWeek.weekNumber !== week) {
1900
+ // Create a new week by adding outside start days
1901
+ var startDays = getOutsideStartDays(date, { locale: locale });
1902
+ lastWeek = { weekNumber: week, dates: startDays };
1903
+ weeks.push(lastWeek);
1904
+ }
1905
+ lastWeek.dates.push(date);
1906
+ }
1907
+ var lastDay = lastWeek.dates[lastWeek.dates.length - 1];
1908
+ var endDays = getOutsideEndDays(lastDay, { locale: locale });
1909
+ lastWeek.dates = lastWeek.dates.concat(endDays);
1910
+ // Add extra weeks to the month, up to 6 weeks
1911
+ if (fixedWeeks) {
1912
+ var lastWeekDate = lastWeek.dates[lastWeek.dates.length - 1];
1913
+ var weeksInMonth = dateFns.getWeeksInMonth(month, { locale: locale });
1914
+ if (weeksInMonth < 6) {
1915
+ var diffDays = dateFns.differenceInCalendarDays(dateFns.addWeeks(lastWeekDate, 6 - weeksInMonth), lastWeekDate);
1916
+ for (var i = 0; i < diffDays; i++) {
1917
+ var date = dateFns.addDays(lastWeekDate, i + 1);
1918
+ var week = dateFns.getWeek(date, { locale: locale });
1919
+ if (lastWeek.weekNumber !== week) {
1920
+ lastWeek = { weekNumber: week, dates: [] };
1921
+ weeks.push(lastWeek);
1922
+ }
1923
+ lastWeek.dates.push(date);
1924
+ }
1925
+ }
1926
+ }
1927
+ return weeks;
1928
+ }
1929
+
1930
+ /** Render the table with the calendar. */
1931
+ function Table(props) {
1932
+ var _a, _b, _c;
1933
+ var _d = useDayPicker(), locale = _d.locale, classNames = _d.classNames, styles = _d.styles, hideHead = _d.hideHead, fixedWeeks = _d.fixedWeeks, components = _d.components;
1934
+ var weeks = getWeeks(props.displayMonth, { locale: locale, fixedWeeks: fixedWeeks });
1935
+ var HeadComponent = (_a = components === null || components === void 0 ? void 0 : components.Head) !== null && _a !== void 0 ? _a : Head;
1936
+ var RowComponent = (_b = components === null || components === void 0 ? void 0 : components.Row) !== null && _b !== void 0 ? _b : Row;
1937
+ var FooterComponent = (_c = components === null || components === void 0 ? void 0 : components.Footer) !== null && _c !== void 0 ? _c : Footer;
1938
+ return (React__default["default"].createElement("table", { className: classNames.table, style: styles.table, role: "grid", "aria-labelledby": props['aria-labelledby'] },
1939
+ !hideHead && React__default["default"].createElement(HeadComponent, null),
1940
+ React__default["default"].createElement("tbody", { className: classNames.tbody, style: styles.tbody }, weeks.map(function (week) { return (React__default["default"].createElement(RowComponent, { displayMonth: props.displayMonth, key: week.weekNumber, dates: week.dates, weekNumber: week.weekNumber })); })),
1941
+ React__default["default"].createElement(FooterComponent, null)));
1942
+ }
1943
+
1944
+ /** Render a month. */
1945
+ function Month(props) {
1946
+ var _a;
1947
+ var _b;
1948
+ var dayPicker = useDayPicker();
1949
+ var dir = dayPicker.dir, classNames = dayPicker.classNames, styles = dayPicker.styles, components = dayPicker.components;
1950
+ var displayMonths = useNavigation().displayMonths;
1951
+ var captionId = useId();
1952
+ var className = [classNames.month];
1953
+ var style = styles.month;
1954
+ var isStart = props.displayIndex === 0;
1955
+ var isEnd = props.displayIndex === displayMonths.length - 1;
1956
+ var isCenter = !isStart && !isEnd;
1957
+ if (dir === 'rtl') {
1958
+ _a = [isStart, isEnd], isEnd = _a[0], isStart = _a[1];
1959
+ }
1960
+ if (isStart) {
1961
+ className.push(classNames.caption_start);
1962
+ style = __assign(__assign({}, style), styles.caption_start);
1963
+ }
1964
+ if (isEnd) {
1965
+ className.push(classNames.caption_end);
1966
+ style = __assign(__assign({}, style), styles.caption_end);
1967
+ }
1968
+ if (isCenter) {
1969
+ className.push(classNames.caption_between);
1970
+ style = __assign(__assign({}, style), styles.caption_between);
1971
+ }
1972
+ var CaptionComponent = (_b = components === null || components === void 0 ? void 0 : components.Caption) !== null && _b !== void 0 ? _b : Caption;
1973
+ return (React__default["default"].createElement("div", { key: props.displayIndex, className: className.join(' '), style: style },
1974
+ React__default["default"].createElement(CaptionComponent, { id: captionId, displayMonth: props.displayMonth }),
1975
+ React__default["default"].createElement(Table, { "aria-labelledby": captionId, displayMonth: props.displayMonth })));
1976
+ }
1977
+
1978
+ /** Render the container with the months according to the number of months to display. */
1979
+ function Root() {
1980
+ var _a;
1981
+ var dayPicker = useDayPicker();
1982
+ var focusContext = useFocusContext();
1983
+ var navigation = useNavigation();
1984
+ var _b = React.useState(false), hasInitialFocus = _b[0], setHasInitialFocus = _b[1];
1985
+ // Focus the focus target when initialFocus is passed in
1986
+ React.useEffect(function () {
1987
+ if (!dayPicker.initialFocus)
1988
+ return;
1989
+ if (!focusContext.focusTarget)
1990
+ return;
1991
+ if (hasInitialFocus)
1992
+ return;
1993
+ focusContext.focus(focusContext.focusTarget);
1994
+ setHasInitialFocus(true);
1995
+ }, [
1996
+ dayPicker.initialFocus,
1997
+ hasInitialFocus,
1998
+ focusContext.focus,
1999
+ focusContext.focusTarget,
2000
+ focusContext
2001
+ ]);
2002
+ // Apply classnames according to props
2003
+ var classNames = [(_a = dayPicker.className) !== null && _a !== void 0 ? _a : dayPicker.classNames.root];
2004
+ if (dayPicker.numberOfMonths > 1) {
2005
+ classNames.push(dayPicker.classNames.multiple_months);
2006
+ }
2007
+ if (dayPicker.showWeekNumber) {
2008
+ classNames.push(dayPicker.classNames.with_weeknumber);
2009
+ }
2010
+ var style = __assign(__assign({}, dayPicker.styles.root), dayPicker.style);
2011
+ return (React__default["default"].createElement("div", { className: classNames.join(' '), style: style, dir: dayPicker.dir },
2012
+ React__default["default"].createElement("div", { className: dayPicker.classNames.months, style: dayPicker.styles.months }, navigation.displayMonths.map(function (month, i) { return (React__default["default"].createElement(Month, { key: i, displayIndex: i, displayMonth: month })); }))));
2013
+ }
2014
+
2015
+ /** Provide the value for all the context providers. */
2016
+ function RootProvider(props) {
2017
+ var children = props.children, initialProps = __rest(props, ["children"]);
2018
+ return (React__default["default"].createElement(DayPickerProvider, { initialProps: initialProps },
2019
+ React__default["default"].createElement(NavigationProvider, null,
2020
+ React__default["default"].createElement(SelectSingleProvider, { initialProps: initialProps },
2021
+ React__default["default"].createElement(SelectMultipleProvider, { initialProps: initialProps },
2022
+ React__default["default"].createElement(SelectRangeProvider, { initialProps: initialProps },
2023
+ React__default["default"].createElement(ModifiersProvider, null,
2024
+ React__default["default"].createElement(FocusProvider, null, children))))))));
2025
+ }
2026
+
2027
+ /**
2028
+ * DayPicker render a date picker component to let users pick dates from a
2029
+ * calendar. See http://react-day-picker.js.org for updated documentation and
2030
+ * examples.
2031
+ *
2032
+ * ### Customization
2033
+ *
2034
+ * DayPicker offers different customization props. For example,
2035
+ *
2036
+ * - show multiple months using `numberOfMonths`
2037
+ * - display a dropdown to navigate the months via `captionLayout`
2038
+ * - display the week numbers with `showWeekNumbers`
2039
+ * - disable or hide days with `disabled` or `hidden`
2040
+ *
2041
+ * ### Controlling the months
2042
+ *
2043
+ * Change the initially displayed month using the `defaultMonth` prop. The
2044
+ * displayed months are controlled by DayPicker and stored in its internal
2045
+ * state. To control the months yourself, use `month` instead of `defaultMonth`
2046
+ * and use the `onMonthChange` event to set it.
2047
+ *
2048
+ * To limit the months the user can navigate to, use
2049
+ * `fromDate`/`fromMonth`/`fromYear` or `toDate`/`toMonth`/`toYear`.
2050
+ *
2051
+ * ### Selection modes
2052
+ *
2053
+ * DayPicker supports different selection mode that can be toggled using the
2054
+ * `mode` prop:
2055
+ *
2056
+ * - `mode="single"`: only one day can be selected. Use `required` to make the
2057
+ * selection required. Use the `onSelect` event handler to get the selected
2058
+ * days.
2059
+ * - `mode="multiple"`: users can select one or more days. Limit the amount of
2060
+ * days that can be selected with the `min` or the `max` props.
2061
+ * - `mode="range"`: users can select a range of days. Limit the amount of days
2062
+ * in the range with the `min` or the `max` props.
2063
+ * - `mode="custom"`: implement your own selection mode with `onDayClick`.
2064
+ *
2065
+ * These selection modes should cover the most common use cases. In case you
2066
+ * need a more refined way of selecting days, use `mode="custom"`. Use the
2067
+ * `selected` props and add the day event handlers to add/remove days from the
2068
+ * selection.
2069
+ *
2070
+ * ### Modifiers
2071
+ *
2072
+ * A _modifier_ represents different styles or states for the days displayed in
2073
+ * the calendar (like "selected" or "disabled"). Define custom modifiers using
2074
+ * the `modifiers` prop.
2075
+ *
2076
+ * ### Formatters and custom component
2077
+ *
2078
+ * You can customize how the content is displayed in the date picker by using
2079
+ * either the formatters or replacing the internal components.
2080
+ *
2081
+ * For the most common cases you want to use the `formatters` prop to change how
2082
+ * the content is formatted in the calendar. Use the `components` prop to
2083
+ * replace the internal components, like the navigation icons.
2084
+ *
2085
+ * ### Styling
2086
+ *
2087
+ * DayPicker comes with a default, basic style in `react-day-picker/style` – use
2088
+ * it as template for your own style.
2089
+ *
2090
+ * If you are using CSS modules, pass the imported styles object the
2091
+ * `classNames` props.
2092
+ *
2093
+ * You can also style the elements via inline-styles using the `styles` prop.
2094
+ *
2095
+ * ### Form fields
2096
+ *
2097
+ * If you need to bind the date picker to a form field, you can use the
2098
+ * `useInput` hooks for a basic behavior. See the `useInput` source as an
2099
+ * example to bind the date picker with form fields.
2100
+ *
2101
+ * ### Localization
2102
+ *
2103
+ * To localize DayPicker, import the locale from `date-fns` package and use the
2104
+ * `locale` prop.
2105
+ *
2106
+ * For example, to use Spanish locale:
2107
+ *
2108
+ * ```
2109
+ * import es from 'date-fns/locale/es';
2110
+ * <DayPicker locale={es} />
2111
+ * ```
2112
+ */
2113
+ function DayPicker(props) {
2114
+ return (React__default["default"].createElement(RootProvider, __assign({}, props),
2115
+ React__default["default"].createElement(Root, null)));
2116
+ }
2117
+
2118
+ /** @private */
2119
+ function isValidDate(day) {
2120
+ return !isNaN(day.getTime());
2121
+ }
2122
+
2123
+ /** Return props and setters for binding an input field to DayPicker. */
2124
+ function useInput(options) {
2125
+ if (options === void 0) { options = {}; }
2126
+ var _a = options.locale, locale = _a === void 0 ? enUS__default["default"] : _a, required = options.required, _b = options.format, format = _b === void 0 ? 'PP' : _b, defaultSelected = options.defaultSelected, _c = options.today, today = _c === void 0 ? new Date() : _c;
2127
+ var _d = parseFromToProps(options), fromDate = _d.fromDate, toDate = _d.toDate;
2128
+ // Shortcut to the DateFns functions
2129
+ var parseValue = function (value) { return dateFns.parse(value, format, today, { locale: locale }); };
2130
+ // Initialize states
2131
+ var _e = React.useState(defaultSelected !== null && defaultSelected !== void 0 ? defaultSelected : today), month = _e[0], setMonth = _e[1];
2132
+ var _f = React.useState(defaultSelected), selectedDay = _f[0], setSelectedDay = _f[1];
2133
+ var defaultInputValue = defaultSelected
2134
+ ? dateFns.format(defaultSelected, format, { locale: locale })
2135
+ : '';
2136
+ var _g = React.useState(defaultInputValue), inputValue = _g[0], setInputValue = _g[1];
2137
+ var reset = function () {
2138
+ setSelectedDay(defaultSelected);
2139
+ setMonth(defaultSelected !== null && defaultSelected !== void 0 ? defaultSelected : today);
2140
+ setInputValue(defaultInputValue !== null && defaultInputValue !== void 0 ? defaultInputValue : '');
2141
+ };
2142
+ var setSelected = function (date) {
2143
+ setSelectedDay(date);
2144
+ setMonth(date !== null && date !== void 0 ? date : today);
2145
+ setInputValue(date ? dateFns.format(date, format, { locale: locale }) : '');
2146
+ };
2147
+ var handleDayClick = function (day, _a) {
2148
+ var selected = _a.selected;
2149
+ if (!required && selected) {
2150
+ setSelectedDay(undefined);
2151
+ setInputValue('');
2152
+ return;
2153
+ }
2154
+ setSelectedDay(day);
2155
+ setInputValue(day ? dateFns.format(day, format, { locale: locale }) : '');
2156
+ };
2157
+ var handleMonthChange = function (month) {
2158
+ setMonth(month);
2159
+ };
2160
+ // When changing the input field, save its value in state and check if the
2161
+ // string is a valid date. If it is a valid day, set it as selected and update
2162
+ // the calendar’s month.
2163
+ var handleChange = function (e) {
2164
+ setInputValue(e.target.value);
2165
+ var day = parseValue(e.target.value);
2166
+ var isBefore = fromDate && dateFns.differenceInCalendarDays(fromDate, day) > 0;
2167
+ var isAfter = toDate && dateFns.differenceInCalendarDays(day, toDate) > 0;
2168
+ if (!isValidDate(day) || isBefore || isAfter) {
2169
+ setSelectedDay(undefined);
2170
+ return;
2171
+ }
2172
+ setSelectedDay(day);
2173
+ setMonth(day);
2174
+ };
2175
+ // Special case for _required_ fields: on blur, if the value of the input is not
2176
+ // a valid date, reset the calendar and the input value.
2177
+ var handleBlur = function (e) {
2178
+ var day = parseValue(e.target.value);
2179
+ if (!isValidDate(day)) {
2180
+ reset();
2181
+ }
2182
+ };
2183
+ // When focusing, make sure DayPicker visualizes the month of the date in the
2184
+ // input field.
2185
+ var handleFocus = function (e) {
2186
+ if (!e.target.value) {
2187
+ reset();
2188
+ return;
2189
+ }
2190
+ var day = parseValue(e.target.value);
2191
+ if (isValidDate(day)) {
2192
+ setMonth(day);
2193
+ }
2194
+ };
2195
+ var dayPickerProps = {
2196
+ mode: 'custom',
2197
+ month: month,
2198
+ onDayClick: handleDayClick,
2199
+ onMonthChange: handleMonthChange,
2200
+ selected: selectedDay,
2201
+ locale: locale,
2202
+ fromDate: options === null || options === void 0 ? void 0 : options.fromDate,
2203
+ toDate: options === null || options === void 0 ? void 0 : options.toDate,
2204
+ today: today
2205
+ };
2206
+ var inputProps = {
2207
+ onBlur: handleBlur,
2208
+ onChange: handleChange,
2209
+ onFocus: handleFocus,
2210
+ value: inputValue,
2211
+ placeholder: dateFns.format(new Date(), format, { locale: locale })
2212
+ };
2213
+ return { dayPickerProps: dayPickerProps, inputProps: inputProps, reset: reset, setSelected: setSelected };
2214
+ }
2215
+
2216
+ /** Returns true when the props are of type [[DayPickerCustom]]. */
2217
+ function isDayPickerCustom(props) {
2218
+ return props.mode === 'custom';
1844
2219
  }
1845
2220
 
1846
2221
  exports.Button = Button;
@@ -1849,6 +2224,8 @@ exports.CaptionLabel = CaptionLabel;
1849
2224
  exports.Day = Day;
1850
2225
  exports.DayContent = DayContent;
1851
2226
  exports.DayPicker = DayPicker;
2227
+ exports.DayPickerContext = DayPickerContext;
2228
+ exports.DayPickerProvider = DayPickerProvider;
1852
2229
  exports.Dropdown = Dropdown;
1853
2230
  exports.FocusContext = FocusContext;
1854
2231
  exports.FocusProvider = FocusProvider;
@@ -1857,11 +2234,8 @@ exports.Head = Head;
1857
2234
  exports.IconDropdown = IconDropdown;
1858
2235
  exports.IconLeft = IconLeft;
1859
2236
  exports.IconRight = IconRight;
1860
- exports.MonthsDropdown = MonthsDropdown;
1861
- exports.Navigation = Navigation;
1862
2237
  exports.NavigationContext = NavigationContext;
1863
2238
  exports.NavigationProvider = NavigationProvider;
1864
- exports.Root = Root;
1865
2239
  exports.RootProvider = RootProvider;
1866
2240
  exports.Row = Row;
1867
2241
  exports.SelectMultipleContext = SelectMultipleContext;
@@ -1873,9 +2247,7 @@ exports.SelectRangeProviderInternal = SelectRangeProviderInternal;
1873
2247
  exports.SelectSingleContext = SelectSingleContext;
1874
2248
  exports.SelectSingleProvider = SelectSingleProvider;
1875
2249
  exports.SelectSingleProviderInternal = SelectSingleProviderInternal;
1876
- exports.Table = Table;
1877
2250
  exports.WeekNumber = WeekNumber;
1878
- exports.YearsDropdown = YearsDropdown;
1879
2251
  exports.isDateAfterType = isDateAfterType;
1880
2252
  exports.isDateBeforeType = isDateBeforeType;
1881
2253
  exports.isDateInterval = isDateInterval;
@@ -1885,13 +2257,13 @@ exports.isDayPickerCustom = isDayPickerCustom;
1885
2257
  exports.isDayPickerMultiple = isDayPickerMultiple;
1886
2258
  exports.isDayPickerRange = isDayPickerRange;
1887
2259
  exports.isDayPickerSingle = isDayPickerSingle;
1888
- exports.useDay = useDay;
2260
+ exports.useActiveModifiers = useActiveModifiers;
1889
2261
  exports.useDayPicker = useDayPicker;
1890
- exports.useFocus = useFocus;
2262
+ exports.useDayRender = useDayRender;
2263
+ exports.useFocusContext = useFocusContext;
1891
2264
  exports.useInput = useInput;
1892
- exports.useModifiers = useModifiers;
1893
2265
  exports.useNavigation = useNavigation;
1894
2266
  exports.useSelectMultiple = useSelectMultiple;
1895
2267
  exports.useSelectRange = useSelectRange;
1896
2268
  exports.useSelectSingle = useSelectSingle;
1897
- //# sourceMappingURL=main.js.map
2269
+ //# sourceMappingURL=index.js.map