@atlaskit/datetime-picker 12.3.6 → 12.3.8
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 +12 -0
- package/dist/cjs/components/date-picker.js +81 -160
- 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 +47 -85
- 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 +83 -156
- 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 +1 -0
- package/package.json +2 -2
- package/report.api.md +13 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @atlaskit/datetime-picker
|
|
2
2
|
|
|
3
|
+
## 12.3.8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
|
|
9
|
+
## 12.3.7
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [`98891267a5e`](https://bitbucket.org/atlassian/atlassian-frontend/commits/98891267a5e) - [ux] Dates entered with 5+ digit years will no longer throw a RangeError
|
|
14
|
+
|
|
3
15
|
## 12.3.6
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -1,74 +1,43 @@
|
|
|
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.8";
|
|
40
|
+
|
|
72
41
|
/* eslint-disable react/no-unused-prop-types */
|
|
73
42
|
|
|
74
43
|
function getDateObj(date) {
|
|
@@ -78,12 +47,10 @@ function getDateObj(date) {
|
|
|
78
47
|
year: date.getFullYear()
|
|
79
48
|
};
|
|
80
49
|
}
|
|
81
|
-
|
|
82
50
|
function getValidDate(iso) {
|
|
83
51
|
var date = (0, _dateFns.parseISO)(iso);
|
|
84
52
|
return (0, _dateFns.isValid)(date) ? getDateObj(date) : {};
|
|
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,32 +127,28 @@ 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
|
view: 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
|
inputValue: '',
|
|
197
154
|
isOpen: false,
|
|
@@ -199,7 +156,6 @@ var DatePicker = /*#__PURE__*/function (_Component) {
|
|
|
199
156
|
view: iso,
|
|
200
157
|
value: iso
|
|
201
158
|
});
|
|
202
|
-
|
|
203
159
|
_this.props.onChange(iso);
|
|
204
160
|
});
|
|
205
161
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onInputClick", function () {
|
|
@@ -221,14 +177,12 @@ var DatePicker = /*#__PURE__*/function (_Component) {
|
|
|
221
177
|
isFocused: false
|
|
222
178
|
});
|
|
223
179
|
}
|
|
224
|
-
|
|
225
180
|
_this.props.onBlur(event);
|
|
226
181
|
});
|
|
227
182
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onSelectFocus", function (event) {
|
|
228
183
|
var _this$getSafeState = _this.getSafeState(),
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
184
|
+
clearingFromIcon = _this$getSafeState.clearingFromIcon,
|
|
185
|
+
value = _this$getSafeState.value;
|
|
232
186
|
if (clearingFromIcon) {
|
|
233
187
|
// Don't open menu if focussing after the user has clicked clear
|
|
234
188
|
_this.setState({
|
|
@@ -241,16 +195,13 @@ var DatePicker = /*#__PURE__*/function (_Component) {
|
|
|
241
195
|
isFocused: true
|
|
242
196
|
});
|
|
243
197
|
}
|
|
244
|
-
|
|
245
198
|
_this.props.onFocus(event);
|
|
246
199
|
});
|
|
247
200
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onSelectInput", function (event) {
|
|
248
201
|
var value = event.target.value;
|
|
249
|
-
|
|
250
202
|
if (value) {
|
|
251
|
-
var parsed = _this.parseDate(value);
|
|
252
|
-
|
|
253
|
-
|
|
203
|
+
var parsed = _this.parseDate(value);
|
|
204
|
+
// Only try to set the date if we have month & day
|
|
254
205
|
if (parsed && (0, _dateFns.isValid)(parsed)) {
|
|
255
206
|
// We format the parsed date to YYYY-MM-DD here because
|
|
256
207
|
// this is the format expected by the @atlaskit/calendar component
|
|
@@ -259,54 +210,53 @@ var DatePicker = /*#__PURE__*/function (_Component) {
|
|
|
259
210
|
});
|
|
260
211
|
}
|
|
261
212
|
}
|
|
262
|
-
|
|
263
213
|
_this.setState({
|
|
264
214
|
isOpen: true
|
|
265
215
|
});
|
|
266
216
|
});
|
|
217
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getSafeView", function (view) {
|
|
218
|
+
// If view has a year that is greater than 9999, default to today's date
|
|
219
|
+
var yearIsOverLimit = view.match(/^\d{5,}/);
|
|
220
|
+
if (yearIsOverLimit) {
|
|
221
|
+
var today = new Date();
|
|
222
|
+
var year = today.getFullYear();
|
|
223
|
+
var month = (today.getMonth() + 1).toString().padStart(2, '0');
|
|
224
|
+
var day = today.getDate().toString().padStart(2, '0');
|
|
225
|
+
return "".concat(year, "-").concat(month, "-").concat(day);
|
|
226
|
+
}
|
|
227
|
+
return view;
|
|
228
|
+
});
|
|
267
229
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onSelectKeyDown", function (event) {
|
|
268
230
|
var _this$getSafeState2 = _this.getSafeState(),
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
231
|
+
view = _this$getSafeState2.view,
|
|
232
|
+
selectedValue = _this$getSafeState2.selectedValue;
|
|
272
233
|
var keyPressed = event.key.toLowerCase();
|
|
273
|
-
|
|
274
234
|
switch (keyPressed) {
|
|
275
235
|
case 'arrowup':
|
|
276
236
|
case 'arrowdown':
|
|
277
237
|
if (_this.calendarRef) {
|
|
278
238
|
event.preventDefault();
|
|
279
239
|
var key = keyPressed === 'arrowup' ? 'up' : 'down';
|
|
280
|
-
|
|
281
240
|
_this.calendarRef.navigate(key);
|
|
282
241
|
}
|
|
283
|
-
|
|
284
242
|
_this.setState({
|
|
285
243
|
isOpen: true
|
|
286
244
|
});
|
|
287
|
-
|
|
288
245
|
break;
|
|
289
|
-
|
|
290
246
|
case 'arrowleft':
|
|
291
247
|
case 'arrowright':
|
|
292
248
|
if (_this.calendarRef) {
|
|
293
249
|
event.preventDefault();
|
|
294
|
-
|
|
295
250
|
var _key = keyPressed === 'arrowleft' ? 'left' : 'right';
|
|
296
|
-
|
|
297
251
|
_this.calendarRef.navigate(_key);
|
|
298
252
|
}
|
|
299
|
-
|
|
300
253
|
break;
|
|
301
|
-
|
|
302
254
|
case 'escape':
|
|
303
255
|
case 'tab':
|
|
304
256
|
_this.setState({
|
|
305
257
|
isOpen: false
|
|
306
258
|
});
|
|
307
|
-
|
|
308
259
|
break;
|
|
309
|
-
|
|
310
260
|
case 'backspace':
|
|
311
261
|
case 'delete':
|
|
312
262
|
if (selectedValue && event.target instanceof HTMLInputElement && event.target.value.length < 1) {
|
|
@@ -315,40 +265,34 @@ var DatePicker = /*#__PURE__*/function (_Component) {
|
|
|
315
265
|
clearingFromIcon: false
|
|
316
266
|
});
|
|
317
267
|
}
|
|
318
|
-
|
|
319
268
|
break;
|
|
320
|
-
|
|
321
269
|
case 'enter':
|
|
322
270
|
if (!_this.state.isOpen) {
|
|
323
271
|
return;
|
|
324
|
-
}
|
|
272
|
+
}
|
|
273
|
+
// Prevent form submission when a date is selected
|
|
325
274
|
// using enter. See https://product-fabric.atlassian.net/browse/DSP-2501
|
|
326
275
|
// for more details.
|
|
327
|
-
|
|
328
|
-
|
|
329
276
|
event.preventDefault();
|
|
330
|
-
|
|
331
277
|
if (!_this.isDateDisabled(view)) {
|
|
332
278
|
var _this$getSafeState3 = _this.getSafeState(),
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
279
|
+
_value = _this$getSafeState3.value;
|
|
280
|
+
// Get a safe `view` value in case the value exceeds the maximum
|
|
281
|
+
// allowed by ISO 8601
|
|
282
|
+
var safeView = _this.getSafeView(view);
|
|
283
|
+
var valueChanged = safeView !== _value;
|
|
337
284
|
_this.setState({
|
|
338
285
|
inputValue: '',
|
|
339
286
|
isOpen: false,
|
|
340
|
-
selectedValue:
|
|
341
|
-
value:
|
|
342
|
-
view:
|
|
287
|
+
selectedValue: safeView,
|
|
288
|
+
value: safeView,
|
|
289
|
+
view: safeView
|
|
343
290
|
});
|
|
344
|
-
|
|
345
291
|
if (valueChanged) {
|
|
346
|
-
_this.props.onChange(
|
|
292
|
+
_this.props.onChange(safeView);
|
|
347
293
|
}
|
|
348
294
|
}
|
|
349
|
-
|
|
350
295
|
break;
|
|
351
|
-
|
|
352
296
|
default:
|
|
353
297
|
break;
|
|
354
298
|
}
|
|
@@ -359,15 +303,12 @@ var DatePicker = /*#__PURE__*/function (_Component) {
|
|
|
359
303
|
value: '',
|
|
360
304
|
view: _this.props.defaultValue || (0, _dateFns.format)(new Date(), (0, _utils.convertTokens)('YYYY-MM-DD'))
|
|
361
305
|
};
|
|
362
|
-
|
|
363
306
|
if (!_this.props.hideIcon) {
|
|
364
307
|
changedState = _objectSpread(_objectSpread({}, changedState), {}, {
|
|
365
308
|
clearingFromIcon: true
|
|
366
309
|
});
|
|
367
310
|
}
|
|
368
|
-
|
|
369
311
|
_this.setState(changedState);
|
|
370
|
-
|
|
371
312
|
_this.props.onChange('');
|
|
372
313
|
});
|
|
373
314
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onSelectChange", function (value, action) {
|
|
@@ -382,71 +323,58 @@ var DatePicker = /*#__PURE__*/function (_Component) {
|
|
|
382
323
|
});
|
|
383
324
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleInputChange", function (inputValue, actionMeta) {
|
|
384
325
|
var onInputChange = _this.props.selectProps.onInputChange;
|
|
385
|
-
|
|
386
326
|
if (onInputChange) {
|
|
387
327
|
onInputChange(inputValue, actionMeta);
|
|
388
328
|
}
|
|
389
|
-
|
|
390
329
|
_this.setState({
|
|
391
330
|
inputValue: inputValue
|
|
392
331
|
});
|
|
393
332
|
});
|
|
394
333
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getContainerRef", function (ref) {
|
|
395
334
|
var oldRef = _this.containerRef;
|
|
396
|
-
_this.containerRef = ref;
|
|
335
|
+
_this.containerRef = ref;
|
|
336
|
+
// Cause a re-render if we're getting the container ref for the first time
|
|
397
337
|
// as the layered menu requires it for dimension calculation
|
|
398
|
-
|
|
399
338
|
if (oldRef == null && ref != null) {
|
|
400
339
|
_this.forceUpdate();
|
|
401
340
|
}
|
|
402
341
|
});
|
|
403
342
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "parseDate", function (date) {
|
|
404
343
|
var _this$props = _this.props,
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
344
|
+
parseInputValue = _this$props.parseInputValue,
|
|
345
|
+
dateFormat = _this$props.dateFormat;
|
|
408
346
|
if (parseInputValue) {
|
|
409
347
|
return parseInputValue(date, dateFormat || _internal.defaultDateFormat);
|
|
410
348
|
}
|
|
411
|
-
|
|
412
349
|
var _this$getSafeState4 = _this.getSafeState(),
|
|
413
|
-
|
|
414
|
-
|
|
350
|
+
l10n = _this$getSafeState4.l10n;
|
|
415
351
|
return l10n.parseDate(date);
|
|
416
352
|
});
|
|
417
353
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "formatDate", function (value) {
|
|
418
354
|
var _this$props2 = _this.props,
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
355
|
+
formatDisplayLabel = _this$props2.formatDisplayLabel,
|
|
356
|
+
dateFormat = _this$props2.dateFormat;
|
|
422
357
|
var _this$getSafeState5 = _this.getSafeState(),
|
|
423
|
-
|
|
424
|
-
|
|
358
|
+
l10n = _this$getSafeState5.l10n;
|
|
425
359
|
if (formatDisplayLabel) {
|
|
426
360
|
return formatDisplayLabel(value, dateFormat || _internal.defaultDateFormat);
|
|
427
361
|
}
|
|
428
|
-
|
|
429
362
|
var date = (0, _dateFns.parseISO)(value);
|
|
430
363
|
return dateFormat ? (0, _dateFns.format)(date, (0, _utils.convertTokens)(dateFormat)) : l10n.formatDate(date);
|
|
431
364
|
});
|
|
432
365
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getPlaceholder", function () {
|
|
433
366
|
var placeholder = _this.props.placeholder;
|
|
434
|
-
|
|
435
367
|
if (placeholder) {
|
|
436
368
|
return placeholder;
|
|
437
369
|
}
|
|
438
|
-
|
|
439
370
|
var _this$getSafeState6 = _this.getSafeState(),
|
|
440
|
-
|
|
441
|
-
|
|
371
|
+
l10n = _this$getSafeState6.l10n;
|
|
442
372
|
return l10n.formatDate(_internal.placeholderDatetime);
|
|
443
373
|
});
|
|
444
|
-
|
|
445
374
|
var _getDateObj = getDateObj(new Date()),
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
375
|
+
_day = _getDateObj.day,
|
|
376
|
+
_month = _getDateObj.month,
|
|
377
|
+
_year = _getDateObj.year;
|
|
450
378
|
_this.state = {
|
|
451
379
|
isOpen: _this.props.defaultIsOpen,
|
|
452
380
|
isFocused: false,
|
|
@@ -454,12 +382,11 @@ var DatePicker = /*#__PURE__*/function (_Component) {
|
|
|
454
382
|
inputValue: _this.props.selectProps.inputValue,
|
|
455
383
|
selectedValue: _this.props.value || _this.props.defaultValue,
|
|
456
384
|
value: _this.props.defaultValue,
|
|
457
|
-
view: _this.props.value || _this.props.defaultValue || "".concat(_year, "-").concat((0, _internal.padToTwo)(_month), "-").concat((0, _internal.padToTwo)(
|
|
385
|
+
view: _this.props.value || _this.props.defaultValue || "".concat(_year, "-").concat((0, _internal.padToTwo)(_month), "-").concat((0, _internal.padToTwo)(_day)),
|
|
458
386
|
l10n: (0, _locale.createLocalizationProvider)(_this.props.locale)
|
|
459
387
|
};
|
|
460
388
|
return _this;
|
|
461
389
|
}
|
|
462
|
-
|
|
463
390
|
(0, _createClass2.default)(DatePicker, [{
|
|
464
391
|
key: "UNSAFE_componentWillReceiveProps",
|
|
465
392
|
value: function UNSAFE_componentWillReceiveProps(nextProps) {
|
|
@@ -468,54 +395,51 @@ var DatePicker = /*#__PURE__*/function (_Component) {
|
|
|
468
395
|
l10n: (0, _locale.createLocalizationProvider)(nextProps.locale)
|
|
469
396
|
});
|
|
470
397
|
}
|
|
471
|
-
}
|
|
472
|
-
// correctly to allow controlled/uncontrolled usage.
|
|
398
|
+
}
|
|
473
399
|
|
|
400
|
+
// All state needs to be accessed via this function so that the state is mapped from props
|
|
401
|
+
// correctly to allow controlled/uncontrolled usage.
|
|
474
402
|
}, {
|
|
475
403
|
key: "render",
|
|
476
404
|
value: function render() {
|
|
477
405
|
var _this$props3 = this.props,
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
406
|
+
appearance = _this$props3.appearance,
|
|
407
|
+
autoFocus = _this$props3.autoFocus,
|
|
408
|
+
disabled = _this$props3.disabled,
|
|
409
|
+
hideIcon = _this$props3.hideIcon,
|
|
410
|
+
icon = _this$props3.icon,
|
|
411
|
+
id = _this$props3.id,
|
|
412
|
+
innerProps = _this$props3.innerProps,
|
|
413
|
+
isDisabled = _this$props3.isDisabled,
|
|
414
|
+
disabledDateFilter = _this$props3.disabledDateFilter,
|
|
415
|
+
maxDate = _this$props3.maxDate,
|
|
416
|
+
minDate = _this$props3.minDate,
|
|
417
|
+
isInvalid = _this$props3.isInvalid,
|
|
418
|
+
name = _this$props3.name,
|
|
419
|
+
nextMonthLabel = _this$props3.nextMonthLabel,
|
|
420
|
+
previousMonthLabel = _this$props3.previousMonthLabel,
|
|
421
|
+
selectProps = _this$props3.selectProps,
|
|
422
|
+
spacing = _this$props3.spacing,
|
|
423
|
+
locale = _this$props3.locale,
|
|
424
|
+
testId = _this$props3.testId,
|
|
425
|
+
weekStartDay = _this$props3.weekStartDay;
|
|
498
426
|
var ICON_PADDING = 2;
|
|
499
|
-
|
|
500
427
|
var _this$getSafeState7 = this.getSafeState(),
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
428
|
+
value = _this$getSafeState7.value,
|
|
429
|
+
view = _this$getSafeState7.view,
|
|
430
|
+
isOpen = _this$getSafeState7.isOpen,
|
|
431
|
+
inputValue = _this$getSafeState7.inputValue;
|
|
506
432
|
var menuIsOpen = isOpen && !isDisabled;
|
|
507
433
|
var showClearIndicator = Boolean((value || inputValue) && !hideIcon);
|
|
508
434
|
var dropDownIcon = appearance === 'subtle' || hideIcon || showClearIndicator ? null : icon;
|
|
509
|
-
|
|
510
435
|
var selectComponents = _objectSpread({
|
|
511
436
|
DropdownIndicator: dropDownIcon,
|
|
512
437
|
Menu: Menu
|
|
513
438
|
}, !showClearIndicator && {
|
|
514
439
|
ClearIndicator: _internal.EmptyComponent
|
|
515
440
|
});
|
|
516
|
-
|
|
517
441
|
var _selectProps$styles = selectProps.styles,
|
|
518
|
-
|
|
442
|
+
selectStyles = _selectProps$styles === void 0 ? {} : _selectProps$styles;
|
|
519
443
|
var disabledStyle = isDisabled ? {
|
|
520
444
|
pointerEvents: 'none',
|
|
521
445
|
color: "var(--ds-icon-disabled, inherit)"
|
|
@@ -589,10 +513,8 @@ var DatePicker = /*#__PURE__*/function (_Component) {
|
|
|
589
513
|
}]);
|
|
590
514
|
return DatePicker;
|
|
591
515
|
}(_react.Component);
|
|
592
|
-
|
|
593
516
|
exports.DatePickerWithoutAnalytics = DatePicker;
|
|
594
517
|
(0, _defineProperty2.default)(DatePicker, "defaultProps", datePickerDefaultProps);
|
|
595
|
-
|
|
596
518
|
var _default = (0, _analyticsNext.withAnalyticsContext)({
|
|
597
519
|
componentName: 'datePicker',
|
|
598
520
|
packageName: packageName,
|
|
@@ -608,5 +530,4 @@ var _default = (0, _analyticsNext.withAnalyticsContext)({
|
|
|
608
530
|
}
|
|
609
531
|
})
|
|
610
532
|
})(DatePicker));
|
|
611
|
-
|
|
612
533
|
exports.default = _default;
|