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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (241) hide show
  1. package/CHANGELOG.md +12 -3
  2. package/build/DayPicker.d.ts +3 -2
  3. package/build/DayPicker.js +6 -5
  4. package/build/DayPicker.js.map +1 -1
  5. package/build/components/Button/Button.d.ts +1 -1
  6. package/build/components/Button/Button.js +1 -1
  7. package/build/components/Button/Button.js.map +1 -1
  8. package/build/components/Caption/Caption.d.ts +7 -0
  9. package/build/components/Caption/Caption.js +8 -8
  10. package/build/components/Caption/Caption.js.map +1 -1
  11. package/build/components/CaptionLabel/CaptionLabel.js +1 -1
  12. package/build/components/CaptionLabel/CaptionLabel.js.map +1 -1
  13. package/build/components/Day/Day.js +1 -1
  14. package/build/components/Day/Day.js.map +1 -1
  15. package/build/components/Day/hooks/useDay.d.ts +2 -2
  16. package/build/components/Day/hooks/useDay.js +5 -5
  17. package/build/components/Day/hooks/useDay.js.map +1 -1
  18. package/build/components/Day/hooks/useDayFocus.d.ts +1 -1
  19. package/build/components/Day/hooks/useDayFocus.js +1 -1
  20. package/build/components/Day/hooks/useDayFocus.js.map +1 -1
  21. package/build/components/DayContent/DayContent.js +1 -1
  22. package/build/components/DayContent/DayContent.js.map +1 -1
  23. package/build/components/Dropdown/Dropdown.d.ts +1 -1
  24. package/build/components/Dropdown/Dropdown.js +1 -1
  25. package/build/components/Dropdown/Dropdown.js.map +1 -1
  26. package/build/components/Footer/Footer.js +1 -1
  27. package/build/components/Footer/Footer.js.map +1 -1
  28. package/build/components/Head/Head.js +1 -1
  29. package/build/components/Head/Head.js.map +1 -1
  30. package/build/components/IconDropdown/IconDropdown.d.ts +2 -2
  31. package/build/components/IconDropdown/IconDropdown.js +1 -1
  32. package/build/components/IconDropdown/IconDropdown.js.map +1 -1
  33. package/build/components/IconLeft/IconLeft.d.ts +2 -2
  34. package/build/components/IconLeft/IconLeft.js +3 -3
  35. package/build/components/IconLeft/IconLeft.js.map +1 -1
  36. package/build/components/IconRight/IconRight.d.ts +2 -2
  37. package/build/components/IconRight/IconRight.js +3 -3
  38. package/build/components/IconRight/IconRight.js.map +1 -1
  39. package/build/components/MonthsDropdown/MonthsDropdown.d.ts +1 -1
  40. package/build/components/MonthsDropdown/MonthsDropdown.js +1 -1
  41. package/build/components/MonthsDropdown/MonthsDropdown.js.map +1 -1
  42. package/build/components/Navigation/Navigation.d.ts +1 -1
  43. package/build/components/Navigation/Navigation.js +1 -1
  44. package/build/components/Navigation/Navigation.js.map +1 -1
  45. package/build/components/Root/Root.js +1 -2
  46. package/build/components/Root/Root.js.map +1 -1
  47. package/build/components/Row/Row.js +1 -1
  48. package/build/components/Row/Row.js.map +1 -1
  49. package/build/components/Table/Table.js +1 -1
  50. package/build/components/Table/Table.js.map +1 -1
  51. package/build/components/WeekNumber/WeekNumber.js +1 -1
  52. package/build/components/WeekNumber/WeekNumber.js.map +1 -1
  53. package/build/components/YearsDropdown/YearsDropdown.d.ts +1 -1
  54. package/build/components/YearsDropdown/YearsDropdown.js +1 -1
  55. package/build/components/YearsDropdown/YearsDropdown.js.map +1 -1
  56. package/build/contexts/DayPicker/DayPickerContext.d.ts +3 -2
  57. package/build/contexts/DayPicker/DayPickerContext.js +1 -1
  58. package/build/contexts/DayPicker/DayPickerContext.js.map +1 -1
  59. package/build/contexts/DayPicker/DayPickerProvider.d.ts +1 -1
  60. package/build/contexts/DayPicker/DayPickerProvider.js +1 -1
  61. package/build/contexts/DayPicker/DayPickerProvider.js.map +1 -1
  62. package/build/contexts/DayPicker/defaultClassNames.js +1 -3
  63. package/build/contexts/DayPicker/defaultClassNames.js.map +1 -1
  64. package/build/contexts/DayPicker/labels/labelDay.d.ts +2 -2
  65. package/build/contexts/DayPicker/labels/labelDay.js +1 -1
  66. package/build/contexts/DayPicker/labels/labelDay.js.map +1 -1
  67. package/build/contexts/DayPicker/labels/labelNext.d.ts +2 -2
  68. package/build/contexts/DayPicker/labels/labelNext.js.map +1 -1
  69. package/build/contexts/DayPicker/labels/labelPrevious.d.ts +2 -2
  70. package/build/contexts/DayPicker/labels/labelPrevious.js.map +1 -1
  71. package/build/contexts/DayPicker/labels/labelWeekNumber.d.ts +2 -2
  72. package/build/contexts/DayPicker/labels/labelWeekNumber.js.map +1 -1
  73. package/build/contexts/DayPicker/labels/labelWeekday.d.ts +2 -2
  74. package/build/contexts/DayPicker/labels/labelWeekday.js.map +1 -1
  75. package/build/contexts/DayPicker/useDayPicker.js +1 -1
  76. package/build/contexts/DayPicker/useDayPicker.js.map +1 -1
  77. package/build/contexts/DayPicker/utils/parseModifierProps.js +1 -0
  78. package/build/contexts/DayPicker/utils/parseModifierProps.js.map +1 -1
  79. package/build/contexts/Focus/FocusContext.d.ts +5 -1
  80. package/build/contexts/Focus/FocusContext.js +63 -3
  81. package/build/contexts/Focus/FocusContext.js.map +1 -1
  82. package/build/contexts/Focus/index.d.ts +0 -1
  83. package/build/contexts/Focus/useFocus.js +1 -1
  84. package/build/contexts/Focus/useFocus.js.map +1 -1
  85. package/build/contexts/Navigation/NavigationContext.d.ts +5 -1
  86. package/build/contexts/Navigation/NavigationContext.js +23 -3
  87. package/build/contexts/Navigation/NavigationContext.js.map +1 -1
  88. package/build/contexts/Navigation/index.d.ts +0 -1
  89. package/build/contexts/Navigation/useNavigation.js +1 -1
  90. package/build/contexts/Navigation/useNavigation.js.map +1 -1
  91. package/build/contexts/RootProvider.d.ts +8 -0
  92. package/build/contexts/{ContextProvider.js → RootProvider.js} +9 -14
  93. package/build/contexts/RootProvider.js.map +1 -0
  94. package/build/contexts/SelectMultiple/SelectMultipleContext.d.ts +14 -2
  95. package/build/contexts/SelectMultiple/SelectMultipleContext.js +73 -3
  96. package/build/contexts/SelectMultiple/SelectMultipleContext.js.map +1 -1
  97. package/build/contexts/SelectMultiple/index.d.ts +0 -1
  98. package/build/contexts/SelectMultiple/useSelectMultiple.js +1 -1
  99. package/build/contexts/SelectMultiple/useSelectMultiple.js.map +1 -1
  100. package/build/contexts/SelectRange/SelectRangeContext.d.ts +14 -3
  101. package/build/contexts/SelectRange/SelectRangeContext.js +114 -3
  102. package/build/contexts/SelectRange/SelectRangeContext.js.map +1 -1
  103. package/build/contexts/SelectRange/index.d.ts +0 -1
  104. package/build/contexts/SelectRange/useSelectRange.js +1 -1
  105. package/build/contexts/SelectRange/useSelectRange.js.map +1 -1
  106. package/build/contexts/SelectSingle/SelectSingleContext.d.ts +17 -3
  107. package/build/contexts/SelectSingle/SelectSingleContext.js +36 -3
  108. package/build/contexts/SelectSingle/SelectSingleContext.js.map +1 -1
  109. package/build/contexts/SelectSingle/index.d.ts +0 -1
  110. package/build/contexts/SelectSingle/useSelectSingle.js +1 -1
  111. package/build/contexts/SelectSingle/useSelectSingle.js.map +1 -1
  112. package/build/contexts/index.d.ts +1 -1
  113. package/build/hooks/useControlledValue/useControlledValue.js +2 -2
  114. package/build/hooks/useControlledValue/useControlledValue.js.map +1 -1
  115. package/build/hooks/useInput/useInput.d.ts +11 -32
  116. package/build/hooks/useInput/useInput.js +2 -4
  117. package/build/hooks/useInput/useInput.js.map +1 -1
  118. package/build/hooks/useModifiers/useModifiers.js +3 -5
  119. package/build/hooks/useModifiers/useModifiers.js.map +1 -1
  120. package/build/hooks/useModifiers/utils/isDateInRange.d.ts +1 -1
  121. package/build/hooks/useModifiers/utils/isDateInRange.js.map +1 -1
  122. package/build/hooks/useModifiers/utils/isMatch.d.ts +1 -1
  123. package/build/hooks/useModifiers/utils/isMatch.js +10 -8
  124. package/build/hooks/useModifiers/utils/isMatch.js.map +1 -1
  125. package/build/main.js +11 -22
  126. package/build/main.js.map +1 -1
  127. package/build/types/{DayPickerProps.d.ts → DayPicker.d.ts} +35 -16
  128. package/build/types/DayPickerCustom.d.ts +11 -0
  129. package/build/types/{isDayPickerCustom.js → DayPickerCustom.js} +1 -1
  130. package/build/types/DayPickerCustom.js.map +1 -0
  131. package/build/types/{DayPickerMultipleProps.d.ts → DayPickerMultiple.d.ts} +5 -5
  132. package/build/types/{isDayPickerMultiple.js → DayPickerMultiple.js} +1 -1
  133. package/build/types/DayPickerMultiple.js.map +1 -0
  134. package/build/types/{DayPickerRangeProps.d.ts → DayPickerRange.d.ts} +6 -6
  135. package/build/types/{isDayPickerRange.js → DayPickerRange.js} +1 -1
  136. package/build/types/DayPickerRange.js.map +1 -0
  137. package/build/types/DayPickerSingle.d.ts +14 -0
  138. package/build/types/{isDayPickerSingle.js → DayPickerSingle.js} +1 -1
  139. package/build/types/DayPickerSingle.js.map +1 -0
  140. package/build/types/EventHandlers.d.ts +51 -0
  141. package/build/types/Formatters.d.ts +10 -5
  142. package/build/types/Labels.d.ts +24 -12
  143. package/build/types/Matchers.d.ts +34 -0
  144. package/build/types/Matchers.js +27 -0
  145. package/build/types/Matchers.js.map +1 -0
  146. package/build/types/Modifiers.d.ts +15 -4
  147. package/build/types/Styles.d.ts +83 -2
  148. package/build/types/index.d.ts +7 -50
  149. package/dist/main.js +555 -589
  150. package/dist/main.js.map +1 -1
  151. package/package.json +3 -2
  152. package/build/contexts/ContextProvider.d.ts +0 -8
  153. package/build/contexts/ContextProvider.js.map +0 -1
  154. package/build/contexts/Focus/FocusProvider.d.ts +0 -5
  155. package/build/contexts/Focus/FocusProvider.js +0 -66
  156. package/build/contexts/Focus/FocusProvider.js.map +0 -1
  157. package/build/contexts/Navigation/NavigationProvider.d.ts +0 -5
  158. package/build/contexts/Navigation/NavigationProvider.js +0 -26
  159. package/build/contexts/Navigation/NavigationProvider.js.map +0 -1
  160. package/build/contexts/SelectMultiple/SelectMultipleProvider.d.ts +0 -9
  161. package/build/contexts/SelectMultiple/SelectMultipleProvider.js +0 -23
  162. package/build/contexts/SelectMultiple/SelectMultipleProvider.js.map +0 -1
  163. package/build/contexts/SelectMultiple/SelectMultipleProviderInternal.d.ts +0 -8
  164. package/build/contexts/SelectMultiple/SelectMultipleProviderInternal.js +0 -61
  165. package/build/contexts/SelectMultiple/SelectMultipleProviderInternal.js.map +0 -1
  166. package/build/contexts/SelectRange/SelectRangeProvider.d.ts +0 -9
  167. package/build/contexts/SelectRange/SelectRangeProvider.js +0 -26
  168. package/build/contexts/SelectRange/SelectRangeProvider.js.map +0 -1
  169. package/build/contexts/SelectRange/SelectRangeProviderInternal.d.ts +0 -8
  170. package/build/contexts/SelectRange/SelectRangeProviderInternal.js +0 -99
  171. package/build/contexts/SelectRange/SelectRangeProviderInternal.js.map +0 -1
  172. package/build/contexts/SelectSingle/SelectSingleProvider.d.ts +0 -9
  173. package/build/contexts/SelectSingle/SelectSingleProvider.js +0 -20
  174. package/build/contexts/SelectSingle/SelectSingleProvider.js.map +0 -1
  175. package/build/contexts/SelectSingle/SelectSingleProviderInternal.d.ts +0 -8
  176. package/build/contexts/SelectSingle/SelectSingleProviderInternal.js +0 -27
  177. package/build/contexts/SelectSingle/SelectSingleProviderInternal.js.map +0 -1
  178. package/build/types/CaptionLayout.d.ts +0 -7
  179. package/build/types/ClassNames.d.ts +0 -3
  180. package/build/types/Components.d.ts +0 -39
  181. package/build/types/CustomModifiers.d.ts +0 -4
  182. package/build/types/DateAfter.d.ts +0 -7
  183. package/build/types/DateBefore.d.ts +0 -7
  184. package/build/types/DateFormatter.d.ts +0 -6
  185. package/build/types/DateInterval.d.ts +0 -8
  186. package/build/types/DateRange.d.ts +0 -8
  187. package/build/types/DayClickEventHandler.d.ts +0 -6
  188. package/build/types/DayFocusEventHandler.d.ts +0 -6
  189. package/build/types/DayKeyboardEventHandler.d.ts +0 -6
  190. package/build/types/DayLabelFormatter.d.ts +0 -7
  191. package/build/types/DayMouseEventHandler.d.ts +0 -6
  192. package/build/types/DayOfWeekMatcher.d.ts +0 -7
  193. package/build/types/DayPickerCustomProps.d.ts +0 -11
  194. package/build/types/DayPickerSingleProps.d.ts +0 -14
  195. package/build/types/DayTouchEventHandler.d.ts +0 -6
  196. package/build/types/InternalModifier.d.ts +0 -2
  197. package/build/types/Matcher.d.ts +0 -10
  198. package/build/types/Modifier.d.ts +0 -5
  199. package/build/types/ModifierClassNames.d.ts +0 -5
  200. package/build/types/ModifierStatus.d.ts +0 -5
  201. package/build/types/ModifierStyles.d.ts +0 -4
  202. package/build/types/MonthChangeEventHandler.d.ts +0 -4
  203. package/build/types/NavButtonLabelFormatter.d.ts +0 -7
  204. package/build/types/SelectMultipleEventHandler.d.ts +0 -12
  205. package/build/types/SelectRangeEventHandler.d.ts +0 -10
  206. package/build/types/SelectSingleEventHandler.d.ts +0 -12
  207. package/build/types/StyledComponentProps.d.ts +0 -10
  208. package/build/types/StyledElement.d.ts +0 -76
  209. package/build/types/WeekNumberClickEventHandler.d.ts +0 -9
  210. package/build/types/WeekNumberFormatter.d.ts +0 -6
  211. package/build/types/WeekNumberLabelFormatter.d.ts +0 -5
  212. package/build/types/WeekdayLabelFormatter.d.ts +0 -4
  213. package/build/types/isArrayOfDates.d.ts +0 -2
  214. package/build/types/isArrayOfDates.js +0 -9
  215. package/build/types/isArrayOfDates.js.map +0 -1
  216. package/build/types/isDateAfterType.d.ts +0 -3
  217. package/build/types/isDateAfterType.js +0 -7
  218. package/build/types/isDateAfterType.js.map +0 -1
  219. package/build/types/isDateBeforeType.d.ts +0 -3
  220. package/build/types/isDateBeforeType.js +0 -7
  221. package/build/types/isDateBeforeType.js.map +0 -1
  222. package/build/types/isDateInterval.d.ts +0 -3
  223. package/build/types/isDateInterval.js +0 -10
  224. package/build/types/isDateInterval.js.map +0 -1
  225. package/build/types/isDateRange.d.ts +0 -3
  226. package/build/types/isDateRange.js +0 -8
  227. package/build/types/isDateRange.js.map +0 -1
  228. package/build/types/isDateType.d.ts +0 -2
  229. package/build/types/isDateType.js +0 -9
  230. package/build/types/isDateType.js.map +0 -1
  231. package/build/types/isDayOfWeekType.d.ts +0 -3
  232. package/build/types/isDayOfWeekType.js +0 -7
  233. package/build/types/isDayOfWeekType.js.map +0 -1
  234. package/build/types/isDayPickerCustom.d.ts +0 -4
  235. package/build/types/isDayPickerCustom.js.map +0 -1
  236. package/build/types/isDayPickerMultiple.d.ts +0 -4
  237. package/build/types/isDayPickerMultiple.js.map +0 -1
  238. package/build/types/isDayPickerRange.d.ts +0 -4
  239. package/build/types/isDayPickerRange.js.map +0 -1
  240. package/build/types/isDayPickerSingle.d.ts +0 -4
  241. package/build/types/isDayPickerSingle.js.map +0 -1
