td-stylekit 28.35.0 → 28.35.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [28.35.1](https://github.com/treasure-data/td-stylekit/compare/v28.35.0...v28.35.1) (2024-02-23)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **CON-15052:** Pass through locale to isStringCorrectFormat check ([#1530](https://github.com/treasure-data/td-stylekit/issues/1530)) ([be0b850](https://github.com/treasure-data/td-stylekit/commit/be0b850))
7
+
1
8
  # [28.35.0](https://github.com/treasure-data/td-stylekit/compare/v28.34.1...v28.35.0) (2024-02-12)
2
9
 
3
10
 
@@ -294,7 +294,7 @@ var UnstyledDateControl = function UnstyledDateControl(_ref) {
294
294
  var onInputChange = function onInputChange(_ref2) {
295
295
  var name = _ref2.name,
296
296
  value = _ref2.value;
297
- var date = typeof value === 'string' && isStringCorrectFormat(value, [resolvedDisplayFormat].concat(DATE_FORMATS)) ? stringToDate(value, [resolvedDisplayFormat].concat(DATE_FORMATS), locale) : null;
297
+ var date = typeof value === 'string' && isStringCorrectFormat(value, [resolvedDisplayFormat].concat(DATE_FORMATS), locale) ? stringToDate(value, [resolvedDisplayFormat].concat(DATE_FORMATS), locale) : null;
298
298
  setInputValue(String(value)); // If we have a validation function and it's test doesn't pass then
299
299
  // we don't want to call onChange, but we want to keep local state
300
300
  // up to date so that the input respects the users inputs
@@ -345,7 +345,7 @@ var UnstyledDateControl = function UnstyledDateControl(_ref) {
345
345
 
346
346
  (0, _react.useEffect)(function () {
347
347
  var errorList = error ? (0, _utils.getErrorList)(error) : [];
348
- var date = isStringCorrectFormat(inputValue, [resolvedDisplayFormat].concat(DATE_FORMATS)) ? stringToDate(inputValue, [resolvedDisplayFormat].concat(DATE_FORMATS), locale) : undefined;
348
+ var date = isStringCorrectFormat(inputValue, [resolvedDisplayFormat].concat(DATE_FORMATS), locale) ? stringToDate(inputValue, [resolvedDisplayFormat].concat(DATE_FORMATS), locale) : undefined;
349
349
 
350
350
  if (inputValue && !date) {
351
351
  errorList.unshift(errorMessage);
@@ -1,3 +1,3 @@
1
- export { default, CLOSE_KEYS } from './DateControl';
1
+ export { default, CLOSE_KEYS, DATE_FORMATS } from './DateControl';
2
2
  export type { DateControlProps } from './DateControl';
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -11,6 +11,12 @@ Object.defineProperty(exports, "CLOSE_KEYS", {
11
11
  return _DateControl.CLOSE_KEYS;
12
12
  }
13
13
  });
14
+ Object.defineProperty(exports, "DATE_FORMATS", {
15
+ enumerable: true,
16
+ get: function get() {
17
+ return _DateControl.DATE_FORMATS;
18
+ }
19
+ });
14
20
  Object.defineProperty(exports, "default", {
15
21
  enumerable: true,
16
22
  get: function get() {
@@ -71,7 +71,8 @@ if (typeof window !== "undefined" && !window.gsC) window.gsC = function () {};
71
71
 
72
72
  var dateToString = _DatePicker.DatePickerUtils.dateToString,
73
73
  stringToDate = _DatePicker.DatePickerUtils.stringToDate,
74
- isStringCorrectFormat = _DatePicker.DatePickerUtils.isStringCorrectFormat;
74
+ isStringCorrectFormat = _DatePicker.DatePickerUtils.isStringCorrectFormat,
75
+ DEFAULT_FORMAT = _DatePicker.DatePickerUtils.DEFAULT_FORMAT;
75
76
  var CLOSE_KEYS = [String.fromCharCode(25), // Gets sent when you press shift+tab with Chrome...
76
77
  'Enter', 'Escape', 'Tab']; // @TODO: Change to YYYY-MM-DD?
77
78
 
@@ -164,7 +165,7 @@ var UnstyledDateField = /*#__PURE__*/function (_Component) {
164
165
  _defineProperty(_assertThisInitialized(_this), "_onInputChange", function (_ref) {
165
166
  var name = _ref.name,
166
167
  value = _ref.value;
167
- var date = typeof value === 'string' && isStringCorrectFormat(value) ? stringToDate(value) : null;
168
+ var date = typeof value === 'string' && isStringCorrectFormat(value, DEFAULT_FORMAT, _this.props.locale) ? stringToDate(value) : null;
168
169
  var _this$props2 = _this.props,
169
170
  onChange = _this$props2.onChange,
170
171
  disabledDays = _this$props2.disabledDays,
@@ -7,7 +7,7 @@ export declare function isDateValid(value: Value, format?: string | string[], lo
7
7
  /** Convert the String specified into a Date if it valid */
8
8
  export declare function stringToDate(string: Value, format?: string | string[], locale?: string): Date | undefined;
9
9
  /** Verify that the length of the provided string value matches the length of one of the provided formats */
10
- export declare function isStringCorrectFormat(string: string, format?: string | string[]): boolean;
10
+ export declare function isStringCorrectFormat(string: string, format?: string | string[], locale?: string): boolean;
11
11
  /** Convert the specified Date to a String */
12
12
  export declare function dateToString(date: Value, format?: string, locale?: string): string;
13
13
  /** Custom locale utils used to override day headers */
@@ -112,19 +112,28 @@ function stringToDate(string) {
112
112
 
113
113
  function isStringCorrectFormat(string) {
114
114
  var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_FORMAT;
115
+ var locale = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'en';
115
116
 
116
117
  if (Array.isArray(format)) {
117
118
  for (var i = 0; i < format.length; i++) {
118
- var date = (0, _dateFns.parse)(string.toString(), format[i], Date.now());
119
+ var date = (0, _dateFns.parse)(string.toString(), format[i], Date.now(), {
120
+ locale: getLocale(locale)
121
+ });
119
122
 
120
- if (date.toString() !== 'Invalid Date' && (0, _dateFns.format)(date, format[i]) === string) {
123
+ if (date.toString() !== 'Invalid Date' && (0, _dateFns.format)(date, format[i], {
124
+ locale: getLocale(locale)
125
+ }) === string) {
121
126
  return true;
122
127
  }
123
128
  }
124
129
  } else {
125
- var _date = (0, _dateFns.parse)(string.toString(), format, Date.now());
130
+ var _date = (0, _dateFns.parse)(string.toString(), format, Date.now(), {
131
+ locale: getLocale(locale)
132
+ });
126
133
 
127
- if (_date.toString() !== 'Invalid Date' && (0, _dateFns.format)(_date, format) === string) {
134
+ if (_date.toString() !== 'Invalid Date' && (0, _dateFns.format)(_date, format, {
135
+ locale: getLocale(locale)
136
+ }) === string) {
128
137
  return true;
129
138
  }
130
139
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "td-stylekit",
3
- "version": "28.35.0",
3
+ "version": "28.35.1",
4
4
  "main": "dist/es/index.js",
5
5
  "module": "dist/es/index.js",
6
6
  "types": "dist/es/index.d.ts",