@cashub/ui 0.48.11 → 0.48.13
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.
|
@@ -18,6 +18,10 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
18
18
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
19
19
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
20
20
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
21
|
+
const setDateTime = (date, value) => {
|
|
22
|
+
const [hh, mm, ss] = value.split(':');
|
|
23
|
+
date.setHours(Number(hh) || 0, Number(mm) || 0, Number(ss) || 0, 0);
|
|
24
|
+
};
|
|
21
25
|
const DatetimePickerV3 = _ref => {
|
|
22
26
|
let {
|
|
23
27
|
selected = '',
|
|
@@ -35,16 +39,35 @@ const DatetimePickerV3 = _ref => {
|
|
|
35
39
|
allowTimeInputEmpty = false
|
|
36
40
|
} = _ref;
|
|
37
41
|
const datepickerRef = (0, _react.useRef)(null);
|
|
42
|
+
const pendingTimeRef = (0, _react.useRef)(null);
|
|
38
43
|
const handleOnBlur = () => {
|
|
39
|
-
|
|
44
|
+
pendingTimeRef.current = null;
|
|
45
|
+
if (typeof onBlur === 'function') {
|
|
46
|
+
onBlur();
|
|
47
|
+
}
|
|
40
48
|
};
|
|
41
49
|
const selectedDate = (0, _react.useMemo)(() => {
|
|
42
50
|
return selected ? new Date(Date.parse(selected)) : '';
|
|
43
51
|
}, [selected]);
|
|
52
|
+
const handleChange = (0, _react.useCallback)(date => {
|
|
53
|
+
// when showTimeInput and DatetimePicker no value yet
|
|
54
|
+
if (showTimeInput && !selected && date) {
|
|
55
|
+
// if time selected before date, use selected time
|
|
56
|
+
if (pendingTimeRef.current) {
|
|
57
|
+
setDateTime(date, pendingTimeRef.current);
|
|
58
|
+
pendingTimeRef.current = null;
|
|
59
|
+
} else {
|
|
60
|
+
// if date selected before time, use current time
|
|
61
|
+
const now = new Date();
|
|
62
|
+
date.setHours(now.getHours(), now.getMinutes(), now.getSeconds(), 0);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
onChange(date);
|
|
66
|
+
}, [onChange, selected, showTimeInput]);
|
|
44
67
|
const datePickerProps = {
|
|
45
68
|
dateFormat,
|
|
46
69
|
disabled,
|
|
47
|
-
onChange,
|
|
70
|
+
onChange: handleChange,
|
|
48
71
|
selected: selectedDate,
|
|
49
72
|
minDate: minDate ? new Date(Date.parse(minDate)) : '',
|
|
50
73
|
maxDate: maxDate ? new Date(Date.parse(maxDate)) : '',
|
|
@@ -54,9 +77,10 @@ const DatetimePickerV3 = _ref => {
|
|
|
54
77
|
};
|
|
55
78
|
const handleSelectTime = (0, _react.useCallback)(value => {
|
|
56
79
|
if (selectedDate) {
|
|
57
|
-
|
|
58
|
-
selectedDate.setHours(Number(hh) || 0, Number(mm) || 0, Number(ss) || 0);
|
|
80
|
+
setDateTime(selectedDate, value);
|
|
59
81
|
onChange(selectedDate);
|
|
82
|
+
} else {
|
|
83
|
+
pendingTimeRef.current = value;
|
|
60
84
|
}
|
|
61
85
|
},
|
|
62
86
|
// NOTE: Adding onChange to the dependency list will cause a rerender loop
|
|
@@ -69,9 +93,7 @@ const DatetimePickerV3 = _ref => {
|
|
|
69
93
|
allowEmpty: allowTimeInputEmpty && !selected
|
|
70
94
|
});
|
|
71
95
|
}
|
|
72
|
-
|
|
73
|
-
datePickerProps.onCalendarClose = handleOnBlur;
|
|
74
|
-
}
|
|
96
|
+
datePickerProps.onCalendarClose = handleOnBlur;
|
|
75
97
|
(0, _react.useEffect)(() => {
|
|
76
98
|
// set input to readonly
|
|
77
99
|
if (datepickerRef && datepickerRef.current && readOnly) {
|
|
@@ -36,6 +36,20 @@ const EMPTY_TIME = {
|
|
|
36
36
|
minute: '',
|
|
37
37
|
second: ''
|
|
38
38
|
};
|
|
39
|
+
const getTimeFromSelected = (selected, allowEmpty) => {
|
|
40
|
+
let time = new Date(Date.parse(selected));
|
|
41
|
+
if (isNaN(time)) {
|
|
42
|
+
if (allowEmpty) {
|
|
43
|
+
return EMPTY_TIME;
|
|
44
|
+
}
|
|
45
|
+
time = new Date();
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
hour: (0, _pad.default)(time.getHours(), LENGTH, PAD_STRING),
|
|
49
|
+
minute: (0, _pad.default)(time.getMinutes(), LENGTH, PAD_STRING),
|
|
50
|
+
second: (0, _pad.default)(time.getSeconds(), LENGTH, PAD_STRING)
|
|
51
|
+
};
|
|
52
|
+
};
|
|
39
53
|
const TimePickerV2 = _ref => {
|
|
40
54
|
let {
|
|
41
55
|
selected,
|
|
@@ -46,20 +60,7 @@ const TimePickerV2 = _ref => {
|
|
|
46
60
|
const [targetElement, setTargetElement] = (0, _react.useState)(null);
|
|
47
61
|
const [popperElement, setPopperElement] = (0, _react.useState)(null);
|
|
48
62
|
const [time, setTime] = (0, _react.useState)(() => {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
// use current time when time value is invalid
|
|
52
|
-
if (isNaN(time)) {
|
|
53
|
-
if (allowEmpty) {
|
|
54
|
-
return EMPTY_TIME;
|
|
55
|
-
}
|
|
56
|
-
time = new Date();
|
|
57
|
-
}
|
|
58
|
-
return {
|
|
59
|
-
hour: (0, _pad.default)(time.getHours(), LENGTH, PAD_STRING),
|
|
60
|
-
minute: (0, _pad.default)(time.getMinutes(), LENGTH, PAD_STRING),
|
|
61
|
-
second: (0, _pad.default)(time.getSeconds(), LENGTH, PAD_STRING)
|
|
62
|
-
};
|
|
63
|
+
return getTimeFromSelected(selected, allowEmpty);
|
|
63
64
|
});
|
|
64
65
|
const {
|
|
65
66
|
styles,
|
|
@@ -74,22 +75,19 @@ const TimePickerV2 = _ref => {
|
|
|
74
75
|
update();
|
|
75
76
|
};
|
|
76
77
|
const handleChange = (type, value) => {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
[type]: value
|
|
80
|
-
});
|
|
78
|
+
const next = _objectSpread(_objectSpread({}, time), {}, {
|
|
79
|
+
[type]: value
|
|
81
80
|
});
|
|
81
|
+
setTime(next);
|
|
82
|
+
if (typeof onSelect === 'function' && next.hour && next.minute && next.second) {
|
|
83
|
+
onSelect("".concat(next.hour, ":").concat(next.minute, ":").concat(next.second));
|
|
84
|
+
}
|
|
82
85
|
};
|
|
86
|
+
|
|
87
|
+
// sync time picker state when selected value changes
|
|
83
88
|
(0, _react.useEffect)(() => {
|
|
84
|
-
|
|
85
|
-
setTime(EMPTY_TIME);
|
|
86
|
-
}
|
|
89
|
+
setTime(getTimeFromSelected(selected, allowEmpty));
|
|
87
90
|
}, [allowEmpty, selected]);
|
|
88
|
-
(0, _react.useEffect)(() => {
|
|
89
|
-
if (typeof onSelect === 'function' && time.hour && time.minute && time.second) {
|
|
90
|
-
onSelect("".concat(time.hour, ":").concat(time.minute, ":").concat(time.second));
|
|
91
|
-
}
|
|
92
|
-
}, [onSelect, time.hour, time.minute, time.second]);
|
|
93
91
|
(0, _react.useEffect)(() => {
|
|
94
92
|
if (display) {
|
|
95
93
|
const {
|