design-system-next 2.7.37 → 2.7.40
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/dist/design-system-next.js +4776 -4857
- package/dist/design-system-next.js.gz +0 -0
- package/dist/main.css +1 -1
- package/dist/main.css.gz +0 -0
- package/package.json +1 -1
- package/src/components/date-picker/__tests__/date-picker.test.ts +112 -0
- package/src/components/date-picker/date-picker.ts +5 -0
- package/src/components/date-picker/date-picker.vue +5 -5
- package/src/components/date-picker/use-date-picker.ts +55 -19
- package/src/components/table/table-pagination/use-table-pagination.ts +1 -1
|
@@ -29,7 +29,7 @@ interface MonthsList {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
export const useDatePicker = (props: DatePickerPropTypes, emit: SetupContext<DatePickerEmitTypes>['emit']) => {
|
|
32
|
-
const { active, disabled, readonly, error, currentYear, minMaxYear, restDays, disabledDates } = toRefs(props);
|
|
32
|
+
const { active, disabled, readonly, error, currentYear, minMaxYear, restDays, disabledDates, format } = toRefs(props);
|
|
33
33
|
|
|
34
34
|
const modelValue = useVModel(props, 'modelValue', emit);
|
|
35
35
|
|
|
@@ -450,7 +450,7 @@ export const useDatePicker = (props: DatePickerPropTypes, emit: SetupContext<Dat
|
|
|
450
450
|
};
|
|
451
451
|
|
|
452
452
|
const calendarTabHandleDateInput = (day: { date: Date }) => {
|
|
453
|
-
const selectedDate = dayjs(day.date
|
|
453
|
+
const selectedDate = dayjs(day.date);
|
|
454
454
|
|
|
455
455
|
const formattedMonth = selectedDate.format('MM');
|
|
456
456
|
const formattedDate = selectedDate.format('DD');
|
|
@@ -460,6 +460,9 @@ export const useDatePicker = (props: DatePickerPropTypes, emit: SetupContext<Dat
|
|
|
460
460
|
dateInput.value = formattedDate;
|
|
461
461
|
yearInput.value = formattedYear;
|
|
462
462
|
|
|
463
|
+
// Update the model value with the formatted date using the specified format
|
|
464
|
+
modelValue.value = selectedDate.format(format.value);
|
|
465
|
+
|
|
463
466
|
calendarTabPageData.value.selectedMonth = day.date.getMonth();
|
|
464
467
|
calendarTabPageData.value.selectedYear = day.date.getFullYear();
|
|
465
468
|
|
|
@@ -610,28 +613,52 @@ export const useDatePicker = (props: DatePickerPropTypes, emit: SetupContext<Dat
|
|
|
610
613
|
|
|
611
614
|
const setModelValue = () => {
|
|
612
615
|
if (modelValue.value) {
|
|
613
|
-
|
|
616
|
+
// First try to parse with the specified format, then try default format as fallback
|
|
617
|
+
let formattedDate = dayjs(modelValue.value, format.value);
|
|
618
|
+
|
|
619
|
+
// If the date is not valid with the specified format, try with the default format
|
|
620
|
+
if (!formattedDate.isValid()) {
|
|
621
|
+
formattedDate = dayjs(modelValue.value, 'MM-DD-YYYY');
|
|
622
|
+
}
|
|
614
623
|
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
624
|
+
// If still not valid, try other common formats
|
|
625
|
+
if (!formattedDate.isValid()) {
|
|
626
|
+
const commonFormats = ['YYYY-MM-DD', 'MM/DD/YYYY', 'DD/MM/YYYY', 'YYYY/MM/DD'];
|
|
627
|
+
for (const fmt of commonFormats) {
|
|
628
|
+
const tempDate = dayjs(modelValue.value, fmt);
|
|
629
|
+
if (tempDate.isValid()) {
|
|
630
|
+
formattedDate = tempDate;
|
|
631
|
+
break;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
}
|
|
618
635
|
|
|
619
|
-
|
|
636
|
+
if (formattedDate.isValid()) {
|
|
637
|
+
const month = formattedDate.format('MM');
|
|
638
|
+
const date = formattedDate.format('DD');
|
|
639
|
+
const year = formattedDate.format('YYYY');
|
|
620
640
|
|
|
621
|
-
|
|
622
|
-
dateInput.value = date;
|
|
623
|
-
yearInput.value = year;
|
|
641
|
+
handleValidateDate();
|
|
624
642
|
|
|
625
|
-
|
|
643
|
+
monthInput.value = month;
|
|
644
|
+
dateInput.value = date;
|
|
645
|
+
yearInput.value = year;
|
|
626
646
|
|
|
627
|
-
|
|
628
|
-
|
|
647
|
+
// Apply the specified format for the model value
|
|
648
|
+
modelValue.value = formattedDate.format(format.value);
|
|
629
649
|
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
emitDateFormats();
|
|
650
|
+
calendarTabPageData.value.selectedMonth = formattedDate.get('month');
|
|
651
|
+
calendarTabPageData.value.selectedYear = formattedDate.get('year');
|
|
633
652
|
|
|
634
|
-
|
|
653
|
+
handleConvertMonthIfValid();
|
|
654
|
+
calendarTabUpdateCalendar();
|
|
655
|
+
emitDateFormats();
|
|
656
|
+
|
|
657
|
+
// Use the specified format for the input value
|
|
658
|
+
emit('getInputValue', formattedDate.format(format.value));
|
|
659
|
+
} else {
|
|
660
|
+
console.error(`Error: Could not parse date "${modelValue.value}" with format "${format.value}"`);
|
|
661
|
+
}
|
|
635
662
|
}
|
|
636
663
|
};
|
|
637
664
|
|
|
@@ -742,7 +769,7 @@ export const useDatePicker = (props: DatePickerPropTypes, emit: SetupContext<Dat
|
|
|
742
769
|
if (!isYearValid) {
|
|
743
770
|
errorMessage = `Year must be between ${minMaxYear.value.min} and ${minMaxYear.value.max}.`;
|
|
744
771
|
} else {
|
|
745
|
-
errorMessage =
|
|
772
|
+
errorMessage = `Invalid Date Format. Please use ${format.value}`;
|
|
746
773
|
}
|
|
747
774
|
|
|
748
775
|
datePickerErrors.value.push({
|
|
@@ -850,7 +877,16 @@ export const useDatePicker = (props: DatePickerPropTypes, emit: SetupContext<Dat
|
|
|
850
877
|
}
|
|
851
878
|
}
|
|
852
879
|
|
|
853
|
-
|
|
880
|
+
// Format the date according to the format prop
|
|
881
|
+
const dateObj = dayjs(`${emittedMonth}-${dateInput.value}-${yearInput.value}`, 'MM-DD-YYYY');
|
|
882
|
+
|
|
883
|
+
// Use the specified format for the input value
|
|
884
|
+
emit('getInputValue', dateObj.format(format.value));
|
|
885
|
+
|
|
886
|
+
// Update the model value with the formatted date
|
|
887
|
+
if (dateObj.isValid()) {
|
|
888
|
+
modelValue.value = dateObj.format(format.value);
|
|
889
|
+
}
|
|
854
890
|
};
|
|
855
891
|
|
|
856
892
|
const emitMonthList = () => {
|