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