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