@atlaskit/datetime-picker 14.0.2 → 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.
@@ -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.2";
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.2";
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({