@atlaskit/datetime-picker 15.12.2 → 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 (40) hide show
  1. package/CHANGELOG.md +9 -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-ts4.5/components/date-picker.d.ts +18 -19
  14. package/dist/types-ts4.5/components/date-time-picker.d.ts +14 -31
  15. package/package.json +5 -8
  16. package/dist/cjs/components/date-picker-class.js +0 -685
  17. package/dist/cjs/components/date-picker-fc.js +0 -639
  18. package/dist/cjs/components/date-time-picker-class.js +0 -436
  19. package/dist/cjs/components/date-time-picker-fc.js +0 -394
  20. package/dist/cjs/internal/ff-component.js +0 -58
  21. package/dist/es2019/components/date-picker-class.js +0 -649
  22. package/dist/es2019/components/date-picker-fc.js +0 -563
  23. package/dist/es2019/components/date-time-picker-class.js +0 -400
  24. package/dist/es2019/components/date-time-picker-fc.js +0 -354
  25. package/dist/es2019/internal/ff-component.js +0 -47
  26. package/dist/esm/components/date-picker-class.js +0 -680
  27. package/dist/esm/components/date-picker-fc.js +0 -630
  28. package/dist/esm/components/date-time-picker-class.js +0 -434
  29. package/dist/esm/components/date-time-picker-fc.js +0 -384
  30. package/dist/esm/internal/ff-component.js +0 -49
  31. package/dist/types/components/date-picker-class.d.ts +0 -110
  32. package/dist/types/components/date-picker-fc.d.ts +0 -20
  33. package/dist/types/components/date-time-picker-class.d.ts +0 -85
  34. package/dist/types/components/date-time-picker-fc.d.ts +0 -15
  35. package/dist/types/internal/ff-component.d.ts +0 -34
  36. package/dist/types-ts4.5/components/date-picker-class.d.ts +0 -110
  37. package/dist/types-ts4.5/components/date-picker-fc.d.ts +0 -20
  38. package/dist/types-ts4.5/components/date-time-picker-class.d.ts +0 -85
  39. package/dist/types-ts4.5/components/date-time-picker-fc.d.ts +0 -15
  40. package/dist/types-ts4.5/internal/ff-component.d.ts +0 -34
