opus-toolkit-components 0.8.2 → 0.8.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.
@@ -3780,7 +3780,7 @@ function DatePicker(_ref) {
3780
3780
  initialDate = '',
3781
3781
  label = 'Select a Date:',
3782
3782
  isValid = true,
3783
- errorMessage = "Error message",
3783
+ errorMessage = 'Error message',
3784
3784
  name = 'date',
3785
3785
  onChange,
3786
3786
  value,
@@ -3790,53 +3790,42 @@ function DatePicker(_ref) {
3790
3790
  dataCy,
3791
3791
  disabled = false
3792
3792
  } = _ref;
3793
- const [selectedDate, setSelectedDate] = (0,external_react_.useState)(value || initialDate);
3793
+ const [selectedDate, setSelectedDate] = (0,external_react_.useState)('');
3794
3794
  const inputRef = (0,external_react_.useRef)(null);
3795
- function convertToInputDateFormat(dateString) {
3795
+ const normalizeToInputFormat = dateString => {
3796
3796
  if (!dateString) return '';
3797
- const parts = dateString.split('/');
3797
+ const [datePart] = dateString.split(' '); // Remove time if present
3798
+
3799
+ if (/^\d{4}-\d{2}-\d{2}$/.test(datePart)) {
3800
+ return datePart; // Already ISO format
3801
+ }
3802
+ const parts = datePart.split('/');
3798
3803
  if (parts.length !== 3) return '';
3799
- const [day, month, year] = parts;
3800
- return "".concat(year, "-").concat(month.padStart(2, '0'), "-").concat(day.padStart(2, '0'));
3801
- }
3802
- (0,external_react_.useEffect)(() => {
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 [part1, part2, part3] = parts.map(p => p.padStart(2, '0'));
3805
+ if (parseInt(part1, 10) > 12) {
3806
+ // Assume dd/MM/yyyy
3807
+ const [day, month, year] = [part1, part2, part3];
3808
+ return "".concat(year, "-").concat(month, "-").concat(day);
3819
3809
  } else {
3820
- setSelectedDate(normalizedInitialDate);
3810
+ // Assume MM/dd/yyyy
3811
+ const [month, day, year] = [part1, part2, part3];
3812
+ return "".concat(year, "-").concat(month, "-").concat(day);
3821
3813
  }
3822
- }, [value, initialDate]);
3814
+ };
3823
3815
  (0,external_react_.useEffect)(() => {
3824
- if (value !== undefined && value !== selectedDate) {
3825
- setSelectedDate(value); // Sync selectedDate when value prop changes
3816
+ const newDate = normalizeToInputFormat(value || initialDate);
3817
+ if (newDate !== selectedDate) {
3818
+ setSelectedDate(newDate);
3826
3819
  }
3827
- }, [value, selectedDate]);
3820
+ }, [value, initialDate]);
3828
3821
  const handleDateChange = e => {
3829
3822
  const rawValue = e.target.value; // yyyy-MM-dd
3830
3823
  setSelectedDate(rawValue);
3831
3824
  if (onChange && rawValue) {
3832
- const [year, month, day] = rawValue.split('-');
3833
- const formattedValue = "".concat(day, "/").concat(month, "/").concat(year);
3834
3825
  onChange({
3835
3826
  target: {
3836
3827
  name,
3837
- value: formattedValue,
3838
- // dd/MM/yyyy
3839
- rawValue // yyyy-MM-dd
3828
+ value: rawValue // Keep value in ISO format for form submission
3840
3829
  }
3841
3830
  });
3842
3831
  }
@@ -12552,4 +12541,4 @@ const Pill = _ref => {
12552
12541
  /******/ })()
12553
12542
  ;
12554
12543
  });
12555
- //# sourceMappingURL=main.ac163118cf08b8a8b6fc.js.map
12544
+ //# sourceMappingURL=main.4f1c65e3bc1a8de293ea.js.map