@elliemae/ds-controlled-form 2.4.1-rc.6 → 2.4.1

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 (170) hide show
  1. package/cjs/date-time-picker/ControlledDateTimePickerCTX.js +1 -114
  2. package/cjs/date-time-picker/ControlledDateTimePickerDatatestid.js +0 -2
  3. package/cjs/date-time-picker/config/useChangeHandlers.js +264 -0
  4. package/cjs/date-time-picker/config/useControlledDateTimePicker.js +37 -420
  5. package/cjs/date-time-picker/config/useGetDestructuredValues.js +25 -68
  6. package/cjs/date-time-picker/config/useGetFlags.js +173 -0
  7. package/cjs/date-time-picker/config/useGetPropsBasedOnType.js +101 -0
  8. package/cjs/date-time-picker/config/useGetPropsWithDefault.js +2 -3
  9. package/cjs/date-time-picker/config/useGetReferences.js +86 -0
  10. package/cjs/date-time-picker/config/useGlobalKeyHandlers.js +106 -0
  11. package/cjs/date-time-picker/config/useRelevantValueFromProps.js +39 -0
  12. package/cjs/date-time-picker/config/useValidateProps.js +47 -42
  13. package/cjs/date-time-picker/parts/ClearButton/ClearButton.js +20 -8
  14. package/cjs/date-time-picker/parts/ControlledDateTimePickerContent.js +14 -12
  15. package/cjs/date-time-picker/parts/DateInputs/useDateInputs.js +5 -5
  16. package/cjs/date-time-picker/parts/Pickers/Calendar/Calendar.js +11 -13
  17. package/cjs/date-time-picker/parts/Pickers/Calendar/CalendarContent.js +4 -1
  18. package/cjs/date-time-picker/parts/Pickers/Calendar/CalendarContext.js +1 -49
  19. package/cjs/date-time-picker/parts/Pickers/Calendar/CalendarDaysList.js +4 -4
  20. package/cjs/date-time-picker/parts/Pickers/Calendar/CalendarHead.js +10 -7
  21. package/cjs/date-time-picker/parts/Pickers/Calendar/CalendarIconTrigger.js +8 -4
  22. package/cjs/date-time-picker/parts/Pickers/Calendar/CalendarMonthDays.js +5 -2
  23. package/cjs/date-time-picker/parts/Pickers/Calendar/CalendarWrapper.js +5 -2
  24. package/cjs/date-time-picker/parts/Pickers/Calendar/Day.js +18 -18
  25. package/cjs/date-time-picker/parts/Pickers/Calendar/useConfigCalendarCTX.js +24 -122
  26. package/cjs/date-time-picker/parts/Pickers/Calendar/useCurrentDisplayedMonthYearLogic.js +32 -4
  27. package/cjs/date-time-picker/parts/Pickers/Calendar/useFocusLogic.js +10 -6
  28. package/cjs/date-time-picker/parts/Pickers/Calendar/useKeyboardHandlers.js +30 -14
  29. package/cjs/date-time-picker/parts/Pickers/Calendar/usePopperTriggerLogic.js +7 -4
  30. package/cjs/date-time-picker/parts/Pickers/CalendarWithTimeWheel/CalendarWithTimeWheel.js +7 -3
  31. package/cjs/date-time-picker/parts/Pickers/CalendarWithTimeWheel/CalendarWithTimeWheelContext.js +1 -16
  32. package/cjs/date-time-picker/parts/Pickers/CalendarWithTimeWheel/CalendarWithTimeWheelIconTrigger.js +0 -1
  33. package/cjs/date-time-picker/parts/Pickers/CalendarWithTimeWheel/useConfigCalendarWithTimeWheelCTX.js +10 -10
  34. package/cjs/date-time-picker/parts/Pickers/TimeWheel/HoursList.js +18 -13
  35. package/cjs/date-time-picker/parts/Pickers/TimeWheel/MeridiemList.js +60 -33
  36. package/cjs/date-time-picker/parts/Pickers/TimeWheel/MinutesList.js +18 -13
  37. package/cjs/date-time-picker/parts/Pickers/TimeWheel/TimeWheel.js +11 -13
  38. package/cjs/date-time-picker/parts/Pickers/TimeWheel/TimeWheelContent.js +5 -2
  39. package/cjs/date-time-picker/parts/Pickers/TimeWheel/TimeWheelContext.js +1 -65
  40. package/cjs/date-time-picker/parts/Pickers/TimeWheel/TimeWheelIconTrigger.js +8 -3
  41. package/cjs/date-time-picker/parts/Pickers/TimeWheel/TimeWheelWrapper.js +5 -2
  42. package/cjs/date-time-picker/parts/Pickers/TimeWheel/useConfigTimePickerCTX.js +18 -116
  43. package/cjs/date-time-picker/parts/Pickers/TimeWheel/useCurrentDisplayedWheelsLogic.js +52 -94
  44. package/cjs/date-time-picker/parts/Pickers/TimeWheel/useKeyboardHandlers.js +4 -1
  45. package/cjs/date-time-picker/parts/Pickers/TimeWheel/usePopperTriggerLogic.js +1 -1
  46. package/cjs/date-time-picker/parts/TimeInputs/HHInput.js +1 -3
  47. package/cjs/date-time-picker/parts/TimeInputs/MeridiemInput.js +1 -1
  48. package/cjs/date-time-picker/parts/TimeInputs/TimeInputs.js +3 -7
  49. package/cjs/date-time-picker/parts/TimeInputs/useTimeInputs.js +3 -6
  50. package/cjs/date-time-picker/propTypes.js +56 -23
  51. package/cjs/date-time-picker/sharedTypes.js +2 -0
  52. package/cjs/date-time-picker/utils/dateHelpers.js +56 -56
  53. package/cjs/date-time-picker/utils/hooks/useGetMonthYearFromDateStringOrEmptyStartingMonth.js +2 -5
  54. package/cjs/date-time-picker/utils/hooks/useGetStartingFocusedDay.js +50 -47
  55. package/cjs/date-time-picker/utils/hooks/useOnClickOutside.js +1 -2
  56. package/cjs/date-time-picker/utils/stringHelpers.js +8 -14
  57. package/cjs/date-time-picker/utils/typeGuards.js +14 -0
  58. package/esm/date-time-picker/ControlledDateTimePickerCTX.js +3 -115
  59. package/esm/date-time-picker/ControlledDateTimePickerDatatestid.js +0 -2
  60. package/esm/date-time-picker/config/useChangeHandlers.js +256 -0
  61. package/esm/date-time-picker/config/useControlledDateTimePicker.js +38 -421
  62. package/esm/date-time-picker/config/useGetDestructuredValues.js +21 -68
  63. package/esm/date-time-picker/config/useGetFlags.js +165 -0
  64. package/esm/date-time-picker/config/useGetPropsBasedOnType.js +97 -0
  65. package/esm/date-time-picker/config/useGetPropsWithDefault.js +1 -2
  66. package/esm/date-time-picker/config/useGetReferences.js +82 -0
  67. package/esm/date-time-picker/config/useGlobalKeyHandlers.js +98 -0
  68. package/esm/date-time-picker/config/useRelevantValueFromProps.js +35 -0
  69. package/esm/date-time-picker/config/useValidateProps.js +47 -42
  70. package/esm/date-time-picker/parts/ClearButton/ClearButton.js +20 -9
  71. package/esm/date-time-picker/parts/ControlledDateTimePickerContent.js +14 -12
  72. package/esm/date-time-picker/parts/DateInputs/useDateInputs.js +5 -5
  73. package/esm/date-time-picker/parts/Pickers/Calendar/Calendar.js +11 -13
  74. package/esm/date-time-picker/parts/Pickers/Calendar/CalendarContent.js +4 -1
  75. package/esm/date-time-picker/parts/Pickers/Calendar/CalendarContext.js +2 -50
  76. package/esm/date-time-picker/parts/Pickers/Calendar/CalendarDaysList.js +4 -4
  77. package/esm/date-time-picker/parts/Pickers/Calendar/CalendarHead.js +10 -7
  78. package/esm/date-time-picker/parts/Pickers/Calendar/CalendarIconTrigger.js +9 -5
  79. package/esm/date-time-picker/parts/Pickers/Calendar/CalendarMonthDays.js +5 -2
  80. package/esm/date-time-picker/parts/Pickers/Calendar/CalendarWrapper.js +5 -2
  81. package/esm/date-time-picker/parts/Pickers/Calendar/Day.js +18 -18
  82. package/esm/date-time-picker/parts/Pickers/Calendar/useConfigCalendarCTX.js +23 -125
  83. package/esm/date-time-picker/parts/Pickers/Calendar/useCurrentDisplayedMonthYearLogic.js +33 -5
  84. package/esm/date-time-picker/parts/Pickers/Calendar/useFocusLogic.js +10 -6
  85. package/esm/date-time-picker/parts/Pickers/Calendar/useKeyboardHandlers.js +30 -14
  86. package/esm/date-time-picker/parts/Pickers/Calendar/usePopperTriggerLogic.js +7 -4
  87. package/esm/date-time-picker/parts/Pickers/CalendarWithTimeWheel/CalendarWithTimeWheel.js +9 -5
  88. package/esm/date-time-picker/parts/Pickers/CalendarWithTimeWheel/CalendarWithTimeWheelContext.js +1 -16
  89. package/esm/date-time-picker/parts/Pickers/CalendarWithTimeWheel/CalendarWithTimeWheelIconTrigger.js +1 -2
  90. package/esm/date-time-picker/parts/Pickers/CalendarWithTimeWheel/useConfigCalendarWithTimeWheelCTX.js +10 -10
  91. package/esm/date-time-picker/parts/Pickers/TimeWheel/HoursList.js +18 -13
  92. package/esm/date-time-picker/parts/Pickers/TimeWheel/MeridiemList.js +59 -33
  93. package/esm/date-time-picker/parts/Pickers/TimeWheel/MinutesList.js +18 -13
  94. package/esm/date-time-picker/parts/Pickers/TimeWheel/TimeWheel.js +11 -13
  95. package/esm/date-time-picker/parts/Pickers/TimeWheel/TimeWheelContent.js +5 -2
  96. package/esm/date-time-picker/parts/Pickers/TimeWheel/TimeWheelContext.js +2 -66
  97. package/esm/date-time-picker/parts/Pickers/TimeWheel/TimeWheelIconTrigger.js +8 -3
  98. package/esm/date-time-picker/parts/Pickers/TimeWheel/TimeWheelWrapper.js +5 -2
  99. package/esm/date-time-picker/parts/Pickers/TimeWheel/useConfigTimePickerCTX.js +15 -117
  100. package/esm/date-time-picker/parts/Pickers/TimeWheel/useCurrentDisplayedWheelsLogic.js +54 -96
  101. package/esm/date-time-picker/parts/Pickers/TimeWheel/useKeyboardHandlers.js +4 -1
  102. package/esm/date-time-picker/parts/Pickers/TimeWheel/usePopperTriggerLogic.js +1 -1
  103. package/esm/date-time-picker/parts/TimeInputs/HHInput.js +1 -3
  104. package/esm/date-time-picker/parts/TimeInputs/MeridiemInput.js +1 -1
  105. package/esm/date-time-picker/parts/TimeInputs/TimeInputs.js +3 -7
  106. package/esm/date-time-picker/parts/TimeInputs/useTimeInputs.js +3 -6
  107. package/esm/date-time-picker/propTypes.js +49 -17
  108. package/esm/date-time-picker/sharedTypes.js +1 -0
  109. package/esm/date-time-picker/utils/dateHelpers.js +57 -57
  110. package/esm/date-time-picker/utils/hooks/useGetMonthYearFromDateStringOrEmptyStartingMonth.js +2 -5
  111. package/esm/date-time-picker/utils/hooks/useGetStartingFocusedDay.js +46 -47
  112. package/esm/date-time-picker/utils/hooks/useOnClickOutside.js +1 -2
  113. package/esm/date-time-picker/utils/stringHelpers.js +8 -14
  114. package/esm/date-time-picker/utils/typeGuards.js +8 -0
  115. package/package.json +47 -15
  116. package/types/date-time-picker/ControlledDateTimePicker.d.ts +25 -80
  117. package/types/date-time-picker/ControlledDateTimePickerCTX.d.ts +1 -2
  118. package/types/date-time-picker/ControlledDateTimePickerDatatestid.d.ts +46 -46
  119. package/types/date-time-picker/ControlledDateTimePickerTypes.d.ts +15 -15
  120. package/types/date-time-picker/config/useChangeHandlers.d.ts +25 -0
  121. package/types/date-time-picker/config/useControlledDateTimePicker.d.ts +18 -2
  122. package/types/date-time-picker/config/useGetDestructuredValues.d.ts +30 -4
  123. package/types/date-time-picker/config/useGetFlags.d.ts +27 -0
  124. package/types/date-time-picker/config/useGetPropsBasedOnType.d.ts +28 -0
  125. package/types/date-time-picker/config/useGetPropsWithDefault.d.ts +2 -2
  126. package/types/date-time-picker/config/useGetReferences.d.ts +39 -0
  127. package/types/date-time-picker/config/useGlobalKeyHandlers.d.ts +16 -0
  128. package/types/date-time-picker/config/useRelevantValueFromProps.d.ts +10 -0
  129. package/types/date-time-picker/config/useValidateProps.d.ts +2 -2
  130. package/types/date-time-picker/parts/ClearButton/useClearButton.d.ts +6 -6
  131. package/types/date-time-picker/parts/DateInputs/DDInput.d.ts +6 -6
  132. package/types/date-time-picker/parts/DateInputs/MMInput.d.ts +6 -6
  133. package/types/date-time-picker/parts/DateInputs/YYYYInput.d.ts +6 -6
  134. package/types/date-time-picker/parts/DateInputs/useDateInputs.d.ts +2 -2
  135. package/types/date-time-picker/parts/Pickers/Calendar/Calendar.d.ts +4 -2
  136. package/types/date-time-picker/parts/Pickers/Calendar/CalendarContext.d.ts +3 -63
  137. package/types/date-time-picker/parts/Pickers/Calendar/CalendarDaysList.d.ts +4 -4
  138. package/types/date-time-picker/parts/Pickers/Calendar/CalendarFooter.d.ts +2 -2
  139. package/types/date-time-picker/parts/Pickers/Calendar/Day.d.ts +2 -2
  140. package/types/date-time-picker/parts/Pickers/Calendar/useCurrentDisplayedMonthYearLogic.d.ts +15 -2
  141. package/types/date-time-picker/parts/Pickers/Calendar/useFocusLogic.d.ts +12 -5
  142. package/types/date-time-picker/parts/Pickers/Calendar/useKeyboardHandlers.d.ts +17 -11
  143. package/types/date-time-picker/parts/Pickers/CalendarWithTimeWheel/CalendarWithTimeWheelContext.d.ts +1 -16
  144. package/types/date-time-picker/parts/Pickers/CalendarWithTimeWheel/CalendarWithTimeWheelFooter.d.ts +2 -2
  145. package/types/date-time-picker/parts/Pickers/CalendarWithTimeWheel/useConfigCalendarWithTimeWheelCTX.d.ts +15 -1
  146. package/types/date-time-picker/parts/Pickers/TimeWheel/TimeWheel.d.ts +4 -2
  147. package/types/date-time-picker/parts/Pickers/TimeWheel/TimeWheelContext.d.ts +3 -62
  148. package/types/date-time-picker/parts/Pickers/TimeWheel/TimeWheelFooter.d.ts +2 -2
  149. package/types/date-time-picker/parts/Pickers/TimeWheel/useConfigTimePickerCTX.d.ts +4 -1
  150. package/types/date-time-picker/parts/Pickers/TimeWheel/useCurrentDisplayedWheelsLogic.d.ts +16 -5
  151. package/types/date-time-picker/parts/Pickers/TimeWheel/useKeyboardHandlers.d.ts +18 -3
  152. package/types/date-time-picker/parts/TimeInputs/HHInput.d.ts +6 -6
  153. package/types/date-time-picker/parts/TimeInputs/MeridiemInput.d.ts +6 -6
  154. package/types/date-time-picker/parts/TimeInputs/MinutesInput.d.ts +6 -6
  155. package/types/date-time-picker/parts/TimeInputs/useTimeInputs.d.ts +22 -2
  156. package/types/date-time-picker/parts/config.d.ts +3 -3
  157. package/types/date-time-picker/sharedTypes.d.ts +94 -0
  158. package/types/date-time-picker/utils/constants.d.ts +33 -33
  159. package/types/date-time-picker/utils/dateHelpers.d.ts +15 -14
  160. package/types/date-time-picker/utils/dateTimeHelpers.d.ts +3 -3
  161. package/types/date-time-picker/utils/hooks/useGetDayFromDateString.d.ts +1 -1
  162. package/types/date-time-picker/utils/hooks/useGetMonthYearFromDateStringOrEmptyStartingMonth.d.ts +2 -2
  163. package/types/date-time-picker/utils/hooks/useGetStartingFocusedDay.d.ts +6 -6
  164. package/types/date-time-picker/utils/hooks/useOnClickOutside.d.ts +1 -1
  165. package/types/date-time-picker/utils/timeHelpers.d.ts +2 -2
  166. package/types/date-time-picker/utils/typeGuards.d.ts +4 -0
  167. package/types/date-time-picker/parts/Pickers/Calendar/useConfigCalendarCTX.d.ts +0 -2
  168. package/types/date-time-picker/parts/Pickers/Calendar/usePopperTriggerLogic.d.ts +0 -12
  169. package/types/date-time-picker/parts/Pickers/TimeWheel/usePopperTriggerLogic.d.ts +0 -2
  170. package/types/date-time-picker/propTypes.d.ts +0 -81
