@jetbrains/ring-ui 4.1.0-beta.3 → 4.1.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 (234) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +17 -15
  3. package/babel.config.js +3 -2
  4. package/components/alert/alert.js +9 -3
  5. package/components/alert/alert.test.js +21 -48
  6. package/components/alert/container.css +1 -1
  7. package/components/alert/container.test.js +3 -13
  8. package/components/alert-service/alert-service.examples.css +18 -0
  9. package/components/alert-service/alert-service.examples.js +21 -0
  10. package/components/alert-service/alert-service.js +10 -3
  11. package/components/analytics/analytics__fus-plugin.js +3 -3
  12. package/components/analytics/analytics__ga-plugin.js +2 -2
  13. package/components/auth/auth.test.js +14 -7
  14. package/components/auth/auth__core.js +64 -33
  15. package/components/auth-dialog/auth-dialog.css +2 -3
  16. package/components/auth-dialog/auth-dialog.js +4 -1
  17. package/components/auth-dialog/auth-dialog.test.js +3 -19
  18. package/components/avatar/avatar.css +4 -1
  19. package/components/avatar/avatar.examples.js +3 -2
  20. package/components/avatar/avatar.js +34 -6
  21. package/components/avatar/avatar.test.js +20 -17
  22. package/components/avatar/fallback-avatar.js +136 -0
  23. package/components/avatar-editor-ng/avatar-editor-ng.css +2 -2
  24. package/components/avatar-editor-ng/avatar-editor-ng.js +2 -1
  25. package/components/avatar-editor-ng/{avatar-editor-ng.html → avatar-editor-ng__template.js} +2 -2
  26. package/components/badge/badge.test.js +13 -20
  27. package/components/button/button.css +2 -2
  28. package/components/button/button.js +4 -1
  29. package/components/button/button.test.js +32 -33
  30. package/components/button-group/button-group.js +1 -1
  31. package/components/button-group/caption.js +1 -1
  32. package/components/button-ng/button-ng.js +1 -1
  33. package/components/button-set-ng/button-set-ng.js +3 -1
  34. package/components/checkbox/checkbox.css +1 -1
  35. package/components/code/code.js +2 -5
  36. package/components/confirm/confirm.js +1 -0
  37. package/components/confirm-service/confirm-service.js +5 -5
  38. package/components/content-layout/content-layout.css +1 -1
  39. package/components/data-list/data-list.css +1 -1
  40. package/components/date-picker/date-input.js +5 -4
  41. package/components/date-picker/date-picker.css +34 -22
  42. package/components/date-picker/date-picker.js +16 -14
  43. package/components/date-picker/date-popup.js +22 -7
  44. package/components/date-picker/month-names.js +8 -5
  45. package/components/date-picker/month.js +6 -2
  46. package/components/date-picker/weekdays.js +10 -2
  47. package/components/dialog/dialog.examples.js +3 -1
  48. package/components/dialog/dialog.js +10 -5
  49. package/components/dialog/dialog.test.js +1 -1
  50. package/components/dialog/dialog__body-scroll-preventer.js +51 -31
  51. package/components/dialog-ng/dialog-ng.js +10 -10
  52. package/components/dialog-ng/{dialog-ng.html → dialog-ng__template.js} +2 -2
  53. package/components/dropdown/dropdown.examples.js +36 -1
  54. package/components/dropdown/dropdown.test.js +2 -2
  55. package/components/dropdown-menu/dropdown-menu.examples.js +47 -0
  56. package/components/dropdown-menu/dropdown-menu.js +117 -0
  57. package/components/dropdown-menu/dropdown-menu.test.js +76 -0
  58. package/components/error-bubble/error-bubble-legacy.css +1 -1
  59. package/components/error-bubble/error-bubble.css +1 -1
  60. package/components/error-bubble/error-bubble.examples.js +1 -1
  61. package/components/error-page/error-page.css +2 -2
  62. package/components/footer-ng/footer-ng.js +13 -3
  63. package/components/form/form.css +2 -2
  64. package/components/form-ng/form-ng.js +3 -1
  65. package/components/global/global.css +1 -1
  66. package/components/global/theme.js +1 -1
  67. package/components/global/variables.css +8 -1
  68. package/components/grid/grid.css +10 -9
  69. package/components/header/header.css +1 -1
  70. package/components/header/header.examples.js +7 -8
  71. package/components/header/profile.js +10 -11
  72. package/components/http/http.js +1 -1
  73. package/components/icon/icon.css +5 -4
  74. package/components/input/input-legacy.css +7 -7
  75. package/components/island/header.js +2 -2
  76. package/components/island/island.css +8 -3
  77. package/components/island-legacy/island-legacy.css +3 -1
  78. package/components/list/list.js +6 -1
  79. package/components/list/list__custom.js +9 -3
  80. package/components/list/list__item.js +8 -2
  81. package/components/list/list__link.js +2 -1
  82. package/components/loader-inline/loader-inline.css +1 -1
  83. package/components/loader-screen/loader-screen.css +1 -1
  84. package/components/message/message.css +1 -1
  85. package/components/message/message.examples.js +8 -7
  86. package/components/pager/pager.js +5 -3
  87. package/components/permissions/permissions.js +1 -1
  88. package/components/popup/popup.js +1 -1
  89. package/components/popup/popup.test.js +15 -13
  90. package/components/progress-bar/progress-bar.css +1 -1
  91. package/components/progress-bar/progress-bar.examples.js +3 -3
  92. package/components/progress-bar/progress-bar.js +5 -2
  93. package/components/progress-bar/progress-bar.test.js +12 -13
  94. package/components/progress-bar-ng/progress-bar-ng.examples.js +3 -3
  95. package/components/query-assist/query-assist.css +13 -3
  96. package/components/query-assist/query-assist.examples.js +3 -4
  97. package/components/query-assist/query-assist.js +56 -12
  98. package/components/query-assist/query-assist.test.js +37 -5
  99. package/components/save-field-ng/save-field-ng.css +0 -3
  100. package/components/save-field-ng/save-field-ng.js +3 -1
  101. package/components/save-field-ng/{save-field-ng.html → save-field-ng__template.js} +2 -2
  102. package/components/select/select.css +12 -7
  103. package/components/select/select.examples.js +13 -0
  104. package/components/select/select.js +30 -43
  105. package/components/select/select.test.js +4 -5
  106. package/components/select/select__popup.js +1 -0
  107. package/components/shortcuts-hint-ng/shortcuts-hint-ng.css +1 -1
  108. package/components/shortcuts-hint-ng/shortcuts-hint-ng.js +1 -1
  109. package/components/shortcuts-hint-ng/{shortcuts-hint-ng.html → shortcuts-hint-ng__template.js} +2 -2
  110. package/components/sidebar/sidebar.css +1 -0
  111. package/components/sidebar-ng/sidebar-ng.js +6 -2
  112. package/components/sidebar-ng/{sidebar-ng__button.html → sidebar-ng__button-template.js} +2 -2
  113. package/components/sidebar-ng/{sidebar-ng.html → sidebar-ng__template.js} +2 -2
  114. package/components/table/header.js +9 -1
  115. package/components/table/row.js +2 -1
  116. package/components/table/table.css +2 -1
  117. package/components/table-legacy/table-legacy.css +2 -2
  118. package/components/table-legacy/table-legacy__toolbar.css +2 -2
  119. package/components/table-legacy-ng/table-legacy-ng.js +38 -5
  120. package/components/table-legacy-ng/table-legacy-ng__pager.js +7 -1
  121. package/components/tabs/collapsible-tab.js +2 -2
  122. package/components/tabs/collapsible-tabs.js +5 -9
  123. package/components/tabs/tab-link.js +4 -2
  124. package/components/tabs/tabs.css +32 -5
  125. package/components/tabs-ng/tabs-ng.js +4 -2
  126. package/components/tabs-ng/{tabs-ng.html → tabs-ng__template.js} +6 -2
  127. package/components/tag/tag.css +5 -2
  128. package/components/tag/tag.examples.js +3 -0
  129. package/components/tag/tag.js +19 -16
  130. package/components/tags-input/tag-input.examples.js +1 -1
  131. package/components/tags-input/tags-input.js +5 -2
  132. package/components/template-ng/template-ng.js +1 -1
  133. package/components/tooltip/tooltip.js +7 -2
  134. package/components/user-agreement/user-agreement.css +1 -5
  135. package/components/user-agreement/user-agreement.examples.js +7 -6
  136. package/components/user-agreement/user-agreement.js +11 -3
  137. package/package.json +85 -83
  138. package/webpack.config.js +14 -10
  139. package/components/button-set-ng/button-set-ng.html +0 -1
  140. package/components/footer-ng/footer-ng.html +0 -13
  141. package/components/form-ng/form-ng__error-bubble.html +0 -3
  142. package/components/table-legacy-ng/table-legacy-ng.html +0 -4
  143. package/components/table-legacy-ng/table-legacy-ng__column.html +0 -12
  144. package/components/table-legacy-ng/table-legacy-ng__header.html +0 -4
  145. package/components/table-legacy-ng/table-legacy-ng__pager.html +0 -7
  146. package/components/table-legacy-ng/table-legacy-ng__row.html +0 -12
  147. package/components/table-legacy-ng/table-legacy-ng__title.html +0 -9
  148. package/dist/_helpers/_rollupPluginBabelHelpers.js +0 -123
  149. package/dist/_helpers/background-flow.js +0 -232
  150. package/dist/_helpers/badge.js +0 -3
  151. package/dist/_helpers/button.js +0 -145
  152. package/dist/_helpers/clickableLink.js +0 -65
  153. package/dist/_helpers/data-tests.js +0 -15
  154. package/dist/_helpers/disable-hover-hoc.js +0 -407
  155. package/dist/_helpers/dom.js +0 -101
  156. package/dist/_helpers/get-uid.js +0 -15
  157. package/dist/_helpers/linear-function.js +0 -17
  158. package/dist/_helpers/list.js +0 -1327
  159. package/dist/_helpers/logo.js +0 -36
  160. package/dist/_helpers/memoize.js +0 -17
  161. package/dist/_helpers/popup.js +0 -691
  162. package/dist/_helpers/popup.target.js +0 -27
  163. package/dist/_helpers/rerender-hoc.js +0 -49
  164. package/dist/_helpers/schedule-raf.js +0 -31
  165. package/dist/_helpers/sniffer.js +0 -6
  166. package/dist/_helpers/theme.js +0 -40
  167. package/dist/_helpers/url.js +0 -125
  168. package/dist/alert-service.js +0 -149
  169. package/dist/alert.js +0 -284
  170. package/dist/analytics.js +0 -116
  171. package/dist/auth-dialog-service.js +0 -56
  172. package/dist/auth-dialog.js +0 -122
  173. package/dist/auth.js +0 -1744
  174. package/dist/avatar.js +0 -152
  175. package/dist/badge.js +0 -52
  176. package/dist/button-group.js +0 -48
  177. package/dist/button-set.js +0 -27
  178. package/dist/button-toolbar.js +0 -30
  179. package/dist/button.js +0 -12
  180. package/dist/caret.js +0 -262
  181. package/dist/checkbox.js +0 -108
  182. package/dist/confirm-service.js +0 -102
  183. package/dist/confirm.js +0 -113
  184. package/dist/content-layout.js +0 -184
  185. package/dist/contenteditable.js +0 -81
  186. package/dist/data-list.js +0 -466
  187. package/dist/date-picker.js +0 -1398
  188. package/dist/dialog.js +0 -223
  189. package/dist/dropdown.js +0 -250
  190. package/dist/error-bubble.js +0 -56
  191. package/dist/error-message.js +0 -53
  192. package/dist/footer.js +0 -124
  193. package/dist/grid.js +0 -148
  194. package/dist/group.js +0 -34
  195. package/dist/header.js +0 -658
  196. package/dist/heading.js +0 -76
  197. package/dist/http.js +0 -207
  198. package/dist/hub-source.js +0 -130
  199. package/dist/icon.js +0 -211
  200. package/dist/input.js +0 -228
  201. package/dist/island.js +0 -314
  202. package/dist/link.js +0 -117
  203. package/dist/list.js +0 -29
  204. package/dist/loader-inline.js +0 -165
  205. package/dist/loader-screen.js +0 -45
  206. package/dist/loader.js +0 -338
  207. package/dist/login-dialog.js +0 -173
  208. package/dist/logo.js +0 -8
  209. package/dist/message.js +0 -226
  210. package/dist/old-browsers-message.js +0 -129
  211. package/dist/pager.js +0 -325
  212. package/dist/panel.js +0 -34
  213. package/dist/permissions.js +0 -466
  214. package/dist/popup-menu.js +0 -93
  215. package/dist/popup.js +0 -16
  216. package/dist/progress-bar.js +0 -111
  217. package/dist/proxy-attrs.js +0 -19
  218. package/dist/query-assist.js +0 -1081
  219. package/dist/radio.js +0 -112
  220. package/dist/select.js +0 -1920
  221. package/dist/selection.js +0 -213
  222. package/dist/shortcuts.js +0 -307
  223. package/dist/storage.js +0 -373
  224. package/dist/style.css +0 -1
  225. package/dist/tab-trap.js +0 -174
  226. package/dist/table.js +0 -903
  227. package/dist/tabs.js +0 -721
  228. package/dist/tag.js +0 -187
  229. package/dist/tags-input.js +0 -440
  230. package/dist/tags-list.js +0 -91
  231. package/dist/text.js +0 -38
  232. package/dist/toggle.js +0 -80
  233. package/dist/tooltip.js +0 -202
  234. package/dist/user-card.js +0 -218