@@ -1,685 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- var _typeof = require("@babel/runtime/helpers/typeof");
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.default = exports.DatePickerWithoutAnalytics = void 0;
9
- var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
10
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
12
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
13
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
14
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
15
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
16
- var _react = require("react");
17
- var _react2 = require("@emotion/react");
18
- var _dateFns = require("date-fns");
19
- var _analyticsNext = require("@atlaskit/analytics-next");
20
- var _new = require("@atlaskit/button/new");
21
- var _useId = require("@atlaskit/ds-lib/use-id");
22
- var _calendar = _interopRequireDefault(require("@atlaskit/icon/core/migration/calendar"));
23
- var _locale = require("@atlaskit/locale");
24
- var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
25
- var _primitives = require("@atlaskit/primitives");
26
- var _select = _interopRequireWildcard(require("@atlaskit/select"));
27
- var _internal = require("../internal");
28
- var _datePickerMigration = require("../internal/date-picker-migration");
29
- var _indicatorsContainer = require("../internal/indicators-container");
30
- var _menu = require("../internal/menu");
31
- var _parseDate = require("../internal/parse-date");
32
- var _singleValue = require("../internal/single-value");
33
- 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); }
34
- 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; }
35
- 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; }
36
- 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; }
37
- function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2.default)(o), (0, _possibleConstructorReturn2.default)(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2.default)(t).constructor) : o.apply(t, e)); }
38
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } /**
39
- * @jsxRuntime classic
40
- * @jsx jsx
41
- */ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
42
- var packageName = "@atlaskit/datetime-picker";
43
- var packageVersion = "15.12.2";
44
- var dropdownIndicatorStyles = (0, _primitives.xcss)({
45
- minWidth: "var(--ds-space-300, 24px)",
46
- minHeight: "var(--ds-space-300, 24px)",
47
- display: 'flex',
48
- alignItems: 'center',
49
- justifyContent: 'center'
50
- });
51
- var datePickerDefaultProps = {
52
- defaultIsOpen: false,
53
- defaultValue: '',
54
- disabled: [],
55
- disabledDateFilter: function disabledDateFilter(_) {
56
- return false;
57
- },
58
- locale: 'en-US',
59
- // These disables are here for proper typing when used as defaults. They
60
- // should *not* use the `noop` function.
61
- /* eslint-disable @repo/internal/react/use-noop */
62
- onBlur: function onBlur(_event) {},
63
- onChange: function onChange(_value) {},
64
- onFocus: function onFocus(_event) {}
65
- /* eslint-enable @repo/internal/react/use-noop */
66
- // Not including a default prop for value as it will
67
- // Make the component a controlled component
68
- };
69
- var pickerContainerStyles = (0, _react2.css)({
70
- position: 'relative'
71
- });
72
- var iconContainerStyles = (0, _primitives.xcss)({
73
- display: 'flex',
74
- height: '100%',
75
- position: 'absolute',
76
- alignItems: 'center',
77
- flexBasis: 'inherit',
78
- color: 'color.text.subtlest',
79
- insetBlockStart: 'space.0',
80
- insetInlineEnd: 'space.0',
81
- transition: "color 150ms",
82
- ':hover': {
83
- color: 'color.text.subtle'
84
- }
85
- });
86
- var iconSpacingWithClearButtonStyles = (0, _primitives.xcss)({
87
- marginInlineEnd: 'space.400'
88
- });
89
- var iconSpacingWithoutClearButtonStyles = (0, _primitives.xcss)({
90
- marginInlineEnd: 'space.050'
91
- });
92
-
93
- // eslint-disable-next-line @repo/internal/react/no-class-components
94
- var DatePickerComponent = exports.DatePickerWithoutAnalytics = /*#__PURE__*/function (_Component) {
95
- function DatePickerComponent(props) {
96
- var _this$props$selectPro2;
97
- var _this;
98
- (0, _classCallCheck2.default)(this, DatePickerComponent);
99
- _this = _callSuper(this, DatePickerComponent, [props]);
100
- (0, _defineProperty2.default)(_this, "containerRef", null);
101
- (0, _defineProperty2.default)(_this, "calendarRef", /*#__PURE__*/(0, _react.createRef)());
102
- (0, _defineProperty2.default)(_this, "calendarButtonRef", /*#__PURE__*/(0, _react.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
- (0, _defineProperty2.default)(_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
- (0, _defineProperty2.default)(_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
- (0, _defineProperty2.default)(_this, "onCalendarChange", function (_ref) {
114
- var iso = _ref.iso;
115
- _this.setState({
116
- calendarValue: (0, _datePickerMigration.getParsedISO)({
117
- iso: iso
118
- })
119
- });
120
- });
121
- (0, _defineProperty2.default)(_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
- (0, _defineProperty2.default)(_this, "onInputClick", function () {
151
- if (!_this.props.isDisabled && !_this.getIsOpen()) {
152
- _this.setState({
153
- isOpen: true,
154
- wasOpenedFromCalendarButton: false
155
- });
156
- }
157
- });
158
- (0, _defineProperty2.default)(_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
- (0, _defineProperty2.default)(_this, "onContainerFocus", function () {
171
- _this.setState({
172
- shouldSetFocusOnCurrentDay: false
173
- });
174
- });
175
- (0, _defineProperty2.default)(_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
- (0, _defineProperty2.default)(_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
- (0, _defineProperty2.default)(_this, "onTextInput", function (event) {
213
- var inputValue = event.target.value;
214
- if (inputValue) {
215
- var parsed = (0, _datePickerMigration.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 && (0, _dateFns.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: (0, _parseDate.getShortISOString)(parsed)
226
- });
227
- }
228
- }
229
- _this.setState({
230
- isOpen: true,
231
- wasOpenedFromCalendarButton: false
232
- });
233
- });
234
- (0, _defineProperty2.default)(_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 (!(0, _datePickerMigration.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 = (0, _parseDate.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.shouldSetFocusOnCurrentDay) {
311
- _this.setState({
312
- isOpen: true,
313
- shouldSetFocusOnCurrentDay: true
314
- });
315
- }
316
- break;
317
- default:
318
- break;
319
- }
320
- });
321
- (0, _defineProperty2.default)(_this, "onCalendarButtonKeyDown", function (e) {
322
- // Don't allow an arrow up or down to open the menu, since the input key
323
- // down handler is actually on the parent.
324
- if (e.type === 'keydown' && (e.key === 'ArrowDown' || e.key === 'ArrowUp')) {
325
- e.stopPropagation();
326
- }
327
- // We want to stop this from triggering other keydown events, particularly
328
- // for space and enter presses. Otherwise, it opens and then closes
329
- // immediately.
330
- if (e.type === 'keydown' && (e.key === ' ' || e.key === 'Enter')) {
331
- e.stopPropagation();
332
- _this.setState({
333
- isKeyDown: true,
334
- wasOpenedFromCalendarButton: true
335
- });
336
- }
337
- });
338
- // This event handler is triggered from both keydown and click. It's weird.
339
- (0, _defineProperty2.default)(_this, "onCalendarButtonClick", function (e) {
340
- _this.setState({
341
- isOpen: !_this.state.isOpen,
342
- wasOpenedFromCalendarButton: true
343
- }, function () {
344
- var _this$calendarRef;
345
- // We don't want the focus to move if this is a click event
346
- if (!_this.state.isKeyDown) {
347
- return;
348
- }
349
- _this.setState({
350
- isKeyDown: false
351
- });
352
-
353
- // Focus on the first button within the calendar
354
- (_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();
355
- });
356
- e.stopPropagation();
357
- });
358
- (0, _defineProperty2.default)(_this, "onClear", function () {
359
- var changedState = {
360
- value: '',
361
- calendarValue: _this.props.defaultValue || (0, _parseDate.getShortISOString)(new Date())
362
- };
363
- if (!_this.props.hideIcon) {
364
- changedState = _objectSpread(_objectSpread({}, changedState), {}, {
365
- clearingFromIcon: true
366
- });
367
- }
368
- _this.setState(changedState);
369
- _this.props.onChange('');
370
- });
371
- // `unknown` is used because `value` is unused so it does not matter.
372
- (0, _defineProperty2.default)(_this, "onSelectChange", function (_value, action) {
373
- // Used for native clear event in React Select
374
- // Triggered when clicking ClearIndicator or backspace with no value
375
- if (action.action === 'clear') {
376
- _this.onClear();
377
- }
378
- });
379
- (0, _defineProperty2.default)(_this, "handleSelectInputChange", function (selectInputValue, actionMeta) {
380
- var _this$props$selectPro;
381
- var onInputChange = (_this$props$selectPro = _this.props.selectProps) === null || _this$props$selectPro === void 0 ? void 0 : _this$props$selectPro.onInputChange;
382
- if (onInputChange) {
383
- onInputChange(selectInputValue, actionMeta);
384
- }
385
- _this.setState({
386
- selectInputValue: selectInputValue
387
- });
388
- });
389
- (0, _defineProperty2.default)(_this, "getContainerRef", function (ref) {
390
- var oldRef = _this.containerRef;
391
- _this.containerRef = ref;
392
- // Cause a re-render if we're getting the container ref for the first time
393
- // as the layered menu requires it for dimension calculation
394
- if (oldRef == null && ref != null) {
395
- _this.forceUpdate();
396
- }
397
- });
398
- _this.state = {
399
- isKeyDown: false,
400
- isOpen: _this.props.defaultIsOpen,
401
- isFocused: false,
402
- clearingFromIcon: false,
403
- selectInputValue: ((_this$props$selectPro2 = _this.props.selectProps) === null || _this$props$selectPro2 === void 0 ? void 0 : _this$props$selectPro2.inputValue) || '',
404
- value: _this.props.value || _this.props.defaultValue,
405
- calendarValue: _this.props.value || _this.props.defaultValue || (0, _parseDate.getShortISOString)(new Date()),
406
- l10n: (0, _locale.createLocalizationProvider)(_this.props.locale),
407
- locale: _this.props.locale,
408
- shouldSetFocusOnCurrentDay: false,
409
- wasOpenedFromCalendarButton: false
410
- };
411
- return _this;
412
- }
413
- (0, _inherits2.default)(DatePickerComponent, _Component);
414
- return (0, _createClass2.default)(DatePickerComponent, [{
415
- key: "render",
416
- value: function render() {
417
- var _this2 = this;
418
- var _this$props = this.props,
419
- _this$props$appearanc = _this$props.appearance,
420
- appearance = _this$props$appearanc === void 0 ? 'default' : _this$props$appearanc,
421
- ariaDescribedBy = _this$props['aria-describedby'],
422
- _this$props$autoFocus = _this$props.autoFocus,
423
- autoFocus = _this$props$autoFocus === void 0 ? false : _this$props$autoFocus,
424
- _this$props$clearCont = _this$props.clearControlLabel,
425
- clearControlLabel = _this$props$clearCont === void 0 ? 'Clear' : _this$props$clearCont,
426
- _this$props$hideIcon = _this$props.hideIcon,
427
- hideIcon = _this$props$hideIcon === void 0 ? false : _this$props$hideIcon,
428
- _this$props$openCalen = _this$props.openCalendarLabel,
429
- openCalendarLabel = _this$props$openCalen === void 0 ? 'Open calendar' : _this$props$openCalen,
430
- disabled = _this$props.disabled,
431
- disabledDateFilter = _this$props.disabledDateFilter,
432
- _this$props$icon = _this$props.icon,
433
- Icon = _this$props$icon === void 0 ? _calendar.default : _this$props$icon,
434
- _this$props$id = _this$props.id,
435
- id = _this$props$id === void 0 ? '' : _this$props$id,
436
- _this$props$innerProp = _this$props.innerProps,
437
- innerProps = _this$props$innerProp === void 0 ? {} : _this$props$innerProp,
438
- _this$props$inputLabe = _this$props.inputLabel,
439
- inputLabel = _this$props$inputLabe === void 0 ? 'Date picker' : _this$props$inputLabe,
440
- inputLabelId = _this$props.inputLabelId,
441
- _this$props$isDisable = _this$props.isDisabled,
442
- isDisabled = _this$props$isDisable === void 0 ? false : _this$props$isDisable,
443
- _this$props$isInvalid = _this$props.isInvalid,
444
- isInvalid = _this$props$isInvalid === void 0 ? false : _this$props$isInvalid,
445
- _this$props$isRequire = _this$props.isRequired,
446
- isRequired = _this$props$isRequire === void 0 ? false : _this$props$isRequire,
447
- _this$props$label = _this$props.label,
448
- label = _this$props$label === void 0 ? '' : _this$props$label,
449
- locale = _this$props.locale,
450
- maxDate = _this$props.maxDate,
451
- minDate = _this$props.minDate,
452
- _this$props$name = _this$props.name,
453
- name = _this$props$name === void 0 ? '' : _this$props$name,
454
- nextMonthLabel = _this$props.nextMonthLabel,
455
- previousMonthLabel = _this$props.previousMonthLabel,
456
- _this$props$selectPro3 = _this$props.selectProps,
457
- selectProps = _this$props$selectPro3 === void 0 ? {} : _this$props$selectPro3,
458
- shouldShowCalendarButton = _this$props.shouldShowCalendarButton,
459
- _this$props$spacing = _this$props.spacing,
460
- spacing = _this$props$spacing === void 0 ? 'default' : _this$props$spacing,
461
- testId = _this$props.testId,
462
- weekStartDay = _this$props.weekStartDay;
463
- var _this$state = this.state,
464
- calendarValue = _this$state.calendarValue,
465
- selectInputValue = _this$state.selectInputValue;
466
- var value = this.getValue();
467
- var actualSelectInputValue;
468
- actualSelectInputValue = selectInputValue;
469
- var menuIsOpen = this.getIsOpen() && !isDisabled;
470
- var showClearIndicator = Boolean((value || selectInputValue) && !hideIcon);
471
- var clearIndicator = Icon;
472
-
473
- // eslint-disable-next-line @atlaskit/platform/no-preconditioning
474
- if ((0, _platformFeatureFlags.fg)('platform-visual-refresh-icons')) {
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: this.props.locale
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: this.containerRef,
507
- calendarDisabled: disabled,
508
- calendarDisabledDateFilter: disabledDateFilter,
509
- calendarMaxDate: maxDate,
510
- calendarMinDate: minDate,
511
- calendarRef: this.calendarRef,
512
- calendarValue: value && (0, _parseDate.getShortISOString)((0, _dateFns.parseISO)(value)),
513
- calendarView: calendarValue,
514
- onCalendarChange: this.onCalendarChange,
515
- onCalendarSelect: this.onCalendarSelect,
516
- calendarLocale: locale,
517
- calendarWeekStartDay: weekStartDay,
518
- shouldSetFocusOnCurrentDay: this.state.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 = value ? {
535
- label: (0, _datePickerMigration.formatDate)(value, {
536
- formatDisplayLabel: this.props.formatDisplayLabel,
537
- dateFormat: this.props.dateFormat,
538
- l10n: this.state.l10n
539
- }),
540
- value: value
541
- } : null;
542
-
543
- // `label` takes precedence of the `inputLabel`
544
- var fullopenCalendarLabel = label || inputLabel ? "".concat(label || inputLabel, ", ").concat(openCalendarLabel) : openCalendarLabel;
545
- return (
546
- // These event handlers must be on this element because the events come
547
- // from different child elements.
548
- // Until innerProps is removed, it must remain a div rather than a primitive component.
549
- (0, _react2.jsx)("div", (0, _extends2.default)({}, innerProps, {
550
- css: pickerContainerStyles
551
- // Since the onclick, onfocus are passed down, adding role="presentation" prevents typecheck errors.
552
- ,
553
- role: "presentation",
554
- onBlur: this.onContainerBlur,
555
- onFocus: this.onContainerFocus,
556
- onClick: this.onInputClick,
557
- onInput: this.onTextInput,
558
- onKeyDown: this.onInputKeyDown,
559
- ref: this.getContainerRef,
560
- "data-testid": testId && "".concat(testId, "--container")
561
- }), (0, _react2.jsx)("input", {
562
- name: name,
563
- type: "hidden",
564
- value: value,
565
- "data-testid": testId && "".concat(testId, "--input")
566
- }), (0, _react2.jsx)(_select.default, (0, _extends2.default)({
567
- appearance: this.props.appearance,
568
- "aria-describedby": ariaDescribedBy,
569
- label: label || undefined,
570
- autoFocus: autoFocus,
571
- clearControlLabel: clearControlLabel,
572
- closeMenuOnSelect: true
573
- // FOr some reason, this and the below `styles` type error _only_ show
574
- // up when you alter some of the properties in the `selectComponents`
575
- // object. These errors are still present, and I suspect have always
576
- // been present, without changing the unrelated code. Ignoring as the
577
- // component still works as expected despite this error. And also
578
- // because the select refresh team may solve it later.
579
- ,
580
- components: selectComponents,
581
- enableAnimation: false,
582
- inputId: id,
583
- inputValue: actualSelectInputValue,
584
- isDisabled: isDisabled,
585
- isRequired: isRequired,
586
- menuIsOpen: menuIsOpen,
587
- onBlur: this.onSelectBlur,
588
- onChange: this.onSelectChange,
589
- onFocus: this.onSelectFocus,
590
- onInputChange: this.handleSelectInputChange,
591
- placeholder: (0, _datePickerMigration.getPlaceholder)({
592
- placeholder: this.props.placeholder,
593
- l10n: this.state.l10n
594
- }),
595
- styles: mergedStyles,
596
- value: initialValue
597
- }, selectProps, {
598
- // These are below the spread because I don't know what is in
599
- // selectProps or not and what wil be overwritten
600
- isClearable: true,
601
- isInvalid: isInvalid,
602
- spacing: spacing,
603
- testId: testId
604
- // These aren't part of `Select`'s API, but we're using them here.
605
- // @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<...> & { ...; }>'.
606
- ,
607
- calendarContainerRef: calendarProps.calendarContainerRef,
608
- calendarDisabled: calendarProps.calendarDisabled,
609
- calendarDisabledDateFilter: calendarProps.calendarDisabledDateFilter,
610
- calendarLocale: calendarProps.calendarLocale,
611
- calendarMaxDate: calendarProps.calendarMaxDate,
612
- calendarMinDate: calendarProps.calendarMinDate,
613
- calendarRef: calendarProps.calendarRef,
614
- calendarValue: calendarProps.calendarValue,
615
- calendarView: calendarProps.calendarView,
616
- calendarWeekStartDay: calendarProps.calendarWeekStartDay,
617
- nextMonthLabel: nextMonthLabel,
618
- onCalendarChange: calendarProps.onCalendarChange,
619
- onCalendarSelect: calendarProps.onCalendarSelect,
620
- previousMonthLabel: previousMonthLabel,
621
- shouldSetFocusOnCurrentDay: calendarProps.shouldSetFocusOnCurrentDay
622
- })), shouldShowCalendarButton && !isDisabled ? (0, _react2.jsx)(_useId.IdProvider, {
623
- prefix: "open-calendar-label--"
624
- }, function (_ref3) {
625
- var openCalendarLabelId = _ref3.id;
626
- return (0, _react2.jsx)(_primitives.Box, {
627
- xcss: [iconContainerStyles, value && !hideIcon ? iconSpacingWithClearButtonStyles : iconSpacingWithoutClearButtonStyles]
628
- }, (0, _react2.jsx)(_new.IconButton, {
629
- appearance: "subtle",
630
- label: !inputLabelId ? fullopenCalendarLabel : openCalendarLabel,
631
- "aria-labelledby": inputLabelId ? "".concat(inputLabelId, " ").concat(openCalendarLabelId) : undefined,
632
- id: openCalendarLabelId,
633
- icon: function icon(iconProps) {
634
- return (0, _react2.jsx)(_calendar.default, (0, _extends2.default)({}, iconProps, {
635
- color: "var(--ds-icon, #44546F)"
636
- }));
637
- },
638
- onClick: _this2.onCalendarButtonClick,
639
- onKeyDown: _this2.onCalendarButtonKeyDown,
640
- ref: _this2.calendarButtonRef,
641
- testId: testId && "".concat(testId, "--open-calendar-button")
642
- }));
643
- }) : null)
644
- );
645
- }
646
- }], [{
647
- key: "getDerivedStateFromProps",
648
- value: function getDerivedStateFromProps(nextProps, prevState) {
649
- if (nextProps.locale !== prevState.locale) {
650
- return {
651
- l10n: (0, _locale.createLocalizationProvider)(nextProps.locale),
652
- locale: nextProps.locale
653
- };
654
- } else {
655
- return null;
656
- }
657
- }
658
- }]);
659
- }(_react.Component);
660
- (0, _defineProperty2.default)(DatePickerComponent, "defaultProps", datePickerDefaultProps);
661
- /**
662
- * __Date picker__
663
- *
664
- * A date picker allows the user to select a particular date.
665
- *
666
- * - [Examples](https://atlassian.design/components/datetime-picker/date-picker/examples)
667
- * - [Code](https://atlassian.design/components/datetime-picker/date-picker/code)
668
- * - [Usage](https://atlassian.design/components/datetime-picker/date-picker/usage)
669
- */
670
- var DatePicker = (0, _analyticsNext.withAnalyticsContext)({
671
- componentName: 'datePicker',
672
- packageName: packageName,
673
- packageVersion: packageVersion
674
- })((0, _analyticsNext.withAnalyticsEvents)({
675
- onChange: (0, _analyticsNext.createAndFireEvent)('atlaskit')({
676
- action: 'selectedDate',
677
- actionSubject: 'datePicker',
678
- attributes: {
679
- componentName: 'datePicker',
680
- packageName: packageName,
681
- packageVersion: packageVersion
682
- }
683
- })
684
- })(DatePickerComponent));
685
- var _default = exports.default = DatePicker;