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