@zohodesk/components 1.2.4 → 1.2.6

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 (202) hide show
  1. package/README.md +8 -0
  2. package/coverage/Button/Button.js.html +1 -1
  3. package/coverage/Button/css/Button.module.css.html +1 -1
  4. package/coverage/Button/css/cssJSLogic.js.html +1 -1
  5. package/coverage/Button/css/index.html +1 -1
  6. package/coverage/Button/index.html +1 -1
  7. package/coverage/Button/props/defaultProps.js.html +1 -1
  8. package/coverage/Button/props/index.html +1 -1
  9. package/coverage/Button/props/propTypes.js.html +1 -1
  10. package/coverage/Buttongroup/Buttongroup.js.html +1 -1
  11. package/coverage/Buttongroup/Buttongroup.module.css.html +1 -1
  12. package/coverage/Buttongroup/index.html +1 -1
  13. package/coverage/Buttongroup/props/defaultProps.js.html +1 -1
  14. package/coverage/Buttongroup/props/index.html +1 -1
  15. package/coverage/Buttongroup/props/propTypes.js.html +1 -1
  16. package/coverage/index.html +1 -1
  17. package/coverage/utils/dummyFunction.js.html +1 -1
  18. package/coverage/utils/index.html +1 -1
  19. package/es/AppContainer/AppContainer.js +3 -0
  20. package/es/v1/Accordion/Accordion.js +65 -0
  21. package/es/v1/Accordion/AccordionItem.js +57 -0
  22. package/es/v1/Accordion/index.js +2 -0
  23. package/es/v1/Animation/Animation.js +127 -0
  24. package/es/v1/AppContainer/AppContainer.js +137 -0
  25. package/es/v1/Avatar/Avatar.js +189 -0
  26. package/es/v1/AvatarTeam/AvatarTeam.js +70 -0
  27. package/es/v1/Button/Button.js +68 -0
  28. package/es/v1/Buttongroup/Buttongroup.js +31 -0
  29. package/es/v1/Card/Card.js +271 -0
  30. package/es/v1/CheckBox/CheckBox.js +155 -0
  31. package/es/v1/DateTime/CalendarView.js +218 -0
  32. package/es/v1/DateTime/DateTime.js +783 -0
  33. package/es/v1/DateTime/DateTimePopupFooter.js +47 -0
  34. package/es/v1/DateTime/DateTimePopupHeader.js +105 -0
  35. package/es/v1/DateTime/DateWidget.js +1098 -0
  36. package/es/v1/DateTime/DaysRow.js +31 -0
  37. package/es/v1/DateTime/Time.js +166 -0
  38. package/es/v1/DateTime/YearView.js +264 -0
  39. package/es/v1/DateTime/index.js +1 -0
  40. package/es/v1/DropBox/DropBox.js +91 -0
  41. package/es/v1/DropBox/DropBoxElement/DropBoxElement.js +132 -0
  42. package/es/v1/DropDown/DropDown.js +73 -0
  43. package/es/v1/DropDown/DropDownHeading.js +44 -0
  44. package/es/v1/DropDown/DropDownItem.js +76 -0
  45. package/es/v1/DropDown/DropDownSearch.js +63 -0
  46. package/es/v1/DropDown/DropDownSeparator.js +15 -0
  47. package/es/v1/Heading/Heading.js +32 -0
  48. package/es/v1/Label/Label.js +40 -0
  49. package/es/v1/Layout/Box.js +115 -0
  50. package/es/v1/Layout/Container.js +132 -0
  51. package/es/v1/Layout/index.js +2 -0
  52. package/es/v1/ListItem/ListContainer.js +102 -0
  53. package/es/v1/ListItem/ListItem.js +124 -0
  54. package/es/v1/ListItem/ListItemWithAvatar.js +145 -0
  55. package/es/v1/ListItem/ListItemWithCheckBox.js +104 -0
  56. package/es/v1/ListItem/ListItemWithIcon.js +127 -0
  57. package/es/v1/ListItem/ListItemWithRadio.js +105 -0
  58. package/es/v1/ListItem/index.js +6 -0
  59. package/es/v1/Modal/Modal.js +154 -0
  60. package/es/v1/MultiSelect/AdvancedGroupMultiSelect.js +1079 -0
  61. package/es/v1/MultiSelect/AdvancedMultiSelect.js +568 -0
  62. package/es/v1/MultiSelect/EmptyState.js +64 -0
  63. package/es/v1/MultiSelect/MobileHeader/MobileHeader.js +50 -0
  64. package/es/v1/MultiSelect/MultiSelect.js +1120 -0
  65. package/es/v1/MultiSelect/MultiSelectHeader.js +32 -0
  66. package/es/v1/MultiSelect/MultiSelectWithAvatar.js +216 -0
  67. package/es/v1/MultiSelect/SelectedOptions.js +82 -0
  68. package/es/v1/MultiSelect/Suggestions.js +142 -0
  69. package/es/v1/MultiSelect/index.js +4 -0
  70. package/es/v1/PopOver/PopOver.js +211 -0
  71. package/es/v1/Popup/Popup.js +645 -0
  72. package/es/v1/Radio/Radio.js +115 -0
  73. package/es/v1/Responsive/CustomResponsive.js +195 -0
  74. package/es/v1/Responsive/RefWrapper.js +39 -0
  75. package/es/v1/Responsive/ResizeComponent.js +197 -0
  76. package/es/v1/Responsive/ResizeObserver.js +140 -0
  77. package/es/v1/Responsive/Responsive.js +194 -0
  78. package/es/v1/Responsive/index.js +9 -0
  79. package/es/v1/ResponsiveDropBox/ResponsiveDropBox.js +58 -0
  80. package/es/v1/Ribbon/Ribbon.js +33 -0
  81. package/es/v1/RippleEffect/RippleEffect.js +24 -0
  82. package/es/v1/Select/GroupSelect.js +803 -0
  83. package/es/v1/Select/Select.js +969 -0
  84. package/es/v1/Select/SelectWithAvatar.js +344 -0
  85. package/es/v1/Select/SelectWithIcon.js +535 -0
  86. package/es/v1/Select/index.js +4 -0
  87. package/es/v1/Stencils/Stencils.js +26 -0
  88. package/es/v1/Switch/Switch.js +94 -0
  89. package/es/v1/Tab/Tab.js +108 -0
  90. package/es/v1/Tab/TabContent.js +30 -0
  91. package/es/v1/Tab/TabContentWrapper.js +29 -0
  92. package/es/v1/Tab/TabWrapper.js +57 -0
  93. package/es/v1/Tab/Tabs.js +612 -0
  94. package/es/v1/Tab/index.js +5 -0
  95. package/es/v1/Tag/Tag.js +134 -0
  96. package/es/v1/TextBox/TextBox.js +154 -0
  97. package/es/v1/TextBoxIcon/TextBoxIcon.js +158 -0
  98. package/es/v1/Textarea/Textarea.js +102 -0
  99. package/es/v1/Tooltip/Tooltip.js +518 -0
  100. package/es/v1/Typography/Typography.js +38 -0
  101. package/es/v1/Typography/css/Typography.module.css +376 -0
  102. package/es/v1/Typography/css/cssJSLogic.js +46 -0
  103. package/es/v1/Typography/css/letterSpacingMap.js +12 -0
  104. package/es/v1/Typography/props/defaultProps.js +8 -0
  105. package/es/v1/Typography/props/propTypes.js +24 -0
  106. package/es/v1/VelocityAnimation/VelocityAnimation/VelocityAnimation.js +69 -0
  107. package/es/v1/VelocityAnimation/VelocityAnimationGroup/VelocityAnimationGroup.js +100 -0
  108. package/es/v1/semantic/Button/Button.js +53 -0
  109. package/es/v1/semantic/index.js +1 -0
  110. package/lib/AppContainer/AppContainer.js +5 -0
  111. package/lib/v1/Accordion/Accordion.js +96 -0
  112. package/lib/v1/Accordion/AccordionItem.js +68 -0
  113. package/lib/v1/Accordion/index.js +23 -0
  114. package/lib/v1/Animation/Animation.js +143 -0
  115. package/lib/v1/AppContainer/AppContainer.js +209 -0
  116. package/lib/v1/Avatar/Avatar.js +246 -0
  117. package/lib/v1/AvatarTeam/AvatarTeam.js +81 -0
  118. package/lib/v1/Button/Button.js +82 -0
  119. package/lib/v1/Buttongroup/Buttongroup.js +44 -0
  120. package/lib/v1/Card/Card.js +365 -0
  121. package/lib/v1/CheckBox/CheckBox.js +166 -0
  122. package/lib/v1/DateTime/CalendarView.js +285 -0
  123. package/lib/v1/DateTime/DateTime.js +872 -0
  124. package/lib/v1/DateTime/DateTimePopupFooter.js +96 -0
  125. package/lib/v1/DateTime/DateTimePopupHeader.js +166 -0
  126. package/lib/v1/DateTime/DateWidget.js +1125 -0
  127. package/lib/v1/DateTime/DaysRow.js +80 -0
  128. package/lib/v1/DateTime/Time.js +254 -0
  129. package/lib/v1/DateTime/YearView.js +325 -0
  130. package/lib/v1/DateTime/index.js +15 -0
  131. package/lib/v1/DropBox/DropBox.js +119 -0
  132. package/lib/v1/DropBox/DropBoxElement/DropBoxElement.js +145 -0
  133. package/lib/v1/DropDown/DropDown.js +170 -0
  134. package/lib/v1/DropDown/DropDownHeading.js +93 -0
  135. package/lib/v1/DropDown/DropDownItem.js +127 -0
  136. package/lib/v1/DropDown/DropDownSearch.js +113 -0
  137. package/lib/v1/DropDown/DropDownSeparator.js +64 -0
  138. package/lib/v1/Heading/Heading.js +49 -0
  139. package/lib/v1/Label/Label.js +51 -0
  140. package/lib/v1/Layout/Box.js +128 -0
  141. package/lib/v1/Layout/Container.js +145 -0
  142. package/lib/v1/Layout/index.js +23 -0
  143. package/lib/v1/ListItem/ListContainer.js +120 -0
  144. package/lib/v1/ListItem/ListItem.js +138 -0
  145. package/lib/v1/ListItem/ListItemWithAvatar.js +162 -0
  146. package/lib/v1/ListItem/ListItemWithCheckBox.js +125 -0
  147. package/lib/v1/ListItem/ListItemWithIcon.js +143 -0
  148. package/lib/v1/ListItem/ListItemWithRadio.js +126 -0
  149. package/lib/v1/ListItem/index.js +55 -0
  150. package/lib/v1/Modal/Modal.js +212 -0
  151. package/lib/v1/MultiSelect/AdvancedGroupMultiSelect.js +1167 -0
  152. package/lib/v1/MultiSelect/AdvancedMultiSelect.js +634 -0
  153. package/lib/v1/MultiSelect/EmptyState.js +112 -0
  154. package/lib/v1/MultiSelect/MobileHeader/MobileHeader.js +62 -0
  155. package/lib/v1/MultiSelect/MultiSelect.js +1201 -0
  156. package/lib/v1/MultiSelect/MultiSelectHeader.js +78 -0
  157. package/lib/v1/MultiSelect/MultiSelectWithAvatar.js +270 -0
  158. package/lib/v1/MultiSelect/SelectedOptions.js +126 -0
  159. package/lib/v1/MultiSelect/Suggestions.js +195 -0
  160. package/lib/v1/MultiSelect/index.js +39 -0
  161. package/lib/v1/PopOver/PopOver.js +293 -0
  162. package/lib/v1/Popup/Popup.js +715 -0
  163. package/lib/v1/Radio/Radio.js +126 -0
  164. package/lib/v1/Responsive/CustomResponsive.js +242 -0
  165. package/lib/v1/Responsive/RefWrapper.js +57 -0
  166. package/lib/v1/Responsive/ResizeComponent.js +268 -0
  167. package/lib/v1/Responsive/ResizeObserver.js +168 -0
  168. package/lib/v1/Responsive/Responsive.js +274 -0
  169. package/lib/v1/Responsive/index.js +55 -0
  170. package/lib/v1/ResponsiveDropBox/ResponsiveDropBox.js +79 -0
  171. package/lib/v1/Ribbon/Ribbon.js +44 -0
  172. package/lib/v1/RippleEffect/RippleEffect.js +39 -0
  173. package/lib/v1/Select/GroupSelect.js +877 -0
  174. package/lib/v1/Select/Select.js +1013 -0
  175. package/lib/v1/Select/SelectWithAvatar.js +394 -0
  176. package/lib/v1/Select/SelectWithIcon.js +597 -0
  177. package/lib/v1/Select/index.js +39 -0
  178. package/lib/v1/Stencils/Stencils.js +43 -0
  179. package/lib/v1/Switch/Switch.js +108 -0
  180. package/lib/v1/Tab/Tab.js +132 -0
  181. package/lib/v1/Tab/TabContent.js +42 -0
  182. package/lib/v1/Tab/TabContentWrapper.js +42 -0
  183. package/lib/v1/Tab/TabWrapper.js +89 -0
  184. package/lib/v1/Tab/Tabs.js +680 -0
  185. package/lib/v1/Tab/index.js +47 -0
  186. package/lib/v1/Tag/Tag.js +154 -0
  187. package/lib/v1/TextBox/TextBox.js +168 -0
  188. package/lib/v1/TextBoxIcon/TextBoxIcon.js +196 -0
  189. package/lib/v1/Textarea/Textarea.js +118 -0
  190. package/lib/v1/Tooltip/Tooltip.js +586 -0
  191. package/lib/v1/Typography/Typography.js +56 -0
  192. package/lib/v1/Typography/css/Typography.module.css +376 -0
  193. package/lib/v1/Typography/css/cssJSLogic.js +41 -0
  194. package/lib/v1/Typography/css/letterSpacingMap.js +20 -0
  195. package/lib/v1/Typography/props/defaultProps.js +15 -0
  196. package/lib/v1/Typography/props/propTypes.js +35 -0
  197. package/lib/v1/VelocityAnimation/VelocityAnimation/VelocityAnimation.js +90 -0
  198. package/lib/v1/VelocityAnimation/VelocityAnimationGroup/VelocityAnimationGroup.js +126 -0
  199. package/lib/v1/semantic/Button/Button.js +63 -0
  200. package/lib/v1/semantic/index.js +15 -0
  201. package/package.json +1 -1
  202. package/result.json +1 -1