@@ -1,31 +1,10 @@
1
- import * as React from 'react';
2
- import { DayClickEventHandler, DayPickerProps, MonthChangeEventHandler } from '../../types';
3
- /** Represent the props to attach to the input field. */
4
- export interface UseInputFieldProps {
5
- /** Event handler for the blur event. */
6
- onBlur: React.FocusEventHandler;
7
- /** Event handler for the change event. */
8
- onChange: React.ChangeEventHandler<HTMLInputElement>;
9
- /** Event handler for the focus event. */
10
- onFocus: React.FocusEventHandler;
11
- /** The value of the input field */
12
- value: string;
13
- /** The input field placeholder */
14
- placeholder?: string;
15
- }
16
- /** Represent the props to attach to DayPicker component. */
17
- export interface UseInputDayPickerProps {
18
- mode: 'custom';
19
- fromDate?: Date;
20
- locale: Locale;
21
- min: number;
22
- month: Date;
23
- onDayClick: DayClickEventHandler;
24
- onMonthChange: MonthChangeEventHandler;
25
- selected: Date | undefined;
26
- toDate?: Date;
27
- today: Date;
28
- }
1
+ import React from 'react';
2
+ import { DayPickerProps } from '../../types/DayPicker';
3
+ import { DayPickerCustomProps } from '../../types';
4
+ /** The props to attach to the input field when using [[useInput]]. */
5
+ export declare type InputHTMLAttributes = Pick<React.InputHTMLAttributes<HTMLInputElement>, 'onBlur' | 'onChange' | 'onFocus' | 'value' | 'placeholder'>;
6
+ /** The props to attach to the DayPicker component when using [[useInput]]. */
7
+ export declare type InputDayPickerProps = Pick<DayPickerCustomProps, 'mode' | 'fromDate' | 'toDate' | 'locale' | 'month' | 'onDayClick' | 'onMonthChange' | 'selected' | 'today'>;
29
8
  export interface UseInputOptions extends Pick<DayPickerProps, 'locale' | 'fromDate' | 'toDate' | 'fromMonth' | 'toMonth' | 'fromYear' | 'toYear' | 'today'> {
30
9
  /** The initially selected date */
31
10
  defaultSelected?: Date;
@@ -36,10 +15,10 @@ export interface UseInputOptions extends Pick<DayPickerProps, 'locale' | 'fromDa
36
15
  }
37
16
  /** Represent the value returned by [[useInput]]. */
