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