@@ -0,0 +1,165 @@
1
+ import 'core-js/modules/esnext.async-iterator.filter.js';
2
+ import 'core-js/modules/esnext.iterator.constructor.js';
3
+ import 'core-js/modules/esnext.iterator.filter.js';
4
+ import 'core-js/modules/esnext.async-iterator.for-each.js';
5
+ import 'core-js/modules/esnext.iterator.for-each.js';
6
+ import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
7
+ import { useMemo } from 'react';
8
+ import { CONTROLLED_DATE_TIME_PICKER_TYPES } from '../ControlledDateTimePickerTypes.js';
9
+ import { getIsDateTime, getIsDate } from '../utils/typeGuards.js';
10
+
11
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
12
+
13
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
14
+
15
+ const getDateTimeFlags = props => {
16
+ const {
17
+ type,
18
+ isClearable,
19
+ dateTime,
20
+ autoFocus
21
+ } = props;
22
+ const constants = {
23
+ hideDatePicker: true,
24
+ hideTimePicker: true,
25
+ isDateSelector: false,
26
+ isTimeSelector: false,
27
+ isDateTimeSelector: true,
28
+ isWithDateInputsOnly: false,
29
+ isWithTimeInputsOnly: false,
30
+ autoFocusHourInput: false,
31
+ autoFocusHourTimeWheel: false
32
+ };
33
+ const withAnyInputs = type === CONTROLLED_DATE_TIME_PICKER_TYPES.DATE_TIME.FULL || type === CONTROLLED_DATE_TIME_PICKER_TYPES.DATE_TIME.INPUTS;
34
+ const hideDateTimePicker = type !== CONTROLLED_DATE_TIME_PICKER_TYPES.DATE_TIME.FULL && type !== CONTROLLED_DATE_TIME_PICKER_TYPES.DATE_TIME.PICKER && type !== CONTROLLED_DATE_TIME_PICKER_TYPES.DATE_TIME.CONTROLLER_ONLY;
35
+ const isControllerOnly = type === CONTROLLED_DATE_TIME_PICKER_TYPES.DATE_TIME.CONTROLLER_ONLY;
36
+ const withAnyPicker = !hideDateTimePicker;
37
+ const withClearBtn = withAnyInputs && isClearable && dateTime !== '' && dateTime !== '__/__/____ __:__ __';
38
+ const shouldPreserveClearableSpace = isClearable && withAnyInputs;
39
+
40
+ const finalFlags = _objectSpread({
41
+ hideDate: !withAnyInputs,
42
+ hideTime: !withAnyInputs,
43
+ hideDateTimePicker,
44
+ isControllerOnly,
45
+ isWithTimeWheelToo: !hideDateTimePicker,
46
+ isWithCalendarToo: !hideDateTimePicker,
47
+ withAnyInputs,
48
+ withAnyPicker,
49
+ withClearBtn,
50
+ isWithDateInputs: withAnyInputs,
51
+ isWithTimeInputs: withAnyInputs,
52
+ autoFocusMonthInput: withAnyInputs && autoFocus,
53
+ autoFocusPrevMonthArrow: isControllerOnly && autoFocus,
54
+ shouldPreserveClearableSpace,
55
+ withAnyRightController: withAnyPicker || withClearBtn || shouldPreserveClearableSpace
56
+ }, constants);
57
+
58
+ return finalFlags;
59
+ };
60
+
61
+ const getDateFlags = props => {
62
+ const {
63
+ type,
64
+ isClearable,
65
+ date,
66
+ autoFocus
67
+ } = props;
68
+ const constants = {
69
+ isDateSelector: true,
70
+ hideTime: true,
71
+ hideDateTimePicker: true,
72
+ hideTimePicker: true,
73
+ isTimeSelector: false,
74
+ isDateTimeSelector: false,
75
+ isWithCalendarToo: false,
76
+ isWithTimeWheelToo: false,
77
+ isWithTimeInputs: false,
78
+ isWithTimeInputsOnly: false,
79
+ autoFocusHourTimeWheel: false,
80
+ autoFocusHourInput: false
81
+ };
82
+ const withAnyInputs = type === CONTROLLED_DATE_TIME_PICKER_TYPES.DATE.FULL || type === CONTROLLED_DATE_TIME_PICKER_TYPES.DATE.INPUTS;
83
+ const hideDatePicker = type !== CONTROLLED_DATE_TIME_PICKER_TYPES.DATE.FULL && type !== CONTROLLED_DATE_TIME_PICKER_TYPES.DATE.PICKER && type !== CONTROLLED_DATE_TIME_PICKER_TYPES.DATE.CONTROLLER_ONLY;
84
+ const isControllerOnly = type === CONTROLLED_DATE_TIME_PICKER_TYPES.DATE.CONTROLLER_ONLY;
85
+ const withAnyPicker = !hideDatePicker;
86
+ const withClearBtn = withAnyInputs && isClearable && date !== '' && date !== '__/__/____';
87
+ const shouldPreserveClearableSpace = isClearable && withAnyInputs;
88
+
89
+ const finalFlags = _objectSpread({
90
+ hideDate: !withAnyInputs,
91
+ hideDatePicker,
92
+ isControllerOnly,
93
+ withAnyInputs,
94
+ withAnyPicker,
95
+ withClearBtn,
96
+ isWithDateInputs: withAnyInputs,
97
+ isWithDateInputsOnly: withAnyInputs,
98
+ autoFocusMonthInput: withAnyInputs && autoFocus,
99
+ autoFocusPrevMonthArrow: isControllerOnly && autoFocus,
100
+ shouldPreserveClearableSpace,
101
+ withAnyRightController: withAnyPicker || withClearBtn || shouldPreserveClearableSpace
102
+ }, constants);
103
+
104
+ return finalFlags;
105
+ };
106
+
107
+ const getTimeFlags = props => {
108
+ const {
109
+ type,
110
+ isClearable,
111
+ time,
112
+ autoFocus
113
+ } = props;
114
+ const constants = {
115
+ hideDate: true,
116
+ hideDateTimePicker: true,
117
+ hideDatePicker: true,
118
+ isDateSelector: false,
119
+ isDateTimeSelector: false,
120
+ isWithDateInputs: false,
121
+ isWithDateInputsOnly: false,
122
+ isTimeSelector: true,
123
+ isWithTimeWheelToo: false,
124
+ isWithCalendarToo: false,
125
+ autoFocusMonthInput: false,
126
+ autoFocusPrevMonthArrow: false
127
+ };
128
+ const withAnyInputs = type === CONTROLLED_DATE_TIME_PICKER_TYPES.TIME.FULL || type === CONTROLLED_DATE_TIME_PICKER_TYPES.TIME.INPUTS;
129
+ const hideTimePicker = type !== CONTROLLED_DATE_TIME_PICKER_TYPES.TIME.FULL && type !== CONTROLLED_DATE_TIME_PICKER_TYPES.TIME.PICKER && type !== CONTROLLED_DATE_TIME_PICKER_TYPES.TIME.CONTROLLER_ONLY;
130
+ const isControllerOnly = type === CONTROLLED_DATE_TIME_PICKER_TYPES.TIME.CONTROLLER_ONLY;
131
+ const withClearBtn = withAnyInputs && isClearable && time !== '' && time !== '__:__ __';
132
+ const shouldPreserveClearableSpace = isClearable && withAnyInputs;
133
+ const withAnyPicker = !hideTimePicker;
134
+
135
+ const finalFlags = _objectSpread({
136
+ hideTime: !withAnyInputs,
137
+ hideTimePicker,
138
+ isControllerOnly,
139
+ withAnyInputs,
140
+ withAnyPicker,
141
+ withClearBtn,
142
+ isWithTimeInputs: withAnyInputs,
143
+ isWithTimeInputsOnly: withAnyInputs,
144
+ autoFocusHourInput: withAnyInputs && autoFocus,
145
+ autoFocusHourTimeWheel: isControllerOnly && autoFocus,
146
+ shouldPreserveClearableSpace,
147
+ withAnyRightController: withAnyPicker || withClearBtn || shouldPreserveClearableSpace
148
+ }, constants);
149
+
150
+ return finalFlags;
151
+ };
152
+
153
+ const useGetFlags = props => useMemo(() => {
154
+ if (getIsDateTime(props)) {
155
+ return getDateTimeFlags(props);
156
+ }
157
+
158
+ if (getIsDate(props)) {
159
+ return getDateFlags(props);
160
+ }
161
+
162
+ return getTimeFlags(props);
163
+ }, [props]);
164
+
165
+ export { useGetFlags };
@@ -0,0 +1,97 @@
1
+ import { useMemo } from 'react';
2
+ import { getIsDateTime, getIsDate, getIsTime } from '../utils/typeGuards.js';
3
+
4
+ /* eslint-disable max-lines */
5
+
6
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
7
+ const noop = () => {};
8
+
9
+ const defaultReturnFalse = () => false;
10
+
11
+ const useGetPropsBasedOnType = propsWithDefaults => {
12
+ const isDateTime = getIsDateTime(propsWithDefaults);
13
+ const isDate = getIsDate(propsWithDefaults);
14
+ const isTime = getIsTime(propsWithDefaults);
15
+ /* -------------------------- -------------- --------------------------*/
16
+
17
+ /* -------------------------- DATE OPTIONALS --------------------------*/
18
+
19
+ /* -------------------------- -------------- --------------------------*/
20
+
21
+ const getIsDisabledDay = (isDateTime || isDate) && propsWithDefaults.getIsDisabledDay ? propsWithDefaults.getIsDisabledDay : defaultReturnFalse;
22
+ const getIsOutOfRangeDay = (isDateTime || isDate) && propsWithDefaults.getIsOutOfRangeDay ? propsWithDefaults.getIsOutOfRangeDay : defaultReturnFalse;
23
+ const appOnMonthChange = (isDateTime || isDate) && propsWithDefaults.onMonthChange ? propsWithDefaults.onMonthChange : noop;
24
+ const appOnDayChange = (isDateTime || isDate) && propsWithDefaults.onDayChange ? propsWithDefaults.onDayChange : noop;
25
+ const appOnYearChange = (isDateTime || isDate) && propsWithDefaults.onYearChange ? propsWithDefaults.onYearChange : noop;
26
+ const emptyPickerStartingMonthDefault = "".concat(new Date().getMonth() + 1, "/__/").concat(new Date().getFullYear());
27
+ const emptyPickerStartingMonth = (isDateTime || isDate) && propsWithDefaults.emptyPickerStartingMonth ? propsWithDefaults.emptyPickerStartingMonth : emptyPickerStartingMonthDefault;
28
+ const onCalendarOpenFocusedDay = (isDateTime || isDate) && propsWithDefaults.onCalendarOpenFocusedDay ? propsWithDefaults.onCalendarOpenFocusedDay : undefined;
29
+ /* -------------------------- -------------- --------------------------*/
30
+
31
+ /* -------------------------- TIME OPTIONALS --------------------------*/
32
+
33
+ /* -------------------------- -------------- --------------------------*/
34
+
35
+ const getIsDisabledTime = (isDateTime || isTime) && propsWithDefaults.getIsDisabledTime ? propsWithDefaults.getIsDisabledTime : defaultReturnFalse;
36
+ const appOnHourChange = (isDateTime || isTime) && propsWithDefaults.onHourChange ? propsWithDefaults.onHourChange : noop;
37
+ const appOnMinuteChange = (isDateTime || isTime) && propsWithDefaults.onMinuteChange ? propsWithDefaults.onMinuteChange : noop;
38
+ const appOnMeridiemChange = (isDateTime || isTime) && propsWithDefaults.onMeridiemChange ? propsWithDefaults.onMeridiemChange : noop;
39
+ const minutesInterval = (isDateTime || isTime) && propsWithDefaults.minutesInterval ? propsWithDefaults.minutesInterval : 1;
40
+ const onTimeWheelOpenStartingTime = (isDateTime || isTime) && propsWithDefaults.onTimeWheelOpenStartingTime ? propsWithDefaults.onTimeWheelOpenStartingTime : '01:00 AM';
41
+ /* --------- ------------------------------------ ---------------------*/
42
+
43
+ /* --------- SPECIFIC REQUIRED DATETIME OPTIONALS ---------------------*/
44
+
45
+ /* --------- ------------------------------------ ---------------------*/
46
+
47
+ const appOnDateChange = (isDateTime || isDate) && propsWithDefaults.onDateChange ? propsWithDefaults.onDateChange : noop;
48
+ const appOnTimeChange = (isDateTime || isTime) && propsWithDefaults.onTimeChange ? propsWithDefaults.onTimeChange : noop;
49
+ /* ---------------------- ---------------------- ----------------------*/
50
+
51
+ /* ---------------------- DATE-RELATED OPTIONALS ----------------------*/
52
+
53
+ /* ---------------------- ---------------------- ----------------------*/
54
+
55
+ const getIsStartRangeDay = (isDateTime || isDate) && propsWithDefaults.getIsStartRangeDay ? propsWithDefaults.getIsStartRangeDay : noop;
56
+ const getIsDayInRange = (isDateTime || isDate) && propsWithDefaults.getIsDayInRange ? propsWithDefaults.getIsDayInRange : noop;
57
+ const getIsEndRangeDay = (isDateTime || isDate) && propsWithDefaults.getIsEndRangeDay ? propsWithDefaults.getIsEndRangeDay : noop;
58
+ /* --------------------- ----------------------- ------------------------*/
59
+
60
+ /* --------------------- TYPE SPECIFIC REQUIREDS ------------------------*/
61
+
62
+ /* --------------------- ----------------------- ------------------------*/
63
+
64
+ const appDate = isDate ? propsWithDefaults.date : '';
65
+ const appTime = isTime ? propsWithDefaults.time : '';
66
+ const appDateTime = isDateTime ? propsWithDefaults.dateTime : '';
67
+ const appOnDateTimeChange = isDateTime ? propsWithDefaults.onDateTimeChange : noop;
68
+ return useMemo(() => ({
69
+ getIsDisabledDay,
70
+ getIsOutOfRangeDay,
71
+ getIsStartRangeDay,
72
+ getIsDayInRange,
73
+ getIsEndRangeDay,
74
+ appOnDateChange,
75
+ appOnMonthChange,
76
+ appOnDayChange,
77
+ appOnYearChange,
78
+ appDate,
79
+ getIsDisabledTime,
80
+ appOnTimeChange,
81
+ appOnHourChange,
82
+ appOnMinuteChange,
83
+ appOnMeridiemChange,
84
+ appTime,
85
+ appDateTime,
86
+ appOnDateTimeChange,
87
+ emptyPickerStartingMonth,
88
+ onCalendarOpenFocusedDay,
89
+ minutesInterval,
90
+ onTimeWheelOpenStartingTime,
91
+ isDate,
92
+ isTime,
93
+ isDateTime
94
+ }), [getIsDisabledDay, getIsOutOfRangeDay, getIsStartRangeDay, getIsDayInRange, getIsEndRangeDay, appOnDateChange, appOnMonthChange, appOnDayChange, appOnYearChange, appDate, getIsDisabledTime, appOnTimeChange, appOnHourChange, appOnMinuteChange, appOnMeridiemChange, appTime, appDateTime, appOnDateTimeChange, emptyPickerStartingMonth, onCalendarOpenFocusedDay, minutesInterval, onTimeWheelOpenStartingTime, isDate, isTime, isDateTime]);
95
+ };
96
+
97
+ export { useGetPropsBasedOnType };
@@ -1,7 +1,6 @@
1
1
  import { useMemoMergePropsWithDefault } from '@elliemae/ds-props-helpers';