38
17
  export interface UseInput {
39
- /** The props to pass to a DayPicker component: `<DayPicker {...dayPickerProps} />` */
40
- dayPickerProps: UseInputDayPickerProps;
41
- /** The props to pass to an input field: `<input {...inputProps} />` */
42
- inputProps: UseInputFieldProps;
18
+ /** The props to pass to a DayPicker component. */
19
+ dayPickerProps: InputDayPickerProps;
20
+ /** The props to pass to an input field. */
21
+ inputProps: InputHTMLAttributes;
43
22
  /** A function to reset to the initial state. */
44
23
  reset: () => void;
45
24
  /** A function to set the selected day. */
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
1
+ import React from 'react';
2
2
  import { format, parse, differenceInCalendarDays } from 'date-fns';
3
3
  import enUS from 'date-fns/locale/en-US';
4
4
  import { parseFromToProps } from '../../contexts/DayPicker/utils/parseFromToProps.js';
@@ -9,7 +9,6 @@ function useInput(options) {
9
9
  if (options === void 0) { options = {}; }
10
10
  var _a = options.locale, locale = _a === void 0 ? enUS : _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;
11
11
  var _d = parseFromToProps(options), fromDate = _d.fromDate, toDate = _d.toDate;
12
- var min = required ? 1 : 0;
13
12
  // Shortcut to the DateFns functions
14
13
  var parseValue = function (value) { return parse(value, format$1, today, { locale: locale }); };
15
14
  // Initialize states
@@ -86,8 +85,7 @@ function useInput(options) {
86
85
  locale: locale,
87
86
  fromDate: options === null || options === void 0 ? void 0 : options.fromDate,
88
87
  toDate: options === null || options === void 0 ? void 0 : options.toDate,
89
- today: today,
90
- min: min
88
+ today: today
91
89
  };
92
90
  var inputProps = {
93
91
  onBlur: handleBlur,
@@ -1 +1 @@
1
- {"version":3,"file":"useInput.js","sources":["../../../src/hooks/useInput/useInput.ts"],"sourcesContent":["import * as React from 'react';\n\nimport { differenceInCalendarDays, format as _format, parse } from 'date-fns';\nimport enUS from 'date-fns/locale/en-US';\n\nimport { parseFromToProps } from '../../contexts/DayPicker/utils';\nimport {\n DayClickEventHandler,\n DayPickerProps,\n MonthChangeEventHandler\n} from '../../types';\nimport { isValidDate } from './utils/isValidDate';\n\n/** Represent the props to attach to the input field. */\nexport interface UseInputFieldProps {\n /** Event handler for the blur event. */\n onBlur: React.FocusEventHandler;\n /** Event handler for the change event. */\n onChange: React.ChangeEventHandler<HTMLInputElement>;\n /** Event handler for the focus event. */\n onFocus: React.FocusEventHandler;\n /** The value of the input field */\n value: string;\n /** The input field placeholder */\n placeholder?: string;\n}\n\n/** Represent the props to attach to DayPicker component. */\nexport interface UseInputDayPickerProps {\n mode: 'custom';\n fromDate?: Date;\n locale: Locale;\n min: number;\n month: Date;\n onDayClick: DayClickEventHandler;\n onMonthChange: MonthChangeEventHandler;\n selected: Date | undefined;\n toDate?: Date;\n today: Date;\n}\n\nexport interface UseInputOptions\n extends Pick<\n DayPickerProps,\n | 'locale'\n | 'fromDate'\n | 'toDate'\n | 'fromMonth'\n | 'toMonth'\n | 'fromYear'\n | 'toYear'\n | 'today'\n > {\n /** The initially selected date */\n defaultSelected?: Date;\n /** The format string for formatting the input field. See https://date-fns.org/docs/format for a list of format strings. Default to `PP`. */\n format?: string;\n /** Make the selection required. */\n required?: boolean;\n}\n\n/** Represent the value returned by [[useInput]]. */\nexport interface UseInput {\n /** The props to pass to a DayPicker component: `<DayPicker {...dayPickerProps} />` */\n dayPickerProps: UseInputDayPickerProps;\n /** The props to pass to an input field: `<input {...inputProps} />` */\n inputProps: UseInputFieldProps;\n /** A function to reset to the initial state. */\n reset: () => void;\n /** A function to set the selected day. */\n setSelected: (day: Date) => void;\n}\n\n/** Return props and setters for binding an input field to DayPicker. */\nexport function useInput(options: UseInputOptions = {}): UseInput {\n const {\n locale = enUS,\n required,\n format = 'PP',\n defaultSelected,\n today = new Date()\n } = options;\n const { fromDate, toDate } = parseFromToProps(options);\n\n const min = required ? 1 : 0;\n\n // Shortcut to the DateFns functions\n const parseValue = (value: string) => parse(value, format, today, { locale });\n\n // Initialize states\n const [month, setMonth] = React.useState(defaultSelected ?? today);\n const [selectedDay, setSelectedDay] = React.useState(defaultSelected);\n const defaultInputValue = defaultSelected\n ? _format(defaultSelected, format, { locale })\n : '';\n const [inputValue, setInputValue] = React.useState(defaultInputValue);\n\n const reset = () => {\n setSelectedDay(defaultSelected);\n setMonth(defaultSelected ?? today);\n setInputValue(defaultInputValue ?? '');\n };\n\n const setSelected = (date: Date | undefined) => {\n setSelectedDay(date);\n setMonth(date ?? today);\n setInputValue(date ? _format(date, format, { locale }) : '');\n };\n\n const handleDayClick: DayClickEventHandler = (day, { selected }) => {\n if (!required && selected) {\n setSelectedDay(undefined);\n setInputValue('');\n return;\n }\n setSelectedDay(day);\n setInputValue(day ? _format(day, format, { locale }) : '');\n };\n\n const handleMonthChange: MonthChangeEventHandler = (month) => {\n setMonth(month);\n };\n\n // When changing the input field, save its value in state and check if the\n // string is a valid date. If it is a valid day, set it as selected and update\n // the calendar’s month.\n const handleChange: React.ChangeEventHandler<HTMLInputElement> = (e) => {\n setInputValue(e.target.value);\n const day = parseValue(e.target.value);\n const isBefore = fromDate && differenceInCalendarDays(fromDate, day) > 0;\n const isAfter = toDate && differenceInCalendarDays(day, toDate) > 0;\n if (!isValidDate(day) || isBefore || isAfter) {\n setSelectedDay(undefined);\n return;\n }\n setSelectedDay(day);\n setMonth(day);\n };\n\n // Special case for _required_ fields: on blur, if the value of the input is not\n // a valid date, reset the calendar and the input value.\n const handleBlur: React.FocusEventHandler<HTMLInputElement> = (e) => {\n const day = parseValue(e.target.value);\n if (!isValidDate(day)) {\n reset();\n }\n };\n\n // When focusing, make sure DayPicker visualizes the month of the date in the\n // input field.\n const handleFocus: React.FocusEventHandler<HTMLInputElement> = (e) => {\n if (!e.target.value) {\n reset();\n return;\n }\n const day = parseValue(e.target.value);\n if (isValidDate(day)) {\n setMonth(day);\n }\n };\n\n const dayPickerProps: UseInputDayPickerProps = {\n mode: 'custom',\n month: month,\n onDayClick: handleDayClick,\n onMonthChange: handleMonthChange,\n selected: selectedDay,\n locale,\n fromDate: options?.fromDate,\n toDate: options?.toDate,\n today,\n min\n };\n\n const inputProps: UseInputFieldProps = {\n onBlur: handleBlur,\n onChange: handleChange,\n onFocus: handleFocus,\n value: inputValue,\n placeholder: _format(new Date(), format, { locale })\n };\n\n return { dayPickerProps, inputProps, reset, setSelected };\n}\n"],"names":["format","_format"],"mappings":";;;;;;AAyEA;SACgB,QAAQ,CAAC,OAA6B;IAA7B,wBAAA,EAAA,YAA6B;IAElD,IAAA,KAKE,OAAO,OALI,EAAb,MAAM,mBAAG,IAAI,KAAA,EACb,QAAQ,GAIN,OAAO,SAJD,EACR,KAGE,OAAO,OAHI,EAAbA,QAAM,mBAAG,IAAI,KAAA,EACb,eAAe,GAEb,OAAO,gBAFM,EACf,KACE,OAAO,MADS,EAAlB,KAAK,mBAAG,IAAI,IAAI,EAAE,KAAA,CACR;IACN,IAAA,KAAuB,gBAAgB,CAAC,OAAO,CAAC,EAA9C,QAAQ,cAAA,EAAE,MAAM,YAA8B,CAAC;IAEvD,IAAM,GAAG,GAAG,QAAQ,GAAG,CAAC,GAAG,CAAC,CAAC;;IAG7B,IAAM,UAAU,GAAG,UAAC,KAAa,IAAK,OAAA,KAAK,CAAC,KAAK,EAAEA,QAAM,EAAE,KAAK,EAAE,EAAE,MAAM,QAAA,EAAE,CAAC,GAAA,CAAC;;IAGxE,IAAA,KAAoB,KAAK,CAAC,QAAQ,CAAC,eAAe,aAAf,eAAe,cAAf,eAAe,GAAI,KAAK,CAAC,EAA3D,KAAK,QAAA,EAAE,QAAQ,QAA4C,CAAC;IAC7D,IAAA,KAAgC,KAAK,CAAC,QAAQ,CAAC,eAAe,CAAC,EAA9D,WAAW,QAAA,EAAE,cAAc,QAAmC,CAAC;IACtE,IAAM,iBAAiB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E,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ;QAC3B,MAAM,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM;QACvB,KAAK,OAAA;QACL,GAAG,KAAA;KACJ,CAAC;IAEF,IAAM,UAAU,GAAuB;QACrC,MAAM,EAAE,UAAU;QAClB,QAAQ,EAAE,YAAY;QACtB,OAAO,EAAE,WAAW;QACpB,KAAK,EAAE,UAAU;QACjB,WAAW,EAAEC,MAAO,CAAC,IAAI,IAAI,EAAE,EAAED,QAAM,EAAE,EAAE,MAAM,QAAA,EAAE,CAAC;KACrD,CAAC;IAEF,OAAO,EAAE,cAAc,gBAAA,EAAE,UAAU,YAAA,EAAE,KAAK,OAAA,EAAE,WAAW,aAAA,EAAE,CAAC;AAC5D;;;;"}
1
+ {"version":3,"file":"useInput.js","sources":["../../../src/hooks/useInput/useInput.ts"],"sourcesContent":["import React from 'react';\n\nimport { differenceInCalendarDays, format as _format, parse } from 'date-fns';\nimport enUS from 'date-fns/locale/en-US';\n\nimport { parseFromToProps } from '../../contexts/DayPicker/utils';\nimport { isValidDate } from './utils/isValidDate';\nimport {\n DayClickEventHandler,\n MonthChangeEventHandler\n} from '../../types/EventHandlers';\nimport { DayPickerProps } from '../../types/DayPicker';\nimport { DayPickerCustomProps } from '../../types';\n\n/** The props to attach to the input field when using [[useInput]]. */\nexport type InputHTMLAttributes = Pick<\n React.InputHTMLAttributes<HTMLInputElement>,\n 'onBlur' | 'onChange' | 'onFocus' | 'value' | 'placeholder'\n>;\n\n/** The props to attach to the DayPicker component when using [[useInput]]. */\nexport type InputDayPickerProps = Pick<\n DayPickerCustomProps,\n | 'mode'\n | 'fromDate'\n | 'toDate'\n | 'locale'\n | 'month'\n | 'onDayClick'\n | 'onMonthChange'\n | 'selected'\n | 'today'\n>;\n\nexport interface UseInputOptions\n extends Pick<\n DayPickerProps,\n | 'locale'\n | 'fromDate'\n | 'toDate'\n | 'fromMonth'\n | 'toMonth'\n | 'fromYear'\n | 'toYear'\n | 'today'\n > {\n /** The initially selected date */\n defaultSelected?: Date;\n /** The format string for formatting the input field. See https://date-fns.org/docs/format for a list of format strings. Default to `PP`. */\n format?: string;\n /** Make the selection required. */\n required?: boolean;\n}\n\n/** Represent the value returned by [[useInput]]. */\nexport interface UseInput {\n /** The props to pass to a DayPicker component. */\n dayPickerProps: InputDayPickerProps;\n /** The props to pass to an input field. */\n inputProps: InputHTMLAttributes;\n /** A function to reset to the initial state. */\n reset: () => void;\n /** A function to set the selected day. */\n setSelected: (day: Date) => void;\n}\n\n/** Return props and setters for binding an input field to DayPicker. */\nexport function useInput(options: UseInputOptions = {}): UseInput {\n const {\n locale = enUS,\n required,\n format = 'PP',\n defaultSelected,\n today = new Date()\n } = options;\n const { fromDate, toDate } = parseFromToProps(options);\n\n const min = required ? 1 : 0;\n\n // Shortcut to the DateFns functions\n const parseValue = (value: string) => parse(value, format, today, { locale });\n\n // Initialize states\n const [month, setMonth] = React.useState(defaultSelected ?? today);\n const [selectedDay, setSelectedDay] = React.useState(defaultSelected);\n const defaultInputValue = defaultSelected\n ? _format(defaultSelected, format, { locale })\n : '';\n const [inputValue, setInputValue] = React.useState(defaultInputValue);\n\n const reset = () => {\n setSelectedDay(defaultSelected);\n setMonth(defaultSelected ?? today);\n setInputValue(defaultInputValue ?? '');\n };\n\n const setSelected = (date: Date | undefined) => {\n setSelectedDay(date);\n setMonth(date ?? today);\n setInputValue(date ? _format(date, format, { locale }) : '');\n };\n\n const handleDayClick: DayClickEventHandler = (day, { selected }) => {\n if (!required && selected) {\n setSelectedDay(undefined);\n setInputValue('');\n return;\n }\n setSelectedDay(day);\n setInputValue(day ? _format(day, format, { locale }) : '');\n };\n\n const handleMonthChange: MonthChangeEventHandler = (month) => {\n setMonth(month);\n };\n\n // When changing the input field, save its value in state and check if the\n // string is a valid date. If it is a valid day, set it as selected and update\n // the calendar’s month.\n const handleChange: React.ChangeEventHandler<HTMLInputElement> = (e) => {\n setInputValue(e.target.value);\n const day = parseValue(e.target.value);\n const isBefore = fromDate && differenceInCalendarDays(fromDate, day) > 0;\n const isAfter = toDate && differenceInCalendarDays(day, toDate) > 0;\n if (!isValidDate(day) || isBefore || isAfter) {\n setSelectedDay(undefined);\n return;\n }\n setSelectedDay(day);\n setMonth(day);\n };\n\n // Special case for _required_ fields: on blur, if the value of the input is not\n // a valid date, reset the calendar and the input value.\n const handleBlur: React.FocusEventHandler<HTMLInputElement> = (e) => {\n const day = parseValue(e.target.value);\n if (!isValidDate(day)) {\n reset();\n }\n };\n\n // When focusing, make sure DayPicker visualizes the month of the date in the\n // input field.\n const handleFocus: React.FocusEventHandler<HTMLInputElement> = (e) => {\n if (!e.target.value) {\n reset();\n return;\n }\n const day = parseValue(e.target.value);\n if (isValidDate(day)) {\n setMonth(day);\n }\n };\n\n const dayPickerProps: InputDayPickerProps = {\n mode: 'custom',\n month: month,\n onDayClick: handleDayClick,\n onMonthChange: handleMonthChange,\n selected: selectedDay,\n locale,\n fromDate: options?.fromDate,\n toDate: options?.toDate,\n today\n };\n\n const inputProps: InputHTMLAttributes = {\n onBlur: handleBlur,\n onChange: handleChange,\n onFocus: handleFocus,\n value: inputValue,\n placeholder: _format(new Date(), format, { locale })\n };\n\n return { dayPickerProps, inputProps, reset, setSelected };\n}\n"],"names":["format","_format"],"mappings":";;;;;;AAkEA;SACgB,QAAQ,CAAC,OAA6B;IAA7B,wBAAA,EAAA,YAA6B;IAElD,IAAA,KAKE,OAAO,OALI,EAAb,MAAM,mBAAG,IAAI,KAAA,EACb,QAAQ,GAIN,OAAO,SAJD,EACR,KAGE,OAAO,OAHI,EAAbA,QAAM,mBAAG,IAAI,KAAA,EACb,eAAe,GAEb,OAAO,gBAFM,EACf,KACE,OAAO,MADS,EAAlB,KAAK,mBAAG,IAAI,IAAI,EAAE,KAAA,CACR;IACN,IAAA,KAAuB,gBAAgB,CAAC,OAAO,CAAC,EAA9C,QAAQ,cAAA,EAAE,MAAM,YAA8B,CAAC;;IAKvD,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ACnB,KAAK,EAAE,CAAC;YACR,OAAO;SACR;QACD,IAAM,GAAG,GAAG,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvC,IAAI,WAAW,CAAC,GAAG,CAAC,EAAE;YACpB,QAAQ,CAAC,GAAG,CAAC,CAAC;SACf;KACF,CAAC;IAEF,IAAM,cAAc,GAAwB;QAC1C,IAAI,EAAE,QAAQ;QACd,KAAK,EAAE,KAAK;QACZ,UAAU,EAAE,cAAc;QAC1B,aAAa,EAAE,iBAAiB;QAChC,QAAQ,EAAE,WAAW;QACrB,MAAM,QAAA;QACN,QAAQ,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ;QAC3B,MAAM,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM;QACvB,KAAK,OAAA;KACN,CAAC;IAEF,IAAM,UAAU,GAAwB;QACtC,MAAM,EAAE,UAAU;QAClB,QAAQ,EAAE,YAAY;QACtB,OAAO,EAAE,WAAW;QACpB,KAAK,EAAE,UAAU;QACjB,WAAW,EAAEC,MAAO,CAAC,IAAI,IAAI,EAAE,EAAED,QAAM,EAAE,EAAE,MAAM,QAAA,EAAE,CAAC;KACrD,CAAC;IAEF,OAAO,EAAE,cAAc,gBAAA,EAAE,UAAU,YAAA,EAAE,KAAK,OAAA,EAAE,WAAW,aAAA,EAAE,CAAC;AAC5D;;;;"}
@@ -1,11 +1,9 @@
1
1
  import { __assign } from '../../_virtual/_tslib.js';
2
- import 'date-fns';
3
- import { isDayPickerMultiple } from '../../types/isDayPickerMultiple.js';
4
- import { isDayPickerRange } from '../../types/isDayPickerRange.js';
5
- import { isDayPickerSingle } from '../../types/isDayPickerSingle.js';
2
+ import { isDayPickerMultiple } from '../../types/DayPickerMultiple.js';
3
+ import { isDayPickerRange } from '../../types/DayPickerRange.js';
4
+ import { isDayPickerSingle } from '../../types/DayPickerSingle.js';
6
5
  import { useDayPicker } from '../../contexts/DayPicker/useDayPicker.js';
7
6
  import '../../contexts/SelectMultiple/SelectMultipleContext.js';
8
- import 'react';
9
7
  import { useSelectMultiple } from '../../contexts/SelectMultiple/useSelectMultiple.js';
10
8
  import '../../contexts/SelectRange/SelectRangeContext.js';
11
9
  import { useSelectRange } from '../../contexts/SelectRange/useSelectRange.js';
@@ -1 +1 @@
1
- {"version":3,"file":"useModifiers.js","sources":["../../../src/hooks/useModifiers/useModifiers.ts"],"sourcesContent":["import {\n isDayPickerMultiple,\n isDayPickerRange,\n isDayPickerSingle,\n Modifiers\n} from '../../types';\n\nimport { useDayPicker } from '../../contexts/DayPicker';\nimport { useSelectMultiple } from '../../contexts/SelectMultiple';\nimport { useSelectRange } from '../../contexts/SelectRange';\nimport { useSelectSingle } from '../../contexts/SelectSingle';\n\nimport { UseModifiers } from './types';\nimport { getModifierStatus } from './utils/getModifierStatus';\n\n/** Return the modifiers and its styles for the specified date. */\nexport function useModifiers(date: Date): UseModifiers {\n const context = useDayPicker();\n\n const singleSelect = useSelectSingle();\n const multipleSelect = useSelectMultiple();\n const rangeSelect = useSelectRange();\n\n // TODO: modifiers from context should not be overridden\n const modifiers: Modifiers = {\n ...context.modifiers,\n today: context.modifiers.today ?? [context.today],\n disabled: context.modifiers.disabled\n };\n\n if (isDayPickerSingle(context)) {\n modifiers.selected = modifiers.selected.concat(\n singleSelect.modifiers.selected ?? []\n );\n } else if (isDayPickerMultiple(context)) {\n modifiers.selected = modifiers.selected.concat(\n multipleSelect.modifiers.selected ?? []\n );\n modifiers.disabled = modifiers.disabled.concat(\n multipleSelect.modifiers.disabled ?? []\n );\n } else if (isDayPickerRange(context)) {\n modifiers.selected = modifiers.selected.concat(\n rangeSelect.modifiers.selected ?? []\n );\n modifiers.disabled = modifiers.disabled.concat(\n rangeSelect.modifiers.disabled ?? []\n );\n modifiers.range_start = rangeSelect.modifiers.range_start ?? [];\n modifiers.range_middle = rangeSelect.modifiers.range_middle ?? [];\n modifiers.range_end = rangeSelect.modifiers.range_end ?? [];\n }\n\n const status = getModifierStatus(date, modifiers);\n\n const modifierClassNames: string[] = [];\n\n Object.keys(status)\n .filter((modifier) => Boolean(status[modifier]))\n .forEach((modifier) => {\n const customClassName = context.modifierClassNames[modifier];\n if (customClassName) {\n modifierClassNames.push(customClassName);\n } else {\n modifierClassNames.push(`${context.modifierPrefix}${modifier}`);\n }\n });\n\n let modifierStyle = {};\n if (context.modifierStyles) {\n Object.keys(status).forEach((modifier) => {\n modifierStyle = {\n ...modifierStyle,\n ...context.modifierStyles?.[modifier]\n };\n });\n }\n\n return {\n modifiers: status,\n modifierClassNames: modifierClassNames,\n modifierStyle\n };\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAeA;SACgB,YAAY,CAAC,IAAU;;IACrC,IAAM,OAAO,GAAG,YAAY,EAAE,CAAC;IAE/B,IAAM,YAAY,GAAG,eAAe,EAAE,CAAC;IACvC,IAAM,cAAc,GAAG,iBAAiB,EAAE,CAAC;IAC3C,IAAM,WAAW,GAAG,cAAc,EAAE,CAAC;;IAGrC,IAAM,SAAS,yBACV,OAAO,CAAC,SAAS,KACpB,KAAK,EAAE,MAAA,OAAO,CAAC,SAAS,CAAC,KAAK,mCAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EACjD,QAAQ,EAAE,OAAO,CAAC,SAAS,CAAC,QAAQ,GACrC,CAAC;IAEF,IAAI,iBAAiB,CAAC,OAAO,CAAC,EAAE;QAC9B,SAAS,CAAC,QAAQ,GAAG,SAAS,CAAC,QAAQ,CAAC,MAAM,CAC5C,MAAA,YAAY,CAAC,SAAS,CAAC,QAAQ,mCAAI,EAAE,CACtC,CAAC;KACH;SAAM,IAAI,mBAAmB,CAAC,OAAO,CAAC,EAAE;QACvC,SAAS,CAAC,QAAQ,GAAG,SAAS,CAAC,QAAQ,CAAC,MAAM,CAC5C,MAAA,cAAc,CAAC,SAAS,CAAC,QAAQ,mCAAI,EAAE,CACxC,CAAC;QACF,SAAS,CAAC,QAAQ,GAAG,SAAS,CAAC,QA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CAAC;IACvB,IAAI,OAAO,CAAC,cAAc,EAAE;QAC1B,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,UAAC,QAAQ;;YACnC,aAAa,yBACR,aAAa,GACb,MAAA,OAAO,CAAC,cAAc,0CAAG,QAAQ,CAAC,CACtC,CAAC;SACH,CAAC,CAAC;KACJ;IAED,OAAO;QACL,SAAS,EAAE,MAAM;QACjB,kBAAkB,EAAE,kBAAkB;QACtC,aAAa,eAAA;KACd,CAAC;AACJ;;;;"}
1
+ {"version":3,"file":"useModifiers.js","sources":["../../../src/hooks/useModifiers/useModifiers.ts"],"sourcesContent":["import {\n isDayPickerMultiple,\n isDayPickerRange,\n isDayPickerSingle,\n Modifiers\n} from '../../types';\n\nimport { useDayPicker } from '../../contexts/DayPicker';\nimport { useSelectMultiple } from '../../contexts/SelectMultiple';\nimport { useSelectRange } from '../../contexts/SelectRange';\nimport { useSelectSingle } from '../../contexts/SelectSingle';\n\nimport { UseModifiers } from './types';\nimport { getModifierStatus } from './utils/getModifierStatus';\n\n/** Return the modifiers and its styles for the specified date. */\nexport function useModifiers(date: Date): UseModifiers {\n const context = useDayPicker();\n\n const singleSelect = useSelectSingle();\n const multipleSelect = useSelectMultiple();\n const rangeSelect = useSelectRange();\n\n // TODO: modifiers from context should not be overridden\n const modifiers: Modifiers = {\n ...context.modifiers,\n today: context.modifiers.today ?? [context.today],\n disabled: context.modifiers.disabled\n };\n\n if (isDayPickerSingle(context)) {\n modifiers.selected = modifiers.selected.concat(\n singleSelect.modifiers.selected ?? []\n );\n } else if (isDayPickerMultiple(context)) {\n modifiers.selected = modifiers.selected.concat(\n multipleSelect.modifiers.selected ?? []\n );\n modifiers.disabled = modifiers.disabled.concat(\n multipleSelect.modifiers.disabled ?? []\n );\n } else if (isDayPickerRange(context)) {\n modifiers.selected = modifiers.selected.concat(\n rangeSelect.modifiers.selected ?? []\n );\n modifiers.disabled = modifiers.disabled.concat(\n rangeSelect.modifiers.disabled ?? []\n );\n modifiers.range_start = rangeSelect.modifiers.range_start ?? [];\n modifiers.range_middle = rangeSelect.modifiers.range_middle ?? [];\n modifiers.range_end = rangeSelect.modifiers.range_end ?? [];\n }\n\n const status = getModifierStatus(date, modifiers);\n\n const modifierClassNames: string[] = [];\n\n Object.keys(status)\n .filter((modifier) => Boolean(status[modifier]))\n .forEach((modifier) => {\n const customClassName = context.modifierClassNames[modifier];\n if (customClassName) {\n modifierClassNames.push(customClassName);\n } else {\n modifierClassNames.push(`${context.modifierPrefix}${modifier}`);\n }\n });\n\n let modifierStyle = {};\n if (context.modifierStyles) {\n Object.keys(status).forEach((modifier) => {\n modifierStyle = {\n ...modifierStyle,\n ...context.modifierStyles?.[modifier]\n };\n });\n }\n\n return {\n modifiers: status,\n modifierClassNames: modifierClassNames,\n modifierStyle\n };\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;AAeA;SACgB,YAAY,CAAC,IAAU;;IACrC,IAAM,OAAO,GAAG,YAAY,EAAE,CAAC;IAE/B,IAAM,YAAY,GAAG,eAAe,EAAE,CAAC;IACvC,IAAM,cAAc,GAAG,iBAAiB,EAAE,CAAC;IAC3C,IAAM,WAAW,GAAG,cAAc,EAAE,CAAC;;IAGrC,IAAM,SAAS,yBACV,OAAO,CAAC,SAAS,KACpB,KAAK,EAAE,MAAA,OAAO,CAAC,SAAS,CAAC,KAAK,mCAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EACjD,QAAQ,EAAE,OAAO,CAAC,SAAS,CAAC,QAAQ,GACrC,CAAC;IAEF,IAAI,iBAAiB,CAAC,OAAO,CAAC,EAAE;QAC9B,SAAS,CAAC,QAAQ,GAAG,SAAS,CAAC,QAAQ,CAAC,MAAM,CAC5C,MAAA,YAAY,CAAC,SAAS,CAAC,QAAQ,mCAAI,EAAE,CACtC,CAAC;KACH;SAAM,IAAI,mBAAmB,CAAC,OAAO,CAAC,EAAE;QACvC,SAAS,CAAC,QAAQ,GAAG,SAAS,CAAC,QAAQ,CAA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kB,CAAC,IAAI,CAAC,KAAG,OAAO,CAAC,cAAc,GAAG,QAAU,CAAC,CAAC;SACjE;KACF,CAAC,CAAC;IAEL,IAAI,aAAa,GAAG,EAAE,CAAC;IACvB,IAAI,OAAO,CAAC,cAAc,EAAE;QAC1B,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,UAAC,QAAQ;;YACnC,aAAa,yBACR,aAAa,GACb,MAAA,OAAO,CAAC,cAAc,0CAAG,QAAQ,CAAC,CACtC,CAAC;SACH,CAAC,CAAC;KACJ;IAED,OAAO;QACL,SAAS,EAAE,MAAM;QACjB,kBAAkB,EAAE,kBAAkB;QACtC,aAAa,eAAA;KACd,CAAC;AACJ;;;;"}
@@ -1,3 +1,3 @@
1
- import { DateRange } from '../../../types';
1
+ import { DateRange } from '../../../types/Matchers';
2
2
  /** Return `true` whether the given date is inside the range. */
3
3
  export declare function isDateInRange(date: Date, range: DateRange): boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"isDateInRange.js","sources":["../../../../src/hooks/useModifiers/utils/isDateInRange.ts"],"sourcesContent":["import { differenceInCalendarDays, isSameDay } from 'date-fns';\n\nimport { DateRange } from '../../../types';\n\n/** Return `true` whether the given date is inside the range. */\nexport function isDateInRange(date: Date, range: DateRange): boolean {\n let { from, to } = range;\n if (!from) {\n return false;\n }\n if (!to && isSameDay(from, date)) {\n return true;\n }\n if (!to) {\n return false;\n }\n const isToBeforeFrom = differenceInCalendarDays(to, from) < 0;\n if (to && isToBeforeFrom) {\n [from, to] = [to, from];\n }\n return (\n differenceInCalendarDays(date, from) >= 0 &&\n differenceInCalendarDays(to, date) >= 0\n );\n}\n"],"names":[],"mappings":";;AAIA;SACgB,aAAa,CAAC,IAAU,EAAE,KAAgB;;IAClD,IAAA,IAAI,GAAS,KAAK,KAAd,EAAE,EAAE,GAAK,KAAK,GAAV,CAAW;IACzB,IAAI,CAAC,IAAI,EAAE;QACT,OAAO,KAAK,CAAC;KACd;IACD,IAAI,CAAC,EAAE,IAAI,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE;QAChC,OAAO,IAAI,CAAC;KACb;IACD,IAAI,CAAC,EAAE,EAAE;QACP,OAAO,KAAK,CAAC;KACd;IACD,IAAM,cAAc,GAAG,wBAAwB,CAAC,EAAE,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IAC9D,IAAI,EAAE,IAAI,cAAc,EAAE;QACxB,KAAa,CAAC,EAAE,EAAE,IAAI,CAAC,EAAtB,IAAI,QAAA,EAAE,EAAE,QAAA,CAAe;KACzB;IACD,QACE,wBAAwB,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC;QACzC,wBAAwB,CAAC,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,EACvC;AACJ;;;;"}
1
+ {"version":3,"file":"isDateInRange.js","sources":["../../../../src/hooks/useModifiers/utils/isDateInRange.ts"],"sourcesContent":["import { differenceInCalendarDays, isSameDay } from 'date-fns';\n\nimport { DateRange } from '../../../types/Matchers';\n\n/** Return `true` whether the given date is inside the range. */\nexport function isDateInRange(date: Date, range: DateRange): boolean {\n let { from, to } = range;\n if (!from) {\n return false;\n }\n if (!to && isSameDay(from, date)) {\n return true;\n }\n if (!to) {\n return false;\n }\n const isToBeforeFrom = differenceInCalendarDays(to, from) < 0;\n if (to && isToBeforeFrom) {\n [from, to] = [to, from];\n }\n return (\n differenceInCalendarDays(date, from) >= 0 &&\n differenceInCalendarDays(to, date) >= 0\n );\n}\n"],"names":[],"mappings":";;AAIA;SACgB,aAAa,CAAC,IAAU,EAAE,KAAgB;;IAClD,IAAA,IAAI,GAAS,KAAK,KAAd,EAAE,EAAE,GAAK,KAAK,GAAV,CAAW;IACzB,IAAI,CAAC,IAAI,EAAE;QACT,OAAO,KAAK,CAAC;KACd;IACD,IAAI,CAAC,EAAE,IAAI,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE;QAChC,OAAO,IAAI,CAAC;KACb;IACD,IAAI,CAAC,EAAE,EAAE;QACP,OAAO,KAAK,CAAC;KACd;IACD,IAAM,cAAc,GAAG,wBAAwB,CAAC,EAAE,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IAC9D,IAAI,EAAE,IAAI,cAAc,EAAE;QACxB,KAAa,CAAC,EAAE,EAAE,IAAI,CAAC,EAAtB,IAAI,QAAA,EAAE,EAAE,QAAA,CAAe;KACzB;IACD,QACE,wBAAwB,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC;QACzC,wBAAwB,CAAC,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,EACvC;AACJ;;;;"}
@@ -1,4 +1,4 @@
1
- import { Matcher } from '../../../types';
1
+ import { Matcher } from '../../../types/Matchers';
2
2
  /**
3
3
  * Returns `true` whether the day matches against the given matchers.
4
4
  */
@@ -1,13 +1,15 @@
1
- import { isSameDay, differenceInCalendarDays } from 'date-fns';
2
- import { isArrayOfDates } from '../../../types/isArrayOfDates.js';
3
- import { isDateAfterType } from '../../../types/isDateAfterType.js';
4
- import { isDateBeforeType } from '../../../types/isDateBeforeType.js';
5
- import { isDateInterval } from '../../../types/isDateInterval.js';
6
- import { isDateRange } from '../../../types/isDateRange.js';
7
- import { isDateType } from '../../../types/isDateType.js';
8
- import { isDayOfWeekType } from '../../../types/isDayOfWeekType.js';
1
+ import { isDate, isSameDay, differenceInCalendarDays } from 'date-fns';
2
+ import { isDateRange, isDayOfWeekType, isDateInterval, isDateAfterType, isDateBeforeType } from '../../../types/Matchers.js';
9
3
  import { isDateInRange } from './isDateInRange.js';
10
4
 
5
+ /** Returns true if `value` is a Date type. */
6
+ function isDateType(value) {
7
+ return isDate(value);
8
+ }
9
+ /** Returns true if `value` is an array of valid dates. */
10
+ function isArrayOfDates(value) {
11
+ return Array.isArray(value) && value.every(isDate);
12
+ }
11
13
  /**
12
14
  * Returns `true` whether the day matches against the given matchers.
13
15
  */
@@ -1 +1 @@
1
- {"version":3,"file":"isMatch.js","sources":["../../../../src/hooks/useModifiers/utils/isMatch.ts"],"sourcesContent":["import { differenceInCalendarDays, isSameDay } from 'date-fns';\n\nimport {\n isArrayOfDates,\n isDateAfterType,\n isDateBeforeType,\n isDateInterval,\n isDateRange,\n isDateType,\n isDayOfWeekType,\n Matcher\n} from '../../../types';\n\nimport { isDateInRange } from './isDateInRange';\n\n/**\n * Returns `true` whether the day matches against the given matchers.\n */\nexport function isMatch(day: Date, matchers: Matcher[]): boolean {\n return matchers.some((matcher: Matcher) => {\n if (typeof matcher === 'boolean') {\n return matcher;\n }\n if (isDateType(matcher)) {\n return isSameDay(day, matcher);\n }\n if (isArrayOfDates(matcher)) {\n return matcher.includes(day);\n }\n if (isDateRange(matcher)) {\n return isDateInRange(day, matcher);\n }\n if (isDayOfWeekType(matcher)) {\n return matcher.dayOfWeek.includes(day.getDay());\n }\n if (isDateInterval(matcher)) {\n const isBefore = differenceInCalendarDays(matcher.before, day) > 0;\n const isAfter = differenceInCalendarDays(day, matcher.after) > 0;\n return isBefore && isAfter;\n }\n if (isDateAfterType(matcher)) {\n return differenceInCalendarDays(day, matcher.after) > 0;\n }\n if (isDateBeforeType(matcher)) {\n return differenceInCalendarDays(matcher.before, day) > 0;\n }\n if (typeof matcher === 'function') {\n return matcher(day);\n }\n return false;\n });\n}\n"],"names":[],"mappings":";;;;;;;;;;AAeA;;;SAGgB,OAAO,CAAC,GAAS,EAAE,QAAmB;IACpD,OAAO,QAAQ,CAAC,IAAI,CAAC,UAAC,OAAgB;QACpC,IAAI,OAAO,OAAO,KAAK,SAAS,EAAE;YAChC,OAAO,OAAO,CAAC;SAChB;QACD,IAAI,UAAU,CAAC,OAAO,CAAC,EAAE;YACvB,OAAO,SAAS,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;SAChC;QACD,IAAI,cAAc,CAAC,OAAO,CAAC,EAAE;YAC3B,OAAO,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;SAC9B;QACD,IAAI,WAAW,CAAC,OAAO,CAAC,EAAE;YACxB,OAAO,aAAa,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;SACpC;QACD,IAAI,eAAe,CAAC,OAAO,CAAC,EAAE;YAC5B,OAAO,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;SACjD;QACD,IAAI,cAAc,CAAC,OAAO,CAAC,EAAE;YAC3B,IAAM,QAAQ,GAAG,wBAAwB,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;YACnE,IAAM,OAAO,GAAG,wBAAwB,CAAC,GAAG,EAAE,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACjE,OAAO,QAAQ,IAAI,OAAO,CAAC;SAC5B;QACD,IAAI,eAAe,CAAC,OAAO,CAAC,EAAE;YAC5B,OAAO,wBAAwB,CAAC,GAAG,EAAE,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;SACzD;QACD,IAAI,gBAAgB,CAAC,OAAO,CAAC,EAAE;YAC7B,OAAO,wBAAwB,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;SAC1D;QACD,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE;YACjC,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC;SACrB;QACD,OAAO,KAAK,CAAC;KACd,CAAC,CAAC;AACL;;;;"}
1
+ {"version":3,"file":"isMatch.js","sources":["../../../../src/hooks/useModifiers/utils/isMatch.ts"],"sourcesContent":["import { differenceInCalendarDays, isDate, isSameDay } from 'date-fns';\nimport {\n isDateAfterType,\n isDateBeforeType,\n isDateInterval,\n isDateRange,\n isDayOfWeekType,\n Matcher\n} from '../../../types/Matchers';\n\nimport { isDateInRange } from './isDateInRange';\n\n/** Returns true if `value` is a Date type. */\nfunction isDateType(value: unknown): value is Date {\n return isDate(value);\n}\n\n/** Returns true if `value` is an array of valid dates. */\nfunction isArrayOfDates(value: unknown): value is Date[] {\n return Array.isArray(value) && value.every(isDate);\n}\n\n/**\n * Returns `true` whether the day matches against the given matchers.\n */\nexport function isMatch(day: Date, matchers: Matcher[]): boolean {\n return matchers.some((matcher: Matcher) => {\n if (typeof matcher === 'boolean') {\n return matcher;\n }\n if (isDateType(matcher)) {\n return isSameDay(day, matcher);\n }\n if (isArrayOfDates(matcher)) {\n return matcher.includes(day);\n }\n if (isDateRange(matcher)) {\n return isDateInRange(day, matcher);\n }\n if (isDayOfWeekType(matcher)) {\n return matcher.dayOfWeek.includes(day.getDay());\n }\n if (isDateInterval(matcher)) {\n const isBefore = differenceInCalendarDays(matcher.before, day) > 0;\n const isAfter = differenceInCalendarDays(day, matcher.after) > 0;\n return isBefore && isAfter;\n }\n if (isDateAfterType(matcher)) {\n return differenceInCalendarDays(day, matcher.after) > 0;\n }\n if (isDateBeforeType(matcher)) {\n return differenceInCalendarDays(matcher.before, day) > 0;\n }\n if (typeof matcher === 'function') {\n return matcher(day);\n }\n return false;\n });\n}\n"],"names":[],"mappings":";;;;AAYA;AACA,SAAS,UAAU,CAAC,KAAc;IAChC,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AAED;AACA,SAAS,cAAc,CAAC,KAAc;IACpC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AACrD,CAAC;AAED;;;SAGgB,OAAO,CAAC,GAAS,EAAE,QAAmB;IACpD,OAAO,QAAQ,CAAC,IAAI,CAAC,UAAC,OAAgB;QACpC,IAAI,OAAO,OAAO,KAAK,SAAS,EAAE;YAChC,OAAO,OAAO,CAAC;SAChB;QACD,IAAI,UAAU,CAAC,OAAO,CAAC,EAAE;YACvB,OAAO,SAAS,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;SAChC;QACD,IAAI,cAAc,CAAC,OAAO,CAAC,EAAE;YAC3B,OAAO,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;SAC9B;QACD,IAAI,WAAW,CAAC,OAAO,CAAC,EAAE;YACxB,OAAO,aAAa,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;SACpC;QACD,IAAI,eAAe,CAAC,OAAO,CAAC,EAAE;YAC5B,OAAO,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;SACjD;QACD,IAAI,cAAc,CAAC,OAAO,CAAC,EAAE;YAC3B,IAAM,QAAQ,GAAG,wBAAwB,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;YACnE,IAAM,OAAO,GAAG,wBAAwB,CAAC,GAAG,EAAE,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACjE,OAAO,QAAQ,IAAI,OAAO,CAAC;SAC5B;QACD,IAAI,eAAe,CAAC,OAAO,CAAC,EAAE;YAC5B,OAAO,wBAAwB,CAAC,GAAG,EAAE,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;SACzD;QACD,IAAI,gBAAgB,CAAC,OAAO,CAAC,EAAE;YAC7B,OAAO,wBAAwB,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;SAC1D;QACD,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE;YACjC,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC;SACrB;QACD,OAAO,KAAK,CAAC;KACd,CAAC,CAAC;AACL;;;;"}
package/build/main.js CHANGED
@@ -18,34 +18,23 @@ export { Row } from './components/Row/Row.js';
18
18
  export { Table } from './components/Table/Table.js';
19
19
  export { WeekNumber } from './components/WeekNumber/WeekNumber.js';
20
20
  export { YearsDropdown } from './components/YearsDropdown/YearsDropdown.js';
21
- export { ContextProvider } from './contexts/ContextProvider.js';
21
+ export { RootProvider } from './contexts/RootProvider.js';
22
22
  export { useDayPicker } from './contexts/DayPicker/useDayPicker.js';
23
- export { FocusContext } from './contexts/Focus/FocusContext.js';
24
- export { FocusProvider } from './contexts/Focus/FocusProvider.js';
23
+ export { FocusContext, FocusProvider } from './contexts/Focus/FocusContext.js';
25
24
  export { useFocus } from './contexts/Focus/useFocus.js';
26
- export { NavigationContext } from './contexts/Navigation/NavigationContext.js';
27
- export { NavigationProvider } from './contexts/Navigation/NavigationProvider.js';
25
+ export { NavigationContext, NavigationProvider } from './contexts/Navigation/NavigationContext.js';
28
26
  export { useNavigation } from './contexts/Navigation/useNavigation.js';
29
- export { SelectMultipleContext } from './contexts/SelectMultiple/SelectMultipleContext.js';
30
- export { SelectMultipleProvider } from './contexts/SelectMultiple/SelectMultipleProvider.js';
27
+ export { SelectMultipleContext, SelectMultipleProvider, SelectMultipleProviderInternal } from './contexts/SelectMultiple/SelectMultipleContext.js';
31
28
  export { useSelectMultiple } from './contexts/SelectMultiple/useSelectMultiple.js';
32
- export { SelectRangeContext } from './contexts/SelectRange/SelectRangeContext.js';
33
- export { SelectRangeProvider } from './contexts/SelectRange/SelectRangeProvider.js';
29
+ export { SelectRangeContext, SelectRangeProvider, SelectRangeProviderInternal } from './contexts/SelectRange/SelectRangeContext.js';
34
30
  export { useSelectRange } from './contexts/SelectRange/useSelectRange.js';
35
- export { SelectSingleContext } from './contexts/SelectSingle/SelectSingleContext.js';
36
- export { SelectSingleProvider } from './contexts/SelectSingle/SelectSingleProvider.js';
31
+ export { SelectSingleContext, SelectSingleProvider, SelectSingleProviderInternal } from './contexts/SelectSingle/SelectSingleContext.js';
37
32
  export { useSelectSingle } from './contexts/SelectSingle/useSelectSingle.js';
38
- export { isArrayOfDates } from './types/isArrayOfDates.js';
39
- export { isDateAfterType } from './types/isDateAfterType.js';
40
- export { isDateBeforeType } from './types/isDateBeforeType.js';
41
- export { isDateInterval } from './types/isDateInterval.js';
42
- export { isDateRange } from './types/isDateRange.js';
43
- export { isDateType } from './types/isDateType.js';
44
- export { isDayOfWeekType } from './types/isDayOfWeekType.js';
45
- export { isDayPickerCustom } from './types/isDayPickerCustom.js';
46
- export { isDayPickerMultiple } from './types/isDayPickerMultiple.js';
47
- export { isDayPickerRange } from './types/isDayPickerRange.js';
48
- export { isDayPickerSingle } from './types/isDayPickerSingle.js';
33
+ export { isDayPickerCustom } from './types/DayPickerCustom.js';
34
+ export { isDayPickerMultiple } from './types/DayPickerMultiple.js';
35
+ export { isDayPickerRange } from './types/DayPickerRange.js';
36
+ export { isDayPickerSingle } from './types/DayPickerSingle.js';
37
+ export { isDateAfterType, isDateBeforeType, isDateInterval, isDateRange, isDayOfWeekType } from './types/Matchers.js';
49
38
  export { useInput } from './hooks/useInput/useInput.js';
50
39
  export { useModifiers } from './hooks/useModifiers/useModifiers.js';
51
40
  //# sourceMappingURL=main.js.map
package/build/main.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"main.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"main.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,22 +1,12 @@
1
1
  /// <reference types="react" />
2
2
  import { Locale } from 'date-fns';
3
- import { CaptionLayout } from './CaptionLayout';
4
- import { ClassNames } from './ClassNames';
5
- import { Components } from './Components';
6
- import { CustomModifiers } from './CustomModifiers';
7
- import { DayClickEventHandler } from './DayClickEventHandler';
8
- import { DayFocusEventHandler } from './DayFocusEventHandler';
9
- import { DayKeyboardEventHandler } from './DayKeyboardEventHandler';
10
- import { DayMouseEventHandler } from './DayMouseEventHandler';
11
- import { DayTouchEventHandler } from './DayTouchEventHandler';
3
+ import { CaptionLabelProps, CaptionLayout, CaptionProps, DayContentProps, DayProps, DropdownProps, RowProps, WeekNumberProps } from '../components';
4
+ import { DayClickEventHandler, DayFocusEventHandler, DayKeyboardEventHandler, DayMouseEventHandler, DayTouchEventHandler, MonthChangeEventHandler, WeekNumberClickEventHandler } from './EventHandlers';
12
5
  import { Formatters } from './Formatters';
13
6
  import { Labels } from './Labels';
14
- import { Matcher } from './Matcher';
15
- import { ModifierClassNames } from './ModifierClassNames';
16
- import { ModifierStyles } from './ModifierStyles';
17
- import { MonthChangeEventHandler } from './MonthChangeEventHandler';
18
- import { Styles } from './Styles';
19
- import { WeekNumberClickEventHandler } from './WeekNumberClickEventHandler';
7
+ import { Matcher } from './Matchers';
8
+ import { CustomModifiers, ModifierClassNames, ModifierStyles } from './Modifiers';
9
+ import { ClassNames, StyledComponent, Styles } from './Styles';
20
10
  /**
21
11
  * The props for the [[DayPicker]] component.
22
12
  */
@@ -167,10 +157,12 @@ export interface DayPickerProps {
167
157
  /**
168
158
  * Toggle the controlled selection mode.
169
159
  *
170
- * - `custom`: customize what is selected
160
+ * As default, no selection mode is set and the days are not interactive.
161
+ *
171
162
  * - `single`: control the selection of single days
172
163
  * - `multiple`: control the selection of multiple days
173
164
  * - `range`: control the selection of a range of days
165
+ * - `custom`: customize what is selected by using `onDayClick`
174
166
  */
175
167
  mode?: 'custom' | 'single' | 'multiple' | 'range';
176
168
  /**
@@ -207,3 +199,30 @@ export interface DayPickerProps {
207
199
  onPrevClick?: MonthChangeEventHandler;
208
200
  onWeekNumberClick?: WeekNumberClickEventHandler;
209
201
  }
202
+ /** A map of the component that can be changed via the `components` prop. */
203
+ export interface Components {
204
+ /** The component for the caption element. */
205
+ Caption: (props: CaptionProps) => JSX.Element | null;
206
+ /** The component for the caption element. */
207
+ CaptionLabel: (props: CaptionLabelProps) => JSX.Element | null;
208
+ /** The component for the day element. This is a button or a span. */
209
+ Day: (props: DayProps) => JSX.Element | null;
210
+ /** The component for the content of the day element. */
211
+ DayContent: (props: DayContentProps) => JSX.Element | null;
212
+ /** The component for the drop-down elements. */
213
+ Dropdown: (props: DropdownProps) => JSX.Element | null;
214
+ /** The component for the table footer. */
215
+ Footer: () => JSX.Element | null;
216
+ /** The component for the table’s head. */
217
+ Head: () => JSX.Element | null;
218
+ /** The component for the small icon in the drop-downs. */
219
+ IconDropdown: (props: StyledComponent) => JSX.Element | null;
220
+ /** The arrow right icon (used for the Navigation buttons). */
221
+ IconRight: (props: StyledComponent) => JSX.Element | null;
222
+ /** The arrow left icon (used for the Navigation buttons). */
223
+ IconLeft: (props: StyledComponent) => JSX.Element | null;
224
+ /** The component for the table rows. */
225
+ Row: (props: RowProps) => JSX.Element | null;
226
+ /** The component for the week number in the table rows. */
227
+ WeekNumber: (props: WeekNumberProps) => JSX.Element | null;
228
+ }
@@ -0,0 +1,11 @@
1
+ import { DayPickerProps } from './DayPicker';
2
+ /** The props for the [[DayPicker]] component when using `mode="custom"`. */
3
+ export interface DayPickerCustomProps extends DayPickerProps {
4
+ mode: 'custom';
5
+ /** The selected day(s). */
6
+ selected?: unknown;
7
+ /** Use `onDayClick` and related event instead. */
8
+ onSelect: never;
9
+ }
10
+ /** Returns true when the props are of type [[DayPickerCustom]]. */
11
+ export declare function isDayPickerCustom(props: DayPickerProps): props is DayPickerCustomProps;
@@ -4,4 +4,4 @@ function isDayPickerCustom(props) {
4
4
  }
5
5
 
6
6
  export { isDayPickerCustom };
7
- //# sourceMappingURL=isDayPickerCustom.js.map
7
+ //# sourceMappingURL=DayPickerCustom.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DayPickerCustom.js","sources":["../../src/types/DayPickerCustom.ts"],"sourcesContent":["import { DayPickerProps } from './DayPicker';\n\n/** The props for the [[DayPicker]] component when using `mode=\"custom\"`. */\nexport interface DayPickerCustomProps extends DayPickerProps {\n mode: 'custom';\n /** The selected day(s). */\n selected?: unknown;\n /** Use `onDayClick` and related event instead. */\n onSelect: never;\n}\n\n/** Returns true when the props are of type [[DayPickerCustom]]. */\nexport function isDayPickerCustom(\n props: DayPickerProps\n): props is DayPickerCustomProps {\n return props.mode === 'custom';\n}\n"],"names":[],"mappings":"AAWA;SACgB,iBAAiB,CAC/B,KAAqB;IAErB,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC;AACjC;;;;"}
@@ -1,8 +1,6 @@
1
- import { DayPickerProps } from '.';
2
- import { SelectMultipleEventHandler } from './SelectMultipleEventHandler';
3
- /**
4
- * The props for the [[DayPicker]] component when using `mode="multiple"`.
5
- */
1
+ import { DayPickerProps } from './DayPicker';
2
+ import { SelectMultipleEventHandler } from './EventHandlers';
3
+ /** The props for the [[DayPicker]] component when using `mode="multiple"`. */
6
4
  export interface DayPickerMultipleProps extends DayPickerProps {
7
5
  mode: 'multiple';
8
6
  /** The selected days. */
@@ -14,3 +12,5 @@ export interface DayPickerMultipleProps extends DayPickerProps {
14
12
  /** The maximum amount of days that can be selected. */
15
13
  max?: number;
16
14
  }
15
+ /** Returns true when the props are of type [[DayPickerMultiple]]. */
16
+ export declare function isDayPickerMultiple(props: DayPickerProps): props is DayPickerMultipleProps;
@@ -4,4 +4,4 @@ function isDayPickerMultiple(props) {
4
4
  }
5
5
 
6
6
  export { isDayPickerMultiple };
7
- //# sourceMappingURL=isDayPickerMultiple.js.map
7
+ //# sourceMappingURL=DayPickerMultiple.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DayPickerMultiple.js","sources":["../../src/types/DayPickerMultiple.ts"],"sourcesContent":["import { DayPickerProps } from './DayPicker';\nimport { SelectMultipleEventHandler } from './EventHandlers';\n\n/** The props for the [[DayPicker]] component when using `mode=\"multiple\"`. */\nexport interface DayPickerMultipleProps extends DayPickerProps {\n mode: 'multiple';\n /** The selected days. */\n selected?: Date[];\n /** Event fired when a days added or removed to the selection. */\n onSelect?: SelectMultipleEventHandler;\n /** The minimum amount of days that can be selected. */\n min?: number;\n /** The maximum amount of days that can be selected. */\n max?: number;\n}\n\n/** Returns true when the props are of type [[DayPickerMultiple]]. */\nexport function isDayPickerMultiple(\n props: DayPickerProps\n): props is DayPickerMultipleProps {\n return props.mode === 'multiple';\n}\n"],"names":[],"mappings":"AAgBA;SACgB,mBAAmB,CACjC,KAAqB;IAErB,OAAO,KAAK,CAAC,IAAI,KAAK,UAAU,CAAC;AACnC;;;;"}
@@ -1,9 +1,7 @@
1
- import { DateRange } from './DateRange';
2
- import { DayPickerProps } from './DayPickerProps';
3
- import { SelectRangeEventHandler } from './SelectRangeEventHandler';
4
- /**
5
- * The props for the [[DayPicker]] component when using `mode="range"`.
6
- */
1
+ import { DayPickerProps } from './DayPicker';
2
+ import { SelectRangeEventHandler } from './EventHandlers';
3
+ import { DateRange } from './Matchers';
4
+ /** The props for the [[DayPicker]] component when using `mode="range"`. */
7
5
  export interface DayPickerRangeProps extends DayPickerProps {
8
6
  mode: 'range';
9
7
  /** The selected range of days. */
@@ -15,3 +13,5 @@ export interface DayPickerRangeProps extends DayPickerProps {
15
13
  /** The maximum amount of days that can be selected. */
16
14
  max?: number;
17
15
  }
16
+ /** Returns true when the props are of type [[DayPickerRange]]. */
17
+ export declare function isDayPickerRange(props: DayPickerProps): props is DayPickerRangeProps;
@@ -4,4 +4,4 @@ function isDayPickerRange(props) {
4
4
  }
5
5
 
6
6
  export { isDayPickerRange };
7
- //# sourceMappingURL=isDayPickerRange.js.map
7
+ //# sourceMappingURL=DayPickerRange.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DayPickerRange.js","sources":["../../src/types/DayPickerRange.ts"],"sourcesContent":["import { DayPickerProps } from './DayPicker';\nimport { SelectRangeEventHandler } from './EventHandlers';\nimport { DateRange } from './Matchers';\n\n/** The props for the [[DayPicker]] component when using `mode=\"range\"`. */\nexport interface DayPickerRangeProps extends DayPickerProps {\n mode: 'range';\n /** The selected range of days. */\n selected?: DateRange;\n /** Event fired when a range (or a part of the range) is selected. */\n onSelect?: SelectRangeEventHandler;\n /** The minimum amount of days that can be selected. */\n min?: number;\n /** The maximum amount of days that can be selected. */\n max?: number;\n}\n\n/** Returns true when the props are of type [[DayPickerRange]]. */\nexport function isDayPickerRange(\n props: DayPickerProps\n): props is DayPickerRangeProps {\n return props.mode === 'range';\n}\n"],"names":[],"mappings":"AAiBA;SACgB,gBAAgB,CAC9B,KAAqB;IAErB,OAAO,KAAK,CAAC,IAAI,KAAK,OAAO,CAAC;AAChC;;;;"}
@@ -0,0 +1,14 @@
1
+ import { DayPickerProps } from './DayPicker';
2
+ import { SelectSingleEventHandler } from './EventHandlers';
3
+ /** The props for the [[DayPicker]] component when using `mode="single"`. */
4
+ export interface DayPickerSingleProps extends DayPickerProps {
5
+ mode: 'single';
6
+ /** The selected day. */
7
+ selected?: Date | undefined;
8
+ /** Event fired when a day is selected. */
9
+ onSelect?: SelectSingleEventHandler;
10
+ /** Make the selection required. */
11
+ required?: boolean;
12
+ }
13
+ /** Returns true when the props are of type [[DayPickerSingle]]. */
14
+ export declare function isDayPickerSingle(props: DayPickerProps): props is DayPickerSingleProps;
@@ -4,4 +4,4 @@ function isDayPickerSingle(props) {
4
4
  }
5
5
 
6
6
  export { isDayPickerSingle };
7
- //# sourceMappingURL=isDayPickerSingle.js.map
7
+ //# sourceMappingURL=DayPickerSingle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DayPickerSingle.js","sources":["../../src/types/DayPickerSingle.ts"],"sourcesContent":["import { DayPickerProps } from './DayPicker';\nimport { SelectSingleEventHandler } from './EventHandlers';\n\n/** The props for the [[DayPicker]] component when using `mode=\"single\"`. */\nexport interface DayPickerSingleProps extends DayPickerProps {\n mode: 'single';\n /** The selected day. */\n selected?: Date | undefined;\n /** Event fired when a day is selected. */\n onSelect?: SelectSingleEventHandler;\n /** Make the selection required. */\n required?: boolean;\n}\n\n/** Returns true when the props are of type [[DayPickerSingle]]. */\nexport function isDayPickerSingle(\n props: DayPickerProps\n): props is DayPickerSingleProps {\n return props.mode === 'single';\n}\n"],"names":[],"mappings":"AAcA;SACgB,iBAAiB,CAC/B,KAAqB;IAErB,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC;AACjC;;;;"}
@@ -0,0 +1,51 @@
1
+ /// <reference types="react" />
2
+ import { DateRange } from '../types';
3
+ import { ModifierStatus } from './Modifiers';
4
+ /** The event handler when a day is clicked. */
5
+ export declare type DayClickEventHandler = (day: Date, modifiers: ModifierStatus, e: React.MouseEvent) => void;
6
+ /** The event handler when a day is focused. */
7
+ export declare type DayFocusEventHandler = (day: Date, modifiers: ModifierStatus, e: React.FocusEvent | React.KeyboardEvent) => void;
8
+ /** The event handler when a day gets a keyboard event. */
9
+ export declare type DayKeyboardEventHandler = (day: Date, modifiers: ModifierStatus, e: React.KeyboardEvent) => void;
10
+ /** The event handler when a day gets a mouse event. */
11
+ export declare type DayMouseEventHandler = (day: Date, modifiers: ModifierStatus, e: React.MouseEvent) => void;
12
+ /** The event handler when a month is changed in the calendar. */
13
+ export declare type MonthChangeEventHandler = (month: Date) => void;
14
+ /** The event handler when selecting multiple days. */
15
+ export declare type SelectMultipleEventHandler = (
16
+ /** The selected days */
17
+ days: Date[] | undefined,
18
+ /** The day that was clicked triggering the event. */
19
+ selectedDay: Date,
20
+ /** The day that was clicked */
21
+ modifiers: ModifierStatus,
22
+ /** The mouse event that triggered this event. */
23
+ e: React.MouseEvent) => void;
24
+ /** The event handler when selecting a range of days. */
25
+ export declare type SelectRangeEventHandler = (
26
+ /** The current range of the selected days. */
27
+ range: DateRange | undefined,
28
+ /** The day that was selected (or clicked) triggering the event. */
29
+ selectedDay: Date,
30
+ /** The modifiers of the selected day. */
31
+ modifiers: ModifierStatus, e: React.MouseEvent) => void;
32
+ /** The event handler when selecting a single day. */
33
+ export interface SelectSingleEventHandler {
34
+ (
35
+ /** The selected day, `undefined` when `required={false}` (default) and the day is clicked again. */
36
+ day: Date | undefined,
37
+ /** The day that was selected (or clicked) triggering the event. */
38
+ selectedDay: Date,
39
+ /** The modifiers of the selected day. */
40
+ modifiers: ModifierStatus, e: React.MouseEvent): void;
41
+ }
42
+ /**The event handler when the week number is clicked. */
43
+ export declare type WeekNumberClickEventHandler = (
44
+ /** The week number that has been clicked. */
45
+ weekNumber: number,
46
+ /** The dates in the clicked week. */
47
+ dates: Date[],
48
+ /** The mouse event that triggered this event. */
49
+ e: React.MouseEvent) => void;
50
+ /** The event handler when a day gets a touch event. */
51
+ export declare type DayTouchEventHandler = (day: Date, modifiers: ModifierStatus, e: React.TouchEvent) => void;
@@ -1,8 +1,9 @@
1
- import { DateFormatter } from './DateFormatter';
2
- import { WeekNumberFormatter } from './WeekNumberFormatter';
3
- /**
4
- * Represent a map of formatters used to render localized content.
5
- */
1
+ import React from 'react';
2
+ /** Represents a function to format a date. */
3
+ export declare type DateFormatter = (date: Date, options?: {
4
+ locale?: Locale;
5
+ }) => React.ReactNode;
6
+ /** Represent a map of formatters used to render localized content. */
6
7
  export declare type Formatters = {
7
8
  /** Format the month in the caption when `captionLayout` is `buttons`. */
8
9
  formatCaption: DateFormatter;
@@ -17,3 +18,7 @@ export declare type Formatters = {
17
18
  /** Format the week day name in the header */
18
19
  formatWeekdayName: DateFormatter;
19
20
  };
21
+ /** Represent a function to format the week number. */
22
+ export declare type WeekNumberFormatter = (weekNumber: number, options?: {
23
+ locale?: Locale;
24
+ }) => React.ReactNode;
@@ -1,16 +1,28 @@
1
- import { DayLabelFormatter } from './DayLabelFormatter';
2
- import { NavButtonLabelFormatter } from './NavButtonLabelFormatter';
3
- import { WeekdayLabelFormatter } from './WeekdayLabelFormatter';
4
- import { WeekNumberLabelFormatter } from './WeekNumberLabelFormatter';
5
- /**
6
- * Map of functions to translate ARIA labels for the relative elements.
7
- */
1
+ import { Locale } from 'date-fns';
2
+ import { ModifierStatus } from '../types';
3
+ /** Map of functions to translate ARIA labels for the relative elements. */
8
4
  export declare type Labels = {
9
5
  labelMonthDropdown: () => string;
10
6
  labelYearDropdown: () => string;
11
- labelNext: NavButtonLabelFormatter;
12
- labelPrevious: NavButtonLabelFormatter;
13
- labelDay: DayLabelFormatter;
14
- labelWeekday: WeekdayLabelFormatter;
15
- labelWeekNumber: WeekNumberLabelFormatter;
7
+ labelNext: NavButtonLabel;
8
+ labelPrevious: NavButtonLabel;
9
+ labelDay: DayLabel;
10
+ labelWeekday: WeekdayLabel;
11
+ labelWeekNumber: WeekNumberLabel;
16
12
  };
13
+ /** Return the ARIA label for the [[Day]] component. */
14
+ export declare type DayLabel = (day: Date, modifiers: ModifierStatus, options?: {
15
+ locale?: Locale;
16
+ }) => string;
17
+ /** Return the ARIA label for the "next month" / "prev month" buttons in the navigation.*/
18
+ export declare type NavButtonLabel = (month?: Date, options?: {
19
+ locale?: Locale;
20
+ }) => string;
21
+ /** Return the ARIA label for the Head component.*/
22
+ export declare type WeekdayLabel = (day: Date, options?: {
23
+ locale?: Locale;
24
+ }) => string;
25
+ /** Return the ARIA label of the week number.*/
26
+ export declare type WeekNumberLabel = (n: number, options?: {
27
+ locale?: Locale;
28
+ }) => string;