td-stylekit 28.30.1 → 28.30.3

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,17 @@
1
+ ## [28.30.3](https://github.com/treasure-data/td-stylekit/compare/v28.30.2...v28.30.3) (2023-12-18)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **CON-11008:** Properly fix migration to date-fns in `TimeControl` ([#1518](https://github.com/treasure-data/td-stylekit/issues/1518)) ([53bf9fe](https://github.com/treasure-data/td-stylekit/commit/53bf9fe))
7
+
8
+ ## [28.30.2](https://github.com/treasure-data/td-stylekit/compare/v28.30.1...v28.30.2) (2023-12-15)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **CON-11008:** Fix issue in TimeControl ([#1517](https://github.com/treasure-data/td-stylekit/issues/1517)) ([85fdca4](https://github.com/treasure-data/td-stylekit/commit/85fdca4))
14
+
1
15
  ## [28.30.1](https://github.com/treasure-data/td-stylekit/compare/v28.30.0...v28.30.1) (2023-12-14)
2
16
 
3
17
 
@@ -7,6 +7,8 @@ exports.useDisplayValue = useDisplayValue;
7
7
 
8
8
  var _react = require("react");
9
9
 
10
+ var _DatePicker = require("../DatePicker");
11
+
10
12
  var _dateFns = require("date-fns");
11
13
 
12
14
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
@@ -23,10 +25,11 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
23
25
 
24
26
  if (typeof window !== "undefined" && !window.gs) window.gs = function () {};
25
27
  if (typeof window !== "undefined" && !window.gsC) window.gsC = function () {};
26
- var TIME_FORMAT_24 = 'hh:mm:ss';
27
- var TIME_FORMAT_12 = 'hh:mm:ss A';
28
+ var isStringCorrectFormat = _DatePicker.DatePickerUtils.isStringCorrectFormat;
29
+ var TIME_FORMAT_24 = 'HH:mm:ss';
30
+ var TIME_FORMAT_12 = 'hh:mm:ss a';
28
31
  var TIME_FORMAT_MS = ':mm:ss';
29
- var TIME_FORMAT_HM = 'hh:mm'; // This hook contains all the logic needed to handle user input
32
+ var TIME_FORMAT_HM = 'HH:mm'; // This hook contains all the logic needed to handle user input
30
33
  // and the editing mode for the TimeControl component.
31
34
  // TODO: as soon as we find a nice way to test hooks we can test all
32
35
  // this logic without any UI interaction directly in our unit tests.
@@ -66,9 +69,14 @@ function useDisplayValue(time, editor, onChange) {
66
69
  }, [period, editor]);
67
70
 
68
71
  var reconcileShadowValue = function reconcileShadowValue() {
69
- if (time && (0, _dateFns.isValid)(new Date(time))) {
70
- var twentyFourHourTime = (0, _dateFns.format)(new Date(time !== null && time !== void 0 ? time : '00:00'), TIME_FORMAT_24);
71
- setShadowValue((0, _dateFns.format)(new Date(twentyFourHourTime), displayFormat));
72
+ var referenceDate = new Date();
73
+ var date = (0, _dateFns.parse)(time !== null && time !== void 0 ? time : '00:00:00', TIME_FORMAT_24, referenceDate);
74
+
75
+ if (time && (0, _dateFns.isValid)(date)) {
76
+ setShadowValue((0, _dateFns.format)(date, displayFormat));
77
+ } else {
78
+ var defaultDate = new Date(referenceDate.getFullYear(), referenceDate.getMonth(), referenceDate.getMinutes(), 0, 0, 0);
79
+ setShadowValue((0, _dateFns.format)(defaultDate, displayFormat));
72
80
  }
73
81
  }; // If we do not have an initial value then we use the current time (when editing
74
82
  // hh:mm:ss) or always 00:00 when editing mm:ss. We override default behaviour of TimePicker.
@@ -111,9 +119,9 @@ function useDisplayValue(time, editor, onChange) {
111
119
  return;
112
120
  }
113
121
 
114
- var date = new Date(value);
122
+ var date = (0, _dateFns.parse)(value, displayFormat, new Date());
115
123
 
116
- if ((0, _dateFns.isValid)(date)) {
124
+ if ((0, _dateFns.isValid)(date) && isStringCorrectFormat(value, displayFormat)) {
117
125
  setErrors(undefined);
118
126
  onChange((0, _dateFns.format)(date, TIME_FORMAT_24)); // Editing the value from AM to PM (or vice-versa) causes the default
119
127
  // period in the TimePicker to change (we do not want to always have 24h if user
@@ -140,7 +148,7 @@ function useDisplayValue(time, editor, onChange) {
140
148
  setErrors(undefined);
141
149
  onChange(value);
142
150
  }
143
- }; // Display value is (rougly...) the shadow value when editing
151
+ }; // Display value is (roughly...) the shadow value when editing
144
152
  // or the input value formatted according to the `period`.
145
153
  // I18N: note that for a truly internationalized control the 12 format
146
154
  // is not always `TIME_FORMAT_12` because different countries (Japan, for example)
@@ -152,7 +160,7 @@ function useDisplayValue(time, editor, onChange) {
152
160
  return shadowValue;
153
161
  }
154
162
 
155
- var date = new Date(time);
163
+ var date = (0, _dateFns.parse)(time, displayFormat, Date.now());
156
164
  return (0, _dateFns.isValid)(date) ? (0, _dateFns.format)(date, displayFormat) : ''; // eslint-disable-next-line react-hooks/exhaustive-deps
157
165
  }, [time, shadowValue, errors, isEditing, displayFormat]);
158
166
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "td-stylekit",
3
- "version": "28.30.1",
3
+ "version": "28.30.3",
4
4
  "main": "dist/es/index.js",
5
5
  "module": "dist/es/index.js",
6
6
  "types": "dist/es/index.d.ts",