td-stylekit 28.30.2 → 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 +7 -0
- package/dist/es/TimeControl/utils.js +15 -8
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
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
|
+
|
|
1
8
|
## [28.30.2](https://github.com/treasure-data/td-stylekit/compare/v28.30.1...v28.30.2) (2023-12-15)
|
|
2
9
|
|
|
3
10
|
|
|
@@ -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
|
|
27
|
-
var
|
|
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 = '
|
|
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,10 +69,14 @@ function useDisplayValue(time, editor, onChange) {
|
|
|
66
69
|
}, [period, editor]);
|
|
67
70
|
|
|
68
71
|
var reconcileShadowValue = function reconcileShadowValue() {
|
|
69
|
-
var
|
|
72
|
+
var referenceDate = new Date();
|
|
73
|
+
var date = (0, _dateFns.parse)(time !== null && time !== void 0 ? time : '00:00:00', TIME_FORMAT_24, referenceDate);
|
|
70
74
|
|
|
71
75
|
if (time && (0, _dateFns.isValid)(date)) {
|
|
72
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));
|
|
73
80
|
}
|
|
74
81
|
}; // If we do not have an initial value then we use the current time (when editing
|
|
75
82
|
// hh:mm:ss) or always 00:00 when editing mm:ss. We override default behaviour of TimePicker.
|
|
@@ -112,9 +119,9 @@ function useDisplayValue(time, editor, onChange) {
|
|
|
112
119
|
return;
|
|
113
120
|
}
|
|
114
121
|
|
|
115
|
-
var date = new Date(
|
|
122
|
+
var date = (0, _dateFns.parse)(value, displayFormat, new Date());
|
|
116
123
|
|
|
117
|
-
if ((0, _dateFns.isValid)(date)) {
|
|
124
|
+
if ((0, _dateFns.isValid)(date) && isStringCorrectFormat(value, displayFormat)) {
|
|
118
125
|
setErrors(undefined);
|
|
119
126
|
onChange((0, _dateFns.format)(date, TIME_FORMAT_24)); // Editing the value from AM to PM (or vice-versa) causes the default
|
|
120
127
|
// period in the TimePicker to change (we do not want to always have 24h if user
|
|
@@ -141,7 +148,7 @@ function useDisplayValue(time, editor, onChange) {
|
|
|
141
148
|
setErrors(undefined);
|
|
142
149
|
onChange(value);
|
|
143
150
|
}
|
|
144
|
-
}; // Display value is (
|
|
151
|
+
}; // Display value is (roughly...) the shadow value when editing
|
|
145
152
|
// or the input value formatted according to the `period`.
|
|
146
153
|
// I18N: note that for a truly internationalized control the 12 format
|
|
147
154
|
// is not always `TIME_FORMAT_12` because different countries (Japan, for example)
|
|
@@ -153,7 +160,7 @@ function useDisplayValue(time, editor, onChange) {
|
|
|
153
160
|
return shadowValue;
|
|
154
161
|
}
|
|
155
162
|
|
|
156
|
-
var date =
|
|
163
|
+
var date = (0, _dateFns.parse)(time, displayFormat, Date.now());
|
|
157
164
|
return (0, _dateFns.isValid)(date) ? (0, _dateFns.format)(date, displayFormat) : ''; // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
158
165
|
}, [time, shadowValue, errors, isEditing, displayFormat]);
|
|
159
166
|
return {
|