@atlaskit/datetime-picker 14.0.3 → 14.0.4

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @atlaskit/datetime-picker
2
2
 
3
+ ## 14.0.4
4
+
5
+ ### Patch Changes
6
+
7
+ - [#137180](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/137180)
8
+ [`a12a34f29c819`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/a12a34f29c819) -
9
+ Refactor internal functions.
10
+ - Updated dependencies
11
+
3
12
  ## 14.0.3
4
13
 
5
14
  ### Patch Changes
@@ -7,7 +7,6 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.default = exports.DatePickerWithoutAnalytics = void 0;
9
9
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
10
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
10
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
12
11
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
12
  var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
@@ -23,9 +22,9 @@ var _calendar = _interopRequireDefault(require("@atlaskit/icon/glyph/calendar"))
23
22
  var _locale = require("@atlaskit/locale");
24
23
  var _select = _interopRequireWildcard(require("@atlaskit/select"));
25
24
  var _internal = require("../internal");
25
+ var _datePickerMigration = require("../internal/date-picker-migration");
26
26
  var _menu = require("../internal/menu");
27
27
  var _parseDate = require("../internal/parse-date");
28
- var _parseTokens = require("../internal/parse-tokens");
29
28
  var _singleValue = require("../internal/single-value");
30
29
  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); }
31
30
  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 && Object.prototype.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; }
@@ -37,7 +36,7 @@ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.
37
36
  * @jsx jsx
38
37
  */ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
39
38
  var packageName = "@atlaskit/datetime-picker";
40
- var packageVersion = "14.0.3";
39
+ var packageVersion = "14.0.4";
41
40
  var datePickerDefaultProps = {
42
41
  appearance: 'default',
43
42
  autoFocus: false,
@@ -86,29 +85,12 @@ var DatePickerComponent = exports.DatePickerWithoutAnalytics = /*#__PURE__*/func
86
85
  var _this$props$isOpen;
87
86
  return (_this$props$isOpen = _this.props.isOpen) !== null && _this$props$isOpen !== void 0 ? _this$props$isOpen : _this.state.isOpen;
88
87
  });
89
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "isDateDisabled", function (date) {
90
- return _this.props.disabled.indexOf(date) > -1;
91
- });
92
88
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onCalendarChange", function (_ref) {
93
89
  var iso = _ref.iso;
94
- var _iso$split = iso.split('-'),
95
- _iso$split2 = (0, _slicedToArray2.default)(_iso$split, 3),
96
- year = _iso$split2[0],
97
- month = _iso$split2[1],
98
- date = _iso$split2[2];
99
- var newIso = iso;
100
- var parsedDate = parseInt(date, 10);
101
- var parsedMonth = parseInt(month, 10);
102
- var parsedYear = parseInt(year, 10);
103
- var lastDayInMonth = (0, _dateFns.lastDayOfMonth)(new Date(parsedYear, parsedMonth - 1) // This needs to be -1, because the Date constructor expects an index of the given month
104
- ).getDate();
105
- if (lastDayInMonth < parsedDate) {
106
- newIso = "".concat(year, "-").concat((0, _internal.padToTwo)(parsedMonth), "-").concat((0, _internal.padToTwo)(lastDayInMonth));
107
- } else {
108
- newIso = "".concat(year, "-").concat((0, _internal.padToTwo)(parsedMonth), "-").concat((0, _internal.padToTwo)(parsedDate));
109
- }
110
90
  _this.setState({
111
- calendarValue: newIso
91
+ calendarValue: (0, _datePickerMigration.getParsedISO)({
92
+ iso: iso
93
+ })
112
94
  });
113
95
  });
114
96
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onCalendarSelect", function (_ref2) {
@@ -193,7 +175,11 @@ var DatePickerComponent = exports.DatePickerWithoutAnalytics = /*#__PURE__*/func
193
175
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onTextInput", function (event) {
194
176
  var inputValue = event.target.value;
