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