2
- import { defaultProps } from '../ControlledDateTimePickerCTX.js';
2
+ import { defaultProps } from '../propTypes.js';
3
3
 
4
- // we have to merge the "default" nested default values with what the user gives us...
5
4
  const useGetDatePickerWithDefaultsProps = props => useMemoMergePropsWithDefault(props, defaultProps);
6
5
 
7
6
  export { useGetDatePickerWithDefaultsProps };
@@ -0,0 +1,82 @@
1
+ import { useRef, useMemo } from 'react';
2
+
3
+ /* eslint-disable complexity */
4
+ const useGetReferences = _ref => {
5
+ let {
6
+ isWithDateInputs,
7
+ isWithTimeInputs,
8
+ withAnyPicker,
9
+ withClearBtn
10
+ } = _ref;
11
+ // refs are used for "auto-advance" feature
12
+ const monthInputRef = useRef(null);
13
+ const dayInputRef = useRef(null);
14
+ const yearInputRef = useRef(null);
15
+ const hourInputRef = useRef(null);
16
+ const minutesInputRef = useRef(null);
17
+ const meridiemInputRef = useRef(null);
18
+ const clearButtonRef = useRef(null);
19
+ const pickerButtonRef = useRef(null);
20
+ const prevYearBtnRef = useRef(null);
21
+ const prevMonthBtnRef = useRef(null);
22
+ const nextMonthBtnRef = useRef(null);
23
+ const nextYearBtnRef = useRef(null);
24
+ const calendarDaysWrapperRef = useRef(null);
25
+ const prevHourBtnRef = useRef(null);
26
+ const currHourBtnRef = useRef(null);
27
+ const nextHourBtnRef = useRef(null);
28
+ const prevMinutesBtnRef = useRef(null);
29
+ const currMinutesBtnRef = useRef(null);
30
+ const nextMinutesBtnRef = useRef(null);
31
+ const prevMeridiemBtnRef = useRef(null);
32
+ const currMeridiemBtnRef = useRef(null);
33
+ const nextMeridiemBtnRef = useRef(null);
34
+ let firstSegmentRef = useRef(null);
35
+ if (isWithDateInputs) firstSegmentRef = monthInputRef;else if (isWithTimeInputs) firstSegmentRef = hourInputRef;else if (withAnyPicker) firstSegmentRef = pickerButtonRef; // we need some non-ref to force refresh of the hooks dependencies when using firstSegmentRef
36
+
37
+ const firstFragmentRefUpdateDeps = useMemo(() => ({
38
+ isWithDateInputs,
39
+ isWithTimeInputs,
40
+ withAnyPicker
41
+ }), [isWithDateInputs, isWithTimeInputs, withAnyPicker]);
42
+ let lastSegmentRef = useRef(null);
43
+ if (withAnyPicker) lastSegmentRef = pickerButtonRef;else if (withClearBtn) lastSegmentRef = clearButtonRef;else if (isWithTimeInputs) lastSegmentRef = meridiemInputRef;else if (isWithDateInputs) lastSegmentRef = yearInputRef; // we need some non-ref to force refresh of the hooks dependencies when using lastSegmentRef
44
+
45
+ const lastFragmentRefUpdateDeps = useMemo(() => ({
46
+ withAnyPicker,
47
+ withClearBtn,
48
+ isWithTimeInputs,
49
+ isWithDateInputs
50
+ }), [isWithDateInputs, isWithTimeInputs, withAnyPicker, withClearBtn]);
51
+ return useMemo(() => ({
52
+ monthInputRef,
53
+ dayInputRef,
54
+ yearInputRef,
55
+ hourInputRef,
56
+ minutesInputRef,
57
+ meridiemInputRef,
58
+ clearButtonRef,
59
+ pickerButtonRef,
60
+ prevYearBtnRef,
61
+ prevMonthBtnRef,
62
+ nextMonthBtnRef,
63
+ nextYearBtnRef,
64
+ calendarDaysWrapperRef,
65
+ prevHourBtnRef,
66
+ currHourBtnRef,
67
+ nextHourBtnRef,
68
+ prevMinutesBtnRef,
69
+ currMinutesBtnRef,
70
+ nextMinutesBtnRef,
71
+ prevMeridiemBtnRef,
72
+ currMeridiemBtnRef,
73
+ nextMeridiemBtnRef,
74
+ firstSegmentRef,
75
+ lastSegmentRef,
76
+ firstFragmentRefUpdateDeps,
77
+ lastFragmentRefUpdateDeps
78
+ }), [firstFragmentRefUpdateDeps, lastFragmentRefUpdateDeps] // if we remove this last/first segment won't work
79
+ );
80
+ };
81
+
82
+ export { useGetReferences };
@@ -0,0 +1,98 @@
1
+ import 'core-js/modules/esnext.async-iterator.filter.js';
2
+ import 'core-js/modules/esnext.iterator.constructor.js';
3
+ import 'core-js/modules/esnext.iterator.filter.js';
4
+ import 'core-js/modules/esnext.async-iterator.for-each.js';
5
+ import 'core-js/modules/esnext.iterator.for-each.js';
6
+ import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
7
+ import { useCallback, useMemo } from 'react';
8
+ import { getDateStringFromDay, getTimeStringFromDay, getValidationDateStringMetaInfo } from '../utils/dateHelpers.js';
9
+ import { getValidationTimeStringMetaInfo } from '../utils/timeHelpers.js';
10
+ import { deconstructValuesFromDateString, deconstructValuesFromTimeString } from '../utils/stringHelpers.js';
11
+
12
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
13
+
14
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
15
+ const useGlobalKeyHandlers = _ref => {
16
+ let {
17
+ propsBasedOnType,
18
+ changeHandlers,
19
+ DOMRefs,
20
+ flags
21
+ } = _ref;
22
+ const {
23
+ getIsOutOfRangeDay,
24
+ getIsDisabledDay,
25
+ getIsDisabledTime,
26
+ appOnMonthChange,
27
+ appOnDayChange,
28
+ appOnYearChange,
29
+ appOnHourChange,
30
+ appOnMinuteChange,
31
+ appOnMeridiemChange
32
+ } = propsBasedOnType;
33
+ const {
34
+ handleChangeComposedDateTimeString,
35
+ handleClearAll
36
+ } = changeHandlers;
37
+ const {
38
+ lastSegmentRef,
39
+ clearButtonRef
40
+ } = DOMRefs;
41
+ const {
42
+ shouldPreserveClearableSpace
43
+ } = flags;
44
+ const onFillWithCurrentDateKeys = useCallback(function (e) {
45
+ let metaInfo = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
46
+ isAutomaticFillTrigger: true
47
+ };
48
+ const now = new Date();
49
+ const nowDateString = getDateStringFromDay(now);
50
+ const nowTimeString = getTimeStringFromDay(now);
51
+
52
+ const finalMetaInfo = _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, metaInfo), getValidationDateStringMetaInfo(nowDateString, getIsOutOfRangeDay, getIsDisabledDay)), getValidationTimeStringMetaInfo(nowTimeString, getIsDisabledTime)), {}, {
53
+ newDateString: nowDateString
54
+ });
55
+
56
+ const {
57
+ month,
58
+ day,
59
+ year
60
+ } = deconstructValuesFromDateString(nowDateString);
61
+ appOnMonthChange(month, e, metaInfo);
62
+ appOnDayChange(day, e, metaInfo);
63
+ appOnYearChange(year, e, metaInfo);
64
+ const {
65
+ hours,
66
+ minutes,
67
+ meridiem
68
+ } = deconstructValuesFromTimeString(nowTimeString);
69
+ appOnHourChange(hours, e, metaInfo);
70
+ appOnMinuteChange(minutes, e, metaInfo);
71
+ appOnMeridiemChange(meridiem, e, metaInfo);
72
+ handleChangeComposedDateTimeString(nowDateString, nowTimeString, finalMetaInfo);
73
+ setTimeout(() => {
74
+ var _clearButtonRef$curre, _lastSegmentRef$curre;
75
+
76
+ if (shouldPreserveClearableSpace) (_clearButtonRef$curre = clearButtonRef.current) === null || _clearButtonRef$curre === void 0 ? void 0 : _clearButtonRef$curre.focus();else (_lastSegmentRef$curre = lastSegmentRef.current) === null || _lastSegmentRef$curre === void 0 ? void 0 : _lastSegmentRef$curre.focus();
77
+ });
78
+ }, [appOnDayChange, appOnHourChange, appOnMeridiemChange, appOnMinuteChange, appOnMonthChange, appOnYearChange, clearButtonRef, getIsDisabledDay, getIsDisabledTime, getIsOutOfRangeDay, handleChangeComposedDateTimeString, lastSegmentRef, shouldPreserveClearableSpace]);
79
+ const onGlobalKeyDown = useCallback(e => {
80
+ const {
81
+ key,
82
+ ctrlKey,
83
+ metaKey
84
+ } = e;
85
+
86
+ if ((ctrlKey || metaKey) && key === ';') {
87
+ onFillWithCurrentDateKeys(e);
88
+ }
89
+
90
+ if ((ctrlKey || metaKey) && (key === 'Delete' || key === 'Backspace')) handleClearAll(e);
91
+ }, [handleClearAll, onFillWithCurrentDateKeys]);
92
+ return useMemo(() => ({
93
+ onFillWithCurrentDateKeys,
94
+ onGlobalKeyDown
95
+ }), [onFillWithCurrentDateKeys, onGlobalKeyDown]);
96
+ };
97
+
98
+ export { useGlobalKeyHandlers };
@@ -0,0 +1,35 @@
1
+ import 'core-js/modules/web.dom-collections.iterator.js';
2
+ import { useMemo, useState } from 'react';
3
+ import { getIsDateTime, getIsDate, getIsTime } from '../utils/typeGuards.js';
4
+ import { dateTimeToDate, dateTimeToTime } from '../utils/stringHelpers.js';
5
+
6
+ const useRelevantValueFromProps = props => {
7
+ const dateStringFromProps = useMemo(() => {
8
+ if (getIsDateTime(props)) return props.dateTime !== '' ? dateTimeToDate(props.dateTime) : '__/__/____';
9
+ if (getIsDate(props)) return props.date !== '' ? props.date : '__/__/____';
10
+ return '__/__/____';
11
+ }, [props]);
12
+ const timeStringFromProps = useMemo(() => {
13
+ if (getIsDateTime(props)) return props.dateTime !== '' ? dateTimeToTime(props.dateTime) : '__:__ __';
14
+ if (getIsTime(props)) return props.time !== '' ? props.time : '__:__ __';
15
+ return '__:__ __';
16
+ }, [props]); // don't use tempDateString to trigger useEffect for onDateChange
17
+ // that is an anti-pattern and leads to a lot of issue
18
+ // if you don't believe me, check date-time-picker v1 which is doing it
19
+
20
+ const [tempDateString, setTempDateString] = useState(dateStringFromProps); // don't use tempTimeString to trigger useEffect for onTimeChange
21
+ // that is an anti-pattern and leads to a lot of issue
22
+ // if you don't believe me, check date-time-picker v1 which is doing it
23
+
24
+ const [tempTimeString, setTimeString] = useState(timeStringFromProps);
25
+ return useMemo(() => ({
26
+ dateStringFromProps,
27
+ timeStringFromProps,
28
+ tempDateString,
29
+ setTempDateString,
30
+ tempTimeString,
31
+ setTimeString
32
+ }), [dateStringFromProps, tempDateString, tempTimeString, timeStringFromProps]);
33
+ };
34
+
35
+ export { useRelevantValueFromProps };
@@ -1,8 +1,8 @@
1
- import { CONTROLLED_DATE_TIME_PICKER_TYPES } from '../ControlledDateTimePickerTypes.js';
2
1
  import { deconstructValuesFromDateString, isValidDateString, dateTimeToDate, isValidTimeString, dateTimeToTime } from '../utils/stringHelpers.js';
