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