@atlaskit/datetime-picker 12.3.7 → 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 +6 -0
- package/dist/cjs/components/date-picker.js +61 -158
- 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 +27 -83
- 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 +63 -155
- 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/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -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,7 +210,6 @@ var DatePicker = /*#__PURE__*/function (_Component) {
|
|
|
259
210
|
});
|
|
260
211
|
}
|
|
261
212
|
}
|
|
262
|
-
|
|
263
213
|
_this.setState({
|
|
264
214
|
isOpen: true
|
|
265
215
|
});
|
|
@@ -267,7 +217,6 @@ var DatePicker = /*#__PURE__*/function (_Component) {
|
|
|
267
217
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getSafeView", function (view) {
|
|
268
218
|
// If view has a year that is greater than 9999, default to today's date
|
|
269
219
|
var yearIsOverLimit = view.match(/^\d{5,}/);
|
|
270
|
-
|
|
271
220
|
if (yearIsOverLimit) {
|
|
272
221
|
var today = new Date();
|
|
273
222
|
var year = today.getFullYear();
|
|
@@ -275,52 +224,39 @@ 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
227
|
return view;
|
|
280
228
|
});
|
|
281
229
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onSelectKeyDown", function (event) {
|
|
282
230
|
var _this$getSafeState2 = _this.getSafeState(),
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
231
|
+
view = _this$getSafeState2.view,
|
|
232
|
+
selectedValue = _this$getSafeState2.selectedValue;
|
|
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
262
|
if (selectedValue && event.target instanceof HTMLInputElement && event.target.value.length < 1) {
|
|
@@ -329,29 +265,22 @@ var DatePicker = /*#__PURE__*/function (_Component) {
|
|
|
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
277
|
if (!_this.isDateDisabled(view)) {
|
|
346
278
|
var _this$getSafeState3 = _this.getSafeState(),
|
|
347
|
-
|
|
279
|
+
_value = _this$getSafeState3.value;
|
|
280
|
+
// Get a safe `view` value in case the value exceeds the maximum
|
|
348
281
|
// allowed by ISO 8601
|
|
349
|
-
|
|
350
|
-
|
|
351
282
|
var safeView = _this.getSafeView(view);
|
|
352
|
-
|
|
353
283
|
var valueChanged = safeView !== _value;
|
|
354
|
-
|
|
355
284
|
_this.setState({
|
|
356
285
|
inputValue: '',
|
|
357
286
|
isOpen: false,
|
|
@@ -359,14 +288,11 @@ var DatePicker = /*#__PURE__*/function (_Component) {
|
|
|
359
288
|
value: safeView,
|
|
360
289
|
view: safeView
|
|
361
290
|
});
|
|
362
|
-
|
|
363
291
|
if (valueChanged) {
|
|
364
292
|
_this.props.onChange(safeView);
|
|
365
293
|
}
|
|
366
294
|
}
|
|
367
|
-
|
|
368
295
|
break;
|
|
369
|
-
|
|
370
296
|
default:
|
|
371
297
|
break;
|
|
372
298
|
}
|
|
@@ -377,15 +303,12 @@ var DatePicker = /*#__PURE__*/function (_Component) {
|
|
|
377
303
|
value: '',
|
|
378
304
|
view: _this.props.defaultValue || (0, _dateFns.format)(new Date(), (0, _utils.convertTokens)('YYYY-MM-DD'))
|
|
379
305
|
};
|
|
380
|
-
|
|
381
306
|
if (!_this.props.hideIcon) {
|
|
382
307
|
changedState = _objectSpread(_objectSpread({}, changedState), {}, {
|
|
383
308
|
clearingFromIcon: true
|
|
384
309
|
});
|
|
385
310
|
}
|
|
386
|
-
|
|
387
311
|
_this.setState(changedState);
|
|
388
|
-
|
|
389
312
|
_this.props.onChange('');
|
|
390
313
|
});
|
|
391
314
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onSelectChange", function (value, action) {
|
|
@@ -400,71 +323,58 @@ var DatePicker = /*#__PURE__*/function (_Component) {
|
|
|
400
323
|
});
|
|
401
324
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleInputChange", function (inputValue, actionMeta) {
|
|
402
325
|
var onInputChange = _this.props.selectProps.onInputChange;
|
|
403
|
-
|
|
404
326
|
if (onInputChange) {
|
|
405
327
|
onInputChange(inputValue, actionMeta);
|
|
406
328
|
}
|
|
407
|
-
|
|
408
329
|
_this.setState({
|
|
409
330
|
inputValue: inputValue
|
|
410
331
|
});
|
|
411
332
|
});
|
|
412
333
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getContainerRef", function (ref) {
|
|
413
334
|
var oldRef = _this.containerRef;
|
|
414
|
-
_this.containerRef = ref;
|
|
335
|
+
_this.containerRef = ref;
|
|
336
|
+
// Cause a re-render if we're getting the container ref for the first time
|
|
415
337
|
// as the layered menu requires it for dimension calculation
|
|
416
|
-
|
|
417
338
|
if (oldRef == null && ref != null) {
|
|
418
339
|
_this.forceUpdate();
|
|
419
340
|
}
|
|
420
341
|
});
|
|
421
342
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "parseDate", function (date) {
|
|
422
343
|
var _this$props = _this.props,
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
344
|
+
parseInputValue = _this$props.parseInputValue,
|
|
345
|
+
dateFormat = _this$props.dateFormat;
|
|
426
346
|
if (parseInputValue) {
|
|
427
347
|
return parseInputValue(date, dateFormat || _internal.defaultDateFormat);
|
|
428
348
|
}
|
|
429
|
-
|
|
430
349
|
var _this$getSafeState4 = _this.getSafeState(),
|
|
431
|
-
|
|
432
|
-
|
|
350
|
+
l10n = _this$getSafeState4.l10n;
|
|
433
351
|
return l10n.parseDate(date);
|
|
434
352
|
});
|
|
435
353
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "formatDate", function (value) {
|
|
436
354
|
var _this$props2 = _this.props,
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
355
|
+
formatDisplayLabel = _this$props2.formatDisplayLabel,
|
|
356
|
+
dateFormat = _this$props2.dateFormat;
|
|
440
357
|
var _this$getSafeState5 = _this.getSafeState(),
|
|
441
|
-
|
|
442
|
-
|
|
358
|
+
l10n = _this$getSafeState5.l10n;
|
|
443
359
|
if (formatDisplayLabel) {
|
|
444
360
|
return formatDisplayLabel(value, dateFormat || _internal.defaultDateFormat);
|
|
445
361
|
}
|
|
446
|
-
|
|
447
362
|
var date = (0, _dateFns.parseISO)(value);
|
|
448
363
|
return dateFormat ? (0, _dateFns.format)(date, (0, _utils.convertTokens)(dateFormat)) : l10n.formatDate(date);
|
|
449
364
|
});
|
|
450
365
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getPlaceholder", function () {
|
|
451
366
|
var placeholder = _this.props.placeholder;
|
|
452
|
-
|
|
453
367
|
if (placeholder) {
|
|
454
368
|
return placeholder;
|
|
455
369
|
}
|
|
456
|
-
|
|
457
370
|
var _this$getSafeState6 = _this.getSafeState(),
|
|
458
|
-
|
|
459
|
-
|
|
371
|
+
l10n = _this$getSafeState6.l10n;
|
|
460
372
|
return l10n.formatDate(_internal.placeholderDatetime);
|
|
461
373
|
});
|
|
462
|
-
|
|
463
374
|
var _getDateObj = getDateObj(new Date()),
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
375
|
+
_day = _getDateObj.day,
|
|
376
|
+
_month = _getDateObj.month,
|
|
377
|
+
_year = _getDateObj.year;
|
|
468
378
|
_this.state = {
|
|
469
379
|
isOpen: _this.props.defaultIsOpen,
|
|
470
380
|
isFocused: false,
|
|
@@ -477,7 +387,6 @@ var DatePicker = /*#__PURE__*/function (_Component) {
|
|
|
477
387
|
};
|
|
478
388
|
return _this;
|
|
479
389
|
}
|
|
480
|
-
|
|
481
390
|
(0, _createClass2.default)(DatePicker, [{
|
|
482
391
|
key: "UNSAFE_componentWillReceiveProps",
|
|
483
392
|
value: function UNSAFE_componentWillReceiveProps(nextProps) {
|
|
@@ -486,54 +395,51 @@ var DatePicker = /*#__PURE__*/function (_Component) {
|
|
|
486
395
|
l10n: (0, _locale.createLocalizationProvider)(nextProps.locale)
|
|
487
396
|
});
|
|
488
397
|
}
|
|
489
|
-
}
|
|
490
|
-
// correctly to allow controlled/uncontrolled usage.
|
|
398
|
+
}
|
|
491
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.
|
|
492
402
|
}, {
|
|
493
403
|
key: "render",
|
|
494
404
|
value: function render() {
|
|
495
405
|
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
|
-
|
|
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;
|
|
516
426
|
var ICON_PADDING = 2;
|
|
517
|
-
|
|
518
427
|
var _this$getSafeState7 = this.getSafeState(),
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
428
|
+
value = _this$getSafeState7.value,
|
|
429
|
+
view = _this$getSafeState7.view,
|
|
430
|
+
isOpen = _this$getSafeState7.isOpen,
|
|
431
|
+
inputValue = _this$getSafeState7.inputValue;
|
|
524
432
|
var menuIsOpen = isOpen && !isDisabled;
|
|
525
433
|
var showClearIndicator = Boolean((value || inputValue) && !hideIcon);
|
|
526
434
|
var dropDownIcon = appearance === 'subtle' || hideIcon || showClearIndicator ? null : icon;
|
|
527
|
-
|
|
528
435
|
var selectComponents = _objectSpread({
|
|
529
436
|
DropdownIndicator: dropDownIcon,
|
|
530
437
|
Menu: Menu
|
|
531
438
|
}, !showClearIndicator && {
|
|
532
439
|
ClearIndicator: _internal.EmptyComponent
|
|
533
440
|
});
|
|
534
|
-
|
|
535
441
|
var _selectProps$styles = selectProps.styles,
|
|
536
|
-
|
|
442
|
+
selectStyles = _selectProps$styles === void 0 ? {} : _selectProps$styles;
|
|
537
443
|
var disabledStyle = isDisabled ? {
|
|
538
444
|
pointerEvents: 'none',
|
|
539
445
|
color: "var(--ds-icon-disabled, inherit)"
|
|
@@ -607,10 +513,8 @@ var DatePicker = /*#__PURE__*/function (_Component) {
|
|
|
607
513
|
}]);
|
|
608
514
|
return DatePicker;
|
|
609
515
|
}(_react.Component);
|
|
610
|
-
|
|
611
516
|
exports.DatePickerWithoutAnalytics = DatePicker;
|
|
612
517
|
(0, _defineProperty2.default)(DatePicker, "defaultProps", datePickerDefaultProps);
|
|
613
|
-
|
|
614
518
|
var _default = (0, _analyticsNext.withAnalyticsContext)({
|
|
615
519
|
componentName: 'datePicker',
|
|
616
520
|
packageName: packageName,
|
|
@@ -626,5 +530,4 @@ var _default = (0, _analyticsNext.withAnalyticsContext)({
|
|
|
626
530
|
}
|
|
627
531
|
})
|
|
628
532
|
})(DatePicker));
|
|
629
|
-
|
|
630
533
|
exports.default = _default;
|