@atlaskit/datetime-picker 15.3.1 → 15.4.1

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