@@ -0,0 +1,783 @@
1
+ /* eslint css-modules/no-unused-class: [0, { markAsUsed: ['datesStr', 'dateContainer', 'dateRow', 'today', 'emptySpan', 'dropDown'] }] */
2
+
3
+ /* eslint-disable react/forbid-component-props */
4
+ import React from 'react';
5
+ import { DateTime_propTypes } from '../../DateTime/props/propTypes';
6
+ import { DateTime_defaultProps } from '../../DateTime/props/defaultProps';
7
+ import datetime from '@zohodesk/datetimejs';
8
+ import CalendarView from './CalendarView';
9
+ import YearView from './YearView';
10
+ import DateTimePopupHeader from './DateTimePopupHeader';
11
+ import DateTimePopupFooter from './DateTimePopupFooter';
12
+ import Time from './Time';
13
+ import style from '../../DateTime/DateTime.module.css';
14
+ import { formatDate, getMonthEnd } from '../../utils/datetime/common';
15
+ import { getIsEmptyValue } from '../../utils/Common';
16
+ import { monthNamesDefault, monthNamesShortDefault, dayNamesDefault, dayNamesShortDefault, ampmTextDefault } from '../../DateTime/constants';
17
+ import ResponsiveDropBox from '../ResponsiveDropBox/ResponsiveDropBox';
18
+ import { Box } from '../Layout';
19
+ import { getHourSuggestions, getMinuteSuggestions, addZeroIfNeeded } from '../../DateTime/dateFormatUtils';
20
+
21
+ function title(date, year, month) {
22
+ let monthNames = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
23
+ const HeadingText = `${monthNames[month] || ''} ${year}`;
24
+ return HeadingText;
25
+ }
26
+
27
+ export default class DateTime extends React.PureComponent {
28
+ constructor(props) {
29
+ super(props);
30
+ this.getHours = this.getHours.bind(this);
31
+ this.amPmSelect = this.amPmSelect.bind(this);
32
+ this.hoursSelect = this.hoursSelect.bind(this);
33
+ this.dateSelect = this.dateSelect.bind(this);
34
+ this.handleClear = this.handleClear.bind(this);
35
+ this.handleSelect = this.handleSelect.bind(this);
36
+ this.minutesSelect = this.minutesSelect.bind(this);
37
+ this.modifyCalendar = this.modifyCalendar.bind(this);
38
+ this.handleGetSelectedDate = this.handleGetSelectedDate.bind(this);
39
+ this.handleChange = this.handleChange.bind(this);
40
+ this.handleCalendarNavigation = this.handleCalendarNavigation.bind(this);
41
+ this.handleExposeMethods = this.handleExposeMethods.bind(this);
42
+ this.handleDateReset = this.handleDateReset.bind(this);
43
+ this.handleOpenYearView = this.handleOpenYearView.bind(this);
44
+ this.handleSelectMonth = this.handleSelectMonth.bind(this);
45
+ this.handleSelectYear = this.handleSelectYear.bind(this);
46
+ this.handleSelectMonthViaYearView = this.handleSelectMonthViaYearView.bind(this);
47
+ this.handleGetStateValues = this.handleGetStateValues.bind(this);
48
+ this.handleYearViewToggle = this.handleYearViewToggle.bind(this);
49
+ this.getInitialDate = this.getInitialDate.bind(this);
50
+ const {
51
+ ampmText = ampmTextDefault
52
+ } = props.i18nKeys;
53
+
54
+ this.ampmSuggestions = (() => {
55
+ const ampmSuggestions = [];
56
+ ampmText.forEach((text, index) => {
57
+ if (index === 0) {
58
+ ampmSuggestions.push({
59
+ text,
60
+ id: 'AM'
61
+ });
62
+ } else if (index === 1) {
63
+ ampmSuggestions.push({
64
+ text,
65
+ id: 'PM'
66
+ });
67
+ }
68
+ });
69
+ return ampmSuggestions;
70
+ })();
71
+
72
+ const initalStateObj = this.getStateFromProps(props);
73
+ this.state = Object.assign({}, initalStateObj, {
74
+ isYearView: false,
75
+ isMonthOpen: false
76
+ });
77
+ }
78
+
79
+ componentDidMount() {
80
+ this.handleExposeMethods(true);
81
+ }
82
+
83
+ componentDidUpdate(prevProps) {
84
+ const {
85
+ value,
86
+ isActive,
87
+ is24Hour
88
+ } = this.props;
89
+
90
+ if (prevProps.value !== value || is24Hour !== prevProps.is24Hour) {
91
+ this.setState(this.getStateFromProps(this.props));
92
+ }
93
+
94
+ if (prevProps.isActive !== isActive && !isActive) {
95
+ this.setState({
96
+ isYearView: false,
97
+ isMonthOpen: false
98
+ });
99
+ }
100
+ }
101
+
102
+ componentWillUnmount() {
103
+ this.handleExposeMethods(false);
104
+ }
105
+
106
+ getInitialDate(value) {
107
+ let timeZone = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
108
+ let isDateTime = arguments.length > 2 ? arguments[2] : undefined;
109
+ let result = null;
110
+
111
+ if (isDateTime) {
112
+ if (timeZone && value) {
113
+ result = datetime.toDate(datetime.tz.utcToTz(value, timeZone));
114
+ } else {
115
+ value = value ? value.replace('Z', '') : null;
116
+ result = value ? new Date(value) : new Date();
117
+ }
118
+ } else {
119
+ if (value) {
120
+ if (timeZone) {
121
+ result = datetime.toDate(value);
122
+ } else {
123
+ result = new Date(value);
124
+ }
125
+ } else {
126
+ result = new Date();
127
+ }
128
+ }
129
+
130
+ return result;
131
+ }
132
+
133
+ getStateFromProps(props) {
134
+ let date, month, year, hours, mins, amPm;
135
+ let {
136
+ value,
137
+ timeZone,
138
+ defaultTime,
139
+ needDefaultTime,
140
+ isDateTimeField,
141
+ is24Hour
142
+ } = props; //defaultTime --> 12:00:PM
143
+
144
+ defaultTime = needDefaultTime ? defaultTime ? defaultTime : '12:00:PM' : '';
145
+ let defaultHour, defaultMin, defaultAmPm;
146
+ let todayObj = new Date();
147
+ let todayDate = todayObj.getDate();
148
+ let todayMonth = todayObj.getMonth();
149
+ let todayYear = todayObj.getFullYear();
150
+
151
+ if (!value) {
152
+ [defaultHour, defaultMin, defaultAmPm] = defaultTime ? defaultTime.split(':') : [];
153
+ defaultHour = parseInt(defaultHour);
154
+ defaultMin = parseInt(defaultMin);
155
+ }
156
+
157
+ const dateObj = this.getInitialDate(value, timeZone, isDateTimeField);
158
+ date = dateObj.getDate();
159
+ month = dateObj.getMonth();
160
+ year = dateObj.getFullYear();
161
+ hours = defaultHour ? defaultHour : dateObj.getHours();
162
+ mins = !getIsEmptyValue(defaultMin) ? defaultMin : dateObj.getMinutes();
163
+ mins = addZeroIfNeeded(mins);
164
+ amPm = defaultAmPm ? defaultAmPm : hours < 12 ? 'AM' : 'PM';
165
+ hours = this.getHours(hours, is24Hour);
166
+ return {
167
+ date,
168
+ month,
169
+ year,
170
+ mins,
171
+ hours,
172
+ amPm,
173
+ todayDate,
174
+ todayMonth,
175
+ todayYear
176
+ };
177
+ }
178
+
179
+ getHours(hoursParam, is24Hour) {
180
+ let hours = hoursParam;
181
+
182
+ if (!is24Hour) {
183
+ if (hours === 0) {
184
+ hours = 12;
185
+ } else if (hours > 12) {
186
+ hours -= 12;
187
+ }
188
+ }
189
+
190
+ hours = addZeroIfNeeded(hours);
191
+ return hours;
192
+ }
193
+
194
+ handleGetSelectedDate() {
195
+ let selectedInfo = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
196
+ const {
197
+ min,
198
+ max,
199
+ timeZone,
200
+ isDateTimeField,
201
+ dateFormat,
202
+ is24Hour,
203
+ customDateFormat
204
+ } = this.props;
205
+ let {
206
+ year,
207
+ month,
208
+ date,
209
+ hours,
210
+ mins,
211
+ amPm
212
+ } = selectedInfo;
213
+
214
+ if (!is24Hour) {
215
+ if (parseInt(hours) === 12) {
216
+ hours = amPm === 'AM' ? 0 : 12;
217
+ }
218
+
219
+ if (amPm === 'PM') {
220
+ if (hours < 12) {
221
+ hours = parseInt(hours) + 12;
222
+ }
223
+ }
224
+ }
225
+
226
+ let minInMillis = min ? datetime.millis(min) : null,
227
+ maxInMillis = max ? datetime.millis(max) : null,
228
+ selectedInMillis,
229
+ selectedValue = '',
230
+ formattedValue;
231
+ let currentDate = new Date();
232
+ let sec = currentDate.getSeconds();
233
+ let milliSec = currentDate.getMilliseconds();
234
+
235
+ if (isDateTimeField || customDateFormat) {
236
+ const dateArgs = [year, month, date, hours, mins];
237
+
238
+ if (customDateFormat) {
239
+ dateArgs.push(sec, milliSec);
240
+ }
241
+
242
+ selectedInMillis = timeZone ? datetime.tz.tzToUtc(Date.UTC(...dateArgs), timeZone) : Date.UTC(...dateArgs);
243
+ selectedValue = datetime.ISO(selectedInMillis);
244
+ formattedValue = formatDate(new Date(...dateArgs), customDateFormat == null ? is24Hour ? `${dateFormat} HH:mm:ss` : `${dateFormat} hh:mm:ss A` : `${customDateFormat}`);
245
+ } else {
246
+ selectedInMillis = Date.UTC(year, month, date);
247
+ selectedValue = formatDate(new Date(year, month, date), 'YYYY-MM-DD');
248
+ formattedValue = formatDate(new Date(year, month, date), dateFormat);
249
+ }
250
+
251
+ let isError = false;
252
+ let errorType = '';
253
+
254
+ if (minInMillis && minInMillis > selectedInMillis) {
255
+ isError = true;
256
+ errorType = 'MIN';
257
+ } else if (maxInMillis && maxInMillis < selectedInMillis) {
258
+ isError = true;
259
+ errorType = 'MAX';
260
+ }
261
+
262
+ return {
263
+ isError,
264
+ errorType,
265
+ selectedValue,
266
+ formattedValue
267
+ };
268
+ }
269
+
270
+ handleSelect(e) {
271
+ e && e.preventDefault();
272
+ const {
273
+ onError,
274
+ onSelect,
275
+ minErrorText,
276
+ maxErrorText
277
+ } = this.props;
278
+ const {
279
+ year,
280
+ month,
281
+ date,
282
+ hours,
283
+ mins,
284
+ amPm
285
+ } = this.state;
286
+ const {
287
+ isError,
288
+ errorType,
289
+ selectedValue,
290
+ formattedValue
291
+ } = this.handleGetSelectedDate({
292
+ year,
293
+ month,
294
+ date,
295
+ hours,
296
+ mins,
297
+ amPm
298
+ });
299
+
300
+ if (isError) {
301
+ if (errorType === 'MIN') {
302
+ onError && onError(minErrorText, true);
303
+ } else if (errorType === 'MAX') {
304
+ onError && onError(maxErrorText, true);
305
+ }
306
+ } else {
307
+ onSelect(selectedValue, formattedValue, e);
308
+ }
309
+ }
310
+
311
+ handleChange() {
312
+ let selectedInfo = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
313
+ const {
314
+ onError,
315
+ onChange,
316
+ minErrorText,
317
+ maxErrorText
318
+ } = this.props;
319
+ const {
320
+ year: oldYear,
321
+ month: oldMonth,
322
+ date: oldDate,
323
+ hours: oldHours,
324
+ mins: oldMins,
325
+ amPm: oldAMPM
326
+ } = this.state;
327
+ const {
328
+ year,
329
+ month,
330
+ date,
331
+ hours,
332
+ mins,
333
+ amPm
334
+ } = selectedInfo;
335
+ const newSelectedInfo = {
336
+ year: getIsEmptyValue(year) ? oldYear : year,
337
+ month: getIsEmptyValue(month) ? oldMonth : month,
338
+ date: getIsEmptyValue(date) ? oldDate : date,
339
+ hours: getIsEmptyValue(hours) ? oldHours : hours,
340
+ mins: getIsEmptyValue(mins) ? oldMins : mins,
341
+ amPm: getIsEmptyValue(amPm) ? oldAMPM : amPm
342
+ };
343
+
344
+ if (onChange) {
345
+ const {
346
+ isError,
347
+ errorType,
348
+ selectedValue,
349
+ formattedValue
350
+ } = this.handleGetSelectedDate(newSelectedInfo);
351
+
352
+ if (isError) {
353
+ if (errorType === 'MIN') {
354
+ onError && onError(minErrorText, true);
355
+ } else if (errorType === 'MAX') {
356
+ onError && onError(maxErrorText, true);
357
+ }
358
+ } else {
359
+ this.setState(newSelectedInfo);
360
+ onChange(selectedValue, formattedValue);
361
+ }
362
+ } else {
363
+ this.setState(newSelectedInfo);
364
+ }
365
+ }
366
+
367
+ handleClear(e) {
368
+ const {
369
+ onSelect,
370
+ onClear
371
+ } = this.props;
372
+
373
+ if (onClear) {
374
+ onClear(e);
375
+ } else {
376
+ onSelect('', '', e);
377
+ }
378
+ }
379
+
380
+ dateSelect(date, month, year, e) {
381
+ this.handleChange({
382
+ date,
383
+ month,
384
+ year
385
+ });
386
+ e && e.preventDefault();
387
+ const {
388
+ onError,
389
+ onDateSelect,
390
+ minErrorText,
391
+ maxErrorText
392
+ } = this.props;
393
+ const {
394
+ hours,
395
+ mins,
396
+ amPm
397
+ } = this.state;
398
+ const {
399
+ isError,
400
+ errorType,
401
+ selectedValue,
402
+ formattedValue
403
+ } = this.handleGetSelectedDate({
404
+ year,
405
+ month,
406
+ date,
407
+ hours,
408
+ mins,
409
+ amPm
410
+ });
411
+
412
+ if (isError) {
413
+ if (errorType === 'MIN') {
414
+ onError && onError(minErrorText, true);
415
+ } else if (errorType === 'MAX') {
416
+ onError && onError(maxErrorText, true);
417
+ }
418
+ } else {
419
+ onDateSelect && onDateSelect(selectedValue, formattedValue, e);
420
+ }
421
+ }
422
+
423
+ hoursSelect(hours) {
424
+ this.handleChange({
425
+ hours
426
+ });
427
+ }
428
+
429
+ minutesSelect(mins) {
430
+ this.handleChange({
431
+ mins
432
+ });
433
+ }
434
+
435
+ amPmSelect(amPm) {
436
+ this.handleChange({
437
+ amPm
438
+ });
439
+ }
440
+ /*global closeGroupPopups*/
441
+
442
+
443
+ closePopup() {
444
+ closeGroupPopups('calender');
445
+ }
446
+
447
+ handleCalendarNavigation(type, selectedInfo) {
448
+ const {
449
+ year: stateYear,
450
+ month: stateMonth,
451
+ date: stateDate
452
+ } = selectedInfo;
453
+ let date = stateDate;
454
+ let month = stateMonth;
455
+ const year = stateYear;
456
+
457
+ const getDate = (month, year) => {
458
+ const monthEnd = getMonthEnd(month, year);
459
+ return monthEnd >= parseInt(date) ? date : monthEnd;
460
+ };
461
+
462
+ const modifyCalendarRecursion = recursionType => {
463
+ if (recursionType === 'nextYear') {
464
+ //Click next year icon
465
+ const newYear = year + 1;
466
+ return {
467
+ date: getDate(month, newYear),
468
+ month,
469
+ year: newYear
470
+ };
471
+ } else if (recursionType === 'previousYear') {
472
+ //Click previous year icon
473
+ const newYear = year - 1;
474
+ return {
475
+ date: getDate(month, newYear),
476
+ month,
477
+ year: newYear
478
+ };
479
+ } else if (recursionType === 'nextMonth') {
480
+ //Click next month icon
481
+ if (month === 11) {
482
+ month = 0;
483
+ return modifyCalendarRecursion('nextYear');
484
+ }
485
+
486
+ const newMonth = month + 1;
487
+ return {
488
+ date: getDate(newMonth, year),
489
+ month: newMonth,
490
+ year
491
+ };
492
+ } else if (recursionType === 'previousMonth') {
493
+ //Click previous month icon
494
+ if (month === 0) {
495
+ month = 11;
496
+ return modifyCalendarRecursion('previousYear');
497
+ }
498
+
499
+ const newMonth = month - 1;
500
+ return {
501
+ date: getDate(newMonth, year),
502
+ month: newMonth,
503
+ year
504
+ };
505
+ } else if (recursionType === 'nextDate') {
506
+ const monthEnd = getMonthEnd(month, year);
507
+
508
+ if (date === monthEnd) {
509
+ date = 1;
510
+ return modifyCalendarRecursion('nextMonth');
511
+ }
512
+
513
+ const newDate = parseInt(date) + 1;
514
+ return {
515
+ date: newDate,
516
+ month,
517
+ year
518
+ };
519
+ } else if (recursionType === 'previousDate') {
520
+ if (date === 1) {
521
+ date = month === 0 ? getMonthEnd(11, year - 1) : getMonthEnd(month - 1, year);
522
+ return modifyCalendarRecursion('previousMonth');
523
+ }
524
+
525
+ const newDate = parseInt(date) - 1;
526
+ return {
527
+ date: newDate,
528
+ month,
529
+ year
530
+ };
531
+ }
532
+ };
533
+
534
+ return modifyCalendarRecursion(type);
535
+ }
536
+
537
+ modifyCalendar(type) {
538
+ const {
539
+ year,
540
+ month,
541
+ date
542
+ } = this.state;
543
+ return this.handleChange(this.handleCalendarNavigation(type, {
544
+ year,
545
+ month,
546
+ date
547
+ }));
548
+ }
549
+
550
+ handleDateReset() {
551
+ this.setState(this.getStateFromProps(this.props));
552
+ }
553
+
554
+ handleGetStateValues() {
555
+ const {
556
+ isActive
557
+ } = this.props;
558
+ const {
559
+ isYearView,
560
+ isMonthOpen
561
+ } = this.state;
562
+ return {
563
+ isActive,
564
+ isYearView,
565
+ isMonthOpen
566
+ };
567
+ }
568
+
569
+ handleYearViewToggle(isYearOpen, isMonthOpen) {
570
+ this.setState({
571
+ isYearView: isYearOpen,
572
+ isMonthOpen
573
+ });
574
+ }
575
+
576
+ handleExposeMethods(isMount) {
577
+ const {
578
+ getMethods
579
+ } = this.props;
580
+ let methods = {};
581
+
582
+ if (isMount) {
583
+ methods = {
584
+ resetLocalDate: this.handleDateReset,
585
+ getStateValues: this.handleGetStateValues,
586
+ toggleYearView: this.handleYearViewToggle
587
+ };
588
+ } else {
589
+ methods = {
590
+ resetLocalDate: null,
591
+ getStateValues: null,
592
+ toggleYearView: null
593
+ };
594
+ }
595
+
596
+ getMethods && getMethods(methods);
597
+ }
598
+
599
+ handleOpenYearView() {
600
+ const {
601
+ isYearView,
602
+ isMonthOpen
603
+ } = this.state;
604
+ this.setState({
605
+ isYearView: !isYearView,
606
+ isMonthOpen: !isMonthOpen
607
+ });
608
+ }
609
+
610
+ handleSelectYear(year) {
611
+ this.setState({
612
+ year,
613
+ isMonthOpen: true
614
+ });
615
+ }
616
+
617
+ handleSelectMonth(month) {
618
+ const {
619
+ date,
620
+ year
621
+ } = this.state;
622
+ const monthEnd = getMonthEnd(month, year);
623
+ let newDate = date;
624
+
625
+ if (date > monthEnd) {
626
+ newDate = monthEnd;
627
+ }
628
+
629
+ this.setState({
630
+ month,
631
+ date: newDate
632
+ });
633
+ }
634
+
635
+ handleSelectMonthViaYearView(month) {
636
+ this.handleSelectMonth(month);
637
+ this.setState({
638
+ isYearView: false,
639
+ isMonthOpen: false
640
+ });
641
+ }
642
+
643
+ render() {
644
+ const {
645
+ date,
646
+ month,
647
+ year,
648
+ hours,
649
+ mins,
650
+ amPm,
651
+ isYearView,
652
+ isMonthOpen,
653
+ todayDate,
654
+ todayMonth,
655
+ todayYear
656
+ } = this.state;
657
+ const {
658
+ isDateTimeField,
659
+ isActive,
660
+ position,
661
+ isReady,
662
+ getRef,
663
+ onClick,
664
+ dataId,
665
+ needResponsive,
666
+ isAbsolute,
667
+ isAnimate,
668
+ needAction,
669
+ boxSize,
670
+ className,
671
+ innerClass,
672
+ isPadding,
673
+ i18nKeys,
674
+ is24Hour,
675
+ isDefaultPosition,
676
+ positionsOffset,
677
+ targetOffset,
678
+ isRestrictScroll,
679
+ dropBoxPortalId
680
+ } = this.props;
681
+ const {
682
+ timeText = 'Time',
683
+ submitText = 'Set',
684
+ cancelText = 'Clear',
685
+ hourEmptyText = 'No search results',
686
+ minuteEmptyText = 'No search results',
687
+ nextMonthTitleText = 'Next month',
688
+ prevMonthTitleText = 'Prev month',
689
+ monthNames = monthNamesDefault,
690
+ monthNamesShort = monthNamesShortDefault,
691
+ dayNames = dayNamesDefault,
692
+ dayNamesShort = dayNamesShortDefault
693
+ } = i18nKeys;
694
+ const showmonthtxt = title(date, year, month, monthNames);
695
+ const childEle = /*#__PURE__*/React.createElement("div", {
696
+ className: `${style.container} ${innerClass}`,
697
+ "data-id": `${dataId}_Calendar`,
698
+ "data-test-id": `${dataId}_Calendar`,
699
+ onClick: this.closePopup
700
+ }, /*#__PURE__*/React.createElement(DateTimePopupHeader, {
701
+ onOpenYearView: this.handleOpenYearView,
702
+ showMonthTxt: showmonthtxt,
703
+ isYearView: isYearView,
704
+ prevMonthTitleText: prevMonthTitleText,
705
+ nextMonthTitleText: nextMonthTitleText,
706
+ onModifyCalendar: this.modifyCalendar
707
+ }), /*#__PURE__*/React.createElement("div", {
708
+ className: style.subContainer
709
+ }, /*#__PURE__*/React.createElement(CalendarView, {
710
+ needBorder: isDateTimeField || needAction,
711
+ dataId: dataId,
712
+ date: date,
713
+ year: year,
714
+ month: month,
715
+ onSelect: this.dateSelect,
716
+ dayNames: dayNames,
717
+ dayNamesShort: dayNamesShort,
718
+ todayDate: todayDate,
719
+ todayMonth: todayMonth,
720
+ todayYear: todayYear
721
+ }), isDateTimeField ? /*#__PURE__*/React.createElement(Time, {
722
+ timeText: timeText,
723
+ dataId: dataId,
724
+ hourSuggestions: getHourSuggestions(is24Hour),
725
+ onHourSelect: this.hoursSelect,
726
+ hours: hours,
727
+ hourEmptyText: hourEmptyText,
728
+ needResponsive: needResponsive,
729
+ minSuggestions: getMinuteSuggestions(),
730
+ onMinutesSelect: this.minutesSelect,
731
+ mins: mins,
732
+ minuteEmptyText: minuteEmptyText,
733
+ ampmSuggestions: this.ampmSuggestions,
734
+ onAmPmSelect: this.amPmSelect,
735
+ amPm: amPm,
736
+ is24Hour: is24Hour
737
+ }) : null, needAction ? /*#__PURE__*/React.createElement(DateTimePopupFooter, {
738
+ submitText: submitText,
739
+ onSubmit: this.handleSelect,
740
+ cancelText: cancelText,
741
+ onCancel: this.handleClear,
742
+ dataId: dataId
743
+ }) : null, isYearView ? /*#__PURE__*/React.createElement("div", {
744
+ className: style.yearContainer
745
+ }, /*#__PURE__*/React.createElement(YearView, {
746
+ onSelectYear: this.handleSelectYear,
747
+ onSelectMonth: this.handleSelectMonthViaYearView,
748
+ viewedYear: year,
749
+ viewedMonth: month,
750
+ monthNames: monthNames,
751
+ monthNamesShort: monthNamesShort,
752
+ isMonthOpen: isMonthOpen
753
+ })) : null));
754
+ return isDefaultPosition ? /*#__PURE__*/React.createElement("div", {
755
+ className: `${style.dropBox} ${className}`,
756
+ "data-id": `${dataId}_dateBoxContainer`,
757
+ "data-test-id": `${dataId}_dateBoxContainer`
758
+ }, childEle) : isReady ? /*#__PURE__*/React.createElement(ResponsiveDropBox, {
759
+ size: boxSize,
760
+ boxPosition: position,
761
+ isActive: isActive,
762
+ isArrow: false,
763
+ isAnimate: isAnimate,
764
+ animationStyle: "bounce",
765
+ getRef: getRef,
766
+ onClick: onClick,
767
+ dataId: `${dataId}_dateBoxContainer`,
768
+ needResponsive: needResponsive,
769
+ isAbsolutePositioningNeeded: isAbsolute,
770
+ customClass: {
771
+ customDropBoxWrap: className
772
+ },
773
+ isPadding: isPadding,
774
+ positionsOffset: positionsOffset,
775
+ targetOffset: targetOffset,
776
+ isRestrictScroll: isRestrictScroll,
777
+ portalId: dropBoxPortalId
778
+ }, /*#__PURE__*/React.createElement(Box, null, childEle)) : null;
779
+ }
780
+
781
+ }
782
+ DateTime.propTypes = DateTime_propTypes;
783
+ DateTime.defaultProps = DateTime_defaultProps;