3
2
  import { convertToPositiveNumberIfPossible } from '../utils/numberHelpers.js';
3
+ import { getIsDateTime, getIsDate, getIsTime } from '../utils/typeGuards.js';
4
4
 
5
- /* eslint-disable max-len */
5
+ /* eslint-disable max-statements */
6
6
  const PREPEND = "ControlledDateTimePicker:\n Invalid configuration detected::\n \n ";
7
7
  const NOT_A_DEFECT = ''; // '\n\n\t\tThis is not a defect, please check\n\n\t\thttps://qa.dimsum.rd.elliemae.io/?path=/story/components-desktop-components-d-controlledform-date-time-picker--basic\n\n\t\tfor instructions on how to use the component correctly\n\n';
8
8
 
@@ -21,15 +21,15 @@ const throwInvalidTimerror = invalidValue => {
21
21
  };
22
22
 
23
23
  const throwUncontrolledDateError = (date, onDateChange) => {
24
- throw new Error("".concat(PREPEND, "you are trying to use a date selector while providing a non-string \"date\" or providing a non-function to \"onDateChange\"\n the full-controlled pattern must be used\n\tcheck https://reactjs.org/docs/forms.html#controlled-components for more informations\n\n Received:\n ").concat(date, "(").concat(typeof date, ")\n ").concat(onDateChange, "(").concat(typeof onDateChange, ")\n ").concat(NOT_A_DEFECT));
24
+ throw new Error("".concat(PREPEND, "you are trying to use a date selector while providing a non-string \"date\" or providing a non-function to \"onDateChange\"\n the full-controlled pattern must be used\n\tcheck https://reactjs.org/docs/forms.html#controlled-components for more informations\n\n Received:\n date: ").concat(date, "(").concat(typeof date, ")\n onDateChange: (").concat(typeof onDateChange, ")\n ").concat(NOT_A_DEFECT));
25
25
  };
