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