@atlaskit/datetime-picker 15.3.1 → 15.4.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.
@@ -0,0 +1,668 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _typeof = require("@babel/runtime/helpers/typeof");
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = exports.DatePickerWithoutAnalytics = void 0;
9
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
10
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
12
+ var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
13
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
14
+ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
15
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
16
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
17
+ var _react = require("react");
18
+ var _react2 = require("@emotion/react");
19
+ var _dateFns = require("date-fns");
20
+ var _reactUid = require("react-uid");
21
+ var _analyticsNext = require("@atlaskit/analytics-next");
22
+ var _calendar = _interopRequireDefault(require("@atlaskit/icon/glyph/calendar"));
23
+ var _locale = require("@atlaskit/locale");
24
+ var _primitives = require("@atlaskit/primitives");
25
+ var _select = _interopRequireWildcard(require("@atlaskit/select"));
26
+ var _colors = require("@atlaskit/theme/colors");
27
+ var _visuallyHidden = _interopRequireDefault(require("@atlaskit/visually-hidden"));
28
+ var _internal = require("../internal");
29
+ var _datePickerMigration = require("../internal/date-picker-migration");
30
+ var _menu = require("../internal/menu");
31
+ var _parseDate = require("../internal/parse-date");
32
+ var _singleValue = require("../internal/single-value");
33
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
34
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
35
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
36
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
37
+ function _createSuper(t) { var r = _isNativeReflectConstruct(); return function () { var e, o = (0, _getPrototypeOf2.default)(t); if (r) { var s = (0, _getPrototypeOf2.default)(this).constructor; e = Reflect.construct(o, arguments, s); } else e = o.apply(this, arguments); return (0, _possibleConstructorReturn2.default)(this, e); }; }
38
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } /**
39
+ * @jsxRuntime classic
40
+ * @jsx jsx
41
+ */ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
42
+ // This is a deprecated component but we will be able to use the actual hook
43
+ // version very soon from converting this to functional. And also React 18 is on
44
+ // the horizon
45
+ var packageName = "@atlaskit/datetime-picker";
46
+ var packageVersion = "15.4.1";
47
+ var datePickerDefaultProps = {
48
+ defaultIsOpen: false,
49
+ defaultValue: '',
50
+ disabled: [],
51
+ disabledDateFilter: function disabledDateFilter(_) {
52
+ return false;
53
+ },
54
+ locale: 'en-US',
55
+ // These disables are here for proper typing when used as defaults. They
56
+ // should *not* use the `noop` function.
57
+ /* eslint-disable @repo/internal/react/use-noop */
58
+ onBlur: function onBlur(_event) {},
59
+ onChange: function onChange(_value) {},
60
+ onFocus: function onFocus(_event) {}
61
+ /* eslint-enable @repo/internal/react/use-noop */
62
+ // Not including a default prop for value as it will
63
+ // Make the component a controlled component
64
+ };
65
+ var pickerContainerStyles = (0, _react2.css)({
66
+ position: 'relative'
67
+ });
68
+ var iconContainerStyles = (0, _react2.css)({
69
+ display: 'flex',
70
+ height: '100%',
71
+ position: 'absolute',
72
+ alignItems: 'center',
73
+ flexBasis: 'inherit',
74
+ color: "var(--ds-text-subtlest, ".concat(_colors.N70, ")"),
75
+ insetBlockStart: 0,
76
+ insetInlineEnd: 0,
77
+ transition: "color 150ms",
78
+ '&:hover': {
79
+ color: "var(--ds-text-subtle, ".concat(_colors.N500, ")")
80
+ }
81
+ });
82
+ var iconSpacingWithClearButtonStyles = (0, _react2.css)({
83
+ marginInlineEnd: "var(--ds-space-400, 2rem)"
84
+ });
85
+ var iconSpacingWithoutClearButtonStyles = (0, _react2.css)({
86
+ marginInlineEnd: "var(--ds-space-025, 0.125rem)"
87
+ });
88
+ var calendarButtonStyles = (0, _primitives.xcss)({
89
+ borderRadius: 'border.radius',
90
+ ':hover': {
91
+ backgroundColor: 'color.background.neutral.subtle.hovered'
92
+ },
93
+ ':active': {
94
+ backgroundColor: 'color.background.neutral.subtle.pressed'
95
+ }
96
+ });
97
+
98
+ // eslint-disable-next-line @repo/internal/react/no-class-components
99
+ var DatePickerComponent = exports.DatePickerWithoutAnalytics = /*#__PURE__*/function (_Component) {
100
+ (0, _inherits2.default)(DatePickerComponent, _Component);
101
+ var _super = _createSuper(DatePickerComponent);
102
+ function DatePickerComponent(props) {
103
+ var _this$props$selectPro2;
104
+ var _this;
105
+ (0, _classCallCheck2.default)(this, DatePickerComponent);
106
+ _this = _super.call(this, props);
107
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "containerRef", null);
108
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "calendarRef", /*#__PURE__*/(0, _react.createRef)());
109
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "calendarButtonRef", /*#__PURE__*/(0, _react.createRef)());
110
+ // All state needs to be accessed via this function so that the state is mapped from props
111
+ // correctly to allow controlled/uncontrolled usage.
112
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getValue", function () {
113
+ var _this$props$value;
114
+ return (_this$props$value = _this.props.value) !== null && _this$props$value !== void 0 ? _this$props$value : _this.state.value;
115
+ });
116
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getIsOpen", function () {
117
+ var _this$props$isOpen;
118
+ return (_this$props$isOpen = _this.props.isOpen) !== null && _this$props$isOpen !== void 0 ? _this$props$isOpen : _this.state.isOpen;
119
+ });
120
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onCalendarChange", function (_ref) {
121
+ var iso = _ref.iso;
122
+ _this.setState({
123
+ calendarValue: (0, _datePickerMigration.getParsedISO)({
124
+ iso: iso
125
+ })
126
+ });
127
+ });
128
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onCalendarSelect", function (_ref2) {
129
+ var iso = _ref2.iso;
130
+ _this.setState({
131
+ selectInputValue: '',
132
+ isOpen: false,
133
+ calendarValue: iso,
134
+ value: iso,
135
+ wasOpenedFromCalendarButton: false
136
+ });
137
+ _this.props.onChange(iso);
138
+
139
+ // Yes, this is not ideal. The alternative is to be able to place a ref
140
+ // on the inner input of Select itself, which would require a lot of
141
+ // extra stuff in the Select component for only this one thing. While
142
+ // this would be more "React-y", it doesn't seem to pose any other
143
+ // benefits. Performance-wise, we are only searching within the
144
+ // container, so it's quick.
145
+ if (_this.state.wasOpenedFromCalendarButton) {
146
+ var _this$calendarButtonR;
147
+ (_this$calendarButtonR = _this.calendarButtonRef.current) === null || _this$calendarButtonR === void 0 || _this$calendarButtonR.focus();
148
+ } else {
149
+ var _this$containerRef;
150
+ var innerCombobox = (_this$containerRef = _this.containerRef) === null || _this$containerRef === void 0 ? void 0 : _this$containerRef.querySelector('[role="combobox"]');
151
+ innerCombobox === null || innerCombobox === void 0 || innerCombobox.focus();
152
+ }
153
+ _this.setState({
154
+ isOpen: false
155
+ });
156
+ });
157
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onInputClick", function () {
158
+ if (!_this.props.isDisabled && !_this.getIsOpen()) {
159
+ _this.setState({
160
+ isOpen: true,
161
+ wasOpenedFromCalendarButton: false
162
+ });
163
+ }
164
+ });
165
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onContainerBlur", function (event) {
166
+ var _this$containerRef2;
167
+ var newlyFocusedElement = event.relatedTarget;
168
+ if (!((_this$containerRef2 = _this.containerRef) !== null && _this$containerRef2 !== void 0 && _this$containerRef2.contains(newlyFocusedElement))) {
169
+ _this.setState({
170
+ isOpen: false,
171
+ shouldSetFocusOnCurrentDay: false,
172
+ wasOpenedFromCalendarButton: false
173
+ });
174
+ _this.props.onBlur(event);
175
+ }
176
+ });
177
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onContainerFocus", function () {
178
+ _this.setState({
179
+ shouldSetFocusOnCurrentDay: false
180
+ });
181
+ });
182
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onSelectBlur", function (event) {
183
+ var _this$containerRef3;
184
+ var newlyFocusedElement = event.relatedTarget;
185
+ if (_this.state.clearingFromIcon) {
186
+ // Don't close menu if blurring after the user has clicked clear
187
+ _this.setState({
188
+ clearingFromIcon: false
189
+ });
190
+ } else if (!((_this$containerRef3 = _this.containerRef) !== null && _this$containerRef3 !== void 0 && _this$containerRef3.contains(newlyFocusedElement))) {
191
+ // Don't close menu if focus is staying within the date picker's
192
+ // container. Makes keyboard accessibility of calendar possible
193
+ _this.setState({
194
+ isOpen: false,
195
+ isFocused: false,
196
+ wasOpenedFromCalendarButton: false
197
+ });
198
+ }
199
+ });
200
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onSelectFocus", function (event) {
201
+ var clearingFromIcon = _this.state.clearingFromIcon;
202
+ var value = _this.getValue();
203
+ if (clearingFromIcon) {
204
+ // Don't open menu if focussing after the user has clicked clear
205
+ _this.setState({
206
+ clearingFromIcon: false
207
+ });
208
+ } else {
209
+ _this.setState({
210
+ // Don't open when focused into via keyboard if the calendar button is present
211
+ isOpen: !_this.props.shouldShowCalendarButton,
212
+ calendarValue: value,
213
+ isFocused: true,
214
+ wasOpenedFromCalendarButton: false
215
+ });
216
+ }
217
+ _this.props.onFocus(event);
218
+ });
219
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onTextInput", function (event) {
220
+ var inputValue = event.target.value;
221
+ if (inputValue) {
222
+ var parsed = (0, _datePickerMigration.parseDate)(inputValue, {
223
+ parseInputValue: _this.props.parseInputValue,
224
+ dateFormat: _this.props.dateFormat,
225
+ l10n: _this.state.l10n
226
+ });
227
+ // Only try to set the date if we have month & day
228
+ if (parsed && (0, _dateFns.isValid)(parsed)) {
229
+ // We format the parsed date to YYYY-MM-DD here because
230
+ // this is the format expected by the @atlaskit/calendar component
231
+ _this.setState({
232
+ calendarValue: (0, _parseDate.getShortISOString)(parsed)
233
+ });
234
+ }
235
+ }
236
+ _this.setState({
237
+ isOpen: true,
238
+ wasOpenedFromCalendarButton: false
239
+ });
240
+ });
241
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onInputKeyDown", function (event) {
242
+ var calendarValue = _this.state.calendarValue;
243
+ var value = _this.getValue();
244
+ var keyPressed = event.key.toLowerCase();
245
+
246
+ // If the input is focused and the calendar is not visible, handle space and enter clicks
247
+ if (!_this.state.isOpen && (keyPressed === 'enter' || keyPressed === ' ')) {
248
+ _this.setState({
249
+ isOpen: true,
250
+ wasOpenedFromCalendarButton: false
251
+ });
252
+ }
253
+ switch (keyPressed) {
254
+ case 'escape':
255
+ // Yes, this is not ideal. The alternative is to be able to place a ref
256
+ // on the inner input of Select itself, which would require a lot of
257
+ // extra stuff in the Select component for only this one thing. While
258
+ // this would be more "React-y", it doesn't seem to pose any other
259
+ // benefits. Performance-wise, we are only searching within the
260
+ // container, so it's quick.
261
+ if (_this.state.wasOpenedFromCalendarButton) {
262
+ var _this$calendarButtonR2;
263
+ (_this$calendarButtonR2 = _this.calendarButtonRef.current) === null || _this$calendarButtonR2 === void 0 || _this$calendarButtonR2.focus();
264
+ } else {
265
+ var _this$containerRef4;
266
+ var innerCombobox = (_this$containerRef4 = _this.containerRef) === null || _this$containerRef4 === void 0 ? void 0 : _this$containerRef4.querySelector('[role="combobox"]');
267
+ innerCombobox === null || innerCombobox === void 0 || innerCombobox.focus();
268
+ }
269
+ _this.setState({
270
+ isOpen: false,
271
+ shouldSetFocusOnCurrentDay: false,
272
+ wasOpenedFromCalendarButton: false
273
+ });
274
+ break;
275
+ case 'backspace':
276
+ case 'delete':
277
+ {
278
+ var inputCount = 0;
279
+ if (value && event.target instanceof HTMLInputElement && event.target.value.length <= inputCount) {
280
+ // If being cleared from keyboard, don't change behaviour
281
+ _this.setState({
282
+ clearingFromIcon: false,
283
+ value: ''
284
+ });
285
+ }
286
+ break;
287
+ }
288
+ case 'enter':
289
+ if (!_this.state.isOpen) {
290
+ return;
291
+ }
292
+ // Prevent form submission when a date is selected
293
+ // using enter. See https://product-fabric.atlassian.net/browse/DSP-2501
294
+ // for more details.
295
+ event.preventDefault();
296
+ if (!(0, _datePickerMigration.isDateDisabled)(calendarValue, {
297
+ disabled: _this.props.disabled
298
+ })) {
299
+ // Get a safe `calendarValue` in case the value exceeds the maximum
300
+ // allowed by ISO 8601
301
+ var safeCalendarValue = (0, _parseDate.getSafeCalendarValue)(calendarValue);
302
+ var valueChanged = safeCalendarValue !== value;
303
+ _this.setState({
304
+ selectInputValue: '',
305
+ isOpen: false,
306
+ value: safeCalendarValue,
307
+ calendarValue: safeCalendarValue,
308
+ wasOpenedFromCalendarButton: false
309
+ });
310
+ if (valueChanged) {
311
+ _this.props.onChange(safeCalendarValue);
312
+ }
313
+ }
314
+ break;
315
+ case 'arrowdown':
316
+ case 'arrowup':
317
+ if (_this.state.isOpen && !_this.state.shouldSetFocusOnCurrentDay) {
318
+ _this.setState({
319
+ shouldSetFocusOnCurrentDay: true
320
+ });
321
+ }
322
+ break;
323
+ default:
324
+ break;
325
+ }
326
+ });
327
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onCalendarButtonKeyDown", function (e) {
328
+ // We want to stop this from triggering other keydown events, particularly
329
+ // for space and enter presses. Otherwise, it opens and then closes
330
+ // immediately.
331
+ if (e.type === 'keydown' && (e.key === ' ' || e.key === 'Enter')) {
332
+ e.stopPropagation();
333
+ _this.setState({
334
+ isKeyDown: true,
335
+ wasOpenedFromCalendarButton: true
336
+ });
337
+ }
338
+ });
339
+ // This event handler is triggered from both keydown and click. It's weird.
340
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onCalendarButtonClick", function (e) {
341
+ _this.setState({
342
+ isOpen: !_this.state.isOpen,
343
+ wasOpenedFromCalendarButton: true
344
+ }, function () {
345
+ var _this$calendarRef;
346
+ // We don't want the focus to move if this is a click event
347
+ if (!_this.state.isKeyDown) {
348
+ return;
349
+ }
350
+ _this.setState({
351
+ isKeyDown: false
352
+ });
353
+
354
+ // Focus on the first button within the calendar
355
+ (_this$calendarRef = _this.calendarRef) === null || _this$calendarRef === void 0 || (_this$calendarRef = _this$calendarRef.current) === null || _this$calendarRef === void 0 || (_this$calendarRef = _this$calendarRef.querySelector('button')) === null || _this$calendarRef === void 0 || _this$calendarRef.focus();
356
+ });
357
+ e.stopPropagation();
358
+ });
359
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onClear", function () {
360
+ var changedState = {
361
+ value: '',
362
+ calendarValue: _this.props.defaultValue || (0, _parseDate.getShortISOString)(new Date())
363
+ };
364
+ if (!_this.props.hideIcon) {
365
+ changedState = _objectSpread(_objectSpread({}, changedState), {}, {
366
+ clearingFromIcon: true
367
+ });
368
+ }
369
+ _this.setState(changedState);
370
+ _this.props.onChange('');
371
+ });
372
+ // `unknown` is used because `value` is unused so it does not matter.
373
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onSelectChange", function (_value, action) {
374
+ // Used for native clear event in React Select
375
+ // Triggered when clicking ClearIndicator or backspace with no value
376
+ if (action.action === 'clear') {
377
+ _this.onClear();
378
+ }
379
+ });
380
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleSelectInputChange", function (selectInputValue, actionMeta) {
381
+ var _this$props$selectPro;
382
+ var onInputChange = (_this$props$selectPro = _this.props.selectProps) === null || _this$props$selectPro === void 0 ? void 0 : _this$props$selectPro.onInputChange;
383
+ if (onInputChange) {
384
+ onInputChange(selectInputValue, actionMeta);
385
+ }
386
+ _this.setState({
387
+ selectInputValue: selectInputValue
388
+ });
389
+ });
390
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getContainerRef", function (ref) {
391
+ var oldRef = _this.containerRef;
392
+ _this.containerRef = ref;
393
+ // Cause a re-render if we're getting the container ref for the first time
394
+ // as the layered menu requires it for dimension calculation
395
+ if (oldRef == null && ref != null) {
396
+ _this.forceUpdate();
397
+ }
398
+ });
399
+ _this.state = {
400
+ isKeyDown: false,
401
+ isOpen: _this.props.defaultIsOpen,
402
+ isFocused: false,
403
+ clearingFromIcon: false,
404
+ selectInputValue: ((_this$props$selectPro2 = _this.props.selectProps) === null || _this$props$selectPro2 === void 0 ? void 0 : _this$props$selectPro2.inputValue) || '',
405
+ value: _this.props.value || _this.props.defaultValue,
406
+ calendarValue: _this.props.value || _this.props.defaultValue || (0, _parseDate.getShortISOString)(new Date()),
407
+ l10n: (0, _locale.createLocalizationProvider)(_this.props.locale),
408
+ locale: _this.props.locale,
409
+ shouldSetFocusOnCurrentDay: false,
410
+ wasOpenedFromCalendarButton: false
411
+ };
412
+ return _this;
413
+ }
414
+ (0, _createClass2.default)(DatePickerComponent, [{
415
+ key: "render",
416
+ value: function render() {
417
+ var _this2 = this;
418
+ var _this$props = this.props,
419
+ _this$props$appearanc = _this$props.appearance,
420
+ appearance = _this$props$appearanc === void 0 ? 'default' : _this$props$appearanc,
421
+ ariaDescribedBy = _this$props['aria-describedby'],
422
+ _this$props$autoFocus = _this$props.autoFocus,
423
+ autoFocus = _this$props$autoFocus === void 0 ? false : _this$props$autoFocus,
424
+ _this$props$hideIcon = _this$props.hideIcon,
425
+ hideIcon = _this$props$hideIcon === void 0 ? false : _this$props$hideIcon,
426
+ _this$props$openCalen = _this$props.openCalendarLabel,
427
+ openCalendarLabel = _this$props$openCalen === void 0 ? 'Open calendar' : _this$props$openCalen,
428
+ disabled = _this$props.disabled,
429
+ disabledDateFilter = _this$props.disabledDateFilter,
430
+ _this$props$icon = _this$props.icon,
431
+ icon = _this$props$icon === void 0 ? _calendar.default : _this$props$icon,
432
+ _this$props$id = _this$props.id,
433
+ id = _this$props$id === void 0 ? '' : _this$props$id,
434
+ _this$props$innerProp = _this$props.innerProps,
435
+ innerProps = _this$props$innerProp === void 0 ? {} : _this$props$innerProp,
436
+ _this$props$inputLabe = _this$props.inputLabel,
437
+ inputLabel = _this$props$inputLabe === void 0 ? 'Date picker' : _this$props$inputLabe,
438
+ inputLabelId = _this$props.inputLabelId,
439
+ _this$props$isDisable = _this$props.isDisabled,
440
+ isDisabled = _this$props$isDisable === void 0 ? false : _this$props$isDisable,
441
+ _this$props$isInvalid = _this$props.isInvalid,
442
+ isInvalid = _this$props$isInvalid === void 0 ? false : _this$props$isInvalid,
443
+ _this$props$isRequire = _this$props.isRequired,
444
+ isRequired = _this$props$isRequire === void 0 ? false : _this$props$isRequire,
445
+ _this$props$label = _this$props.label,
446
+ label = _this$props$label === void 0 ? '' : _this$props$label,
447
+ locale = _this$props.locale,
448
+ maxDate = _this$props.maxDate,
449
+ minDate = _this$props.minDate,
450
+ _this$props$name = _this$props.name,
451
+ name = _this$props$name === void 0 ? '' : _this$props$name,
452
+ nextMonthLabel = _this$props.nextMonthLabel,
453
+ previousMonthLabel = _this$props.previousMonthLabel,
454
+ _this$props$selectPro3 = _this$props.selectProps,
455
+ selectProps = _this$props$selectPro3 === void 0 ? {} : _this$props$selectPro3,
456
+ shouldShowCalendarButton = _this$props.shouldShowCalendarButton,
457
+ _this$props$spacing = _this$props.spacing,
458
+ spacing = _this$props$spacing === void 0 ? 'default' : _this$props$spacing,
459
+ testId = _this$props.testId,
460
+ weekStartDay = _this$props.weekStartDay;
461
+ var _this$state = this.state,
462
+ calendarValue = _this$state.calendarValue,
463
+ selectInputValue = _this$state.selectInputValue;
464
+ var value = this.getValue();
465
+ var actualSelectInputValue;
466
+ actualSelectInputValue = selectInputValue;
467
+ var menuIsOpen = this.getIsOpen() && !isDisabled;
468
+ var showClearIndicator = Boolean((value || selectInputValue) && !hideIcon);
469
+ var dropDownIcon = appearance === 'subtle' || hideIcon || showClearIndicator ? null : icon;
470
+ var SingleValue = (0, _singleValue.makeSingleValue)({
471
+ lang: this.props.locale
472
+ });
473
+ var selectComponents = _objectSpread({
474
+ DropdownIndicator: shouldShowCalendarButton ? _internal.EmptyComponent : dropDownIcon,
475
+ Menu: _menu.Menu,
476
+ SingleValue: SingleValue
477
+ }, !showClearIndicator && {
478
+ ClearIndicator: _internal.EmptyComponent
479
+ });
480
+ var _selectProps$styles = selectProps.styles,
481
+ selectStyles = _selectProps$styles === void 0 ? {} : _selectProps$styles;
482
+ var disabledStyle = isDisabled ? {
483
+ pointerEvents: 'none',
484
+ color: "var(--ds-icon-disabled, inherit)"
485
+ } : {};
486
+ var calendarProps = {
487
+ calendarContainerRef: this.containerRef,
488
+ calendarDisabled: disabled,
489
+ calendarDisabledDateFilter: disabledDateFilter,
490
+ calendarMaxDate: maxDate,
491
+ calendarMinDate: minDate,
492
+ calendarRef: this.calendarRef,
493
+ calendarValue: value && (0, _parseDate.getShortISOString)((0, _dateFns.parseISO)(value)),
494
+ calendarView: calendarValue,
495
+ onCalendarChange: this.onCalendarChange,
496
+ onCalendarSelect: this.onCalendarSelect,
497
+ calendarLocale: locale,
498
+ calendarWeekStartDay: weekStartDay,
499
+ shouldSetFocusOnCurrentDay: this.state.shouldSetFocusOnCurrentDay
500
+ };
501
+
502
+ // @ts-ignore -- Argument of type 'StylesConfig<OptionType, false, GroupBase<OptionType>>' is not assignable to parameter of type 'StylesConfig<OptionType, boolean, GroupBase<OptionType>>'.
503
+ var mergedStyles = (0, _select.mergeStyles)(selectStyles, {
504
+ control: function control(base) {
505
+ return _objectSpread(_objectSpread({}, base), disabledStyle);
506
+ },
507
+ indicatorsContainer: function indicatorsContainer(base) {
508
+ return _objectSpread(_objectSpread({}, base), {}, {
509
+ paddingLeft: "var(--ds-space-025, 2px)",
510
+ // ICON_PADDING = 2
511
+ paddingRight: "var(--ds-space-075, 6px)" // 8 - ICON_PADDING = 6
512
+ });
513
+ }
514
+ });
515
+ var initialValue = value ? {
516
+ label: (0, _datePickerMigration.formatDate)(value, {
517
+ formatDisplayLabel: this.props.formatDisplayLabel,
518
+ dateFormat: this.props.dateFormat,
519
+ l10n: this.state.l10n
520
+ }),
521
+ value: value
522
+ } : null;
523
+
524
+ // `label` takes precedence of the `inputLabel`
525
+ var fullopenCalendarLabel = label || inputLabel ? "".concat(label || inputLabel, " , ").concat(openCalendarLabel) : openCalendarLabel;
526
+ return (
527
+ // These event handlers must be on this element because the events come
528
+ // from different child elements.
529
+ (0, _react2.jsx)("div", (0, _extends2.default)({}, innerProps, {
530
+ css: pickerContainerStyles,
531
+ role: "presentation",
532
+ onBlur: this.onContainerBlur,
533
+ onFocus: this.onContainerFocus,
534
+ onClick: this.onInputClick,
535
+ onInput: this.onTextInput,
536
+ onKeyDown: this.onInputKeyDown,
537
+ ref: this.getContainerRef,
538
+ "data-testid": testId && "".concat(testId, "--container")
539
+ }), (0, _react2.jsx)("input", {
540
+ name: name,
541
+ type: "hidden",
542
+ value: value,
543
+ "data-testid": testId && "".concat(testId, "--input")
544
+ }), (0, _react2.jsx)(_select.default, (0, _extends2.default)({
545
+ appearance: this.props.appearance,
546
+ "aria-describedby": ariaDescribedBy,
547
+ "aria-label": label || undefined,
548
+ autoFocus: autoFocus,
549
+ closeMenuOnSelect: true
550
+ // FOr some reason, this and the below `styles` type error _only_ show
551
+ // up when you alter some of the properties in the `selectComponents`
552
+ // object. These errors are still present, and I suspect have always
553
+ // been present, without changing the unrelated code. Ignoring as the
554
+ // component still works as expected despite this error. And also
555
+ // because the select refresh team may solve it later.
556
+ ,
557
+ components: selectComponents,
558
+ enableAnimation: false,
559
+ inputId: id,
560
+ inputValue: actualSelectInputValue,
561
+ isDisabled: isDisabled,
562
+ isRequired: isRequired,
563
+ menuIsOpen: menuIsOpen,
564
+ onBlur: this.onSelectBlur,
565
+ onChange: this.onSelectChange,
566
+ onFocus: this.onSelectFocus,
567
+ onInputChange: this.handleSelectInputChange,
568
+ placeholder: (0, _datePickerMigration.getPlaceholder)({
569
+ placeholder: this.props.placeholder,
570
+ l10n: this.state.l10n
571
+ }),
572
+ styles: mergedStyles,
573
+ value: initialValue
574
+ }, selectProps, {
575
+ // These are below the spread because I don't know what is in
576
+ // selectProps or not and what wil be overwritten
577
+ isClearable: true,
578
+ isInvalid: isInvalid,
579
+ spacing: spacing,
580
+ testId: testId
581
+ // These aren't part of `Select`'s API, but we're using them here.
582
+ // @ts-ignore -- Property 'calendarContainerRef' does not exist on type 'IntrinsicAttributes & LibraryManagedAttributes<(<Option extends unknown = OptionType, IsMulti extends boolean = false>(props: AtlaskitSelectProps<Option, IsMulti> & { ...; }) => Element), AtlaskitSelectProps<...> & { ...; }>'.
583
+ ,
584
+ calendarContainerRef: calendarProps.calendarContainerRef,
585
+ calendarDisabled: calendarProps.calendarDisabled,
586
+ calendarDisabledDateFilter: calendarProps.calendarDisabledDateFilter,
587
+ calendarLocale: calendarProps.calendarLocale,
588
+ calendarMaxDate: calendarProps.calendarMaxDate,
589
+ calendarMinDate: calendarProps.calendarMinDate,
590
+ calendarRef: calendarProps.calendarRef,
591
+ calendarValue: calendarProps.calendarValue,
592
+ calendarView: calendarProps.calendarView,
593
+ calendarWeekStartDay: calendarProps.calendarWeekStartDay,
594
+ nextMonthLabel: nextMonthLabel,
595
+ onCalendarChange: calendarProps.onCalendarChange,
596
+ onCalendarSelect: calendarProps.onCalendarSelect,
597
+ previousMonthLabel: previousMonthLabel,
598
+ shouldSetFocusOnCurrentDay: calendarProps.shouldSetFocusOnCurrentDay
599
+ })), shouldShowCalendarButton && !isDisabled ? (0, _react2.jsx)(_reactUid.UID, {
600
+ name: function name(id) {
601
+ return "open-calendar-label--".concat(id);
602
+ }
603
+ }, function (openCalendarLabelId) {
604
+ return (0, _react2.jsx)("div", {
605
+ css: [iconContainerStyles, value && !hideIcon ? iconSpacingWithClearButtonStyles : iconSpacingWithoutClearButtonStyles]
606
+ }, inputLabelId && (0, _react2.jsx)(_visuallyHidden.default, {
607
+ id: openCalendarLabelId
608
+ }, ", ", openCalendarLabel), (0, _react2.jsx)(_primitives.Pressable, (0, _extends2.default)({}, inputLabelId ? {
609
+ 'aria-labelledby': "".concat(inputLabelId, " ").concat(openCalendarLabelId)
610
+ } : {
611
+ 'aria-label': fullopenCalendarLabel
612
+ }, {
613
+ onClick: _this2.onCalendarButtonClick,
614
+ onKeyDown: _this2.onCalendarButtonKeyDown,
615
+ ref: _this2.calendarButtonRef,
616
+ testId: testId && "".concat(testId, "--open-calendar-button"),
617
+ type: "button",
618
+ backgroundColor: "color.background.neutral.subtle",
619
+ padding: "space.050",
620
+ xcss: calendarButtonStyles
621
+ }), (0, _react2.jsx)(_calendar.default, {
622
+ label: "",
623
+ primaryColor: "var(--ds-icon, #44546F)"
624
+ })));
625
+ }) : null)
626
+ );
627
+ }
628
+ }], [{
629
+ key: "getDerivedStateFromProps",
630
+ value: function getDerivedStateFromProps(nextProps, prevState) {
631
+ if (nextProps.locale !== prevState.locale) {
632
+ return {
633
+ l10n: (0, _locale.createLocalizationProvider)(nextProps.locale),
634
+ locale: nextProps.locale
635
+ };
636
+ } else {
637
+ return null;
638
+ }
639
+ }
640
+ }]);
641
+ return DatePickerComponent;
642
+ }(_react.Component);
643
+ (0, _defineProperty2.default)(DatePickerComponent, "defaultProps", datePickerDefaultProps);
644
+ /**
645
+ * __Date picker__
646
+ *
647
+ * A date picker allows the user to select a particular date.
648
+ *
649
+ * - [Examples](https://atlassian.design/components/datetime-picker/date-picker/examples)
650
+ * - [Code](https://atlassian.design/components/datetime-picker/date-picker/code)
651
+ * - [Usage](https://atlassian.design/components/datetime-picker/date-picker/usage)
652
+ */
653
+ var DatePicker = (0, _analyticsNext.withAnalyticsContext)({
654
+ componentName: 'datePicker',
655
+ packageName: packageName,
656
+ packageVersion: packageVersion
657
+ })((0, _analyticsNext.withAnalyticsEvents)({
658
+ onChange: (0, _analyticsNext.createAndFireEvent)('atlaskit')({
659
+ action: 'selectedDate',
660
+ actionSubject: 'datePicker',
661
+ attributes: {
662
+ componentName: 'datePicker',
663
+ packageName: packageName,
664
+ packageVersion: packageVersion
665
+ }
666
+ })
667
+ })(DatePickerComponent));
668
+ var _default = exports.default = DatePicker;