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