@atlaskit/datetime-picker 12.3.7 → 12.3.9
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.
- package/CHANGELOG.md +13 -0
- package/dist/cjs/components/date-picker.js +98 -202
- package/dist/cjs/components/date-time-picker.js +40 -83
- package/dist/cjs/components/time-picker.js +34 -101
- package/dist/cjs/components/utils.js +1 -8
- package/dist/cjs/index.js +0 -4
- package/dist/cjs/internal/fixed-layer.js +6 -34
- package/dist/cjs/internal/index.js +4 -6
- package/dist/cjs/internal/parse-time.js +0 -26
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/components/date-picker.js +71 -135
- package/dist/es2019/components/date-time-picker.js +34 -37
- package/dist/es2019/components/time-picker.js +22 -49
- package/dist/es2019/components/utils.js +1 -7
- package/dist/es2019/internal/fixed-layer.js +4 -9
- package/dist/es2019/internal/index.js +4 -2
- package/dist/es2019/internal/parse-time.js +0 -18
- package/dist/es2019/version.json +1 -1
- package/dist/esm/components/date-picker.js +100 -199
- package/dist/esm/components/date-time-picker.js +42 -72
- package/dist/esm/components/time-picker.js +36 -93
- package/dist/esm/components/utils.js +1 -7
- package/dist/esm/internal/fixed-layer.js +6 -24
- package/dist/esm/internal/index.js +4 -2
- package/dist/esm/internal/parse-time.js +0 -18
- package/dist/esm/version.json +1 -1
- package/dist/types/components/date-picker.d.ts +8 -12
- package/package.json +6 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @atlaskit/datetime-picker
|
|
2
2
|
|
|
3
|
+
## 12.3.9
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`5546747df1e`](https://bitbucket.org/atlassian/atlassian-frontend/commits/5546747df1e) - Refactoring of code to clean tech debt and make future maintenance easier
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
|
|
10
|
+
## 12.3.8
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies
|
|
15
|
+
|
|
3
16
|
## 12.3.7
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
|
@@ -1,89 +1,56 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
6
|
-
|
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
8
|
exports.default = exports.DatePickerWithoutAnalytics = void 0;
|
|
11
|
-
|
|
12
9
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
13
|
-
|
|
14
10
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
15
|
-
|
|
16
11
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
17
|
-
|
|
18
12
|
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
19
|
-
|
|
20
13
|
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
21
|
-
|
|
22
14
|
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
23
|
-
|
|
24
15
|
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
25
|
-
|
|
26
16
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
27
|
-
|
|
28
17
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
29
|
-
|
|
30
18
|
var _react = require("react");
|
|
31
|
-
|
|
32
19
|
var _react2 = require("@emotion/react");
|
|
33
|
-
|
|
34
20
|
var _dateFns = require("date-fns");
|
|
35
|
-
|
|
36
21
|
var _pick = _interopRequireDefault(require("lodash/pick"));
|
|
37
|
-
|
|
38
22
|
var _analyticsNext = require("@atlaskit/analytics-next");
|
|
39
|
-
|
|
40
23
|
var _calendar = _interopRequireDefault(require("@atlaskit/calendar"));
|
|
41
|
-
|
|
42
24
|
var _calendar2 = _interopRequireDefault(require("@atlaskit/icon/glyph/calendar"));
|
|
43
|
-
|
|
44
25
|
var _locale = require("@atlaskit/locale");
|
|
45
|
-
|
|
46
26
|
var _select = _interopRequireWildcard(require("@atlaskit/select"));
|
|
47
|
-
|
|
48
27
|
var _colors = require("@atlaskit/theme/colors");
|
|
49
|
-
|
|
50
28
|
var _constants = require("@atlaskit/theme/constants");
|
|
51
|
-
|
|
52
29
|
var _internal = require("../internal");
|
|
53
|
-
|
|
54
30
|
var _fixedLayer = _interopRequireDefault(require("../internal/fixed-layer"));
|
|
55
|
-
|
|
56
31
|
var _utils = require("./utils");
|
|
57
|
-
|
|
58
32
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
59
|
-
|
|
60
33
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
61
|
-
|
|
62
34
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
63
|
-
|
|
64
35
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
65
|
-
|
|
66
36
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
|
|
67
|
-
|
|
68
37
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
69
|
-
|
|
70
38
|
var packageName = "@atlaskit/datetime-picker";
|
|
71
|
-
var packageVersion = "12.3.
|
|
39
|
+
var packageVersion = "12.3.9";
|
|
40
|
+
|
|
72
41
|
/* eslint-disable react/no-unused-prop-types */
|
|
73
42
|
|
|
74
|
-
function
|
|
75
|
-
|
|
43
|
+
function getValidDate(iso) {
|
|
44
|
+
var date = (0, _dateFns.parseISO)(iso);
|
|
45
|
+
return (0, _dateFns.isValid)(date) ? {
|
|
76
46
|
day: date.getDate(),
|
|
77
47
|
month: date.getMonth() + 1,
|
|
78
48
|
year: date.getFullYear()
|
|
79
|
-
};
|
|
49
|
+
} : {};
|
|
80
50
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
var date = (0, _dateFns.parseISO)(iso);
|
|
84
|
-
return (0, _dateFns.isValid)(date) ? getDateObj(date) : {};
|
|
51
|
+
function getShortISOString(date) {
|
|
52
|
+
return (0, _dateFns.format)(date, (0, _utils.convertTokens)('YYYY-MM-DD'));
|
|
85
53
|
}
|
|
86
|
-
|
|
87
54
|
var menuStyles = (0, _react2.css)({
|
|
88
55
|
zIndex: _constants.layers.dialog(),
|
|
89
56
|
backgroundColor: "var(--ds-surface-overlay, ".concat(_colors.N20, ")"),
|
|
@@ -91,10 +58,9 @@ var menuStyles = (0, _react2.css)({
|
|
|
91
58
|
boxShadow: "var(--ds-shadow-overlay, ".concat("0 4px 8px -2px ".concat(_colors.N50A, ", 0 0 1px ").concat(_colors.N60A), ")"),
|
|
92
59
|
overflow: 'hidden'
|
|
93
60
|
});
|
|
94
|
-
|
|
95
61
|
var Menu = function Menu(_ref) {
|
|
96
62
|
var selectProps = _ref.selectProps,
|
|
97
|
-
|
|
63
|
+
innerProps = _ref.innerProps;
|
|
98
64
|
return (0, _react2.jsx)(_fixedLayer.default, {
|
|
99
65
|
inputValue: selectProps.inputValue,
|
|
100
66
|
containerRef: selectProps.calendarContainerRef,
|
|
@@ -119,7 +85,6 @@ var Menu = function Menu(_ref) {
|
|
|
119
85
|
testId: selectProps.testId
|
|
120
86
|
});
|
|
121
87
|
};
|
|
122
|
-
|
|
123
88
|
var datePickerDefaultProps = {
|
|
124
89
|
appearance: 'default',
|
|
125
90
|
autoFocus: false,
|
|
@@ -141,19 +106,15 @@ var datePickerDefaultProps = {
|
|
|
141
106
|
onFocus: function onFocus(event) {},
|
|
142
107
|
selectProps: {},
|
|
143
108
|
spacing: 'default',
|
|
144
|
-
locale: 'en-US'
|
|
109
|
+
locale: 'en-US'
|
|
110
|
+
// Not including a default prop for value as it will
|
|
145
111
|
// Make the component a controlled component
|
|
146
|
-
|
|
147
112
|
};
|
|
148
|
-
|
|
149
113
|
var DatePicker = /*#__PURE__*/function (_Component) {
|
|
150
114
|
(0, _inherits2.default)(DatePicker, _Component);
|
|
151
|
-
|
|
152
115
|
var _super = _createSuper(DatePicker);
|
|
153
|
-
|
|
154
116
|
function DatePicker(props) {
|
|
155
117
|
var _this;
|
|
156
|
-
|
|
157
118
|
(0, _classCallCheck2.default)(this, DatePicker);
|
|
158
119
|
_this = _super.call(this, props);
|
|
159
120
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "calendarRef", null);
|
|
@@ -166,40 +127,34 @@ var DatePicker = /*#__PURE__*/function (_Component) {
|
|
|
166
127
|
});
|
|
167
128
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onCalendarChange", function (_ref2) {
|
|
168
129
|
var iso = _ref2.iso;
|
|
169
|
-
|
|
170
130
|
var _iso$split = iso.split('-'),
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
131
|
+
_iso$split2 = (0, _slicedToArray2.default)(_iso$split, 3),
|
|
132
|
+
year = _iso$split2[0],
|
|
133
|
+
month = _iso$split2[1],
|
|
134
|
+
date = _iso$split2[2];
|
|
176
135
|
var newIso = iso;
|
|
177
136
|
var parsedDate = parseInt(date, 10);
|
|
178
137
|
var parsedMonth = parseInt(month, 10);
|
|
179
138
|
var parsedYear = parseInt(year, 10);
|
|
180
|
-
var lastDayInMonth = (0, _dateFns.lastDayOfMonth)(new Date(parsedYear, parsedMonth - 1)
|
|
181
|
-
|
|
139
|
+
var lastDayInMonth = (0, _dateFns.lastDayOfMonth)(new Date(parsedYear, parsedMonth - 1) // This needs to be -1, because the Date constructor expects an index of the given month
|
|
140
|
+
).getDate();
|
|
182
141
|
if (lastDayInMonth < parsedDate) {
|
|
183
142
|
newIso = "".concat(year, "-").concat((0, _internal.padToTwo)(parsedMonth), "-").concat((0, _internal.padToTwo)(lastDayInMonth));
|
|
184
143
|
} else {
|
|
185
144
|
newIso = "".concat(year, "-").concat((0, _internal.padToTwo)(parsedMonth), "-").concat((0, _internal.padToTwo)(parsedDate));
|
|
186
145
|
}
|
|
187
|
-
|
|
188
146
|
_this.setState({
|
|
189
|
-
|
|
147
|
+
calendarValue: newIso
|
|
190
148
|
});
|
|
191
149
|
});
|
|
192
150
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onCalendarSelect", function (_ref3) {
|
|
193
151
|
var iso = _ref3.iso;
|
|
194
|
-
|
|
195
152
|
_this.setState({
|
|
196
|
-
|
|
153
|
+
selectInputValue: '',
|
|
197
154
|
isOpen: false,
|
|
198
|
-
|
|
199
|
-
view: iso,
|
|
155
|
+
calendarValue: iso,
|
|
200
156
|
value: iso
|
|
201
157
|
});
|
|
202
|
-
|
|
203
158
|
_this.props.onChange(iso);
|
|
204
159
|
});
|
|
205
160
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onInputClick", function () {
|
|
@@ -221,14 +176,12 @@ var DatePicker = /*#__PURE__*/function (_Component) {
|
|
|
221
176
|
isFocused: false
|
|
222
177
|
});
|
|
223
178
|
}
|
|
224
|
-
|
|
225
179
|
_this.props.onBlur(event);
|
|
226
180
|
});
|
|
227
181
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onSelectFocus", function (event) {
|
|
228
182
|
var _this$getSafeState = _this.getSafeState(),
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
183
|
+
clearingFromIcon = _this$getSafeState.clearingFromIcon,
|
|
184
|
+
value = _this$getSafeState.value;
|
|
232
185
|
if (clearingFromIcon) {
|
|
233
186
|
// Don't open menu if focussing after the user has clicked clear
|
|
234
187
|
_this.setState({
|
|
@@ -237,37 +190,33 @@ var DatePicker = /*#__PURE__*/function (_Component) {
|
|
|
237
190
|
} else {
|
|
238
191
|
_this.setState({
|
|
239
192
|
isOpen: true,
|
|
240
|
-
|
|
193
|
+
calendarValue: value,
|
|
241
194
|
isFocused: true
|
|
242
195
|
});
|
|
243
196
|
}
|
|
244
|
-
|
|
245
197
|
_this.props.onFocus(event);
|
|
246
198
|
});
|
|
247
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "
|
|
199
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onTextInput", function (event) {
|
|
248
200
|
var value = event.target.value;
|
|
249
|
-
|
|
250
201
|
if (value) {
|
|
251
|
-
var parsed = _this.parseDate(value);
|
|
252
|
-
|
|
253
|
-
|
|
202
|
+
var parsed = _this.parseDate(value);
|
|
203
|
+
// Only try to set the date if we have month & day
|
|
254
204
|
if (parsed && (0, _dateFns.isValid)(parsed)) {
|
|
255
205
|
// We format the parsed date to YYYY-MM-DD here because
|
|
256
206
|
// this is the format expected by the @atlaskit/calendar component
|
|
257
207
|
_this.setState({
|
|
258
|
-
|
|
208
|
+
calendarValue: getShortISOString(parsed)
|
|
259
209
|
});
|
|
260
210
|
}
|
|
261
211
|
}
|
|
262
|
-
|
|
263
212
|
_this.setState({
|
|
264
213
|
isOpen: true
|
|
265
214
|
});
|
|
266
215
|
});
|
|
267
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "
|
|
268
|
-
// If
|
|
269
|
-
|
|
270
|
-
|
|
216
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getSafeCalendarValue", function (calendarValue) {
|
|
217
|
+
// If `calendarValue` has a year that is greater than 9999, default to
|
|
218
|
+
// today's date
|
|
219
|
+
var yearIsOverLimit = calendarValue.match(/^\d{5,}/);
|
|
271
220
|
if (yearIsOverLimit) {
|
|
272
221
|
var today = new Date();
|
|
273
222
|
var year = today.getFullYear();
|
|
@@ -275,117 +224,89 @@ var DatePicker = /*#__PURE__*/function (_Component) {
|
|
|
275
224
|
var day = today.getDate().toString().padStart(2, '0');
|
|
276
225
|
return "".concat(year, "-").concat(month, "-").concat(day);
|
|
277
226
|
}
|
|
278
|
-
|
|
279
|
-
return view;
|
|
227
|
+
return calendarValue;
|
|
280
228
|
});
|
|
281
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "
|
|
229
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onInputKeyDown", function (event) {
|
|
282
230
|
var _this$getSafeState2 = _this.getSafeState(),
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
231
|
+
value = _this$getSafeState2.value,
|
|
232
|
+
calendarValue = _this$getSafeState2.calendarValue;
|
|
286
233
|
var keyPressed = event.key.toLowerCase();
|
|
287
|
-
|
|
288
234
|
switch (keyPressed) {
|
|
289
235
|
case 'arrowup':
|
|
290
236
|
case 'arrowdown':
|
|
291
237
|
if (_this.calendarRef) {
|
|
292
238
|
event.preventDefault();
|
|
293
239
|
var key = keyPressed === 'arrowup' ? 'up' : 'down';
|
|
294
|
-
|
|
295
240
|
_this.calendarRef.navigate(key);
|
|
296
241
|
}
|
|
297
|
-
|
|
298
242
|
_this.setState({
|
|
299
243
|
isOpen: true
|
|
300
244
|
});
|
|
301
|
-
|
|
302
245
|
break;
|
|
303
|
-
|
|
304
246
|
case 'arrowleft':
|
|
305
247
|
case 'arrowright':
|
|
306
248
|
if (_this.calendarRef) {
|
|
307
249
|
event.preventDefault();
|
|
308
|
-
|
|
309
250
|
var _key = keyPressed === 'arrowleft' ? 'left' : 'right';
|
|
310
|
-
|
|
311
251
|
_this.calendarRef.navigate(_key);
|
|
312
252
|
}
|
|
313
|
-
|
|
314
253
|
break;
|
|
315
|
-
|
|
316
254
|
case 'escape':
|
|
317
255
|
case 'tab':
|
|
318
256
|
_this.setState({
|
|
319
257
|
isOpen: false
|
|
320
258
|
});
|
|
321
|
-
|
|
322
259
|
break;
|
|
323
|
-
|
|
324
260
|
case 'backspace':
|
|
325
261
|
case 'delete':
|
|
326
|
-
if (
|
|
262
|
+
if (value && event.target instanceof HTMLInputElement && event.target.value.length < 1) {
|
|
327
263
|
// If being cleared from keyboard, don't change behaviour
|
|
328
264
|
_this.setState({
|
|
329
265
|
clearingFromIcon: false
|
|
330
266
|
});
|
|
331
267
|
}
|
|
332
|
-
|
|
333
268
|
break;
|
|
334
|
-
|
|
335
269
|
case 'enter':
|
|
336
270
|
if (!_this.state.isOpen) {
|
|
337
271
|
return;
|
|
338
|
-
}
|
|
272
|
+
}
|
|
273
|
+
// Prevent form submission when a date is selected
|
|
339
274
|
// using enter. See https://product-fabric.atlassian.net/browse/DSP-2501
|
|
340
275
|
// for more details.
|
|
341
|
-
|
|
342
|
-
|
|
343
276
|
event.preventDefault();
|
|
344
|
-
|
|
345
|
-
if (!_this.isDateDisabled(view)) {
|
|
277
|
+
if (!_this.isDateDisabled(calendarValue)) {
|
|
346
278
|
var _this$getSafeState3 = _this.getSafeState(),
|
|
347
|
-
|
|
279
|
+
_value = _this$getSafeState3.value;
|
|
280
|
+
// Get a safe `calendarValue` in case the value exceeds the maximum
|
|
348
281
|
// allowed by ISO 8601
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
var safeView = _this.getSafeView(view);
|
|
352
|
-
|
|
353
|
-
var valueChanged = safeView !== _value;
|
|
354
|
-
|
|
282
|
+
var safeCalendarValue = _this.getSafeCalendarValue(calendarValue);
|
|
283
|
+
var valueChanged = safeCalendarValue !== _value;
|
|
355
284
|
_this.setState({
|
|
356
|
-
|
|
285
|
+
selectInputValue: '',
|
|
357
286
|
isOpen: false,
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
view: safeView
|
|
287
|
+
value: safeCalendarValue,
|
|
288
|
+
calendarValue: safeCalendarValue
|
|
361
289
|
});
|
|
362
|
-
|
|
363
290
|
if (valueChanged) {
|
|
364
|
-
_this.props.onChange(
|
|
291
|
+
_this.props.onChange(safeCalendarValue);
|
|
365
292
|
}
|
|
366
293
|
}
|
|
367
|
-
|
|
368
294
|
break;
|
|
369
|
-
|
|
370
295
|
default:
|
|
371
296
|
break;
|
|
372
297
|
}
|
|
373
298
|
});
|
|
374
299
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onClear", function () {
|
|
375
300
|
var changedState = {
|
|
376
|
-
selectedValue: '',
|
|
377
301
|
value: '',
|
|
378
|
-
|
|
302
|
+
calendarValue: _this.props.defaultValue || getShortISOString(new Date())
|
|
379
303
|
};
|
|
380
|
-
|
|
381
304
|
if (!_this.props.hideIcon) {
|
|
382
305
|
changedState = _objectSpread(_objectSpread({}, changedState), {}, {
|
|
383
306
|
clearingFromIcon: true
|
|
384
307
|
});
|
|
385
308
|
}
|
|
386
|
-
|
|
387
309
|
_this.setState(changedState);
|
|
388
|
-
|
|
389
310
|
_this.props.onChange('');
|
|
390
311
|
});
|
|
391
312
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onSelectChange", function (value, action) {
|
|
@@ -398,86 +319,67 @@ var DatePicker = /*#__PURE__*/function (_Component) {
|
|
|
398
319
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "refCalendar", function (ref) {
|
|
399
320
|
_this.calendarRef = ref;
|
|
400
321
|
});
|
|
401
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "
|
|
322
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleSelectInputChange", function (selectInputValue, actionMeta) {
|
|
402
323
|
var onInputChange = _this.props.selectProps.onInputChange;
|
|
403
|
-
|
|
404
324
|
if (onInputChange) {
|
|
405
|
-
onInputChange(
|
|
325
|
+
onInputChange(selectInputValue, actionMeta);
|
|
406
326
|
}
|
|
407
|
-
|
|
408
327
|
_this.setState({
|
|
409
|
-
|
|
328
|
+
selectInputValue: selectInputValue
|
|
410
329
|
});
|
|
411
330
|
});
|
|
412
331
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getContainerRef", function (ref) {
|
|
413
332
|
var oldRef = _this.containerRef;
|
|
414
|
-
_this.containerRef = ref;
|
|
333
|
+
_this.containerRef = ref;
|
|
334
|
+
// Cause a re-render if we're getting the container ref for the first time
|
|
415
335
|
// as the layered menu requires it for dimension calculation
|
|
416
|
-
|
|
417
336
|
if (oldRef == null && ref != null) {
|
|
418
337
|
_this.forceUpdate();
|
|
419
338
|
}
|
|
420
339
|
});
|
|
421
340
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "parseDate", function (date) {
|
|
422
341
|
var _this$props = _this.props,
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
342
|
+
parseInputValue = _this$props.parseInputValue,
|
|
343
|
+
dateFormat = _this$props.dateFormat;
|
|
426
344
|
if (parseInputValue) {
|
|
427
345
|
return parseInputValue(date, dateFormat || _internal.defaultDateFormat);
|
|
428
346
|
}
|
|
429
|
-
|
|
430
347
|
var _this$getSafeState4 = _this.getSafeState(),
|
|
431
|
-
|
|
432
|
-
|
|
348
|
+
l10n = _this$getSafeState4.l10n;
|
|
433
349
|
return l10n.parseDate(date);
|
|
434
350
|
});
|
|
435
351
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "formatDate", function (value) {
|
|
436
352
|
var _this$props2 = _this.props,
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
353
|
+
formatDisplayLabel = _this$props2.formatDisplayLabel,
|
|
354
|
+
dateFormat = _this$props2.dateFormat;
|
|
440
355
|
var _this$getSafeState5 = _this.getSafeState(),
|
|
441
|
-
|
|
442
|
-
|
|
356
|
+
l10n = _this$getSafeState5.l10n;
|
|
443
357
|
if (formatDisplayLabel) {
|
|
444
358
|
return formatDisplayLabel(value, dateFormat || _internal.defaultDateFormat);
|
|
445
359
|
}
|
|
446
|
-
|
|
447
360
|
var date = (0, _dateFns.parseISO)(value);
|
|
448
361
|
return dateFormat ? (0, _dateFns.format)(date, (0, _utils.convertTokens)(dateFormat)) : l10n.formatDate(date);
|
|
449
362
|
});
|
|
450
363
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getPlaceholder", function () {
|
|
451
364
|
var placeholder = _this.props.placeholder;
|
|
452
|
-
|
|
453
365
|
if (placeholder) {
|
|
454
366
|
return placeholder;
|
|
455
367
|
}
|
|
456
|
-
|
|
457
368
|
var _this$getSafeState6 = _this.getSafeState(),
|
|
458
|
-
|
|
459
|
-
|
|
369
|
+
l10n = _this$getSafeState6.l10n;
|
|
460
370
|
return l10n.formatDate(_internal.placeholderDatetime);
|
|
461
371
|
});
|
|
462
|
-
|
|
463
|
-
var _getDateObj = getDateObj(new Date()),
|
|
464
|
-
_day = _getDateObj.day,
|
|
465
|
-
_month = _getDateObj.month,
|
|
466
|
-
_year = _getDateObj.year;
|
|
467
|
-
|
|
468
372
|
_this.state = {
|
|
469
373
|
isOpen: _this.props.defaultIsOpen,
|
|
470
374
|
isFocused: false,
|
|
471
375
|
clearingFromIcon: false,
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
view: _this.props.value || _this.props.defaultValue || "".concat(_year, "-").concat((0, _internal.padToTwo)(_month), "-").concat((0, _internal.padToTwo)(_day)),
|
|
376
|
+
selectInputValue: _this.props.selectProps.inputValue,
|
|
377
|
+
value: _this.props.value || _this.props.defaultValue,
|
|
378
|
+
calendarValue: _this.props.value || _this.props.defaultValue || getShortISOString(new Date()),
|
|
476
379
|
l10n: (0, _locale.createLocalizationProvider)(_this.props.locale)
|
|
477
380
|
};
|
|
478
381
|
return _this;
|
|
479
382
|
}
|
|
480
|
-
|
|
481
383
|
(0, _createClass2.default)(DatePicker, [{
|
|
482
384
|
key: "UNSAFE_componentWillReceiveProps",
|
|
483
385
|
value: function UNSAFE_componentWillReceiveProps(nextProps) {
|
|
@@ -486,54 +388,51 @@ var DatePicker = /*#__PURE__*/function (_Component) {
|
|
|
486
388
|
l10n: (0, _locale.createLocalizationProvider)(nextProps.locale)
|
|
487
389
|
});
|
|
488
390
|
}
|
|
489
|
-
}
|
|
490
|
-
// correctly to allow controlled/uncontrolled usage.
|
|
391
|
+
}
|
|
491
392
|
|
|
393
|
+
// All state needs to be accessed via this function so that the state is mapped from props
|
|
394
|
+
// correctly to allow controlled/uncontrolled usage.
|
|
492
395
|
}, {
|
|
493
396
|
key: "render",
|
|
494
397
|
value: function render() {
|
|
495
398
|
var _this$props3 = this.props,
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
399
|
+
appearance = _this$props3.appearance,
|
|
400
|
+
autoFocus = _this$props3.autoFocus,
|
|
401
|
+
disabled = _this$props3.disabled,
|
|
402
|
+
hideIcon = _this$props3.hideIcon,
|
|
403
|
+
icon = _this$props3.icon,
|
|
404
|
+
id = _this$props3.id,
|
|
405
|
+
innerProps = _this$props3.innerProps,
|
|
406
|
+
isDisabled = _this$props3.isDisabled,
|
|
407
|
+
disabledDateFilter = _this$props3.disabledDateFilter,
|
|
408
|
+
maxDate = _this$props3.maxDate,
|
|
409
|
+
minDate = _this$props3.minDate,
|
|
410
|
+
isInvalid = _this$props3.isInvalid,
|
|
411
|
+
name = _this$props3.name,
|
|
412
|
+
nextMonthLabel = _this$props3.nextMonthLabel,
|
|
413
|
+
previousMonthLabel = _this$props3.previousMonthLabel,
|
|
414
|
+
selectProps = _this$props3.selectProps,
|
|
415
|
+
spacing = _this$props3.spacing,
|
|
416
|
+
locale = _this$props3.locale,
|
|
417
|
+
testId = _this$props3.testId,
|
|
418
|
+
weekStartDay = _this$props3.weekStartDay;
|
|
516
419
|
var ICON_PADDING = 2;
|
|
517
|
-
|
|
518
420
|
var _this$getSafeState7 = this.getSafeState(),
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
421
|
+
value = _this$getSafeState7.value,
|
|
422
|
+
calendarValue = _this$getSafeState7.calendarValue,
|
|
423
|
+
isOpen = _this$getSafeState7.isOpen,
|
|
424
|
+
selectInputValue = _this$getSafeState7.selectInputValue;
|
|
524
425
|
var menuIsOpen = isOpen && !isDisabled;
|
|
525
|
-
var showClearIndicator = Boolean((value ||
|
|
426
|
+
var showClearIndicator = Boolean((value || selectInputValue) && !hideIcon);
|
|
526
427
|
var dropDownIcon = appearance === 'subtle' || hideIcon || showClearIndicator ? null : icon;
|
|
527
|
-
|
|
528
428
|
var selectComponents = _objectSpread({
|
|
529
429
|
DropdownIndicator: dropDownIcon,
|
|
530
430
|
Menu: Menu
|
|
531
431
|
}, !showClearIndicator && {
|
|
532
432
|
ClearIndicator: _internal.EmptyComponent
|
|
533
433
|
});
|
|
534
|
-
|
|
535
434
|
var _selectProps$styles = selectProps.styles,
|
|
536
|
-
|
|
435
|
+
selectStyles = _selectProps$styles === void 0 ? {} : _selectProps$styles;
|
|
537
436
|
var disabledStyle = isDisabled ? {
|
|
538
437
|
pointerEvents: 'none',
|
|
539
438
|
color: "var(--ds-icon-disabled, inherit)"
|
|
@@ -545,8 +444,8 @@ var DatePicker = /*#__PURE__*/function (_Component) {
|
|
|
545
444
|
calendarDisabledDateFilter: disabledDateFilter,
|
|
546
445
|
calendarMaxDate: maxDate,
|
|
547
446
|
calendarMinDate: minDate,
|
|
548
|
-
calendarValue: value && (
|
|
549
|
-
calendarView:
|
|
447
|
+
calendarValue: value && getShortISOString((0, _dateFns.parseISO)(value)),
|
|
448
|
+
calendarView: calendarValue,
|
|
550
449
|
onCalendarChange: this.onCalendarChange,
|
|
551
450
|
onCalendarSelect: this.onCalendarSelect,
|
|
552
451
|
calendarLocale: locale,
|
|
@@ -557,8 +456,8 @@ var DatePicker = /*#__PURE__*/function (_Component) {
|
|
|
557
456
|
return (0, _react2.jsx)("div", (0, _extends2.default)({}, innerProps, {
|
|
558
457
|
role: "presentation",
|
|
559
458
|
onClick: this.onInputClick,
|
|
560
|
-
onInput: this.
|
|
561
|
-
onKeyDown: this.
|
|
459
|
+
onInput: this.onTextInput,
|
|
460
|
+
onKeyDown: this.onInputKeyDown,
|
|
562
461
|
ref: this.getContainerRef,
|
|
563
462
|
"data-testid": testId && "".concat(testId, "--container")
|
|
564
463
|
}), (0, _react2.jsx)("input", {
|
|
@@ -577,8 +476,8 @@ var DatePicker = /*#__PURE__*/function (_Component) {
|
|
|
577
476
|
isDisabled: isDisabled,
|
|
578
477
|
onBlur: this.onSelectBlur,
|
|
579
478
|
onFocus: this.onSelectFocus,
|
|
580
|
-
inputValue:
|
|
581
|
-
onInputChange: this.
|
|
479
|
+
inputValue: selectInputValue,
|
|
480
|
+
onInputChange: this.handleSelectInputChange,
|
|
582
481
|
components: selectComponents,
|
|
583
482
|
onChange: this.onSelectChange,
|
|
584
483
|
styles: (0, _select.mergeStyles)(selectStyles, {
|
|
@@ -607,10 +506,8 @@ var DatePicker = /*#__PURE__*/function (_Component) {
|
|
|
607
506
|
}]);
|
|
608
507
|
return DatePicker;
|
|
609
508
|
}(_react.Component);
|
|
610
|
-
|
|
611
509
|
exports.DatePickerWithoutAnalytics = DatePicker;
|
|
612
510
|
(0, _defineProperty2.default)(DatePicker, "defaultProps", datePickerDefaultProps);
|
|
613
|
-
|
|
614
511
|
var _default = (0, _analyticsNext.withAnalyticsContext)({
|
|
615
512
|
componentName: 'datePicker',
|
|
616
513
|
packageName: packageName,
|
|
@@ -626,5 +523,4 @@ var _default = (0, _analyticsNext.withAnalyticsContext)({
|
|
|
626
523
|
}
|
|
627
524
|
})
|
|
628
525
|
})(DatePicker));
|
|
629
|
-
|
|
630
526
|
exports.default = _default;
|