@@ -1,1398 +0,0 @@
1
- import { b as _defineProperty, a as _extends, c as _objectSpread2, _ as _objectWithoutProperties } from './_helpers/_rollupPluginBabelHelpers.js';
2
- import React, { Component, PureComponent } from 'react';
3
- import PropTypes from 'prop-types';
4
- import classNames from 'classnames';
5
- import format from 'date-fns/format';
6
- import isSameDay from 'date-fns/isSameDay';
7
- import isSameMonth from 'date-fns/isSameMonth';
8
- import isSameYear from 'date-fns/isSameYear';
9
- import isValid from 'date-fns/isValid';
10
- import parse from 'date-fns/parse';
11
- import set from 'date-fns/set';
12
- import { m as memoize } from './_helpers/memoize.js';
13
- import { P as Popup } from './_helpers/popup.js';
14
- import Dropdown, { Anchor } from './dropdown.js';
15
- import isAfter from 'date-fns/isAfter';
16
- import isBefore from 'date-fns/isBefore';
17
- import startOfDay from 'date-fns/startOfDay';
18
- import calendarIcon from '@jetbrains/icons/calendar';
19
- import Icon from './icon.js';
20
- import Input from './input.js';
21
- import add from 'date-fns/add';
22
- import addMonths from 'date-fns/addMonths';
23
- import getDay from 'date-fns/getDay';
24
- import getDaysInMonth from 'date-fns/getDaysInMonth';
25
- import startOfHour from 'date-fns/startOfHour';
26
- import startOfMonth from 'date-fns/startOfMonth';
27
- import subMonths from 'date-fns/subMonths';
28
- import endOfMonth from 'date-fns/endOfMonth';
29
- import { s as scheduleRAF } from './_helpers/schedule-raf.js';
30
- import { l as linearFunction } from './_helpers/linear-function.js';
31
- import addDays from 'date-fns/addDays';
32
- import setDay from 'date-fns/setDay';
33
- import getDate from 'date-fns/getDate';
34
- import isToday from 'date-fns/isToday';
35
- import isThisMonth from 'date-fns/isThisMonth';
36
- import startOfYear from 'date-fns/startOfYear';
37
- import addYears from 'date-fns/addYears';
38
- import subYears from 'date-fns/subYears';
39
- import getYear from 'date-fns/getYear';
40
- import isThisYear from 'date-fns/isThisYear';
41
- import setYear from 'date-fns/setYear';
42
- import 'react-dom';
43
- import './_helpers/get-uid.js';
44
- import './_helpers/dom.js';
45
- import './shortcuts.js';
46
- import 'combokeys';
47
- import './_helpers/sniffer.js';
48
- import 'sniffr';
49
- import './_helpers/data-tests.js';
50
- import './tab-trap.js';
51
- import './_helpers/popup.target.js';
52
- import '@jetbrains/icons/chevron-10px';
53
- import './_helpers/button.js';
54
- import 'focus-visible';
55
- import './_helpers/theme.js';
56
- import './_helpers/clickableLink.js';
57
- import 'util-deprecate';
58
- import '@jetbrains/icons/close';
59
-
60
- const unit$1 = 8; // px;
61
-
62
- const units = {
63
- unit: unit$1,
64
-
65
- /* eslint-disable no-magic-numbers */
66
- cellSize: unit$1 * 3,
67
- calHeight: unit$1 * 36,
68
- yearHeight: unit$1 * 4
69
- /* eslint-enable */
70
-
71
- };
72
- const YEAR = 12;
73
- const WEEK = 7;
74
- const weekdays = {
75
- MO: 1,
76
- TU: 2,
77
- WE: 3,
78
- TH: 4,
79
- FR: 5,
80
- SA: 6,
81
- SU: 0
82
- };
83
- const MIDDLE_DAY = 15;
84
-
85
- const durationToMillis = duration => +add(0, duration);
86
-
87
- const yearDuration = durationToMillis({
88
- years: 1
89
- });
90
- const yearScrollSpeed = yearDuration / (YEAR * units.cellSize);
91
- const DOUBLE = 2;
92
- const HALF = 0.5;
93
- const deprecatedPropType = replacement => (props, propName) => {
94
- if (propName in props) {
95
- return new Error(`"${propName}" prop is deprecated and will be removed in 5.0. ${replacement} instead. See https://github.com/JetBrains/ring-ui/blob/master/CHANGELOG.md#310 for details`);
96
- }
97
-
98
- return undefined;
99
- };
100
- const dateType = PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.string, PropTypes.number]);
101
- function parseTime(time) {
102
- let result = null;
103
-
104
- if (/^([01][0-9]|2[0-3]):[0-5][0-9]$/.test(time)) {
105
- result = time;
106
- } else if (/^([0-9]|2[0-3]):[0-5][0-9]$/.test(time)) {
107
- result = `0${time}`;
108
- }
109
-
110
- return result;
111
- }
112
-
113
- var modules_0c7b7d96 = {"unit":"8px","resetButton":"global_resetButton__0f8f4370","cellSize":"24px","calHeight":"288px","calWidth":"296px","yearHeight":"32px","yearWidth":"48px","container":"datePicker_container__382b47f4","hoverable":"datePicker_hoverable__382b47f4","datePicker":"datePicker_datePicker__382b47f4","displayDate":"datePicker_displayDate__382b47f4","displayRange":"datePicker_displayRange__382b47f4","clear":"datePicker_clear__382b47f4","datePopup":"datePicker_datePopup__382b47f4","filterWrapper":"datePicker_filterWrapper__382b47f4 selectPopup_filterWrapper__7e997a1d","filter":"datePicker_filter__382b47f4 selectPopup_filter__7e997a1d","filterIcon":"datePicker_filterIcon__382b47f4 selectPopup_filterIcon__7e997a1d","fromInput":"datePicker_fromInput__382b47f4","fromInputWithDivider":"datePicker_fromInputWithDivider__382b47f4","toInput":"datePicker_toInput__382b47f4","dateInput":"datePicker_dateInput__382b47f4","timeInputWithDivider":"datePicker_timeInputWithDivider__382b47f4","weekdays":"datePicker_weekdays__382b47f4","weekday":"datePicker_weekday__382b47f4","weekend":"datePicker_weekend__382b47f4","calendar":"datePicker_calendar__382b47f4","months":"datePicker_months__382b47f4","days":"datePicker_days__382b47f4","month":"datePicker_month__382b47f4","monthTitle":"datePicker_monthTitle__382b47f4","day":"datePicker_day__382b47f4 global_resetButton__0f8f4370","between":"datePicker_between__382b47f4","activeBetween":"datePicker_activeBetween__382b47f4","current":"datePicker_current__382b47f4","active":"datePicker_active__382b47f4","disabled":"datePicker_disabled__382b47f4","from":"datePicker_from__382b47f4","to":"datePicker_to__382b47f4","Monday":"datePicker_Monday__382b47f4","spread":"datePicker_spread__382b47f4","activeSpread":"datePicker_activeSpread__382b47f4","first":"datePicker_first__382b47f4","Tuesday":"datePicker_Tuesday__382b47f4","Friday":"datePicker_Friday__382b47f4","Saturday":"datePicker_Saturday__382b47f4","Sunday":"datePicker_Sunday__382b47f4","empty":"datePicker_empty__382b47f4","today":"datePicker_today__382b47f4","year":"datePicker_year__382b47f4 datePicker_hoverable__382b47f4 global_resetButton__0f8f4370","monthNames":"datePicker_monthNames__382b47f4","monthName":"datePicker_monthName__382b47f4 datePicker_hoverable__382b47f4 global_resetButton__0f8f4370","monthSlider":"datePicker_monthSlider__382b47f4 global_resetButton__0f8f4370","dragging":"datePicker_dragging__382b47f4","range":"datePicker_range__382b47f4","years":"datePicker_years__382b47f4","currentYear":"datePicker_currentYear__382b47f4"};
114
-
115
- class DateInput extends React.PureComponent {
116
- constructor(...args) {
117
- super(...args);
118
-
119
- _defineProperty(this, "inputRef", el => {
120
- this.input = el;
121
- this.updateInput(this.props);
122
- });
123
-
124
- _defineProperty(this, "handleChange", e => this.props.onInput(e.target.value, e.target.dataset.name));
125
-
126
- _defineProperty(this, "handleKeyDown", e => e.key === 'Enter' && this.props.onConfirm());
127
- }
128
-
129
- componentDidUpdate(prevProps) {
130
- const {
131
- hidden,
132
- text,
133
- active
134
- } = this.props;
135
-
136
- if (!hidden && prevProps.hidden || text !== prevProps.text || active !== prevProps.active) {
137
- this.updateInput({
138
- text,
139
- active
140
- });
141
- }
142
- }
143
-
144
- updateInput({
145
- text,
146
- active
147
- }) {
148
- const el = this.input;
149
-
150
- if (!el) {
151
- return;
152
- }
153
-
154
- if (active) {
155
- el.focus();
156
-
157
- if (!text) {
158
- el.select();
159
- }
160
- } else {
161
- el.blur();
162
- }
163
- }
164
-
165
- render() {
166
- const {
167
- active,
168
- divider,
169
- text,
170
- time,
171
- name,
172
- hoverDate,
173
- date,
174
- displayFormat,
175
- translations,
176
- onActivate,
177
- onClear,
178
- fromPlaceholder,
179
- toPlaceholder,
180
- timePlaceholder
181
- } = this.props;
182
- let displayText = '';
183
-
184
- if (active && hoverDate) {
185
- displayText = displayFormat(hoverDate);
186
- } else if (active && text != null) {
187
- displayText = text;
188
- } else if (date) {
189
- displayText = displayFormat(date);
190
- } else if (name === 'time') {
191
- displayText = time || '';
192
- }
193
-
194
- const placeholder = (() => {
195
- switch (name) {
196
- case 'from':
197
- return fromPlaceholder || translations.addFirstDate;
198
-
199
- case 'to':
200
- return toPlaceholder || translations.addSecondDate;
201
-
202
- case 'time':
203
- return timePlaceholder || translations.addTime;
204
-
205
- default:
206
- return translations.selectName.replace('%name%', name);
207
- }
208
- })();
209
-
210
- const classes = classNames(modules_0c7b7d96.filter, modules_0c7b7d96[`${name}Input`], divider && modules_0c7b7d96[`${name}InputWithDivider`], 'ring-js-shortcuts');
211
- return /*#__PURE__*/React.createElement(Input, {
212
- autoComplete: "off",
213
- borderless: true,
214
- "data-name": name,
215
- inputRef: this.inputRef,
216
- className: classes,
217
- value: displayText,
218
- onChange: this.handleChange,
219
- onFocus: onActivate,
220
- onKeyDown: this.handleKeyDown,
221
- onClear: onClear,
222
- placeholder: placeholder
223
- });
224
- }
225
-
226
- }
227
-
228
- _defineProperty(DateInput, "propTypes", {
229
- active: PropTypes.bool,
230
- divider: PropTypes.bool,
231
- name: PropTypes.string,
232
- text: PropTypes.string,
233
- hoverDate: dateType,
234
- date: dateType,
235
- time: PropTypes.string,
236
- displayFormat: PropTypes.func,
237
- hidden: PropTypes.bool,
238
- translations: PropTypes.object,
239
- fromPlaceholder: PropTypes.string,
240
- toPlaceholder: PropTypes.string,
241
- timePlaceholder: PropTypes.string,
242
- onInput: PropTypes.func,
243
- onActivate: PropTypes.func,
244
- onConfirm: PropTypes.func,
245
- onClear: PropTypes.func
246
- });
247
-
248
- _defineProperty(DateInput, "defaultProps", {
249
- fromPlaceholder: null,
250
- toPlaceholder: null,
251
- timePlaceholder: null,
252
- translations: {
253
- addFirstDate: 'Add first date',
254
- addSecondDate: 'Add second date',
255
- addTime: 'Add time',
256
- selectName: 'Select %name%'
257
- }
258
- });
259
-
260
- let hoverTO;
261
- class Day extends Component {
262
- constructor(...args) {
263
- super(...args);
264
-
265
- _defineProperty(this, "handleClick", () => this.props.onSelect(this.props.day));
266
-
267
- _defineProperty(this, "handleMouseOver", () => {
268
- if (hoverTO) {
269
- window.clearTimeout(hoverTO);
270
- hoverTO = null;
271
- }
272
-
273
- this.props.onHover(this.props.day);
274
- });
275
-
276
- _defineProperty(this, "handleMouseOut", () => {
277
- hoverTO = window.setTimeout(this.props.onHover, 0);
278
- });
279
-
280
- _defineProperty(this, "isDay", date => isSameDay(this.props.day, date));
281
-
282
- _defineProperty(this, "is", name => this.props[name] && this.isDay(this.props[name]));
283
-
284
- _defineProperty(this, "inRange", range => range && isAfter(startOfDay(this.props.day), startOfDay(range[0])) && isBefore(startOfDay(this.props.day), startOfDay(range[1])));
285
-
286
- _defineProperty(this, "isDisabled", date => {
287
- const min = this.parse(this.props.minDate);
288
- const max = this.parse(this.props.maxDate);
289
- return this.props.minDate && isBefore(startOfDay(date), startOfDay(min)) || this.props.maxDate && isAfter(startOfDay(date), startOfDay(max));
290
- });
291
- }
292
-
293
- parse(text) {
294
- return this.props.parseDateInput(text);
295
- }
296
-
297
- render() {
298
- const {
299
- day,
300
- from,
301
- currentRange,
302
- activeRange,
303
- empty
304
- } = this.props;
305
- const reverse = activeRange && activeRange[1] === from;
306
-
307
- function makeSpreadRange(range) {
308
- return range && [range[0], addDays(range[1], 1)];
309
- }
310
-
311
- const spreadRange = makeSpreadRange(currentRange);
312
- const disabled = this.isDisabled(day);
313
- const activeSpreadRange = makeSpreadRange(activeRange);
314
- return (
315
- /*#__PURE__*/
316
- // TODO make keyboard navigation actually work
317
- React.createElement("button", {
318
- type: "button",
319
- className: classNames(modules_0c7b7d96.day, modules_0c7b7d96[format(day, 'EEEE')], {
320
- [modules_0c7b7d96.current]: ['date', 'from', 'to'].some(this.is),
321
- [modules_0c7b7d96.active]: !disabled && this.is('activeDate'),
322
- [modules_0c7b7d96.weekend]: [weekdays.SA, weekdays.SU].includes(getDay(day)),
323
- [modules_0c7b7d96.empty]: empty,
324
- [modules_0c7b7d96.from]: currentRange && this.isDay(currentRange[0]) && !reverse || activeRange && this.isDay(activeRange[0]),
325
- [modules_0c7b7d96.to]: currentRange && this.isDay(currentRange[1]) || activeRange && this.isDay(activeRange[1]),
326
- [modules_0c7b7d96.between]: this.inRange(currentRange),
327
- [modules_0c7b7d96.activeBetween]: !disabled && this.inRange(activeRange),
328
- [modules_0c7b7d96.first]: getDate(day) === 1,
329
- [modules_0c7b7d96.spread]: this.inRange(spreadRange),
330
- [modules_0c7b7d96.activeSpread]: !disabled && this.inRange(activeSpreadRange),
331
- [modules_0c7b7d96.disabled]: disabled
332
- }),
333
- onClick: this.handleClick,
334
- onMouseOver: this.handleMouseOver,
335
- onFocus: this.handleMouseOver,
336
- onMouseOut: this.handleMouseOut,
337
- onBlur: this.handleMouseOut,
338
- disabled: disabled
339
- }, empty || /*#__PURE__*/React.createElement("span", {
340
- className: classNames({
341
- [modules_0c7b7d96.today]: isToday(day)
342
- })
343
- }, format(day, 'd')))
344
- );
345
- }
346
-
347
- }
348
- Day.propTypes = {
349
- day: dateType,
350
- from: dateType,
351
- currentRange: PropTypes.arrayOf(dateType),
352
- activeRange: PropTypes.arrayOf(dateType),
353
- empty: PropTypes.bool,
354
- onSelect: PropTypes.func,
355
- parseDateInput: PropTypes.func,
356
- onHover: PropTypes.func,
357
- minDate: dateType,
358
- maxDate: dateType
359
- };
360
-
361
- function Month(props) {
362
- const start = props.month;
363
- const end = endOfMonth(start); // pad with empty cells starting from last friday
364
-
365
- const weekday = getDay(start);
366
- let day = setDay(start, weekday >= weekdays.FR ? weekdays.FR : weekdays.FR - WEEK);
367
- const days = [];
368
-
369
- while (day < end) {
370
- days.push(day);
371
- day = addDays(day, 1);
372
- }
373
-
374
- return /*#__PURE__*/React.createElement("div", {
375
- className: modules_0c7b7d96.month
376
- }, /*#__PURE__*/React.createElement("span", {
377
- className: modules_0c7b7d96.monthTitle
378
- }, format(props.month, 'MMMM')), days.map(date => /*#__PURE__*/React.createElement(Day, _extends({}, props, {
379
- day: date,
380
- empty: date < start,
381
- key: +date
382
- }))));
383
- }
384
- Month.propTypes = {
385
- month: dateType
386
- };
387
-
388
- const COVERYEARS = 3;
389
- class MonthSlider extends PureComponent {
390
- constructor(...args) {
391
- super(...args);
392
-
393
- _defineProperty(this, "state", {
394
- dragging: false
395
- });
396
-
397
- _defineProperty(this, "onMouseDown", () => {
398
- this.setState({
399
- dragging: true
400
- });
401
- });
402
-
403
- _defineProperty(this, "onMouseUp", () => {
404
- this.setState({
405
- dragging: false
406
- });
407
- });
408
-
409
- _defineProperty(this, "onMouseMove", e => {
410
- this.props.onScroll(linearFunction(0, this.props.scrollDate, yearScrollSpeed).y(e.movementY));
411
- });
412
- }
413
-
414
- componentDidUpdate(prevProps, prevState) {
415
- if (this.state.dragging && !prevState.dragging) {
416
- window.addEventListener('mousemove', this.onMouseMove);
417
- window.addEventListener('mouseup', this.onMouseUp);
418
- } else if (!this.state.dragging && prevState.dragging) {
419
- window.removeEventListener('mousemove', this.onMouseMove);
420
- window.removeEventListener('mouseup', this.onMouseUp);
421
- }
422
- }
423
-
424
- render() {
425
- let year = subYears(startOfDay(this.props.scrollDate), 1);
426
- const years = [year];
427
-
428
- for (let i = 0; i <= COVERYEARS; i++) {
429
- year = addYears(year, 1);
430
- years.push(year);
431
- }
432
-
433
- const classes = classNames(modules_0c7b7d96.monthSlider, {
434
- [modules_0c7b7d96.dragging]: this.state.dragging
435
- });
436
- return /*#__PURE__*/React.createElement("div", null, years.map(date => /*#__PURE__*/React.createElement("button", {
437
- type: "button",
438
- key: +date,
439
- className: classes,
440
- style: {
441
- top: Math.floor(this.props.pxToDate.x(date) - units.cellSize)
442
- },
443
- onMouseDown: this.onMouseDown
444
- })));
445
- }
446
-
447
- }
448
-
449
- _defineProperty(MonthSlider, "propTypes", {
450
- scrollDate: dateType,
451
- onScroll: PropTypes.func,
452
- pxToDate: PropTypes.shape({
453
- x: PropTypes.func,
454
- y: PropTypes.func
455
- })
456
- });
457
-
458
- class MonthName extends PureComponent {
459
- constructor(...args) {
460
- super(...args);
461
-
462
- _defineProperty(this, "handleClick", () => {
463
- const end = endOfMonth(this.props.month);
464
- this.props.onScrollChange((+this.props.month + +end) * HALF);
465
- });
466
- }
467
-
468
- render() {
469
- const {
470
- month
471
- } = this.props;
472
- return /*#__PURE__*/React.createElement("button", {
473
- type: "button",
474
- className: classNames(modules_0c7b7d96.monthName, {
475
- [modules_0c7b7d96.today]: isThisMonth(month)
476
- }),
477
- onClick: this.handleClick
478
- }, format(month, 'MMM'));
479
- }
480
-
481
- }
482
-
483
- MonthName.propTypes = {
484
- month: dateType,
485
- onScrollChange: PropTypes.func
486
- };
487
- function MonthNames(props) {
488
- const {
489
- scrollDate
490
- } = props;
491
- const months = [];
492
-
493
- for (let i = 0; i < YEAR; i++) {
494
- const middleDay = set(scrollDate, {
495
- month: i,
496
- date: MIDDLE_DAY
497
- });
498
- months.push(startOfDay(middleDay));
499
- }
500
-
501
- const pxToDate = linearFunction(0, startOfYear(scrollDate), yearScrollSpeed);
502
- let top = 0;
503
- let bottom = 0;
504
-
505
- if (props.currentRange) {
506
- [top, bottom] = props.currentRange.map(date => Math.floor(pxToDate.x(date)));
507
- }
508
-
509
- return /*#__PURE__*/React.createElement("div", {
510
- className: modules_0c7b7d96.monthNames
511
- }, months.map(month => /*#__PURE__*/React.createElement(MonthName, {
512
- key: +month,
513
- month: month,
514
- onScrollChange: props.onScrollChange
515
- })), props.currentRange && /*#__PURE__*/React.createElement("div", {
516
- className: modules_0c7b7d96.range,
517
- style: {
518
- top: top - 1,
519
- height: bottom + 1 - (top - 1)
520
- }
521
- }), /*#__PURE__*/React.createElement(MonthSlider, _extends({}, props, {
522
- pxToDate: pxToDate
523
- })));
524
- }
525
- MonthNames.propTypes = {
526
- scrollDate: dateType,
527
- onScrollChange: PropTypes.func,
528
- currentRange: PropTypes.arrayOf(dateType)
529
- };
530
-
531
- const {
532
- unit,
533
- cellSize,
534
- calHeight: calHeight$1
535
- } = units;
536
- const FridayToSunday = WEEK + weekdays.SU - weekdays.FR;
537
- const FIVELINES = 31;
538
- const TALLMONTH = 6;
539
- const SHORTMONTH = 5;
540
- const PADDING = 2;
541
- const MONTHSBACK = 2;
542
-
543
- function monthHeight(date) {
544
- const monthStart = startOfMonth(date);
545
- const daysSinceLastFriday = (getDay(monthStart) + FridayToSunday) % WEEK;
546
- const monthLines = daysSinceLastFriday + getDaysInMonth(monthStart) > FIVELINES ? TALLMONTH : SHORTMONTH;
547
- return monthLines * cellSize + unit * PADDING;
548
- } // in milliseconds per pixel
549
-
550
-
551
- function scrollSpeed(date) {
552
- const monthStart = startOfMonth(date);
553
- const monthEnd = endOfMonth(date);
554
- return (monthEnd - monthStart) / monthHeight(monthStart);
555
- }
556
-
557
- const scrollSchedule = scheduleRAF();
558
- let dy = 0;
559
- function Months(props) {
560
- const {
561
- scrollDate
562
- } = props; // prevent switching from april to march because of daylight saving time
563
-
564
- const monthStart = startOfHour(set(scrollDate, {
565
- date: 1,
566
- hours: 1
567
- }));
568
- let month = subMonths(monthStart, MONTHSBACK);
569
- const months = [month];
570
-
571
- for (let i = 0; i < MONTHSBACK * DOUBLE; i++) {
572
- month = addMonths(month, 1);
573
- months.push(month);
574
- }
575
-
576
- const currentSpeed = scrollSpeed(scrollDate);
577
- const pxToDate = linearFunction(0, scrollDate, currentSpeed);
578
- const offset = pxToDate.x(monthStart); // is a negative number
579
-
580
- const bottomOffset = monthHeight(scrollDate) + offset;
581
- return /*#__PURE__*/React.createElement("div", {
582
- className: modules_0c7b7d96.months,
583
- onWheel: function handleWheel(e) {
584
- e.preventDefault();
585
- dy += e.deltaY;
586
- scrollSchedule(() => {
587
- let date; // adjust scroll speed to prevent glitches
588
-
589
- if (dy < offset) {
590
- date = pxToDate.y(offset) + (dy - offset) * scrollSpeed(months[1]);
591
- } else if (dy > bottomOffset) {
592
- date = pxToDate.y(bottomOffset) + (dy - bottomOffset) * scrollSpeed(months[MONTHSBACK + 1]);
593
- } else {
594
- date = pxToDate.y(dy);
595
- }
596
-
597
- props.onScroll(date);
598
- dy = 0;
599
- });
600
- }
601
- }, /*#__PURE__*/React.createElement("div", {
602
- style: {
603
- top: Math.floor(calHeight$1 * HALF - monthHeight(months[0]) - monthHeight(months[1]) + offset)
604
- },
605
- className: modules_0c7b7d96.days
606
- }, months.map(date => /*#__PURE__*/React.createElement(Month, _extends({}, props, {
607
- month: date,
608
- key: +date
609
- })))), /*#__PURE__*/React.createElement(MonthNames, props));
610
- }
611
- Months.propTypes = {
612
- onScroll: PropTypes.func,
613
- scrollDate: dateType
614
- };
615
-
616
- const {
617
- yearHeight,
618
- calHeight
619
- } = units;
620
- let scrollTO;
621
- const YEARSBACK = 5;
622
- const scrollDelay = 100;
623
- class Years extends PureComponent {
624
- constructor(...args) {
625
- super(...args);
626
-
627
- _defineProperty(this, "state", {
628
- scrollDate: null
629
- });
630
- }
631
-
632
- componentDidUpdate(prevProps, prevState) {
633
- this.stoppedScrolling = prevState.scrollDate && !this.state.scrollDate;
634
- }
635
-
636
- setYear(date) {
637
- if (scrollTO) {
638
- window.clearTimeout(scrollTO);
639
- scrollTO = null;
640
- }
641
-
642
- this.setState({
643
- scrollDate: null
644
- });
645
- this.props.onScroll(setYear(this.props.scrollDate, getYear(date)));
646
- }
647
-
648
- render() {
649
- const {
650
- onScrollChange,
651
- scrollDate
652
- } = this.props;
653
- const date = this.state.scrollDate || scrollDate;
654
- const yearStart = startOfYear(date);
655
- let year = subYears(yearStart, YEARSBACK);
656
- const years = [year];
657
-
658
- for (let i = 0; i < YEARSBACK * DOUBLE; i++) {
659
- year = addYears(year, 1);
660
- years.push(year);
661
- }
662
-
663
- const pxToDate = linearFunction(0, years[0], yearDuration / yearHeight);
664
-
665
- const handleWheel = e => {
666
- e.preventDefault();
667
- const newScrollDate = linearFunction(0, date, yearDuration / yearHeight).y(e.deltaY);
668
- this.setState({
669
- scrollDate: newScrollDate
670
- });
671
-
672
- if (scrollTO) {
673
- window.clearTimeout(scrollTO);
674
- }
675
-
676
- scrollTO = window.setTimeout(() => this.setYear(newScrollDate), scrollDelay);
677
- };
678
-
679
- return /*#__PURE__*/React.createElement("div", {
680
- className: modules_0c7b7d96.years,
681
- onWheel: handleWheel,
682
- style: {
683
- transition: this.stoppedScrolling ? 'top .2s ease-out 0s' : 'none',
684
- top: Math.floor(calHeight * HALF - pxToDate.x(date))
685
- }
686
- }, years.map(item => /*#__PURE__*/React.createElement("button", {
687
- type: "button",
688
- key: +item,
689
- className: classNames(modules_0c7b7d96.year, {
690
- [modules_0c7b7d96.currentYear]: isSameYear(item, date),
691
- [modules_0c7b7d96.today]: isThisYear(item)
692
- }),
693
- onClick: function handleClick() {
694
- onScrollChange(setYear(scrollDate, getYear(item)));
695
- }
696
- }, format(item, 'yyyy'))));
697
- }
698
-
699
- }
700
-
701
- _defineProperty(Years, "propTypes", {
702
- scrollDate: dateType,
703
- onScroll: PropTypes.func,
704
- onScrollChange: PropTypes.func
705
- });
706
-
707
- function Weekdays() {
708
- const days = Object.keys(weekdays).map(key => startOfDay(setDay(new Date(), weekdays[key])));
709
- return /*#__PURE__*/React.createElement("div", {
710
- className: modules_0c7b7d96.weekdays
711
- }, days.map(day => /*#__PURE__*/React.createElement("span", {
712
- className: classNames(modules_0c7b7d96.weekday, {
713
- [modules_0c7b7d96.weekend]: [weekdays.SA, weekdays.SU].includes(getDay(day))
714
- }),
715
- key: +day
716
- }, format(day, 'EEEEEE'))));
717
- }
718
-
719
- const scrollExpDelay = 10;
720
- class DatePopup extends Component {
721
- static sameDay(next, prev) {
722
- if (next && prev) {
723
- return isSameDay(next, prev);
724
- }
725
-
726
- return next === prev;
727
- }
728
-
729
- constructor(props) {
730
- super(props);
731
-
732
- _defineProperty(this, "isInTimeMode", () => !this.props.range && this.props.withTime || false);
733
-
734
- _defineProperty(this, "componentRef", /*#__PURE__*/React.createRef());
735
-
736
- _defineProperty(this, "handleWheel", e => {
737
- e.preventDefault();
738
- });
739
-
740
- _defineProperty(this, "isValidDate", parsedText => {
741
- const minDate = this.parse(this.props.minDate, 'date');
742
- const maxDate = this.parse(this.props.maxDate, 'date');
743
-
744
- if (parsedText) {
745
- return !(minDate && isBefore(parsedText, minDate) || maxDate && isAfter(parsedText, maxDate));
746
- }
747
-
748
- return false;
749
- });
750
-
751
- _defineProperty(this, "scheduleScroll", () => {
752
- const current = this.state.scrollDate && this.parse(this.state.scrollDate, 'date') || this.parse(this.props[this.state.active], 'date') || new Date();
753
- const goal = this._scrollDate;
754
-
755
- if (!current || !goal || DatePopup.sameDay(goal, current)) {
756
- this._scrollDate = null;
757
- this._scrollTS = null;
758
- return;
759
- }
760
-
761
- if (this._scrollTS) {
762
- const diff = goal - current;
763
-
764
- const dt = Date.now() - this._scrollTS;
765
-
766
- const next = goal - diff * Math.E ** (-dt / scrollExpDelay);
767
- this.setState({
768
- scrollDate: next
769
- });
770
- }
771
-
772
- this._scrollTS = Date.now();
773
- window.requestAnimationFrame(this.scheduleScroll);
774
- });
775
-
776
- _defineProperty(this, "scrollTo", scrollDate => {
777
- this._scrollDate = scrollDate;
778
-
779
- if (!this._scrollTS) {
780
- this.scheduleScroll();
781
- }
782
- });
783
-
784
- _defineProperty(this, "hoverHandler", hoverDate => this.setState({
785
- hoverDate
786
- }));
787
-
788
- _defineProperty(this, "handleActivate", memoize(name => () => this.setState({
789
- active: name
790
- })));
791
-
792
- _defineProperty(this, "handleInput", (text, name) => {
793
- const parsed = this.parse(text, name);
794
-
795
- if (name !== 'time' && this.isValidDate(parsed)) {
796
- this.scrollTo(parsed);
797
- }
798
-
799
- this.setState({
800
- text,
801
- hoverDate: null
802
- });
803
- });
804
-
805
- _defineProperty(this, "handleConfirm", memoize(name => () => this.confirm(name)));
806
-
807
- _defineProperty(this, "selectHandler", date => {
808
- if (this.isInTimeMode()) {
809
- this.setState({
810
- active: 'time'
811
- }, () => this.select({
812
- date
813
- }));
814
- } else {
815
- this.select({
816
- [this.state.active]: date
817
- });
818
- }
819
- });
820
-
821
- _defineProperty(this, "handleScroll", scrollDate => this.setState({
822
- scrollDate
823
- }));
824
-
825
- _defineProperty(this, "onClear", e => {
826
- this.setState({
827
- active: undefined
828
- });
829
- this.props.onClear(e);
830
- });
831
-
832
- const defaultState = {
833
- text: null,
834
- hoverDate: null,
835
- scrollDate: null
836
- };
837
- const {
838
- range,
839
- from,
840
- to,
841
- date: _date,
842
- time,
843
- withTime
844
- } = props;
845
-
846
- if (!range) {
847
- const parsedDate = this.parse(_date, 'date');
848
- const active = withTime && parsedDate && !time ? 'time' : 'date';
849
- this.state = _objectSpread2(_objectSpread2({}, defaultState), {}, {
850
- active
851
- });
852
- } else if (from && !to) {
853
- this.state = _objectSpread2(_objectSpread2({}, defaultState), {}, {
854
- active: 'to'
855
- });
856
- } else {
857
- this.state = _objectSpread2(_objectSpread2({}, defaultState), {}, {
858
- active: 'from'
859
- });
860
- }
861
- }
862
-
863
- componentDidMount() {
864
- if (this.componentRef.current) {
865
- this.componentRef.current.addEventListener('wheel', this.handleWheel);
866
- }
867
- }
868
-
869
- componentDidUpdate(prevProps, prevState) {
870
- if (this.state.active !== prevState.active) {
871
- if (this.state.text && prevState.active) {
872
- this.confirm(prevState.active);
873
- } // eslint-disable-next-line react/no-did-update-set-state
874
-
875
-
876
- this.setState({
877
- text: null
878
- });
879
- }
880
- }
881
-
882
- componentWillUnmount() {
883
- if (this.componentRef.current) {
884
- this.componentRef.current.removeEventListener('wheel', this.handleWheel);
885
- }
886
- }
887
-
888
- parse(text, type) {
889
- if (type === 'time') {
890
- return parseTime(text);
891
- }
892
-
893
- return this.props.parseDateInput(text);
894
- }
895
-
896
- select(changes) {
897
- const {
898
- range,
899
- withTime
900
- } = this.props;
901
- const prevActive = this.state.active;
902
- const date = this.parse(this.props.date, 'date');
903
- const time = this.parse(this.props.time, 'time');
904
-
905
- if (!range && !withTime) {
906
- this.setState({
907
- text: null,
908
- scrollDate: null
909
- });
910
- this.props.onChange(changes.date);
911
- this.props.onComplete();
912
- } else if (!range && withTime) {
913
- const changeToSubmit = {
914
- date: changes.date || date,
915
- time: changes.time || time
916
- };
917
- this.setState({
918
- active: changes.date ? 'time' : 'date',
919
- text: null,
920
- scrollDate: null
921
- });
922
- this.props.onChange(changeToSubmit);
923
-
924
- if (!changes.date && prevActive === 'time' && changeToSubmit.date && changeToSubmit.time) {
925
- this.props.onComplete();
926
- }
927
- } else {
928
- let {
929
- from,
930
- to
931
- } = _objectSpread2(_objectSpread2({}, this.props), changes);
932
-
933
- from = this.parse(from, 'from');
934
- to = this.parse(to, 'to'); // proceed to setting the end by default
935
-
936
- let active = 'to';
937
- let complete = false; // end is before beginning
938
-
939
- if (from && to && isAfter(startOfDay(from), startOfDay(to))) {
940
- // ignore the old end when beginning is changed
941
- if (changes.from) {
942
- to = null; // treat range as reverse when end is changed
943
- } else if (changes.to) {
944
- to = from;
945
- from = changes.to;
946
- }
947
- } else if (changes.to) {
948
- active = 'from';
949
- complete = !!from;
950
- }
951
-
952
- this.setState({
953
- active,
954
- hoverDate: null,
955
- text: null
956
- });
957
- this.props.onChange({
958
- from,
959
- to
960
- });
961
-
962
- if (complete) {
963
- this.props.onComplete();
964
- }
965
- }
966
- }
967
-
968
- confirm(name) {
969
- const text = this.state.text;
970
- let result = this.parse(text, name);
971
-
972
- if (name === 'time') {
973
- const time = this.parse(this.props.time, 'time');
974
- const emptyCase = this.state.active === 'time' ? '00:00' : null;
975
- result = result || time || emptyCase;
976
- } else if (!this.isValidDate(result)) {
977
- result = this.parse(this.props[name], name);
978
- }
979
-
980
- this.select({
981
- [name]: result
982
- });
983
- }
984
-
985
- render() {
986
- const {
987
- range,
988
- hidden,
989
- withTime,
990
- time
991
- } = this.props;
992
- const parsedDate = this.parse(this.props.date, 'date');
993
- const parsedTo = this.parse(this.props.to, 'to');
994
- const names = range ? ['from', 'to'] : ['date'];
995
- const dates = names.reduce((obj, key) => {
996
- const date = this.props[key];
997
- return _objectSpread2(_objectSpread2({}, obj), {}, {
998
- [key]: this.parse(date, key)
999
- });
1000
- }, {});
1001
- const activeDate = this.state.active !== 'time' ? this.state.hoverDate || this.state.text && this.parse(this.state.text, 'date') : this.state.hoverDate || null;
1002
- const currentRange = range && dates.from && dates.to && [dates.from, dates.to] || null;
1003
- let activeRange = null;
1004
-
1005
- if (range && activeDate) {
1006
- switch (this.state.active) {
1007
- case 'from':
1008
- if (dates.to && isAfter(startOfDay(activeDate), startOfDay(dates.to))) {
1009
- activeRange = [activeDate, dates.to];
1010
- }
1011
-
1012
- break;
1013
-
1014
- case 'to':
1015
- if (!dates.from) {
1016
- break;
1017
- }
1018
-
1019
- if (isBefore(startOfDay(activeDate), startOfDay(dates.from))) {
1020
- activeRange = [activeDate, dates.from];
1021
- } else {
1022
- activeRange = [dates.from, activeDate];
1023
- }
1024
-
1025
- break;
1026
- }
1027
- }
1028
-
1029
- const scrollDate = withTime && !range ? this.state.scrollDate || dates.date || new Date() : this.state.scrollDate || dates[this.state.active] || new Date();
1030
-
1031
- const calendarProps = _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, this.props), this.state), dates), {}, {
1032
- scrollDate,
1033
- activeDate,
1034
- currentRange,
1035
- activeRange,
1036
- onScroll: this.handleScroll,
1037
- onScrollChange: this.scrollTo
1038
- });
1039
-
1040
- const clearable = Boolean(this.props.onClear);
1041
- return /*#__PURE__*/React.createElement("div", {
1042
- className: modules_0c7b7d96.datePopup,
1043
- "data-test": "ring-date-popup",
1044
- ref: this.componentRef
1045
- }, /*#__PURE__*/React.createElement("div", {
1046
- className: modules_0c7b7d96.filterWrapper
1047
- }, /*#__PURE__*/React.createElement(Icon, {
1048
- glyph: calendarIcon,
1049
- className: modules_0c7b7d96.filterIcon
1050
- }), names.map(name => {
1051
- let onClear;
1052
-
1053
- if (clearable && name !== 'from' && !this.isInTimeMode()) {
1054
- onClear = this.onClear.bind(this);
1055
- }
1056
-
1057
- return /*#__PURE__*/React.createElement(DateInput, _extends({}, this.props, this.state, {
1058
- divider: name === 'from' && (dates[name] != null || parsedTo != null),
1059
- name: name,
1060
- key: name,
1061
- date: dates[name],
1062
- active: this.state.active === name,
1063
- hidden: hidden,
1064
- onActivate: this.handleActivate(name),
1065
- onInput: this.handleInput,
1066
- onConfirm: this.handleConfirm(name),
1067
- onClear: onClear
1068
- }));
1069
- }), this.isInTimeMode() ? /*#__PURE__*/React.createElement(DateInput, _extends({}, this.props, this.state, {
1070
- divider: !!parsedDate,
1071
- hoverDate: null,
1072
- name: 'time',
1073
- key: 'time',
1074
- date: null,
1075
- time: time,
1076
- active: this.state.active === 'time',
1077
- hidden: hidden,
1078
- onActivate: this.handleActivate('time'),
1079
- onInput: this.handleInput,
1080
- onConfirm: this.handleConfirm('time'),
1081
- onClear: clearable && this.onClear || undefined
1082
- })) : ''), /*#__PURE__*/React.createElement(Weekdays, null), /*#__PURE__*/React.createElement("div", {
1083
- className: modules_0c7b7d96.calendar
1084
- }, /*#__PURE__*/React.createElement(Months, _extends({}, calendarProps, {
1085
- onHover: this.hoverHandler,
1086
- onSelect: this.selectHandler
1087
- })), /*#__PURE__*/React.createElement(Years, calendarProps)), this.props.renderAfterCalendar && this.props.renderAfterCalendar(this.state));
1088
- }
1089
-
1090
- }
1091
-
1092
- _defineProperty(DatePopup, "propTypes", {
1093
- className: PropTypes.string,
1094
- date: dateType,
1095
- range: PropTypes.bool,
1096
- withTime: PropTypes.bool,
1097
- time: PropTypes.string,
1098
- from: dateType,
1099
- to: dateType,
1100
- renderAfterCalendar: PropTypes.func,
1101
- displayFormat: PropTypes.func,
1102
- parseDateInput: PropTypes.func,
1103
- onChange: PropTypes.func,
1104
- onComplete: PropTypes.func,
1105
- onClear: PropTypes.func,
1106
- minDate: dateType,
1107
- maxDate: dateType,
1108
- hidden: PropTypes.bool,
1109
- fromPlaceholder: PropTypes.string,
1110
- toPlaceholder: PropTypes.string,
1111
- timePlaceholder: PropTypes.string
1112
- });
1113
-
1114
- _defineProperty(DatePopup, "defaultProps", {
1115
- onChange() {}
1116
-
1117
- });
1118
-
1119
- var formats = ['d M', 'dd M', 'dd MM', 'd-M', 'dd-M', 'dd-MM', 'd.M', 'dd.M', 'dd.MM', 'd\\M', 'dd\\M', 'dd\\MM', 'd/M', 'dd/M', 'dd/MM', 'd M yy', 'dd M yy', 'dd MM yy', 'd M yyyy', 'dd M yyyy', 'dd MM yyyy', 'd-M-yy', 'dd-M-yy', 'dd-MM-yy', 'd-M-yyyy', 'dd-M-yyyy', 'dd-MM-yyyy', 'd.M.yy', 'dd.M.yy', 'dd.MM.yy', 'd.M.yyyy', 'dd.M.yyyy', 'dd.MM.yyyy', 'd\\M\\yy', 'dd\\M\\yy', 'dd\\MM\\yy', 'd\\M\\yyyy', 'dd\\M\\yyyy', 'dd\\MM\\yyyy', 'd/M/yy', 'dd/M/yy', 'dd/MM/yy', 'd/M/yyyy', 'dd/M/yyyy', 'dd/MM/yyyy', 'd M yy', 'dd M yy', 'dd MM yy', 'd M yyyy', 'dd M yyyy', 'dd MM yyyy', 'd-M-yy', 'dd-M-yy', 'dd-MM-yy', 'd-M-yyyy', 'dd-M-yyyy', 'dd-MM-yyyy', 'd.M.yy', 'dd.M.yy', 'dd.MM.yy', 'd.M.yyyy', 'dd.M.yyyy', 'dd.MM.yyyy', 'd\\M\\yy', 'dd\\M\\yy', 'dd\\MM\\yy', 'd\\M\\yyyy', 'dd\\M\\yyyy', 'dd\\MM\\yyyy', 'd/M/yy', 'dd/M/yy', 'dd/MM/yy', 'd/M/yyyy', 'dd/M/yyyy', 'dd/MM/yyyy', 'yy M d', 'yy M dd', 'yy MM dd', 'yyyy M d', 'yyyy M dd', 'yyyy MM dd', 'yy-M-d', 'yy-M-dd', 'yy-MM-dd', 'yyyy-M-d', 'yyyy-M-dd', 'yyyy-MM-dd', 'yy.M.d', 'yy.M.dd', 'yy.MM.dd', 'yyyy.M.d', 'yyyy.M.dd', 'yyyy.MM.dd', 'yy\\M\\d', 'yy\\M\\dd', 'yy\\MM\\dd', 'yyyy\\M\\d', 'yyyy\\M\\dd', 'yyyy\\MM\\dd', 'yy/M/d', 'yy/M/dd', 'yy/MM/dd', 'yyyy/M/d', 'yyyy/M/dd', 'yyyy/MM/dd', 'yy d M', 'yy dd M', 'yy dd MM', 'yyyy d M', 'yyyy dd MM', 'yyyy dd MM', 'yy-d-M', 'yy-dd-M', 'yy-dd-MM', 'yyyy-d-M', 'yyyy-dd-MM', 'yyyy-dd-MM', 'yy.d.M', 'yy.dd.M', 'yy.dd.MM', 'yyyy.d.M', 'yyyy.dd.MM', 'yyyy.dd.MM', 'yy\\d\\M', 'yy\\dd\\M', 'yy\\dd\\MM', 'yyyy\\d\\M', 'yyyy\\dd\\MM', 'yyyy\\dd\\MM', 'yy/d/M', 'yy/dd/M', 'yy/dd/MM', 'yyyy/d/M', 'yyyy/dd/MM', 'yyyy/dd/MM', 'd MMM', 'd MMMM', 'dd MMM', 'dd MMMM', 'd M HH:mm', 'd M, HH:mm', 'dd M HH:mm', 'dd M, HH:mm', 'dd MM HH:mm', 'dd MM, HH:mm', 'd-M HH:mm', 'd-M, HH:mm', 'dd-M HH:mm', 'dd-M, HH:mm', 'dd-MM HH:mm', 'dd-MM, HH:mm', 'd.M HH:mm', 'd.M, HH:mm', 'dd.M HH:mm', 'dd.M, HH:mm', 'dd.MM HH:mm', 'dd.MM, HH:mm', 'd\\M HH:mm', 'd\\M, HH:mm', 'dd\\M HH:mm', 'dd\\M, HH:mm', 'dd\\MM HH:mm', 'dd\\MM, HH:mm', 'd/M HH:mm', 'd/M, HH:mm', 'dd/M HH:mm', 'dd/M, HH:mm', 'dd/MM HH:mm', 'dd/MM, HH:mm', 'd M yy HH:mm', 'd M yy, HH:mm', 'dd M yy HH:mm', 'dd M yy, HH:mm', 'dd MM yy HH:mm', 'dd MM yy, HH:mm', 'd M yyyy HH:mm', 'd M yyyy, HH:mm', 'dd M yyyy HH:mm', 'dd M yyyy, HH:mm', 'dd MM yyyy HH:mm', 'dd MM yyyy, HH:mm', 'd-M-yy HH:mm', 'd-M-yy, HH:mm', 'dd-M-yy HH:mm', 'dd-M-yy, HH:mm', 'dd-MM-yy HH:mm', 'dd-MM-yy, HH:mm', 'd-M-yyyy HH:mm', 'd-M-yyyy, HH:mm', 'dd-M-yyyy HH:mm', 'dd-M-yyyy, HH:mm', 'dd-MM-yyyy HH:mm', 'dd-MM-yyyy, HH:mm', 'd.M.yy HH:mm', 'd.M.yy, HH:mm', 'dd.M.yy HH:mm', 'dd.M.yy, HH:mm', 'dd.MM.yy HH:mm', 'dd.MM.yy, HH:mm', 'd.M.yyyy HH:mm', 'd.M.yyyy, HH:mm', 'dd.M.yyyy HH:mm', 'dd.M.yyyy, HH:mm', 'dd.MM.yyyy HH:mm', 'dd.MM.yyyy, HH:mm', 'd\\M\\yy HH:mm', 'd\\M\\yy, HH:mm', 'dd\\M\\yy HH:mm', 'dd\\M\\yy, HH:mm', 'dd\\MM\\yy HH:mm', 'dd\\MM\\yy, HH:mm', 'd\\M\\yyyy HH:mm', 'd\\M\\yyyy, HH:mm', 'dd\\M\\yyyy HH:mm', 'dd\\M\\yyyy, HH:mm', 'dd\\MM\\yyyy HH:mm', 'dd\\MM\\yyyy, HH:mm', 'd/M/yy HH:mm', 'd/M/yy, HH:mm', 'dd/M/yy HH:mm', 'dd/M/yy, HH:mm', 'dd/MM/yy HH:mm', 'dd/MM/yy, HH:mm', 'd/M/yyyy HH:mm', 'd/M/yyyy, HH:mm', 'dd/M/yyyy HH:mm', 'dd/M/yyyy, HH:mm', 'dd/MM/yyyy HH:mm', 'dd/MM/yyyy, HH:mm', 'd M yy HH:mm', 'd M yy, HH:mm', 'dd M yy HH:mm', 'dd M yy, HH:mm', 'dd MM yy HH:mm', 'dd MM yy, HH:mm', 'd M yyyy HH:mm', 'd M yyyy, HH:mm', 'dd M yyyy HH:mm', 'dd M yyyy, HH:mm', 'dd MM yyyy HH:mm', 'dd MM yyyy, HH:mm', 'd-M-yy HH:mm', 'd-M-yy, HH:mm', 'dd-M-yy HH:mm', 'dd-M-yy, HH:mm', 'dd-MM-yy HH:mm', 'dd-MM-yy, HH:mm', 'd-M-yyyy HH:mm', 'd-M-yyyy, HH:mm', 'dd-M-yyyy HH:mm', 'dd-M-yyyy, HH:mm', 'dd-MM-yyyy HH:mm', 'dd-MM-yyyy, HH:mm', 'd.M.yy HH:mm', 'd.M.yy, HH:mm', 'dd.M.yy HH:mm', 'dd.M.yy, HH:mm', 'dd.MM.yy HH:mm', 'dd.MM.yy, HH:mm', 'd.M.yyyy HH:mm', 'd.M.yyyy, HH:mm', 'dd.M.yyyy HH:mm', 'dd.M.yyyy, HH:mm', 'dd.MM.yyyy HH:mm', 'dd.MM.yyyy, HH:mm', 'd\\M\\yy HH:mm', 'd\\M\\yy, HH:mm', 'dd\\M\\yy HH:mm', 'dd\\M\\yy, HH:mm', 'dd\\MM\\yy HH:mm', 'dd\\MM\\yy, HH:mm', 'd\\M\\yyyy HH:mm', 'd\\M\\yyyy, HH:mm', 'dd\\M\\yyyy HH:mm', 'dd\\M\\yyyy, HH:mm', 'dd\\MM\\yyyy HH:mm', 'dd\\MM\\yyyy, HH:mm', 'd/M/yy HH:mm', 'd/M/yy, HH:mm', 'dd/M/yy HH:mm', 'dd/M/yy, HH:mm', 'dd/MM/yy HH:mm', 'dd/MM/yy, HH:mm', 'd/M/yyyy HH:mm', 'd/M/yyyy, HH:mm', 'dd/M/yyyy HH:mm', 'dd/M/yyyy, HH:mm', 'dd/MM/yyyy HH:mm', 'dd/MM/yyyy, HH:mm', 'yy M d HH:mm', 'yy M d, HH:mm', 'yy M dd HH:mm', 'yy M dd, HH:mm', 'yy MM dd HH:mm', 'yy MM dd, HH:mm', 'yyyy M d HH:mm', 'yyyy M d, HH:mm', 'yyyy M dd HH:mm', 'yyyy M dd, HH:mm', 'yyyy MM dd HH:mm', 'yyyy MM dd, HH:mm', 'yy-M-d HH:mm', 'yy-M-d, HH:mm', 'yy-M-dd HH:mm', 'yy-M-dd, HH:mm', 'yy-MM-dd HH:mm', 'yy-MM-dd, HH:mm', 'yyyy-M-d HH:mm', 'yyyy-M-d, HH:mm', 'yyyy-M-dd HH:mm', 'yyyy-M-dd, HH:mm', 'yyyy-MM-dd HH:mm', 'yyyy-MM-dd, HH:mm', 'yy.M.d HH:mm', 'yy.M.d, HH:mm', 'yy.M.dd HH:mm', 'yy.M.dd, HH:mm', 'yy.MM.dd HH:mm', 'yy.MM.dd, HH:mm', 'yyyy.M.d HH:mm', 'yyyy.M.d, HH:mm', 'yyyy.M.dd HH:mm', 'yyyy.M.dd, HH:mm', 'yyyy.MM.dd HH:mm', 'yyyy.MM.dd, HH:mm', 'yy\\M\\d HH:mm', 'yy\\M\\d, HH:mm', 'yy\\M\\dd HH:mm', 'yy\\M\\dd, HH:mm', 'yy\\MM\\dd HH:mm', 'yy\\MM\\dd, HH:mm', 'yyyy\\M\\d HH:mm', 'yyyy\\M\\d, HH:mm', 'yyyy\\M\\dd HH:mm', 'yyyy\\M\\dd, HH:mm', 'yyyy\\MM\\dd HH:mm', 'yyyy\\MM\\dd, HH:mm', 'yy/M/d HH:mm', 'yy/M/d, HH:mm', 'yy/M/dd HH:mm', 'yy/M/dd, HH:mm', 'yy/MM/dd HH:mm', 'yy/MM/dd, HH:mm', 'yyyy/M/d HH:mm', 'yyyy/M/d, HH:mm', 'yyyy/M/dd HH:mm', 'yyyy/M/dd, HH:mm', 'yyyy/MM/dd HH:mm', 'yyyy/MM/dd, HH:mm', 'yy d M HH:mm', 'yy d M, HH:mm', 'yy dd M HH:mm', 'yy dd M, HH:mm', 'yy dd MM HH:mm', 'yy dd MM, HH:mm', 'yyyy d M HH:mm', 'yyyy d M, HH:mm', 'yyyy dd MM HH:mm', 'yyyy dd MM, HH:mm', 'yyyy dd MM HH:mm', 'yyyy dd MM, HH:mm', 'yy-d-M HH:mm', 'yy-d-M, HH:mm', 'yy-dd-M HH:mm', 'yy-dd-M, HH:mm', 'yy-dd-MM HH:mm', 'yy-dd-MM, HH:mm', 'yyyy-d-M HH:mm', 'yyyy-d-M, HH:mm', 'yyyy-dd-MM HH:mm', 'yyyy-dd-MM, HH:mm', 'yyyy-dd-MM HH:mm', 'yyyy-dd-MM, HH:mm', 'yy.d.M HH:mm', 'yy.d.M, HH:mm', 'yy.dd.M HH:mm', 'yy.dd.M, HH:mm', 'yy.dd.MM HH:mm', 'yy.dd.MM, HH:mm', 'yyyy.d.M HH:mm', 'yyyy.d.M, HH:mm', 'yyyy.dd.MM HH:mm', 'yyyy.dd.MM, HH:mm', 'yyyy.dd.MM HH:mm', 'yyyy.dd.MM, HH:mm', 'yy\\d\\M HH:mm', 'yy\\d\\M, HH:mm', 'yy\\dd\\M HH:mm', 'yy\\dd\\M, HH:mm', 'yy\\dd\\MM HH:mm', 'yy\\dd\\MM, HH:mm', 'yyyy\\d\\M HH:mm', 'yyyy\\d\\M, HH:mm', 'yyyy\\dd\\MM HH:mm', 'yyyy\\dd\\MM, HH:mm', 'yyyy\\dd\\MM HH:mm', 'yyyy\\dd\\MM, HH:mm', 'yy/d/M HH:mm', 'yy/d/M, HH:mm', 'yy/dd/M HH:mm', 'yy/dd/M, HH:mm', 'yy/dd/MM HH:mm', 'yy/dd/MM, HH:mm', 'yyyy/d/M HH:mm', 'yyyy/d/M, HH:mm', 'yyyy/dd/MM HH:mm', 'yyyy/dd/MM, HH:mm', 'yyyy/dd/MM HH:mm', 'yyyy/dd/MM, HH:mm', 'd MMM HH:mm', 'd MMM, HH:mm', 'd MMMM HH:mm', 'd MMMM, HH:mm', 'dd MMM HH:mm', 'dd MMM, HH:mm', 'dd MMMM HH:mm', 'dd MMMM, HH:mm', 'yyyy MMM d', 'yyyy MMMM d', 'yyyy MMM dd', 'yyyy MMMM dd', 'yyyy d MMM', 'yyyy d MMMM', 'yyyy dd MMM', 'yyyy dd MMMM', 'd MMM yy', 'd MMMM yy', 'dd MMM yy', 'dd MMMM yy', 'd MMM yyyy', 'd MMMM yyyy', 'dd MMM yyyy', 'dd MMMM yyyy', 'd MMM yy', 'd MMMM yy', 'dd MMM yy', 'dd MMMM yy', 'd MMM yyyy', 'd MMMM yyyy', 'dd MMM yyyy', 'dd MMMM yyyy', 'MMM d yyyy', 'MMMM d yyyy', 'MMM dd yyyy', 'MMMM dd yyyy', 'yy MMM d', 'yy MMMM d', 'yy MMM dd', 'yy MMMM dd', 'yy d MMM', 'yy d MMMM', 'yy dd MMM', 'yy dd MMMM', 'd MMM', 'd MMMM', 'dd MMM', 'dd MMMM', 'yyyy MMM d HH:mm', 'yyyy MMM d, HH:mm', 'yyyy MMMM d HH:mm', 'yyyy MMMM d, HH:mm', 'yyyy MMM dd HH:mm', 'yyyy MMM dd, HH:mm', 'yyyy MMMM dd HH:mm', 'yyyy MMMM dd, HH:mm', 'yyyy d MMM HH:mm', 'yyyy d MMM, HH:mm', 'yyyy d MMMM HH:mm', 'yyyy d MMMM, HH:mm', 'yyyy dd MMM HH:mm', 'yyyy dd MMM, HH:mm', 'yyyy dd MMMM HH:mm', 'yyyy dd MMMM, HH:mm', 'd MMM yy HH:mm', 'd MMM yy, HH:mm', 'd MMMM yy HH:mm', 'd MMMM yy, HH:mm', 'dd MMM yy HH:mm', 'dd MMM yy, HH:mm', 'dd MMMM yy HH:mm', 'dd MMMM yy, HH:mm', 'd MMM yyyy HH:mm', 'd MMM yyyy, HH:mm', 'd MMMM yyyy HH:mm', 'd MMMM yyyy, HH:mm', 'dd MMM yyyy HH:mm', 'dd MMM yyyy, HH:mm', 'dd MMMM yyyy HH:mm', 'dd MMMM yyyy, HH:mm', 'd MMM yy HH:mm', 'd MMM yy, HH:mm', 'd MMMM yy HH:mm', 'd MMMM yy, HH:mm', 'dd MMM yy HH:mm', 'dd MMM yy, HH:mm', 'dd MMMM yy HH:mm', 'dd MMMM yy, HH:mm', 'd MMM yyyy HH:mm', 'd MMM yyyy, HH:mm', 'd MMMM yyyy HH:mm', 'd MMMM yyyy, HH:mm', 'dd MMM yyyy HH:mm', 'dd MMM yyyy, HH:mm', 'dd MMMM yyyy HH:mm', 'dd MMMM yyyy, HH:mm', 'MMM d yyyy HH:mm', 'MMM d yyyy, HH:mm', 'MMMM d yyyy HH:mm', 'MMMM d yyyy, HH:mm', 'MMM dd yyyy HH:mm', 'MMM dd yyyy, HH:mm', 'MMMM dd yyyy HH:mm', 'MMMM dd yyyy, HH:mm', 'yy MMM d HH:mm', 'yy MMM d, HH:mm', 'yy MMMM d HH:mm', 'yy MMMM d, HH:mm', 'yy MMM dd HH:mm', 'yy MMM dd, HH:mm', 'yy MMMM dd HH:mm', 'yy MMMM dd, HH:mm', 'yy d MMM HH:mm', 'yy d MMM, HH:mm', 'yy d MMMM HH:mm', 'yy d MMMM, HH:mm', 'yy dd MMM HH:mm', 'yy dd MMM, HH:mm', 'yy dd MMMM HH:mm', 'yy dd MMMM, HH:mm', 'd MMM HH:mm', 'd MMM, HH:mm', 'd MMMM HH:mm', 'd MMMM, HH:mm', 'dd MMM HH:mm', 'dd MMM, HH:mm', 'dd MMMM HH:mm', 'dd MMMM, HH:mm', 'yyyy MMM d', 'yyyy MMMM d', 'yyyy MMM dd', 'yyyy MMMM dd', 'yyyy d MMM', 'yyyy d MMMM', 'yyyy dd MMM', 'yyyy dd MMMM', 'd MMM yy', 'd MMMM yy', 'dd MMM yy', 'dd MMMM yy', 'd MMM yyyy', 'd MMMM yyyy', 'dd MMM yyyy', 'dd MMMM yyyy', 'd MMM yy', 'd MMMM yy', 'dd MMM yy', 'dd MMMM yy', 'd MMM yyyy', 'd MMMM yyyy', 'dd MMM yyyy', 'dd MMMM yyyy', 'MMM d yyyy', 'MMMM d yyyy', 'MMM dd yyyy', 'MMMM dd yyyy', 'yy MMM d', 'yy MMMM d', 'yy MMM dd', 'yy MMMM dd', 'yy d MMM', 'yy d MMMM', 'yy dd MMM', 'yy dd MMMM', 'yyyy MMM d HH:mm', 'yyyy MMM d, HH:mm', 'yyyy MMMM d HH:mm', 'yyyy MMMM d, HH:mm', 'yyyy MMM dd HH:mm', 'yyyy MMM dd, HH:mm', 'yyyy MMMM dd HH:mm', 'yyyy MMMM dd, HH:mm', 'yyyy d MMM HH:mm', 'yyyy d MMM, HH:mm', 'yyyy d MMMM HH:mm', 'yyyy d MMMM, HH:mm', 'yyyy dd MMM HH:mm', 'yyyy dd MMM, HH:mm', 'yyyy dd MMMM HH:mm', 'yyyy dd MMMM, HH:mm', 'd MMM yy HH:mm', 'd MMM yy, HH:mm', 'd MMMM yy HH:mm', 'd MMMM yy, HH:mm', 'dd MMM yy HH:mm', 'dd MMM yy, HH:mm', 'dd MMMM yy HH:mm', 'dd MMMM yy, HH:mm', 'd MMM yyyy HH:mm', 'd MMM yyyy, HH:mm', 'd MMMM yyyy HH:mm', 'd MMMM yyyy, HH:mm', 'dd MMM yyyy HH:mm', 'dd MMM yyyy, HH:mm', 'dd MMMM yyyy HH:mm', 'dd MMMM yyyy, HH:mm', 'd MMM yy HH:mm', 'd MMM yy, HH:mm', 'd MMMM yy HH:mm', 'd MMMM yy, HH:mm', 'dd MMM yy HH:mm', 'dd MMM yy, HH:mm', 'dd MMMM yy HH:mm', 'dd MMMM yy, HH:mm', 'd MMM yyyy HH:mm', 'd MMM yyyy, HH:mm', 'd MMMM yyyy HH:mm', 'd MMMM yyyy, HH:mm', 'dd MMM yyyy HH:mm', 'dd MMM yyyy, HH:mm', 'dd MMMM yyyy HH:mm', 'dd MMMM yyyy, HH:mm', 'MMM d yyyy HH:mm', 'MMM d yyyy, HH:mm', 'MMMM d yyyy HH:mm', 'MMMM d yyyy, HH:mm', 'MMM dd yyyy HH:mm', 'MMM dd yyyy, HH:mm', 'MMMM dd yyyy HH:mm', 'MMMM dd yyyy, HH:mm', 'yy MMM d HH:mm', 'yy MMM d, HH:mm', 'yy MMMM d HH:mm', 'yy MMMM d, HH:mm', 'yy MMM dd HH:mm', 'yy MMM dd, HH:mm', 'yy MMMM dd HH:mm', 'yy MMMM dd, HH:mm', 'yy d MMM HH:mm', 'yy d MMM, HH:mm', 'yy d MMMM HH:mm', 'yy d MMMM, HH:mm', 'yy dd MMM HH:mm', 'yy dd MMM, HH:mm', 'yy dd MMMM HH:mm', 'yy dd MMMM, HH:mm'];
1120
-
1121
- const PopupComponent = (_ref) => {
1122
- let {
1123
- hidden,
1124
- className,
1125
- popupRef,
1126
- onClear,
1127
- datePopupProps,
1128
- onComplete
1129
- } = _ref,
1130
- restProps = _objectWithoutProperties(_ref, ["hidden", "className", "popupRef", "onClear", "datePopupProps", "onComplete"]);
1131
-
1132
- return /*#__PURE__*/React.createElement(Popup, _extends({
1133
- hidden: hidden,
1134
- keepMounted: true,
1135
- className: className,
1136
- ref: popupRef,
1137
- directions: [Popup.PopupProps.Directions.BOTTOM_RIGHT, Popup.PopupProps.Directions.BOTTOM_LEFT, Popup.PopupProps.Directions.TOP_LEFT, Popup.PopupProps.Directions.TOP_RIGHT]
1138
- }, restProps), /*#__PURE__*/React.createElement(DatePopup, _extends({
1139
- onClear: onClear
1140
- }, datePopupProps, {
1141
- onComplete: onComplete,
1142
- hidden: hidden
1143
- })));
1144
- };
1145
-
1146
- PopupComponent.propTypes = {
1147
- hidden: PropTypes.bool,
1148
- className: PropTypes.string,
1149
- popupRef: PropTypes.func,
1150
- onClear: PropTypes.func,
1151
- datePopupProps: PropTypes.shape(DatePopup.propTypes),
1152
- onComplete: PropTypes.func
1153
- };
1154
- /**
1155
- * @name Date Picker
1156
- */
1157
-
1158
- class DatePicker extends PureComponent {
1159
- constructor(...args) {
1160
- super(...args);
1161
-
1162
- _defineProperty(this, "handleChange", change => {
1163
- const {
1164
- onChange,
1165
- onDateChange,
1166
- withTime,
1167
- applyTimeInput
1168
- } = this.props;
1169
- const adjustedChange = withTime && change.date != null ? applyTimeInput(change.date, change.time) : change;
1170
- onChange(adjustedChange);
1171
-
1172
- if (onDateChange != null) {
1173
- onDateChange(adjustedChange);
1174
- }
1175
- });
1176
-
1177
- _defineProperty(this, "clear", () => {
1178
- let change = null;
1179
-
1180
- if (this.props.range) {
1181
- change = {
1182
- from: null,
1183
- to: null
1184
- };
1185
- }
1186
-
1187
- this.handleChange(change);
1188
- });
1189
-
1190
- _defineProperty(this, "popupRef", el => {
1191
- this.popup = el;
1192
- });
1193
-
1194
- _defineProperty(this, "closePopup", () => {
1195
- this.popup._onCloseAttempt();
1196
- });
1197
-
1198
- _defineProperty(this, "parse", memoize(date => {
1199
- const {
1200
- parseDateInput
1201
- } = this.props;
1202
-
1203
- if (date instanceof Date) {
1204
- return date;
1205
- }
1206
-
1207
- if (typeof date === 'number') {
1208
- return new Date(date);
1209
- }
1210
-
1211
- return parseDateInput(date);
1212
- }));
1213
-
1214
- _defineProperty(this, "getAnchorText", () => {
1215
- const {
1216
- range,
1217
- datePlaceholder,
1218
- dateTimePlaceholder,
1219
- rangePlaceholder,
1220
- withTime,
1221
- displayFormat,
1222
- displayMonthFormat,
1223
- displayDayFormat,
1224
- translations
1225
- } = this.props;
1226
- const date = this.parse(this.props.date);
1227
- const from = this.parse(this.props.from);
1228
- const to = this.parse(this.props.to);
1229
- const time = this.formatTime();
1230
- let text;
1231
-
1232
- if (!range && !withTime) {
1233
- text = date ? displayFormat(date) : datePlaceholder || translations.setDate;
1234
- } else if (!range && withTime) {
1235
- if (!date && !time) {
1236
- text = dateTimePlaceholder || translations.setDateTime;
1237
- } else {
1238
- text = `${date && displayFormat(date) || '—'}, ${time || '—'}`;
1239
- }
1240
- } else if (!from && !to) {
1241
- text = rangePlaceholder || translations.setPeriod;
1242
- } else if (!to) {
1243
- text = `${displayFormat(from)} —`;
1244
- } else if (!from) {
1245
- text = `— ${displayFormat(to)}`;
1246
- } else if (!isSameYear(from, to)) {
1247
- text = `${displayFormat(from)} — ${displayFormat(to)}`;
1248
- } else if (!isSameMonth(from, to)) {
1249
- text = `${displayMonthFormat(from)} — ${displayFormat(to)}`;
1250
- } else if (!isSameDay(from, to)) {
1251
- text = `${displayDayFormat(from)} — ${displayFormat(to)}`;
1252
- } else {
1253
- text = `${displayFormat(to)}`;
1254
- }
1255
-
1256
- return text;
1257
- });
1258
- }
1259
-
1260
- formatTime() {
1261
- const {
1262
- displayTimeFormat
1263
- } = this.props;
1264
- const date = this.parse(this.props.date);
1265
-
1266
- if (date != null) {
1267
- return displayTimeFormat(date);
1268
- }
1269
-
1270
- return null;
1271
- }
1272
-
1273
- render() {
1274
- const text = this.getAnchorText();
1275
-
1276
- if (this.props.disabled) {
1277
- return /*#__PURE__*/React.createElement(Anchor, {
1278
- disabled: true
1279
- }, text);
1280
- }
1281
-
1282
- const _this$props = this.props,
1283
- {
1284
- className,
1285
- popupClassName,
1286
- clear,
1287
- dropdownProps,
1288
- translations
1289
- } = _this$props,
1290
- datePopupProps = _objectWithoutProperties(_this$props, ["className", "popupClassName", "clear", "dropdownProps", "translations"]);
1291
-
1292
- const classes = classNames(modules_0c7b7d96.datePicker, className); // We want to provide translations further down to DateInput.
1293
- // Yet we should pass at least DateInput default translations not to have them empty.
1294
-
1295
- datePopupProps.translations = Object.assign({}, DateInput.defaultProps.translations, translations);
1296
- return /*#__PURE__*/React.createElement(Dropdown, _extends({
1297
- className: classes,
1298
- anchor: text
1299
- }, dropdownProps), /*#__PURE__*/React.createElement(PopupComponent, {
1300
- className: popupClassName,
1301
- popupRef: this.popupRef,
1302
- onClear: clear ? this.clear : null,
1303
- datePopupProps: _objectSpread2(_objectSpread2({}, datePopupProps), {}, {
1304
- onChange: this.handleChange,
1305
- parseDateInput: this.parse,
1306
- time: this.formatTime()
1307
- }),
1308
- onComplete: this.closePopup
1309
- }));
1310
- }
1311
-
1312
- }
1313
-
1314
- _defineProperty(DatePicker, "propTypes", {
1315
- className: PropTypes.string,
1316
- popupClassName: PropTypes.string,
1317
- date: dateType,
1318
- withTime: PropTypes.bool,
1319
- range: PropTypes.bool,
1320
- from: dateType,
1321
- to: dateType,
1322
- clear: PropTypes.bool,
1323
- displayFormat: PropTypes.func,
1324
- displayMonthFormat: PropTypes.func,
1325
- displayDayFormat: PropTypes.func,
1326
- displayTimeFormat: PropTypes.func,
1327
- parseDateInput: PropTypes.func,
1328
- applyTimeInput: PropTypes.func,
1329
- datePlaceholder: PropTypes.string,
1330
- dateTimePlaceholder: PropTypes.string,
1331
- rangePlaceholder: PropTypes.string,
1332
- onChange: PropTypes.func,
1333
- // TODO: Remove in 5.0
1334
- onDateChange: deprecatedPropType('Use "onChange"'),
1335
- dropdownProps: PropTypes.object,
1336
- disabled: PropTypes.bool,
1337
- minDate: dateType,
1338
- maxDate: dateType,
1339
- translations: PropTypes.object
1340
- });
1341
-
1342
- _defineProperty(DatePicker, "defaultProps", {
1343
- className: '',
1344
- date: null,
1345
- withTime: false,
1346
- range: false,
1347
- from: null,
1348
- to: null,
1349
- clear: false,
1350
- displayFormat: date => date ? format(date, 'd MMM yyyy') : '',
1351
- displayMonthFormat: date => date ? format(date, 'd MMM') : '',
1352
- displayDayFormat: date => date ? format(date, 'd') : '',
1353
- displayTimeFormat: date => date ? format(date, 'HH:mm') : '',
1354
- datePlaceholder: 'Set a date',
1355
- dateTimePlaceholder: 'Set date and time',
1356
- rangePlaceholder: 'Set a period',
1357
- minDate: null,
1358
- maxDate: null,
1359
-
1360
- onChange() {},
1361
-
1362
- translations: {
1363
- setDate: 'Set a date',
1364
- setDateTime: 'Set date and time',
1365
- setPeriod: 'Set a period'
1366
- },
1367
-
1368
- applyTimeInput(date, timeString) {
1369
- var _timeString$split;
1370
-
1371
- const [hours, minutes] = (_timeString$split = timeString === null || timeString === void 0 ? void 0 : timeString.split(':')) !== null && _timeString$split !== void 0 ? _timeString$split : [];
1372
- return minutes != null ? set(date, {
1373
- hours,
1374
- minutes
1375
- }) : date;
1376
- },
1377
-
1378
- parseDateInput(string) {
1379
- if (!string) {
1380
- return null;
1381
- }
1382
-
1383
- const today = new Date();
1384
-
1385
- for (const format of formats) {
1386
- const date = parse(string, format, today);
1387
-
1388
- if (isValid(date)) {
1389
- return date;
1390
- }
1391
- }
1392
-
1393
- return null;
1394
- }
1395
-
1396
- });
1397
-
1398
- export default DatePicker;