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