26
26
 
27
27
  const throwUncontrolledTimeError = (time, onTimeChange) => {
28
- throw new Error("".concat(PREPEND, "you are trying to use a time selector while providing a non-string \"time\" or providing a non-function to \"onTimeChange\"\n the full-controlled pattern must be used\n\tcheck https://reactjs.org/docs/forms.html#controlled-components for more informations\n\n Received:\n ").concat(time, "(").concat(typeof time, ")\n ").concat(onTimeChange, "(").concat(typeof onTimeChange, ")\n ").concat(NOT_A_DEFECT));
28
+ throw new Error("".concat(PREPEND, "you are trying to use a time selector while providing a non-string \"time\" or providing a non-function to \"onTimeChange\"\n the full-controlled pattern must be used\n\tcheck https://reactjs.org/docs/forms.html#controlled-components for more informations\n\n Received:\n time: ").concat(time, "(").concat(typeof time, ")\n onTimeChange: (").concat(typeof onTimeChange, ")\n ").concat(NOT_A_DEFECT));
29
29
  };
30
30
 
31
31
  const throwUncontrolledDateTimeError = (dateTime, onDateTimeChange) => {
32
- throw new Error("".concat(PREPEND, "you are trying to use a date-time selector while providing a non-string \"dateTime\" or providing a non-function to \"onDateTimeChange\"\n the full-controlled pattern must be used\n\tcheck https://reactjs.org/docs/forms.html#controlled-components for more informations\n\n Received:\n ").concat(dateTime, "(").concat(typeof dateTime, ")\n ").concat(onDateTimeChange, "(").concat(typeof onDateTimeChange, ")\n ").concat(NOT_A_DEFECT));
32
+ throw new Error("".concat(PREPEND, "you are trying to use a date-time selector while providing a non-string \"dateTime\" or providing a non-function to \"onDateTimeChange\"\n the full-controlled pattern must be used\n\tcheck https://reactjs.org/docs/forms.html#controlled-components for more informations\n\n Received:\n dateTime: ").concat(dateTime, "(").concat(typeof dateTime, ")\n onDateTimeChange: (").concat(typeof onDateTimeChange, ")\n ").concat(NOT_A_DEFECT));
33
33
  };
