oolib 2.229.2 → 2.229.4
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.
|
@@ -36,6 +36,10 @@ function DateRangePicker(props) {
|
|
|
36
36
|
var handleOnChange = function (i, v) {
|
|
37
37
|
var newValue = value ? __spreadArray([], value, true) : [];
|
|
38
38
|
newValue[i] = v;
|
|
39
|
+
// If start date changed and is now after end date, clear end date
|
|
40
|
+
if (i === 0 && v && newValue[1] && newValue[1] !== null && new Date(v) > new Date(newValue[1])) {
|
|
41
|
+
newValue[1] = undefined;
|
|
42
|
+
}
|
|
39
43
|
onChange && onChange(id, newValue);
|
|
40
44
|
};
|
|
41
45
|
return (react_1.default.createElement("div", { style: { display: 'flex', flexDirection: 'column' } },
|
|
@@ -49,44 +49,65 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
49
49
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
50
|
exports.DateTimePicker = void 0;
|
|
51
51
|
var react_1 = __importStar(require("react"));
|
|
52
|
+
var Typo2_1 = require("../../v2/components/Typo2");
|
|
52
53
|
var BlockLabel_1 = require("../../v2/components/BlockLabel");
|
|
53
54
|
var TimePicker_1 = require("../TimePicker");
|
|
54
55
|
var getBlockLabelProps_1 = require("../../utils/getBlockLabelProps");
|
|
55
56
|
var DatePicker_1 = __importDefault(require("../DatePicker"));
|
|
56
57
|
var convertTo12Hour_1 = require("../TimePicker/utils/convertTo12Hour");
|
|
58
|
+
/**
|
|
59
|
+
* Parses an ISO string into internal { date, time } format.
|
|
60
|
+
* @param {string} value - ISO string (e.g. "2025-02-24T14:30:00.000Z")
|
|
61
|
+
*/
|
|
62
|
+
var parseISOValue = function (value) {
|
|
63
|
+
if (!value)
|
|
64
|
+
return { date: undefined, time: undefined };
|
|
65
|
+
var d = new Date(value);
|
|
66
|
+
if (isNaN(d.getTime()))
|
|
67
|
+
return { date: undefined, time: undefined };
|
|
68
|
+
var hours = String(d.getHours()).padStart(2, '0');
|
|
69
|
+
var minutes = String(d.getMinutes()).padStart(2, '0');
|
|
70
|
+
var seconds = String(d.getSeconds()).padStart(2, '0');
|
|
71
|
+
return { date: d.toISOString(), time: "".concat(hours, ":").concat(minutes, ":").concat(seconds) };
|
|
72
|
+
};
|
|
57
73
|
var DateTimePicker = function (props) {
|
|
58
|
-
var parentOnChange = props.onChange, value = props.value, id = props.id, readOnly = props.readOnly, futureDateOnly = props.futureDateOnly, previousDateOnly = props.previousDateOnly, passChangeHandlerOps = props.passChangeHandlerOps, invert = props.invert, disabled = props.disabled;
|
|
59
|
-
var
|
|
74
|
+
var parentOnChange = props.onChange, value = props.value, id = props.id, readOnly = props.readOnly, futureDateOnly = props.futureDateOnly, previousDateOnly = props.previousDateOnly, passChangeHandlerOps = props.passChangeHandlerOps, invert = props.invert, disabled = props.disabled, _a = props.debug, debug = _a === void 0 ? false : _a;
|
|
75
|
+
var normalized = (0, react_1.useMemo)(function () { return parseISOValue(value); }, [value]);
|
|
76
|
+
var _b = (0, react_1.useState)({ date: normalized.date, time: normalized.time && (0, convertTo12Hour_1.convertTo12Hour)(normalized.time) }), _value = _b[0], _setValue = _b[1];
|
|
60
77
|
var handleOnChange = function (k, v) {
|
|
61
78
|
var _a;
|
|
62
79
|
var newVal = __assign(__assign({}, _value), (_a = {}, _a[k] = v, _a));
|
|
63
80
|
if (newVal.date && newVal.time) {
|
|
64
|
-
// date returned by datepicker is ISO (meaning GMT time)
|
|
65
|
-
// we need to get IST. Date class will convert it to IST.
|
|
66
81
|
var date = new Date(newVal.date);
|
|
67
82
|
var timeSplit = newVal.time.split(':');
|
|
68
|
-
//set the time within the date string using the timeValue numbers
|
|
69
83
|
date.setHours(timeSplit[0]);
|
|
70
84
|
date.setMinutes(timeSplit[1]);
|
|
71
85
|
date.setSeconds(timeSplit[2] || '00');
|
|
72
86
|
newVal = __assign(__assign({}, newVal), { date: date.toISOString() });
|
|
73
87
|
}
|
|
74
88
|
_setValue(newVal);
|
|
75
|
-
newVal.date &&
|
|
76
|
-
|
|
77
|
-
parentOnChange(id,
|
|
89
|
+
if (newVal.date && parentOnChange) {
|
|
90
|
+
// Emit as ISO string
|
|
91
|
+
parentOnChange(id, newVal.date, passChangeHandlerOps && props);
|
|
92
|
+
}
|
|
78
93
|
};
|
|
79
94
|
(0, react_1.useEffect)(function () {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
_setValue({ date:
|
|
95
|
+
var n = parseISOValue(value);
|
|
96
|
+
if (n.date !== _value.date || n.time !== _value.time) {
|
|
97
|
+
_setValue({ date: n.date, time: n.time && (0, convertTo12Hour_1.convertTo12Hour)(n.time) });
|
|
83
98
|
}
|
|
84
99
|
}, [value]);
|
|
85
|
-
return (react_1.default.createElement(
|
|
86
|
-
react_1.default.createElement(
|
|
87
|
-
|
|
88
|
-
react_1.default.createElement(
|
|
89
|
-
|
|
100
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
101
|
+
react_1.default.createElement("div", { id: id },
|
|
102
|
+
react_1.default.createElement(BlockLabel_1.BlockLabel, __assign({}, (0, getBlockLabelProps_1.getBlockLabelProps)(props))),
|
|
103
|
+
react_1.default.createElement("div", { style: { display: 'flex', alignItems: 'center', gap: '2rem' } },
|
|
104
|
+
react_1.default.createElement(DatePicker_1.default, { value: _value.date, onChange: function (k, v) { return handleOnChange('date', v); }, readOnly: readOnly, futureDateOnly: futureDateOnly, previousDateOnly: previousDateOnly, invert: invert, disabled: disabled }),
|
|
105
|
+
react_1.default.createElement(TimePicker_1.TimePicker, { value: _value.time, onChange: function (k, v) { return handleOnChange('time', v); }, readOnly: readOnly, invert: invert, disabled: disabled }))),
|
|
106
|
+
debug && react_1.default.createElement("pre", { style: { fontSize: 10, color: 'red', marginTop: 4 } },
|
|
107
|
+
"DEBUG prop value: ",
|
|
108
|
+
JSON.stringify(value),
|
|
109
|
+
" | internal _value: ",
|
|
110
|
+
JSON.stringify(_value))));
|
|
90
111
|
};
|
|
91
112
|
exports.DateTimePicker = DateTimePicker;
|
|
92
113
|
// export default React.memo(DateTimePickerV2);
|