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