34
34
 
35
35
  const throwInvalidEmptyPickerStartingMonthError = emptyPickerStartingMonth => {
@@ -41,55 +41,60 @@ const throwInvalidOnCalendarOpenFocusedDayError = onCalendarOpenFocusedDay => {
41
41
  };
42
42
 
43
43
  const useValidateProps = props => {
44
- const {
45
- type,
46
- dateTime,
47
- date,
48
- time,
49
- onDateChange,
50
- onTimeChange,
51
- onDateTimeChange,
52
- emptyPickerStartingMonth,
53
- onCalendarOpenFocusedDay
54
- } = props;
55
- const isDateSelector = type === CONTROLLED_DATE_TIME_PICKER_TYPES.DATE.FULL || type === CONTROLLED_DATE_TIME_PICKER_TYPES.DATE.INPUTS || type === CONTROLLED_DATE_TIME_PICKER_TYPES.DATE.PICKER;
56
- const isTimeSelector = type === CONTROLLED_DATE_TIME_PICKER_TYPES.TIME.FULL || type === CONTROLLED_DATE_TIME_PICKER_TYPES.TIME.INPUTS || type === CONTROLLED_DATE_TIME_PICKER_TYPES.TIME.PICKER;
57
- const isDateTimeSelector = type === CONTROLLED_DATE_TIME_PICKER_TYPES.DATE_TIME.FULL || type === CONTROLLED_DATE_TIME_PICKER_TYPES.DATE_TIME.INPUTS || type === CONTROLLED_DATE_TIME_PICKER_TYPES.DATE_TIME.PICKER; // validate generic use-cases
58
-
59
- if (emptyPickerStartingMonth) {
44
+ // validate date-related props
45
+ if (getIsDateTime(props) || getIsDate(props)) {
60
46
  const {
61
- month: stringMonthVal,
62
- year: stringYearVal
63
- } = deconstructValuesFromDateString(emptyPickerStartingMonth);
64
- const monthNum = convertToPositiveNumberIfPossible(stringMonthVal);
65
- const yearNum = convertToPositiveNumberIfPossible(stringYearVal);
66
- if (monthNum <= 0 || monthNum >= 13 || yearNum <= 0 || yearNum > 9999) throwInvalidEmptyPickerStartingMonthError(emptyPickerStartingMonth);
67
- }
68
-
69
- if (onCalendarOpenFocusedDay) {
70
- const {
71
- month: stringMonthVal,
72
- day: stringDayVal,
73
- year: stringYearVal
74
- } = deconstructValuesFromDateString(onCalendarOpenFocusedDay);
75
- const monthNum = convertToPositiveNumberIfPossible(stringMonthVal);
76
- const dayNum = convertToPositiveNumberIfPossible(stringDayVal);
77
- const yearNum = convertToPositiveNumberIfPossible(stringYearVal);
78
- if (monthNum <= 0 || monthNum >= 13 || dayNum <= 0 || dayNum >= 31 || yearNum <= 0 || yearNum > 9999) throwInvalidOnCalendarOpenFocusedDayError(onCalendarOpenFocusedDay);
47
+ emptyPickerStartingMonth,
48
+ onCalendarOpenFocusedDay
49
+ } = props; // validate generic use-cases
50
+
51
+ if (emptyPickerStartingMonth) {
52
+ const {
53
+ month: stringMonthVal,
54
+ year: stringYearVal
55
+ } = deconstructValuesFromDateString(emptyPickerStartingMonth);
56
+ const monthNum = convertToPositiveNumberIfPossible(stringMonthVal);
57
+ const yearNum = convertToPositiveNumberIfPossible(stringYearVal);
58
+ if (monthNum <= 0 || monthNum >= 13 || yearNum <= 0 || yearNum > 9999) throwInvalidEmptyPickerStartingMonthError(emptyPickerStartingMonth);
59
+ }
60
+
61
+ if (onCalendarOpenFocusedDay) {
62
+ const {
63
+ month: stringMonthVal,
64
+ day: stringDayVal,
65
+ year: stringYearVal
66
+ } = deconstructValuesFromDateString(onCalendarOpenFocusedDay);
67
+ const monthNum = convertToPositiveNumberIfPossible(stringMonthVal);
68
+ const dayNum = convertToPositiveNumberIfPossible(stringDayVal);
69
+ const yearNum = convertToPositiveNumberIfPossible(stringYearVal);
70
+ if (monthNum <= 0 || monthNum >= 13 || dayNum <= 0 || dayNum >= 31 || yearNum <= 0 || yearNum > 9999) throwInvalidOnCalendarOpenFocusedDayError(onCalendarOpenFocusedDay);
71
+ }
79
72
  } // validate full datetime cases
80
73
 
81
74
 
82
- if (isDateTimeSelector) {
75
+ if (getIsDateTime(props)) {
76
+ const {
77
+ dateTime,
78
+ onDateTimeChange
79
+ } = props;
83
80
  if (typeof dateTime !== 'string' || typeof onDateTimeChange !== 'function') throwUncontrolledDateTimeError(dateTime, onDateTimeChange);else if (!isValidDateString(dateTimeToDate(dateTime)) || !isValidTimeString(dateTimeToTime(dateTime))) throwInvalidDateTimeError(dateTimeToTime(dateTime));
84
81
  } // validate date-only cases
85
82
 
86
83
 
87
- if (isDateSelector) {
84
+ if (getIsDate(props)) {
85
+ const {
86
+ date,
87
+ onDateChange
88
+ } = props;
88
89
  if (typeof date !== 'string' || typeof onDateChange !== 'function') throwUncontrolledDateError(date, onDateChange);else if (!isValidDateString(date)) throwInvalidDaterror(date);
89
90
  } // validate time-only cases
90
91
 
91
92
 
92
- if (isTimeSelector) {
93
+ if (getIsTime(props)) {
94
+ const {
95
+ time,
96
+ onTimeChange
97
+ } = props;
93
98
  if (typeof time !== 'string' || typeof onTimeChange !== 'function') throwUncontrolledTimeError(time, onTimeChange);else if (!isValidTimeString(time)) throwInvalidTimerror(time);
94
99
  }
95
100
  };