195
177
  if (inputValue) {
196
- var parsed = _this.parseDate(inputValue);
178
+ var parsed = (0, _datePickerMigration.parseDate)(inputValue, {
179
+ parseInputValue: _this.props.parseInputValue,
180
+ dateFormat: _this.props.dateFormat,
181
+ l10n: _this.state.l10n
182
+ });
197
183
  // Only try to set the date if we have month & day
198
184
  if (parsed && (0, _dateFns.isValid)(parsed)) {
199
185
  // We format the parsed date to YYYY-MM-DD here because
@@ -255,7 +241,9 @@ var DatePickerComponent = exports.DatePickerWithoutAnalytics = /*#__PURE__*/func
255
241
  // using enter. See https://product-fabric.atlassian.net/browse/DSP-2501
256
242
  // for more details.
257
243
  event.preventDefault();
258
- if (!_this.isDateDisabled(calendarValue)) {
244
+ if (!(0, _datePickerMigration.isDateDisabled)(calendarValue, {
245
+ disabled: _this.props.disabled
246
+ })) {
259
247
  // Get a safe `calendarValue` in case the value exceeds the maximum
260
248
  // allowed by ISO 8601
261
249
  var safeCalendarValue = (0, _parseDate.getSafeCalendarValue)(calendarValue);
@@ -322,48 +310,6 @@ var DatePickerComponent = exports.DatePickerWithoutAnalytics = /*#__PURE__*/func
322
310
  _this.forceUpdate();
323
311
  }
324
312
  });
325
- /**
326
- * There are two props that can change how the date is parsed.
327
- * The priority of props used is:
328
- * 1. `parseInputValue`
329
- * 2. `locale`
330
- */
331
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "parseDate", function (date) {
332
- var _this$props = _this.props,
333
- parseInputValue = _this$props.parseInputValue,
334
- dateFormat = _this$props.dateFormat;
335
- if (parseInputValue) {
336
- return parseInputValue(date, dateFormat || _internal.defaultDateFormat);
337
- }
338
- var l10n = _this.state.l10n;
339
- return l10n.parseDate(date);
340
- });
341
- /**
342
- * There are multiple props that can change how the date is formatted.
343
- * The priority of props used is:
344
- * 1. `formatDisplayLabel`
345
- * 2. `dateFormat`
346
- * 3. `locale`
347
- */
348
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "formatDate", function (value) {
349
- var _this$props2 = _this.props,
350
- formatDisplayLabel = _this$props2.formatDisplayLabel,
351
- dateFormat = _this$props2.dateFormat;
352
- var l10n = _this.state.l10n;
353
- if (formatDisplayLabel) {
354
- return formatDisplayLabel(value, dateFormat || _internal.defaultDateFormat);
355
- }
356
- var date = (0, _dateFns.parseISO)(value);
357
- return dateFormat ? (0, _dateFns.format)(date, (0, _parseTokens.convertTokens)(dateFormat)) : l10n.formatDate(date);
358
- });
359
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getPlaceholder", function () {
360
- var placeholder = _this.props.placeholder;
361
- if (placeholder) {
362
- return placeholder;
363
- }
364
- var l10n = _this.state.l10n;
365
- return l10n.formatDate(_internal.placeholderDatetime);
366
- });
367
313
  _this.state = {
368
314
  isOpen: _this.props.defaultIsOpen,
369
315
  isFocused: false,
@@ -380,29 +326,29 @@ var DatePickerComponent = exports.DatePickerWithoutAnalytics = /*#__PURE__*/func
380
326
  (0, _createClass2.default)(DatePickerComponent, [{
381
327
  key: "render",
382
328
  value: function render() {
383
- var _this$props3 = this.props,
384
- appearance = _this$props3.appearance,
385
- ariaDescribedBy = _this$props3['aria-describedby'],
386
- autoFocus = _this$props3.autoFocus,
387
- disabled = _this$props3.disabled,
388
- hideIcon = _this$props3.hideIcon,
389
- icon = _this$props3.icon,
390
- id = _this$props3.id,
391
- innerProps = _this$props3.innerProps,
392
- isDisabled = _this$props3.isDisabled,
393
- disabledDateFilter = _this$props3.disabledDateFilter,
394
- maxDate = _this$props3.maxDate,
395
- minDate = _this$props3.minDate,
396
- isInvalid = _this$props3.isInvalid,
397
- label = _this$props3.label,
398
- name = _this$props3.name,
399
- nextMonthLabel = _this$props3.nextMonthLabel,
400
- previousMonthLabel = _this$props3.previousMonthLabel,
401
- selectProps = _this$props3.selectProps,
402
- spacing = _this$props3.spacing,
403
- locale = _this$props3.locale,
404
- testId = _this$props3.testId,
405
- weekStartDay = _this$props3.weekStartDay;
329
+ var _this$props = this.props,
330
+ appearance = _this$props.appearance,
331
+ ariaDescribedBy = _this$props['aria-describedby'],
332
+ autoFocus = _this$props.autoFocus,
333
+ disabled = _this$props.disabled,
334
+ hideIcon = _this$props.hideIcon,
335
+ icon = _this$props.icon,
336
+ id = _this$props.id,
337
+ innerProps = _this$props.innerProps,
338
+ isDisabled = _this$props.isDisabled,
339
+ disabledDateFilter = _this$props.disabledDateFilter,
340
+ maxDate = _this$props.maxDate,
341
+ minDate = _this$props.minDate,
342
+ isInvalid = _this$props.isInvalid,
343
+ label = _this$props.label,
344
+ name = _this$props.name,
345
+ nextMonthLabel = _this$props.nextMonthLabel,
346
+ previousMonthLabel = _this$props.previousMonthLabel,
347
+ selectProps = _this$props.selectProps,
348
+ spacing = _this$props.spacing,
349
+ locale = _this$props.locale,
350
+ testId = _this$props.testId,
351
+ weekStartDay = _this$props.weekStartDay;
406
352
  var _this$state = this.state,
407
353
  calendarValue = _this$state.calendarValue,
408
354
  selectInputValue = _this$state.selectInputValue;
@@ -455,7 +401,11 @@ var DatePickerComponent = exports.DatePickerWithoutAnalytics = /*#__PURE__*/func
455
401
  }
456
402
  });
457
403
  var initialValue = value ? {
458
- label: this.formatDate(value),
404
+ label: (0, _datePickerMigration.formatDate)(value, {
405
+ formatDisplayLabel: this.props.formatDisplayLabel,
406
+ dateFormat: this.props.dateFormat,
407
+ l10n: this.state.l10n
408
+ }),
459
409
  value: value
460
410
  } : null;
461
411
  return (
@@ -491,7 +441,10 @@ var DatePickerComponent = exports.DatePickerWithoutAnalytics = /*#__PURE__*/func
491
441
  onChange: this.onSelectChange,
492
442
  onFocus: this.onSelectFocus,
493
443
  onInputChange: this.handleSelectInputChange,
494
- placeholder: this.getPlaceholder(),
444
+ placeholder: (0, _datePickerMigration.getPlaceholder)({
445
+ placeholder: this.props.placeholder,
446
+ l10n: this.state.l10n
447
+ }),
495
448
  styles: mergedStyles,
496
449
  value: initialValue
497
450
  }, selectProps, {
@@ -35,7 +35,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
35
35
  * @jsx jsx
36
36
  */ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
37
37
  var packageName = "@atlaskit/datetime-picker";
38
- var packageVersion = "14.0.3";
38
+ var packageVersion = "14.0.4";
39
39
  // Make DatePicker 50% the width of DateTimePicker
40
40
  // If rendering an icon container, shrink the TimePicker
41
41
  var datePickerContainerStyles = (0, _react2.css)({
@@ -29,7 +29,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
29
29
  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; } // eslint-disable-next-line no-restricted-imports
30
30
  // eslint-disable-next-line @atlaskit/design-system/no-deprecated-imports
31
31
  var packageName = "@atlaskit/datetime-picker";
32
- var packageVersion = "14.0.3";
32
+ var packageVersion = "14.0.4";
33
33
  var menuStyles = {
34
34
  /* Need to remove default absolute positioning as that causes issues with position fixed */
35
35
  position: 'static',
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.parseDate = exports.isDateDisabled = exports.getPlaceholder = exports.getParsedISO = exports.formatDate = void 0;
8
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
+ var _dateFns = require("date-fns");
10
+ var _parseTokens = require("./parse-tokens");
11
+ var _index = require("./index");
12
+ /**
13
+ * Everything in this file is to smooth out the migration of the new date picker
14
+ * (https://product-fabric.atlassian.net/browse/DSP-20682). When that ticket is
15
+ * complete, all of these functions will ilkely be merged back into the date
16
+ * picker. Please do not pre-optimize and put these back into the date picker
17
+ * unless you are working on the DTP Refresh and you have a good reason to do
18
+ * so, thank you!
19
+ *
20
+ * All variables within the `di` objects are dependency injections. They should
21
+ * be read from within the component at the end of the day. But because we are
22
+ * extracting them, we have to inject them in every place manually. When we
23
+ * re-introduce them to the components, we can likely remove the `di` variables
24
+ * and instead use internal variables.
25
+ *
26
+ * If component _only_ has injected variables, it is fully internal and was
27
+ * broken out to be it's own function.
28
+ */
29
+
30
+ var isDateDisabled = exports.isDateDisabled = function isDateDisabled(date, di) {
31
+ var disabled = di.disabled;
32
+ return disabled.indexOf(date) > -1;
33
+ };
34
+ var getParsedISO = exports.getParsedISO = function getParsedISO(di) {
35
+ var iso = di.iso;
36
+ var _iso$split = iso.split('-'),
37
+ _iso$split2 = (0, _slicedToArray2.default)(_iso$split, 3),
38
+ year = _iso$split2[0],
39
+ month = _iso$split2[1],
40
+ date = _iso$split2[2];
41
+ var newIso = iso;
42
+ var parsedDate = parseInt(date, 10);
43
+ var parsedMonth = parseInt(month, 10);
44
+ var parsedYear = parseInt(year, 10);
45
+ var lastDayInMonth = (0, _dateFns.lastDayOfMonth)(new Date(parsedYear, parsedMonth - 1) // This needs to be -1, because the Date constructor expects an index of the given month
46
+ ).getDate();
47
+ if (lastDayInMonth < parsedDate) {
48
+ newIso = "".concat(year, "-").concat((0, _index.padToTwo)(parsedMonth), "-").concat((0, _index.padToTwo)(lastDayInMonth));
49
+ } else {
50
+ newIso = "".concat(year, "-").concat((0, _index.padToTwo)(parsedMonth), "-").concat((0, _index.padToTwo)(parsedDate));
51
+ }
52
+ return newIso;
53
+ };
54
+
55
+ /**
56
+ * There are two props that can change how the date is parsed.
57
+ * The priority of props used is:
58
+ * 1. `parseInputValue`
59
+ * 2. `locale`
60
+ */
61
+ var parseDate = exports.parseDate = function parseDate(date, di) {
62
+ var parseInputValue = di.parseInputValue,
63
+ dateFormat = di.dateFormat,
64
+ l10n = di.l10n;
65
+ if (parseInputValue) {
66
+ return parseInputValue(date, dateFormat || _index.defaultDateFormat);
67
+ }
68
+ return l10n.parseDate(date);
69
+ };
70
+
71
+ /**
72
+ * There are multiple props that can change how the date is formatted.
73
+ * The priority of props used is:
74
+ * 1. `formatDisplayLabel`
75
+ * 2. `dateFormat`
76
+ * 3. `locale`
77
+ */
78
+ var formatDate = exports.formatDate = function formatDate(value, di) {
79
+ var formatDisplayLabel = di.formatDisplayLabel,
80
+ dateFormat = di.dateFormat,
81
+ l10n = di.l10n;
82
+ if (formatDisplayLabel) {
83
+ return formatDisplayLabel(value, dateFormat || _index.defaultDateFormat);
84
+ }
85
+ var date = (0, _dateFns.parseISO)(value);
86
+ return dateFormat ? (0, _dateFns.format)(date, (0, _parseTokens.convertTokens)(dateFormat)) : l10n.formatDate(date);
87
+ };
88
+ var getPlaceholder = exports.getPlaceholder = function getPlaceholder(di) {
89
+ var placeholder = di.placeholder,
90
+ l10n = di.l10n;
91
+ return placeholder || l10n.formatDate(_index.placeholderDatetime);
92
+ };
@@ -8,18 +8,18 @@ import { Component } from 'react';
8
8
 
9
9
  // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
10
10
  import { jsx } from '@emotion/react';
11
- import { format, isValid, lastDayOfMonth, parseISO } from 'date-fns';
11
+ import { isValid, parseISO } from 'date-fns';
12
12
  import { createAndFireEvent, withAnalyticsContext, withAnalyticsEvents } from '@atlaskit/analytics-next';
13
13
  import CalendarIcon from '@atlaskit/icon/glyph/calendar';
14
14
  import { createLocalizationProvider } from '@atlaskit/locale';
15
15
  import Select, { mergeStyles } from '@atlaskit/select';
16
- import { defaultDateFormat, EmptyComponent, padToTwo, placeholderDatetime } from '../internal';
16
+ import { EmptyComponent } from '../internal';
17
+ import { formatDate, getParsedISO, getPlaceholder, isDateDisabled, parseDate } from '../internal/date-picker-migration';
17
18
  import { Menu } from '../internal/menu';
18
19
  import { getSafeCalendarValue, getShortISOString } from '../internal/parse-date';
19
- import { convertTokens } from '../internal/parse-tokens';
20
20
  import { makeSingleValue } from '../internal/single-value';
21
21
  const packageName = "@atlaskit/datetime-picker";
22
- const packageVersion = "14.0.3";
22
+ const packageVersion = "14.0.4";
23
23
  const datePickerDefaultProps = {
24
24
  appearance: 'default',
25
25
  autoFocus: false,
@@ -62,26 +62,13 @@ class DatePickerComponent extends Component {
62
62
  var _this$props$isOpen;
63
63
  return (_this$props$isOpen = this.props.isOpen) !== null && _this$props$isOpen !== void 0 ? _this$props$isOpen : this.state.isOpen;
64
64
  });
65
- _defineProperty(this, "isDateDisabled", date => {
66
- return this.props.disabled.indexOf(date) > -1;
67
- });
68
65
  _defineProperty(this, "onCalendarChange", ({
69
66
  iso
70
67
  }) => {
71
- const [year, month, date] = iso.split('-');
72
- let newIso = iso;
73
- const parsedDate = parseInt(date, 10);
74
- const parsedMonth = parseInt(month, 10);
75
- const parsedYear = parseInt(year, 10);
76
- const lastDayInMonth = lastDayOfMonth(new Date(parsedYear, parsedMonth - 1) // This needs to be -1, because the Date constructor expects an index of the given month
77
- ).getDate();
78
- if (lastDayInMonth < parsedDate) {
79
- newIso = `${year}-${padToTwo(parsedMonth)}-${padToTwo(lastDayInMonth)}`;
80
- } else {
81
- newIso = `${year}-${padToTwo(parsedMonth)}-${padToTwo(parsedDate)}`;
82
- }
83
68
  this.setState({
84
- calendarValue: newIso
69
+ calendarValue: getParsedISO({
70
+ iso
71
+ })
85
72
  });
86
73
  });
87
74
  _defineProperty(this, "onCalendarSelect", ({
@@ -169,7 +156,11 @@ class DatePickerComponent extends Component {
169
156
  _defineProperty(this, "onTextInput", event => {
170
157
  const inputValue = event.target.value;
171
158
  if (inputValue) {
172
- const parsed = this.parseDate(inputValue);
159
+ const parsed = parseDate(inputValue, {
160
+ parseInputValue: this.props.parseInputValue,
161
+ dateFormat: this.props.dateFormat,
162
+ l10n: this.state.l10n
163
+ });
173
164
  // Only try to set the date if we have month & day
174
165
  if (parsed && isValid(parsed)) {
175
166
  // We format the parsed date to YYYY-MM-DD here because
@@ -233,7 +224,9 @@ class DatePickerComponent extends Component {
233
224
  // using enter. See https://product-fabric.atlassian.net/browse/DSP-2501
234
225
  // for more details.
235
226
  event.preventDefault();
236
- if (!this.isDateDisabled(calendarValue)) {
227
+ if (!isDateDisabled(calendarValue, {
228
+ disabled: this.props.disabled
229
+ })) {
237
230
  // Get a safe `calendarValue` in case the value exceeds the maximum
238
231
  // allowed by ISO 8601
239
232
  const safeCalendarValue = getSafeCalendarValue(calendarValue);
@@ -303,58 +296,6 @@ class DatePickerComponent extends Component {
303
296
  this.forceUpdate();
304
297
  }
305
298
  });
306
- /**
307
- * There are two props that can change how the date is parsed.
308
- * The priority of props used is:
309
- * 1. `parseInputValue`
310
- * 2. `locale`
311
- */
312
- _defineProperty(this, "parseDate", date => {
313
- const {
314
- parseInputValue,
315
- dateFormat
316
- } = this.props;
317
- if (parseInputValue) {
318
- return parseInputValue(date, dateFormat || defaultDateFormat);
319
- }
320
- const {
321
- l10n
322
- } = this.state;
323
- return l10n.parseDate(date);
324
- });
325
- /**
326
- * There are multiple props that can change how the date is formatted.
327
- * The priority of props used is:
328
- * 1. `formatDisplayLabel`
329
- * 2. `dateFormat`
330
- * 3. `locale`
331
- */
332
- _defineProperty(this, "formatDate", value => {
333
- const {
334
- formatDisplayLabel,
335
- dateFormat
336
- } = this.props;
337
- const {
338
- l10n
339
- } = this.state;
340
- if (formatDisplayLabel) {
341
- return formatDisplayLabel(value, dateFormat || defaultDateFormat);
342
- }
343
- const date = parseISO(value);
344
- return dateFormat ? format(date, convertTokens(dateFormat)) : l10n.formatDate(date);
345
- });
346
- _defineProperty(this, "getPlaceholder", () => {
347
- const {
348
- placeholder
349
- } = this.props;
350
- if (placeholder) {
351
- return placeholder;
352
- }
353
- const {
354
- l10n
355
- } = this.state;
356
- return l10n.formatDate(placeholderDatetime);
357
- });
358
299
  this.state = {
359
300
  isOpen: this.props.defaultIsOpen,
360
301
  isFocused: false,
@@ -457,7 +398,11 @@ class DatePickerComponent extends Component {
457
398
  })
458
399
  });
459
400
  const initialValue = value ? {
460
- label: this.formatDate(value),
401
+ label: formatDate(value, {
402
+ formatDisplayLabel: this.props.formatDisplayLabel,
403
+ dateFormat: this.props.dateFormat,
404
+ l10n: this.state.l10n
405
+ }),
461
406
  value
462
407
  } : null;
463
408
  return (
@@ -493,7 +438,10 @@ class DatePickerComponent extends Component {
493
438
  onChange: this.onSelectChange,
494
439
  onFocus: this.onSelectFocus,
495
440
  onInputChange: this.handleSelectInputChange,
496
- placeholder: this.getPlaceholder(),
441
+ placeholder: getPlaceholder({
442
+ placeholder: this.props.placeholder,
443
+ l10n: this.state.l10n
444
+ }),
497
445
  styles: mergedStyles,
498
446
  value: initialValue
499
447
  }, selectProps, {
@@ -18,7 +18,7 @@ import { convertTokens } from '../internal/parse-tokens';
18
18
  import DatePicker from './date-picker';
19
19
  import TimePicker from './time-picker';
20
20
  const packageName = "@atlaskit/datetime-picker";
21
- const packageVersion = "14.0.3";
21
+ const packageVersion = "14.0.4";
22
22
  // Make DatePicker 50% the width of DateTimePicker
23
23
  // If rendering an icon container, shrink the TimePicker
24
24
  const datePickerContainerStyles = css({
@@ -15,7 +15,7 @@ import parseTime from '../internal/parse-time';
15
15
  import { convertTokens } from '../internal/parse-tokens';
16
16
  import { makeSingleValue } from '../internal/single-value';
17
17
  const packageName = "@atlaskit/datetime-picker";
18
- const packageVersion = "14.0.3";
18
+ const packageVersion = "14.0.4";
19
19
  const menuStyles = {
20
20
  /* Need to remove default absolute positioning as that causes issues with position fixed */
21
21
  position: 'static',
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Everything in this file is to smooth out the migration of the new date picker
3
+ * (https://product-fabric.atlassian.net/browse/DSP-20682). When that ticket is
4
+ * complete, all of these functions will ilkely be merged back into the date
5
+ * picker. Please do not pre-optimize and put these back into the date picker
6
+ * unless you are working on the DTP Refresh and you have a good reason to do
7
+ * so, thank you!
8
+ *
9
+ * All variables within the `di` objects are dependency injections. They should
10
+ * be read from within the component at the end of the day. But because we are
11
+ * extracting them, we have to inject them in every place manually. When we
12
+ * re-introduce them to the components, we can likely remove the `di` variables
13
+ * and instead use internal variables.
14
+ *
15
+ * If component _only_ has injected variables, it is fully internal and was
16
+ * broken out to be it's own function.
17
+ */
18
+
19
+ import { format, lastDayOfMonth, parseISO } from 'date-fns';
20
+ import { convertTokens } from './parse-tokens';
21
+ import { defaultDateFormat, padToTwo, placeholderDatetime } from './index';
22
+ export const isDateDisabled = (date, di) => {
23
+ const {
24
+ disabled
25
+ } = di;
26
+ return disabled.indexOf(date) > -1;
27
+ };
28
+ export const getParsedISO = di => {
29
+ const {
30
+ iso
31
+ } = di;
32
+ const [year, month, date] = iso.split('-');
33
+ let newIso = iso;
34
+ const parsedDate = parseInt(date, 10);
35
+ const parsedMonth = parseInt(month, 10);
36
+ const parsedYear = parseInt(year, 10);
37
+ const lastDayInMonth = lastDayOfMonth(new Date(parsedYear, parsedMonth - 1) // This needs to be -1, because the Date constructor expects an index of the given month
38
+ ).getDate();
39
+ if (lastDayInMonth < parsedDate) {
40
+ newIso = `${year}-${padToTwo(parsedMonth)}-${padToTwo(lastDayInMonth)}`;
41
+ } else {
42
+ newIso = `${year}-${padToTwo(parsedMonth)}-${padToTwo(parsedDate)}`;
43
+ }
44
+ return newIso;
45
+ };
46
+
47
+ /**
48
+ * There are two props that can change how the date is parsed.
49
+ * The priority of props used is:
50
+ * 1. `parseInputValue`
51
+ * 2. `locale`
52
+ */
53
+ export const parseDate = (date, di) => {
54
+ const {
55
+ parseInputValue,
56
+ dateFormat,
57
+ l10n
58
+ } = di;
59
+ if (parseInputValue) {
60
+ return parseInputValue(date, dateFormat || defaultDateFormat);
61
+ }
62
+ return l10n.parseDate(date);
63
+ };
64
+
65
+ /**
66
+ * There are multiple props that can change how the date is formatted.
67
+ * The priority of props used is:
68
+ * 1. `formatDisplayLabel`
69
+ * 2. `dateFormat`
70
+ * 3. `locale`
71
+ */
72
+ export const formatDate = (value, di) => {
73
+ const {
74
+ formatDisplayLabel,
75
+ dateFormat,
76
+ l10n
77
+ } = di;
78
+ if (formatDisplayLabel) {
79
+ return formatDisplayLabel(value, dateFormat || defaultDateFormat);
80
+ }
81
+ const date = parseISO(value);
82
+ return dateFormat ? format(date, convertTokens(dateFormat)) : l10n.formatDate(date);
83
+ };
84
+ export const getPlaceholder = di => {
85
+ const {
86
+ placeholder,
87
+ l10n
88
+ } = di;
89
+ return placeholder || l10n.formatDate(placeholderDatetime);
90
+ };
@@ -1,5 +1,4 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
2
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
4
3
  import _createClass from "@babel/runtime/helpers/createClass";
5
4
  import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
@@ -19,18 +18,18 @@ import { Component } from 'react';
19
18
 
20
19
  // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
21
20
  import { jsx } from '@emotion/react';
22
- import { format, isValid, lastDayOfMonth, parseISO } from 'date-fns';
21
+ import { isValid, parseISO } from 'date-fns';
23
22
  import { createAndFireEvent, withAnalyticsContext, withAnalyticsEvents } from '@atlaskit/analytics-next';
24
23
  import CalendarIcon from '@atlaskit/icon/glyph/calendar';
25
24
  import { createLocalizationProvider } from '@atlaskit/locale';
26
25
  import Select, { mergeStyles } from '@atlaskit/select';
27
- import { defaultDateFormat, EmptyComponent, padToTwo, placeholderDatetime } from '../internal';
26
+ import { EmptyComponent } from '../internal';
27
+ import { formatDate, getParsedISO, getPlaceholder, isDateDisabled, parseDate } from '../internal/date-picker-migration';
28
28
  import { Menu } from '../internal/menu';
29
29
  import { getSafeCalendarValue, getShortISOString } from '../internal/parse-date';
30
- import { convertTokens } from '../internal/parse-tokens';
31
30
  import { makeSingleValue } from '../internal/single-value';
32
31
  var packageName = "@atlaskit/datetime-picker";
33
- var packageVersion = "14.0.3";
32
+ var packageVersion = "14.0.4";
34
33
  var datePickerDefaultProps = {
35
34
  appearance: 'default',
36
35
  autoFocus: false,
@@ -79,29 +78,12 @@ var DatePickerComponent = /*#__PURE__*/function (_Component) {
79
78
  var _this$props$isOpen;
80
79
  return (_this$props$isOpen = _this.props.isOpen) !== null && _this$props$isOpen !== void 0 ? _this$props$isOpen : _this.state.isOpen;
81
80
  });
82
- _defineProperty(_assertThisInitialized(_this), "isDateDisabled", function (date) {
83
- return _this.props.disabled.indexOf(date) > -1;
84
- });
85
81
  _defineProperty(_assertThisInitialized(_this), "onCalendarChange", function (_ref) {
86
82
  var iso = _ref.iso;
87
- var _iso$split = iso.split('-'),
88
- _iso$split2 = _slicedToArray(_iso$split, 3),
89
- year = _iso$split2[0],
90
- month = _iso$split2[1],
91
- date = _iso$split2[2];
92
- var newIso = iso;
93
- var parsedDate = parseInt(date, 10);
94
- var parsedMonth = parseInt(month, 10);
95
- var parsedYear = parseInt(year, 10);
96
- var lastDayInMonth = lastDayOfMonth(new Date(parsedYear, parsedMonth - 1) // This needs to be -1, because the Date constructor expects an index of the given month
97
- ).getDate();
98
- if (lastDayInMonth < parsedDate) {
99
- newIso = "".concat(year, "-").concat(padToTwo(parsedMonth), "-").concat(padToTwo(lastDayInMonth));
100
- } else {
101
- newIso = "".concat(year, "-").concat(padToTwo(parsedMonth), "-").concat(padToTwo(parsedDate));
102
- }
103
83
  _this.setState({
104
- calendarValue: newIso
84
+ calendarValue: getParsedISO({
85
+ iso: iso
86
+ })
105
87
  });
106
88
  });
107
89
  _defineProperty(_assertThisInitialized(_this), "onCalendarSelect", function (_ref2) {
@@ -186,7 +168,11 @@ var DatePickerComponent = /*#__PURE__*/function (_Component) {
186
168
  _defineProperty(_assertThisInitialized(_this), "onTextInput", function (event) {
187
169
  var inputValue = event.target.value;
188
170
  if (inputValue) {
189
- var parsed = _this.parseDate(inputValue);
171
+ var parsed = parseDate(inputValue, {
172
+ parseInputValue: _this.props.parseInputValue,
173
+ dateFormat: _this.props.dateFormat,
174
+ l10n: _this.state.l10n
175
+ });
190
176
  // Only try to set the date if we have month & day
191
177
  if (parsed && isValid(parsed)) {
192
178
  // We format the parsed date to YYYY-MM-DD here because
@@ -248,7 +234,9 @@ var DatePickerComponent = /*#__PURE__*/function (_Component) {
248
234
  // using enter. See https://product-fabric.atlassian.net/browse/DSP-2501
249
235
  // for more details.
250
236
  event.preventDefault();
251
- if (!_this.isDateDisabled(calendarValue)) {
237
+ if (!isDateDisabled(calendarValue, {
238
+ disabled: _this.props.disabled
239
+ })) {
252
240
  // Get a safe `calendarValue` in case the value exceeds the maximum
253
241
  // allowed by ISO 8601
254
242
  var safeCalendarValue = getSafeCalendarValue(calendarValue);
@@ -315,48 +303,6 @@ var DatePickerComponent = /*#__PURE__*/function (_Component) {
315
303
  _this.forceUpdate();
316
304
  }
317
305
  });
318
- /**
319
- * There are two props that can change how the date is parsed.
320
- * The priority of props used is:
321
- * 1. `parseInputValue`
322
- * 2. `locale`
323
- */
324
- _defineProperty(_assertThisInitialized(_this), "parseDate", function (date) {
325
- var _this$props = _this.props,
326
- parseInputValue = _this$props.parseInputValue,
327
- dateFormat = _this$props.dateFormat;
328
- if (parseInputValue) {
329
- return parseInputValue(date, dateFormat || defaultDateFormat);
330
- }
331
- var l10n = _this.state.l10n;
332
- return l10n.parseDate(date);
333
- });
334
- /**
335
- * There are multiple props that can change how the date is formatted.
336
- * The priority of props used is:
337
- * 1. `formatDisplayLabel`
338
- * 2. `dateFormat`
339
- * 3. `locale`
340
- */
341
- _defineProperty(_assertThisInitialized(_this), "formatDate", function (value) {
342
- var _this$props2 = _this.props,
343
- formatDisplayLabel = _this$props2.formatDisplayLabel,
344
- dateFormat = _this$props2.dateFormat;
345
- var l10n = _this.state.l10n;
346
- if (formatDisplayLabel) {
347
- return formatDisplayLabel(value, dateFormat || defaultDateFormat);
348
- }
349
- var date = parseISO(value);
350
- return dateFormat ? format(date, convertTokens(dateFormat)) : l10n.formatDate(date);
351
- });
352
- _defineProperty(_assertThisInitialized(_this), "getPlaceholder", function () {
353
- var placeholder = _this.props.placeholder;
354
- if (placeholder) {
355
- return placeholder;
356
- }
357
- var l10n = _this.state.l10n;
358
- return l10n.formatDate(placeholderDatetime);
359
- });
360
306
  _this.state = {
361
307
  isOpen: _this.props.defaultIsOpen,
362
308
  isFocused: false,
@@ -373,29 +319,29 @@ var DatePickerComponent = /*#__PURE__*/function (_Component) {
373
319
  _createClass(DatePickerComponent, [{
374
320
  key: "render",
375
321
  value: function render() {
376
- var _this$props3 = this.props,
377
- appearance = _this$props3.appearance,
378
- ariaDescribedBy = _this$props3['aria-describedby'],
379
- autoFocus = _this$props3.autoFocus,
380
- disabled = _this$props3.disabled,
381
- hideIcon = _this$props3.hideIcon,
382
- icon = _this$props3.icon,
383
- id = _this$props3.id,
384
- innerProps = _this$props3.innerProps,
385
- isDisabled = _this$props3.isDisabled,
386
- disabledDateFilter = _this$props3.disabledDateFilter,
387
- maxDate = _this$props3.maxDate,
388
- minDate = _this$props3.minDate,
389
- isInvalid = _this$props3.isInvalid,
390
- label = _this$props3.label,
391
- name = _this$props3.name,
392
- nextMonthLabel = _this$props3.nextMonthLabel,
393
- previousMonthLabel = _this$props3.previousMonthLabel,
394
- selectProps = _this$props3.selectProps,
395
- spacing = _this$props3.spacing,
396
- locale = _this$props3.locale,
397
- testId = _this$props3.testId,
398
- weekStartDay = _this$props3.weekStartDay;
322
+ var _this$props = this.props,
323
+ appearance = _this$props.appearance,
324
+ ariaDescribedBy = _this$props['aria-describedby'],
325
+ autoFocus = _this$props.autoFocus,
326
+ disabled = _this$props.disabled,
327
+ hideIcon = _this$props.hideIcon,
328
+ icon = _this$props.icon,
329
+ id = _this$props.id,
330
+ innerProps = _this$props.innerProps,
331
+ isDisabled = _this$props.isDisabled,
332
+ disabledDateFilter = _this$props.disabledDateFilter,
333
+ maxDate = _this$props.maxDate,
334
+ minDate = _this$props.minDate,
335
+ isInvalid = _this$props.isInvalid,
336
+ label = _this$props.label,
337
+ name = _this$props.name,
338
+ nextMonthLabel = _this$props.nextMonthLabel,
339
+ previousMonthLabel = _this$props.previousMonthLabel,
340
+ selectProps = _this$props.selectProps,
341
+ spacing = _this$props.spacing,
342
+ locale = _this$props.locale,
343
+ testId = _this$props.testId,
344
+ weekStartDay = _this$props.weekStartDay;
399
345
  var _this$state = this.state,
400
346
  calendarValue = _this$state.calendarValue,
401
347
  selectInputValue = _this$state.selectInputValue;
@@ -448,7 +394,11 @@ var DatePickerComponent = /*#__PURE__*/function (_Component) {
448
394
  }
449
395
  });
450
396
  var initialValue = value ? {
451
- label: this.formatDate(value),
397
+ label: formatDate(value, {
398
+ formatDisplayLabel: this.props.formatDisplayLabel,
399
+ dateFormat: this.props.dateFormat,
400
+ l10n: this.state.l10n
401
+ }),
452
402
  value: value
453
403
  } : null;
454
404
  return (
@@ -484,7 +434,10 @@ var DatePickerComponent = /*#__PURE__*/function (_Component) {
484
434
  onChange: this.onSelectChange,
485
435
  onFocus: this.onSelectFocus,
486
436
  onInputChange: this.handleSelectInputChange,
487
- placeholder: this.getPlaceholder(),
437
+ placeholder: getPlaceholder({
438
+ placeholder: this.props.placeholder,
439
+ l10n: this.state.l10n
440
+ }),
488
441
  styles: mergedStyles,
489
442
  value: initialValue
490
443
  }, selectProps, {
@@ -31,7 +31,7 @@ import { convertTokens } from '../internal/parse-tokens';
31
31
  import DatePicker from './date-picker';
32
32
  import TimePicker from './time-picker';
33
33
  var packageName = "@atlaskit/datetime-picker";
34
- var packageVersion = "14.0.3";
34
+ var packageVersion = "14.0.4";
35
35
  // Make DatePicker 50% the width of DateTimePicker
36
36
  // If rendering an icon container, shrink the TimePicker
37
37
  var datePickerContainerStyles = css({
@@ -21,7 +21,7 @@ import parseTime from '../internal/parse-time';
21
21
  import { convertTokens } from '../internal/parse-tokens';
22
22
  import { makeSingleValue } from '../internal/single-value';
23
23
  var packageName = "@atlaskit/datetime-picker";
24
- var packageVersion = "14.0.3";
24
+ var packageVersion = "14.0.4";
25
25
  var menuStyles = {
26
26
  /* Need to remove default absolute positioning as that causes issues with position fixed */
27
27
  position: 'static',
@@ -0,0 +1,85 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ /**
3
+ * Everything in this file is to smooth out the migration of the new date picker
4
+ * (https://product-fabric.atlassian.net/browse/DSP-20682). When that ticket is
5
+ * complete, all of these functions will ilkely be merged back into the date
6
+ * picker. Please do not pre-optimize and put these back into the date picker
7
+ * unless you are working on the DTP Refresh and you have a good reason to do
8
+ * so, thank you!
9
+ *
10
+ * All variables within the `di` objects are dependency injections. They should
11
+ * be read from within the component at the end of the day. But because we are
12
+ * extracting them, we have to inject them in every place manually. When we
13
+ * re-introduce them to the components, we can likely remove the `di` variables
14
+ * and instead use internal variables.
15
+ *
16
+ * If component _only_ has injected variables, it is fully internal and was
17
+ * broken out to be it's own function.
18
+ */
19
+
20
+ import { format, lastDayOfMonth, parseISO } from 'date-fns';
21
+ import { convertTokens } from './parse-tokens';
22
+ import { defaultDateFormat, padToTwo, placeholderDatetime } from './index';
23
+ export var isDateDisabled = function isDateDisabled(date, di) {
24
+ var disabled = di.disabled;
25
+ return disabled.indexOf(date) > -1;
26
+ };
27
+ export var getParsedISO = function getParsedISO(di) {
28
+ var iso = di.iso;
29
+ var _iso$split = iso.split('-'),
30
+ _iso$split2 = _slicedToArray(_iso$split, 3),
31
+ year = _iso$split2[0],
32
+ month = _iso$split2[1],
33
+ date = _iso$split2[2];
34
+ var newIso = iso;
35
+ var parsedDate = parseInt(date, 10);
36
+ var parsedMonth = parseInt(month, 10);
37
+ var parsedYear = parseInt(year, 10);
38
+ var lastDayInMonth = lastDayOfMonth(new Date(parsedYear, parsedMonth - 1) // This needs to be -1, because the Date constructor expects an index of the given month
39
+ ).getDate();
40
+ if (lastDayInMonth < parsedDate) {
41
+ newIso = "".concat(year, "-").concat(padToTwo(parsedMonth), "-").concat(padToTwo(lastDayInMonth));
42
+ } else {
43
+ newIso = "".concat(year, "-").concat(padToTwo(parsedMonth), "-").concat(padToTwo(parsedDate));
44
+ }
45
+ return newIso;
46
+ };
47
+
48
+ /**
49
+ * There are two props that can change how the date is parsed.
50
+ * The priority of props used is:
51
+ * 1. `parseInputValue`
52
+ * 2. `locale`
53
+ */
54
+ export var parseDate = function parseDate(date, di) {
55
+ var parseInputValue = di.parseInputValue,
56
+ dateFormat = di.dateFormat,
57
+ l10n = di.l10n;
58
+ if (parseInputValue) {
59
+ return parseInputValue(date, dateFormat || defaultDateFormat);
60
+ }
61
+ return l10n.parseDate(date);
62
+ };
63
+
64
+ /**
65
+ * There are multiple props that can change how the date is formatted.
66
+ * The priority of props used is:
67
+ * 1. `formatDisplayLabel`
68
+ * 2. `dateFormat`
69
+ * 3. `locale`
70
+ */
71
+ export var formatDate = function formatDate(value, di) {
72
+ var formatDisplayLabel = di.formatDisplayLabel,
73
+ dateFormat = di.dateFormat,
74
+ l10n = di.l10n;
75
+ if (formatDisplayLabel) {
76
+ return formatDisplayLabel(value, dateFormat || defaultDateFormat);
77
+ }
78
+ var date = parseISO(value);
79
+ return dateFormat ? format(date, convertTokens(dateFormat)) : l10n.formatDate(date);
80
+ };
81
+ export var getPlaceholder = function getPlaceholder(di) {
82
+ var placeholder = di.placeholder,
83
+ l10n = di.l10n;
84
+ return placeholder || l10n.formatDate(placeholderDatetime);
85
+ };
@@ -77,7 +77,6 @@ declare class DatePickerComponent extends Component<DatePickerProps, State> {
77
77
  } | null;
78
78
  getValue: () => string;
79
79
  getIsOpen: () => boolean;
80
- isDateDisabled: (date: string) => boolean;
81
80
  onCalendarChange: ({ iso }: {
82
81
  iso: string;
83
82
  }) => void;
@@ -95,22 +94,6 @@ declare class DatePickerComponent extends Component<DatePickerProps, State> {
95
94
  onSelectChange: (_value: unknown, action: ActionMeta) => void;
96
95
  handleSelectInputChange: (selectInputValue: string, actionMeta: InputActionMeta) => void;
97
96
  getContainerRef: (ref: HTMLElement | null) => void;
98
- /**
99
- * There are two props that can change how the date is parsed.
100
- * The priority of props used is:
101
- * 1. `parseInputValue`
102
- * 2. `locale`
103
- */
104
- parseDate: (date: string) => Date;
105
- /**
106
- * There are multiple props that can change how the date is formatted.
107
- * The priority of props used is:
108
- * 1. `formatDisplayLabel`
109
- * 2. `dateFormat`
110
- * 3. `locale`
111
- */
112
- formatDate: (value: string) => string;
113
- getPlaceholder: () => string;
114
97
  render(): jsx.JSX.Element;
115
98
  }
116
99
  export { DatePickerComponent as DatePickerWithoutAnalytics };
@@ -123,7 +106,7 @@ export { DatePickerComponent as DatePickerWithoutAnalytics };
123
106
  * - [Code](https://atlassian.design/components/datetime-picker/date-picker/code)
124
107
  * - [Usage](https://atlassian.design/components/datetime-picker/date-picker/usage)
125
108
  */
126
- declare const DatePicker: import("react").ForwardRefExoticComponent<Pick<Pick<Omit<DatePickerProps, keyof import("@atlaskit/analytics-next").WithAnalyticsEventsProps>, "testId" | "placeholder" | "aria-describedby" | "maxDate" | "minDate" | "nextMonthLabel" | "previousMonthLabel" | "weekStartDay" | "value" | "isOpen" | "parseInputValue" | "formatDisplayLabel" | "dateFormat"> & Partial<Pick<Omit<DatePickerProps, keyof import("@atlaskit/analytics-next").WithAnalyticsEventsProps>, "label" | "icon" | "disabled" | "appearance" | "selectProps" | "innerProps" | "isDisabled" | "defaultValue" | "id" | "onFocus" | "onBlur" | "onChange" | "disabledDateFilter" | "locale" | "autoFocus" | "name" | "spacing" | "isInvalid" | "defaultIsOpen" | "hideIcon">> & Partial<Pick<{
109
+ declare const DatePicker: import("react").ForwardRefExoticComponent<Pick<Pick<Omit<DatePickerProps, keyof import("@atlaskit/analytics-next").WithAnalyticsEventsProps>, "parseInputValue" | "dateFormat" | "formatDisplayLabel" | "placeholder" | "testId" | "aria-describedby" | "maxDate" | "minDate" | "nextMonthLabel" | "previousMonthLabel" | "weekStartDay" | "value" | "isOpen"> & Partial<Pick<Omit<DatePickerProps, keyof import("@atlaskit/analytics-next").WithAnalyticsEventsProps>, "disabled" | "label" | "icon" | "appearance" | "selectProps" | "innerProps" | "isDisabled" | "defaultValue" | "id" | "onFocus" | "onBlur" | "onChange" | "disabledDateFilter" | "locale" | "autoFocus" | "name" | "spacing" | "isInvalid" | "defaultIsOpen" | "hideIcon">> & Partial<Pick<{
127
110
  appearance: Appearance;
128
111
  autoFocus: boolean;
129
112
  defaultIsOpen: boolean;
@@ -144,5 +127,5 @@ declare const DatePicker: import("react").ForwardRefExoticComponent<Pick<Pick<Om
144
127
  selectProps: {};
145
128
  spacing: Spacing;
146
129
  locale: string;
147
- }, never>> & import("react").RefAttributes<any> & import("@atlaskit/analytics-next").WithContextProps, "testId" | "label" | "icon" | "disabled" | "appearance" | "selectProps" | "innerProps" | "isDisabled" | "key" | "defaultValue" | "id" | "placeholder" | "aria-describedby" | "onFocus" | "onBlur" | "onChange" | "disabledDateFilter" | "maxDate" | "minDate" | "nextMonthLabel" | "previousMonthLabel" | "locale" | "analyticsContext" | "weekStartDay" | "value" | "autoFocus" | "name" | "spacing" | "isInvalid" | "defaultIsOpen" | "isOpen" | "parseInputValue" | "formatDisplayLabel" | "hideIcon" | "dateFormat"> & import("react").RefAttributes<any>>;
130
+ }, never>> & import("react").RefAttributes<any> & import("@atlaskit/analytics-next").WithContextProps, "disabled" | "parseInputValue" | "dateFormat" | "formatDisplayLabel" | "placeholder" | "testId" | "label" | "icon" | "appearance" | "selectProps" | "innerProps" | "isDisabled" | "key" | "defaultValue" | "id" | "aria-describedby" | "onFocus" | "onBlur" | "onChange" | "disabledDateFilter" | "maxDate" | "minDate" | "nextMonthLabel" | "previousMonthLabel" | "locale" | "analyticsContext" | "weekStartDay" | "value" | "autoFocus" | "name" | "spacing" | "isInvalid" | "defaultIsOpen" | "isOpen" | "hideIcon"> & import("react").RefAttributes<any>>;
148
131
  export default DatePicker;
@@ -9,5 +9,5 @@ import { type TimePickerBaseProps } from '../types';
9
9
  * - [Code](https://atlassian.design/components/datetime-picker/time-picker/code)
10
10
  * - [Usage](https://atlassian.design/components/datetime-picker/time-picker/usage)
11
11
  */
12
- declare const TimePicker: React.ForwardRefExoticComponent<Pick<TimePickerBaseProps, "times" | "testId" | "label" | "appearance" | "selectProps" | "innerProps" | "isDisabled" | "defaultValue" | "id" | "placeholder" | "aria-describedby" | "onFocus" | "onBlur" | "onChange" | "locale" | "analyticsContext" | "createAnalyticsEvent" | "value" | "autoFocus" | "name" | "spacing" | "isInvalid" | "defaultIsOpen" | "isOpen" | "parseInputValue" | "formatDisplayLabel" | "hideIcon" | "timeIsEditable" | "timeFormat"> & React.RefAttributes<unknown>>;
12
+ declare const TimePicker: React.ForwardRefExoticComponent<Pick<TimePickerBaseProps, "times" | "parseInputValue" | "formatDisplayLabel" | "placeholder" | "testId" | "label" | "appearance" | "selectProps" | "innerProps" | "isDisabled" | "defaultValue" | "id" | "aria-describedby" | "onFocus" | "onBlur" | "onChange" | "locale" | "analyticsContext" | "createAnalyticsEvent" | "value" | "autoFocus" | "name" | "spacing" | "isInvalid" | "defaultIsOpen" | "isOpen" | "hideIcon" | "timeIsEditable" | "timeFormat"> & React.RefAttributes<unknown>>;
13
13
  export default TimePicker;
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Everything in this file is to smooth out the migration of the new date picker
3
+ * (https://product-fabric.atlassian.net/browse/DSP-20682). When that ticket is
4
+ * complete, all of these functions will ilkely be merged back into the date
5
+ * picker. Please do not pre-optimize and put these back into the date picker
6
+ * unless you are working on the DTP Refresh and you have a good reason to do
7
+ * so, thank you!
8
+ *
9
+ * All variables within the `di` objects are dependency injections. They should
10
+ * be read from within the component at the end of the day. But because we are
11
+ * extracting them, we have to inject them in every place manually. When we
12
+ * re-introduce them to the components, we can likely remove the `di` variables
13
+ * and instead use internal variables.
14
+ *
15
+ * If component _only_ has injected variables, it is fully internal and was
16
+ * broken out to be it's own function.
17
+ */
18
+ import { type LocalizationProvider } from '@atlaskit/locale';
19
+ export declare const isDateDisabled: (date: string, di: {
20
+ disabled: string[];
21
+ }) => boolean;
22
+ export declare const getParsedISO: (di: {
23
+ iso: string;
24
+ }) => string;
25
+ /**
26
+ * There are two props that can change how the date is parsed.
27
+ * The priority of props used is:
28
+ * 1. `parseInputValue`
29
+ * 2. `locale`
30
+ */
31
+ export declare const parseDate: (date: string, di: {
32
+ parseInputValue: ((date: string, dateFormat: string) => Date) | undefined;
33
+ dateFormat: string | undefined;
34
+ l10n: LocalizationProvider;
35
+ }) => Date;
36
+ /**
37
+ * There are multiple props that can change how the date is formatted.
38
+ * The priority of props used is:
39
+ * 1. `formatDisplayLabel`
40
+ * 2. `dateFormat`
41
+ * 3. `locale`
42
+ */
43
+ export declare const formatDate: (value: string, di: {
44
+ formatDisplayLabel: ((value: string, dateFormat: string) => string) | undefined;
45
+ dateFormat: string | undefined;
46
+ l10n: LocalizationProvider;
47
+ }) => string;
48
+ export declare const getPlaceholder: (di: {
49
+ placeholder: string | undefined;
50
+ l10n: LocalizationProvider;
51
+ }) => string;
@@ -77,7 +77,6 @@ declare class DatePickerComponent extends Component<DatePickerProps, State> {
77
77
  } | null;
78
78
  getValue: () => string;
79
79
  getIsOpen: () => boolean;
80
- isDateDisabled: (date: string) => boolean;
81
80
  onCalendarChange: ({ iso }: {
82
81
  iso: string;
83
82
  }) => void;
@@ -95,22 +94,6 @@ declare class DatePickerComponent extends Component<DatePickerProps, State> {
95
94
  onSelectChange: (_value: unknown, action: ActionMeta) => void;
96
95
  handleSelectInputChange: (selectInputValue: string, actionMeta: InputActionMeta) => void;
97
96
  getContainerRef: (ref: HTMLElement | null) => void;
98
- /**
99
- * There are two props that can change how the date is parsed.
100
- * The priority of props used is:
101
- * 1. `parseInputValue`
102
- * 2. `locale`
103
- */
104
- parseDate: (date: string) => Date;
105
- /**
106
- * There are multiple props that can change how the date is formatted.
107
- * The priority of props used is:
108
- * 1. `formatDisplayLabel`
109
- * 2. `dateFormat`
110
- * 3. `locale`
111
- */
112
- formatDate: (value: string) => string;
113
- getPlaceholder: () => string;
114
97
  render(): jsx.JSX.Element;
115
98
  }
116
99
  export { DatePickerComponent as DatePickerWithoutAnalytics };
@@ -123,7 +106,7 @@ export { DatePickerComponent as DatePickerWithoutAnalytics };
123
106
  * - [Code](https://atlassian.design/components/datetime-picker/date-picker/code)
124
107
  * - [Usage](https://atlassian.design/components/datetime-picker/date-picker/usage)
125
108
  */
126
- declare const DatePicker: import("react").ForwardRefExoticComponent<Pick<Pick<Omit<DatePickerProps, keyof import("@atlaskit/analytics-next").WithAnalyticsEventsProps>, "testId" | "placeholder" | "aria-describedby" | "maxDate" | "minDate" | "nextMonthLabel" | "previousMonthLabel" | "weekStartDay" | "value" | "isOpen" | "parseInputValue" | "formatDisplayLabel" | "dateFormat"> & Partial<Pick<Omit<DatePickerProps, keyof import("@atlaskit/analytics-next").WithAnalyticsEventsProps>, "label" | "icon" | "disabled" | "appearance" | "selectProps" | "innerProps" | "isDisabled" | "defaultValue" | "id" | "onFocus" | "onBlur" | "onChange" | "disabledDateFilter" | "locale" | "autoFocus" | "name" | "spacing" | "isInvalid" | "defaultIsOpen" | "hideIcon">> & Partial<Pick<{
109
+ declare const DatePicker: import("react").ForwardRefExoticComponent<Pick<Pick<Omit<DatePickerProps, keyof import("@atlaskit/analytics-next").WithAnalyticsEventsProps>, "parseInputValue" | "dateFormat" | "formatDisplayLabel" | "placeholder" | "testId" | "aria-describedby" | "maxDate" | "minDate" | "nextMonthLabel" | "previousMonthLabel" | "weekStartDay" | "value" | "isOpen"> & Partial<Pick<Omit<DatePickerProps, keyof import("@atlaskit/analytics-next").WithAnalyticsEventsProps>, "disabled" | "label" | "icon" | "appearance" | "selectProps" | "innerProps" | "isDisabled" | "defaultValue" | "id" | "onFocus" | "onBlur" | "onChange" | "disabledDateFilter" | "locale" | "autoFocus" | "name" | "spacing" | "isInvalid" | "defaultIsOpen" | "hideIcon">> & Partial<Pick<{
127
110
  appearance: Appearance;
128
111
  autoFocus: boolean;
129
112
  defaultIsOpen: boolean;
@@ -144,5 +127,5 @@ declare const DatePicker: import("react").ForwardRefExoticComponent<Pick<Pick<Om
144
127
  selectProps: {};
145
128
  spacing: Spacing;
146
129
  locale: string;
147
- }, never>> & import("react").RefAttributes<any> & import("@atlaskit/analytics-next").WithContextProps, "testId" | "label" | "icon" | "disabled" | "appearance" | "selectProps" | "innerProps" | "isDisabled" | "key" | "defaultValue" | "id" | "placeholder" | "aria-describedby" | "onFocus" | "onBlur" | "onChange" | "disabledDateFilter" | "maxDate" | "minDate" | "nextMonthLabel" | "previousMonthLabel" | "locale" | "analyticsContext" | "weekStartDay" | "value" | "autoFocus" | "name" | "spacing" | "isInvalid" | "defaultIsOpen" | "isOpen" | "parseInputValue" | "formatDisplayLabel" | "hideIcon" | "dateFormat"> & import("react").RefAttributes<any>>;
130
+ }, never>> & import("react").RefAttributes<any> & import("@atlaskit/analytics-next").WithContextProps, "disabled" | "parseInputValue" | "dateFormat" | "formatDisplayLabel" | "placeholder" | "testId" | "label" | "icon" | "appearance" | "selectProps" | "innerProps" | "isDisabled" | "key" | "defaultValue" | "id" | "aria-describedby" | "onFocus" | "onBlur" | "onChange" | "disabledDateFilter" | "maxDate" | "minDate" | "nextMonthLabel" | "previousMonthLabel" | "locale" | "analyticsContext" | "weekStartDay" | "value" | "autoFocus" | "name" | "spacing" | "isInvalid" | "defaultIsOpen" | "isOpen" | "hideIcon"> & import("react").RefAttributes<any>>;
148
131
  export default DatePicker;
@@ -9,5 +9,5 @@ import { type TimePickerBaseProps } from '../types';
9
9
  * - [Code](https://atlassian.design/components/datetime-picker/time-picker/code)
10
10
  * - [Usage](https://atlassian.design/components/datetime-picker/time-picker/usage)
11
11
  */
12
- declare const TimePicker: React.ForwardRefExoticComponent<Pick<TimePickerBaseProps, "times" | "testId" | "label" | "appearance" | "selectProps" | "innerProps" | "isDisabled" | "defaultValue" | "id" | "placeholder" | "aria-describedby" | "onFocus" | "onBlur" | "onChange" | "locale" | "analyticsContext" | "createAnalyticsEvent" | "value" | "autoFocus" | "name" | "spacing" | "isInvalid" | "defaultIsOpen" | "isOpen" | "parseInputValue" | "formatDisplayLabel" | "hideIcon" | "timeIsEditable" | "timeFormat"> & React.RefAttributes<unknown>>;
12
+ declare const TimePicker: React.ForwardRefExoticComponent<Pick<TimePickerBaseProps, "times" | "parseInputValue" | "formatDisplayLabel" | "placeholder" | "testId" | "label" | "appearance" | "selectProps" | "innerProps" | "isDisabled" | "defaultValue" | "id" | "aria-describedby" | "onFocus" | "onBlur" | "onChange" | "locale" | "analyticsContext" | "createAnalyticsEvent" | "value" | "autoFocus" | "name" | "spacing" | "isInvalid" | "defaultIsOpen" | "isOpen" | "hideIcon" | "timeIsEditable" | "timeFormat"> & React.RefAttributes<unknown>>;
13
13
  export default TimePicker;
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Everything in this file is to smooth out the migration of the new date picker
3
+ * (https://product-fabric.atlassian.net/browse/DSP-20682). When that ticket is
4
+ * complete, all of these functions will ilkely be merged back into the date
5
+ * picker. Please do not pre-optimize and put these back into the date picker
6
+ * unless you are working on the DTP Refresh and you have a good reason to do
7
+ * so, thank you!
8
+ *
9
+ * All variables within the `di` objects are dependency injections. They should
10
+ * be read from within the component at the end of the day. But because we are
11
+ * extracting them, we have to inject them in every place manually. When we
12
+ * re-introduce them to the components, we can likely remove the `di` variables
13
+ * and instead use internal variables.
14
+ *
15
+ * If component _only_ has injected variables, it is fully internal and was
16
+ * broken out to be it's own function.
17
+ */
18
+ import { type LocalizationProvider } from '@atlaskit/locale';
19
+ export declare const isDateDisabled: (date: string, di: {
20
+ disabled: string[];
21
+ }) => boolean;
22
+ export declare const getParsedISO: (di: {
23
+ iso: string;
24
+ }) => string;
25
+ /**
26
+ * There are two props that can change how the date is parsed.
27
+ * The priority of props used is:
28
+ * 1. `parseInputValue`
29
+ * 2. `locale`
30
+ */
31
+ export declare const parseDate: (date: string, di: {
32
+ parseInputValue: ((date: string, dateFormat: string) => Date) | undefined;
33
+ dateFormat: string | undefined;
34
+ l10n: LocalizationProvider;
35
+ }) => Date;
36
+ /**
37
+ * There are multiple props that can change how the date is formatted.
38
+ * The priority of props used is:
39
+ * 1. `formatDisplayLabel`
40
+ * 2. `dateFormat`
41
+ * 3. `locale`
42
+ */
43
+ export declare const formatDate: (value: string, di: {
44
+ formatDisplayLabel: ((value: string, dateFormat: string) => string) | undefined;
45
+ dateFormat: string | undefined;
46
+ l10n: LocalizationProvider;
47
+ }) => string;
48
+ export declare const getPlaceholder: (di: {
49
+ placeholder: string | undefined;
50
+ l10n: LocalizationProvider;
51
+ }) => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/datetime-picker",
3
- "version": "14.0.3",
3
+ "version": "14.0.4",
4
4
  "description": "A date time picker allows the user to select an associated date and time.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -38,10 +38,10 @@
38
38
  "@atlaskit/analytics-next": "^10.1.0",
39
39
  "@atlaskit/calendar": "^15.0.0",
40
40
  "@atlaskit/ds-lib": "^2.5.0",
41
- "@atlaskit/icon": "^22.15.0",
41
+ "@atlaskit/icon": "^22.16.0",
42
42
  "@atlaskit/layering": "^0.4.0",
43
43
  "@atlaskit/locale": "^2.8.0",
44
- "@atlaskit/popper": "^6.2.0",
44
+ "@atlaskit/popper": "^6.3.0",
45
45
  "@atlaskit/select": "^17.15.0",
46
46
  "@atlaskit/theme": "^13.0.0",
47
47
  "@atlaskit/tokens": "^1.59.0",
@@ -61,12 +61,12 @@
61
61
  "@atlaskit/docs": "*",
62
62
  "@atlaskit/form": "^10.5.0",
63
63
  "@atlaskit/modal-dialog": "^12.15.0",
64
- "@atlaskit/popup": "^1.24.0",
64
+ "@atlaskit/popup": "^1.25.0",
65
65
  "@atlaskit/range": "^7.4.0",
66
66
  "@atlaskit/section-message": "^6.6.0",
67
67
  "@atlaskit/ssr": "*",
68
68
  "@atlaskit/textfield": "^6.5.0",
69
- "@atlaskit/toggle": "^13.3.0",
69
+ "@atlaskit/toggle": "^13.4.0",
70
70
  "@atlaskit/visual-regression": "*",
71
71
  "@atlassian/feature-flags-test-utils": "*",
72
72
  "@testing-library/react": "^12.1.5",