@atlaskit/datetime-picker 15.13.0 → 16.0.0

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