opus-toolkit-components 0.8.1 → 0.8.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.
|
@@ -3780,7 +3780,7 @@ function DatePicker(_ref) {
|
|
|
3780
3780
|
initialDate = '',
|
|
3781
3781
|
label = 'Select a Date:',
|
|
3782
3782
|
isValid = true,
|
|
3783
|
-
errorMessage =
|
|
3783
|
+
errorMessage = 'Error message',
|
|
3784
3784
|
name = 'date',
|
|
3785
3785
|
onChange,
|
|
3786
3786
|
value,
|
|
@@ -3790,53 +3790,43 @@ function DatePicker(_ref) {
|
|
|
3790
3790
|
dataCy,
|
|
3791
3791
|
disabled = false
|
|
3792
3792
|
} = _ref;
|
|
3793
|
-
const [selectedDate, setSelectedDate] = (0,external_react_.useState)(
|
|
3793
|
+
const [selectedDate, setSelectedDate] = (0,external_react_.useState)('');
|
|
3794
3794
|
const inputRef = (0,external_react_.useRef)(null);
|
|
3795
|
-
|
|
3795
|
+
const normalizeToInputFormat = dateString => {
|
|
3796
3796
|
if (!dateString) return '';
|
|
3797
|
-
const
|
|
3797
|
+
const [datePart] = dateString.split(' '); // Remove time if present
|
|
3798
|
+
|
|
3799
|
+
if (/^\d{4}-\d{2}-\d{2}$/.test(datePart)) {
|
|
3800
|
+
return datePart; // Already in yyyy-MM-dd
|
|
3801
|
+
}
|
|
3802
|
+
const parts = datePart.split('/');
|
|
3798
3803
|
if (parts.length !== 3) return '';
|
|
3799
|
-
const [
|
|
3800
|
-
|
|
3801
|
-
|
|
3802
|
-
|
|
3803
|
-
function normalizeDate(dateString) {
|
|
3804
|
-
if (!dateString) return '';
|
|
3805
|
-
// Remove the time part if it exists
|
|
3806
|
-
const [datePart] = dateString.split(' ');
|
|
3807
|
-
if (datePart.includes('-')) {
|
|
3808
|
-
return datePart;
|
|
3809
|
-
}
|
|
3810
|
-
const parts = datePart.split('/');
|
|
3811
|
-
if (parts.length !== 3) return '';
|
|
3812
|
-
const [month, day, year] = parts; // notice month first here
|
|
3813
|
-
return "".concat(year, "-").concat(month.padStart(2, '0'), "-").concat(day.padStart(2, '0'));
|
|
3814
|
-
}
|
|
3815
|
-
const normalizedValue = normalizeDate(value);
|
|
3816
|
-
const normalizedInitialDate = normalizeDate(initialDate);
|
|
3817
|
-
if (value !== undefined && value !== null) {
|
|
3818
|
-
setSelectedDate(normalizedValue);
|
|
3804
|
+
const [a, b, c] = parts.map(p => p.padStart(2, '0'));
|
|
3805
|
+
if (parseInt(a, 10) > 12) {
|
|
3806
|
+
// Assume dd/MM/yyyy
|
|
3807
|
+
return "".concat(c, "-").concat(b, "-").concat(a);
|
|
3819
3808
|
} else {
|
|
3820
|
-
|
|
3809
|
+
// Assume MM/dd/yyyy
|
|
3810
|
+
return "".concat(c, "-").concat(a, "-").concat(b);
|
|
3821
3811
|
}
|
|
3822
|
-
}
|
|
3812
|
+
};
|
|
3823
3813
|
(0,external_react_.useEffect)(() => {
|
|
3824
|
-
|
|
3825
|
-
|
|
3814
|
+
const newDate = normalizeToInputFormat(value || initialDate);
|
|
3815
|
+
if (newDate !== selectedDate) {
|
|
3816
|
+
setSelectedDate(newDate);
|
|
3826
3817
|
}
|
|
3827
|
-
}, [value,
|
|
3818
|
+
}, [value, initialDate]);
|
|
3828
3819
|
const handleDateChange = e => {
|
|
3829
3820
|
const rawValue = e.target.value; // yyyy-MM-dd
|
|
3830
3821
|
setSelectedDate(rawValue);
|
|
3831
3822
|
if (onChange && rawValue) {
|
|
3832
3823
|
const [year, month, day] = rawValue.split('-');
|
|
3833
|
-
const formattedValue = "".concat(day, "/").concat(month, "/").concat(year);
|
|
3824
|
+
const formattedValue = "".concat(day, "/").concat(month, "/").concat(year); // dd/MM/yyyy
|
|
3834
3825
|
onChange({
|
|
3835
3826
|
target: {
|
|
3836
3827
|
name,
|
|
3837
3828
|
value: formattedValue,
|
|
3838
|
-
|
|
3839
|
-
rawValue // yyyy-MM-dd
|
|
3829
|
+
rawValue
|
|
3840
3830
|
}
|
|
3841
3831
|
});
|
|
3842
3832
|
}
|
|
@@ -12310,8 +12300,7 @@ function Dropdown(_ref) {
|
|
|
12310
12300
|
disabled = false,
|
|
12311
12301
|
dataCy // optional override
|
|
12312
12302
|
} = _ref;
|
|
12313
|
-
const
|
|
12314
|
-
const [selectedItem, setSelectedItem] = (0,external_react_.useState)(initialSelectedItem);
|
|
12303
|
+
const [selectedItem, setSelectedItem] = (0,external_react_.useState)(null);
|
|
12315
12304
|
const [isOpen, setIsOpen] = (0,external_react_.useState)(false);
|
|
12316
12305
|
(0,external_react_.useEffect)(() => {
|
|
12317
12306
|
const newSelectedItem = items.find(item => item.value === value) || null;
|
|
@@ -12553,4 +12542,4 @@ const Pill = _ref => {
|
|
|
12553
12542
|
/******/ })()
|
|
12554
12543
|
;
|
|
12555
12544
|
});
|
|
12556
|
-
//# sourceMappingURL=main.
|
|
12545
|
+
//# sourceMappingURL=main.3cbe68884c7de90ac040.js.map
|