carbon-react 101.4.0 → 101.4.1

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.
@@ -7,6 +7,8 @@ exports.default = void 0;
7
7
 
8
8
  var _moment = _interopRequireDefault(require("moment"));
9
9
 
10
+ require("moment/min/locales");
11
+
10
12
  var _lodash = require("lodash");
11
13
 
12
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -161,14 +163,12 @@ const DateHelper = {
161
163
  * formats - given accepted formats
162
164
  * locale - current locale
163
165
  * strict - moment js strict mode
164
- * sanitize - should value be sanitized before parsing
165
166
  */
166
167
  _defaultMomentOptions: (locale, formats) => {
167
168
  return {
168
169
  locale,
169
170
  formats,
170
- strict: true,
171
- sanitize: true
171
+ strict: true
172
172
  };
173
173
  },
174
174
 
@@ -185,7 +185,7 @@ const DateHelper = {
185
185
  value,
186
186
  options,
187
187
  locale,
188
- formats,
188
+ formats = [],
189
189
  format
190
190
  }) {
191
191
  const opts = (0, _lodash.merge)(DateHelper._defaultMomentOptions(locale, formats), options, {
@@ -193,8 +193,7 @@ const DateHelper = {
193
193
  formats,
194
194
  format
195
195
  });
196
- const val = opts.sanitize ? DateHelper.sanitizeDateInput(value) : value;
197
- return (0, _moment.default)(val, [format, ...opts.formats], opts.locale, opts.strict);
196
+ return (0, _moment.default)(value, [format, isoDateFormat, ...opts.formats], opts.locale, opts.strict);
198
197
  },
199
198
 
200
199
  formatDateToCurrentLocale({
@@ -206,9 +205,6 @@ const DateHelper = {
206
205
  return DateHelper.formatValue({
207
206
  value,
208
207
  formatTo: format,
209
- options: {
210
- formats: [format]
211
- },
212
208
  locale,
213
209
  formats,
214
210
  format
@@ -167,13 +167,11 @@ let BaseDateInput = /*#__PURE__*/function (_React$Component) {
167
167
  _this.reformatVisibleDate();
168
168
 
169
169
  if (_this.props.onBlur && !_this.state.isDatePickerOpen) {
170
- const dateWithSlashes = _date.default.sanitizeDateInput(_this.state.visibleValue);
171
-
172
170
  const event = _this.buildCustomEvent({
173
171
  target: _this.input,
174
172
  type: "blur"
175
173
  }, _date.default.formatValue({
176
- value: dateWithSlashes,
174
+ value: _this.state.visibleValue,
177
175
  ..._this.localeData
178
176
  }));
179
177
 
@@ -365,10 +363,8 @@ let BaseDateInput = /*#__PURE__*/function (_React$Component) {
365
363
  } = _this.props;
366
364
  const value = ev.target.value.formattedValue || ev.target.value;
367
365
 
368
- const dateWithSlashes = _date.default.sanitizeDateInput(value);
369
-
370
366
  const isValidDate = _date.default.isValidDate({
371
- value: dateWithSlashes,
367
+ value,
372
368
  ..._this.localeData
373
369
  });
374
370
 
@@ -378,7 +374,7 @@ let BaseDateInput = /*#__PURE__*/function (_React$Component) {
378
374
 
379
375
  if (isValidDate || _this.canBeEmptyValues(value)) {
380
376
  isoDateString = _date.default.formatValue({
381
- value: dateWithSlashes,
377
+ value,
382
378
  ..._this.localeData
383
379
  });
384
380
 
@@ -440,9 +436,6 @@ let BaseDateInput = /*#__PURE__*/function (_React$Component) {
440
436
  });
441
437
 
442
438
  _defineProperty(_assertThisInitialized(_this), "buildCustomEvent", (ev, isoFormattedValue) => {
443
- const {
444
- type
445
- } = ev;
446
439
  const {
447
440
  id,
448
441
  name,
@@ -477,7 +470,7 @@ let BaseDateInput = /*#__PURE__*/function (_React$Component) {
477
470
  ...(validRawValue && {
478
471
  rawValue: isoFormattedValue
479
472
  }),
480
- ...(type === "blur" && {
473
+ ...(!validRawValue && {
481
474
  formattedValue: value,
482
475
  rawValue: value
483
476
  })
@@ -488,15 +481,19 @@ let BaseDateInput = /*#__PURE__*/function (_React$Component) {
488
481
 
489
482
  _defineProperty(_assertThisInitialized(_this), "renderDatePicker", dateRangeProps => {
490
483
  if (!_this.state.isDatePickerOpen) return null;
491
- let {
484
+ const {
492
485
  visibleValue
493
486
  } = _this.state;
487
+ let isoValue = "";
494
488
 
495
- if (!_date.default.isValidDate({
489
+ if (_date.default.isValidDate({
496
490
  value: visibleValue,
497
491
  ..._this.localeData
498
492
  })) {
499
- visibleValue = "";
493
+ isoValue = _date.default.formatValue({
494
+ value: visibleValue,
495
+ ..._this.localeData
496
+ });
500
497
  }
501
498
 
502
499
  return /*#__PURE__*/_react.default.createElement("div", {
@@ -506,7 +503,7 @@ let BaseDateInput = /*#__PURE__*/function (_React$Component) {
506
503
  inputElement: _this.inputPresentationRef,
507
504
  selectedDate: _this.state.selectedDate,
508
505
  handleDateSelect: _this.handleDateSelect,
509
- inputDate: visibleValue,
506
+ inputDate: isoValue,
510
507
  disablePortal: _this.props.disablePortal
511
508
  }, dateRangeProps)));
512
509
  });
@@ -642,7 +639,7 @@ function generateAdjustedValue({
642
639
  formats,
643
640
  format
644
641
  }) {
645
- if (value !== undefined && canReturnValue(value, allowEmptyValue, locale, formats, format)) {
642
+ if (value !== undefined && canReturnValue(value, allowEmptyValue)) {
646
643
  return _date.default.formatDateToCurrentLocale({
647
644
  value,
648
645
  locale,
@@ -651,7 +648,7 @@ function generateAdjustedValue({
651
648
  });
652
649
  }
653
650
 
654
- if (canReturnValue(defaultValue, allowEmptyValue, locale, formats, format)) {
651
+ if (canReturnValue(defaultValue, allowEmptyValue)) {
655
652
  return _date.default.formatDateToCurrentLocale({
656
653
  value: defaultValue,
657
654
  locale,
@@ -668,25 +665,20 @@ function generateAdjustedValue({
668
665
  });
669
666
  }
670
667
 
671
- function isValidInitialFormat(value, locale, formats, format) {
668
+ function isValidInitialFormat(value) {
672
669
  return _date.default.isValidDate({
673
670
  value,
674
- options: {
675
- defaultValue: hiddenDateFormat
676
- },
677
- locale,
678
- formats,
679
- format
671
+ format: hiddenDateFormat
680
672
  });
681
673
  }
682
674
 
683
- function canReturnValue(value, allowEmptyValue, locale, formats, format) {
675
+ function canReturnValue(value, allowEmptyValue) {
684
676
  if (!allowEmptyValue && value && value.length) {
685
677
  const message = "The Date component must be initialised with a value in the iso (YYYY-MM-DD) format";
686
- (0, _invariant.default)(isValidInitialFormat(value, locale, formats, format), message);
678
+ (0, _invariant.default)(isValidInitialFormat(value), message);
687
679
  }
688
680
 
689
- return isValidInitialFormat(value, locale, formats, format) || allowEmptyValue && !value;
681
+ return isValidInitialFormat(value) || allowEmptyValue && !value;
690
682
  }
691
683
 
692
684
  const DateInput = (0, _withUniqueIdProps.default)(BaseDateInput);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-react",
3
- "version": "101.4.0",
3
+ "version": "101.4.1",
4
4
  "description": "A library of reusable React components for easily building user interfaces.",
5
5
  "engineStrict": true,
6
6
  "engines": {
@@ -62,18 +62,18 @@
62
62
  "@semantic-release/changelog": "^6.0.1",
63
63
  "@semantic-release/exec": "^6.0.2",
64
64
  "@semantic-release/git": "^10.0.1",
65
- "@storybook/addon-a11y": "^6.3.6",
66
- "@storybook/addon-actions": "^6.3.6",
67
- "@storybook/addon-controls": "^6.3.7",
68
- "@storybook/addon-docs": "^6.3.6",
65
+ "@storybook/addon-a11y": "^6.3.12",
66
+ "@storybook/addon-actions": "^6.3.12",
67
+ "@storybook/addon-controls": "^6.3.12",
68
+ "@storybook/addon-docs": "^6.3.12",
69
69
  "@storybook/addon-google-analytics": "^6.2.9",
70
- "@storybook/addon-links": "^6.3.6",
71
- "@storybook/addon-toolbars": "^6.3.8",
72
- "@storybook/addon-viewport": "^6.3.6",
73
- "@storybook/addons": "^6.3.6",
74
- "@storybook/components": "^6.3.6",
75
- "@storybook/react": "^6.3.6",
76
- "@storybook/theming": "^6.3.6",
70
+ "@storybook/addon-links": "^6.3.12",
71
+ "@storybook/addon-toolbars": "^6.3.12",
72
+ "@storybook/addon-viewport": "^6.3.12",
73
+ "@storybook/addons": "^6.3.12",
74
+ "@storybook/components": "^6.3.12",
75
+ "@storybook/react": "^6.3.12",
76
+ "@storybook/theming": "^6.3.12",
77
77
  "@types/enzyme": "^3.10.3",
78
78
  "@types/enzyme-adapter-react-16": "^1.0.5",
79
79
  "@types/jest": "^26.0.19",