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