|
@@ -4,11 +4,13 @@ import {
|
|
|
forwardRef,
|
|
forwardRef,
|
|
|
useEffect,
|
|
useEffect,
|
|
|
useState,
|
|
useState,
|
|
|
- type Ref
|
|
|
|
|
|
|
+ type Ref,
|
|
|
|
|
+ useRef
|
|
|
} from "react";
|
|
} from "react";
|
|
|
import {
|
|
import {
|
|
|
TouchableOpacity,
|
|
TouchableOpacity,
|
|
|
- View
|
|
|
|
|
|
|
+ View,
|
|
|
|
|
+ type ViewStyle
|
|
|
} from "react-native";
|
|
} from "react-native";
|
|
|
import type {
|
|
import type {
|
|
|
CalendarDay,
|
|
CalendarDay,
|
|
@@ -24,6 +26,9 @@ import {
|
|
|
import {
|
|
import {
|
|
|
NCoreUIKitTheme
|
|
NCoreUIKitTheme
|
|
|
} from "../../core/hooks";
|
|
} from "../../core/hooks";
|
|
|
|
|
+import type {
|
|
|
|
|
+ Mutable
|
|
|
|
|
+} from "../../types";
|
|
|
import {
|
|
import {
|
|
|
ChevronRight as ChevronRightIcon,
|
|
ChevronRight as ChevronRightIcon,
|
|
|
ChevronLeft as ChevronLeftIcon
|
|
ChevronLeft as ChevronLeftIcon
|
|
@@ -37,6 +42,7 @@ const DateSelector = ({
|
|
|
dayOfWeekLength = "long",
|
|
dayOfWeekLength = "long",
|
|
|
viewDate: viewDateProp,
|
|
viewDate: viewDateProp,
|
|
|
setIsSheetContentReady,
|
|
setIsSheetContentReady,
|
|
|
|
|
+ selectMultipleObject,
|
|
|
selectObject,
|
|
selectObject,
|
|
|
dateRange,
|
|
dateRange,
|
|
|
dateRule,
|
|
dateRule,
|
|
@@ -69,6 +75,8 @@ const DateSelector = ({
|
|
|
setMonthDays
|
|
setMonthDays
|
|
|
] = useState<Array<CalendarDay>>([]);
|
|
] = useState<Array<CalendarDay>>([]);
|
|
|
|
|
|
|
|
|
|
+ const allSelectedDays = useRef<Array<Date>>([]);
|
|
|
|
|
+
|
|
|
const {
|
|
const {
|
|
|
nextPrevToolChevronButton: nextPrevToolChevronButtonDynamicStyle,
|
|
nextPrevToolChevronButton: nextPrevToolChevronButtonDynamicStyle,
|
|
|
nextPrevToolContainer: nextPrevToolContainerDynamicStyle,
|
|
nextPrevToolContainer: nextPrevToolContainerDynamicStyle,
|
|
@@ -122,6 +130,8 @@ const DateSelector = ({
|
|
|
}: {
|
|
}: {
|
|
|
tDate: Date
|
|
tDate: Date
|
|
|
}): Array<CalendarDay> => {
|
|
}): Array<CalendarDay> => {
|
|
|
|
|
+ allSelectedDays.current = [];
|
|
|
|
|
+
|
|
|
const targetDate = moment(new Date(tDate));
|
|
const targetDate = moment(new Date(tDate));
|
|
|
|
|
|
|
|
const startOfCalendar = targetDate.clone().startOf("month").startOf("week");
|
|
const startOfCalendar = targetDate.clone().startOf("month").startOf("week");
|
|
@@ -137,9 +147,23 @@ const DateSelector = ({
|
|
|
let isSelected = false;
|
|
let isSelected = false;
|
|
|
|
|
|
|
|
if(variant === "single" && date) {
|
|
if(variant === "single" && date) {
|
|
|
|
|
+ allSelectedDays.current = [date];
|
|
|
|
|
+
|
|
|
if(moment(currentDay).isSame(date, "day")) isSelected = true;
|
|
if(moment(currentDay).isSame(date, "day")) isSelected = true;
|
|
|
} else if(variant === "range" && dateRange && dateRange.start) {
|
|
} else if(variant === "range" && dateRange && dateRange.start) {
|
|
|
- if(moment(currentDay).isBetween(dateRange.start, dateRange.end, "day", "[]")) isSelected = true;
|
|
|
|
|
|
|
+ if(dateRange.end) {
|
|
|
|
|
+ allSelectedDays.current = Array.from({
|
|
|
|
|
+ length: moment(dateRange.end).diff(dateRange.start, "days") + 1
|
|
|
|
|
+ }, (_, i) =>
|
|
|
|
|
+ moment(dateRange.start).clone().add(i, "days").toDate()
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ if(moment(currentDay).isBetween(dateRange.start, dateRange.end, "day", "[]")) isSelected = true;
|
|
|
|
|
+ } else if(moment(currentDay).isSame(dateRange.start)) {
|
|
|
|
|
+ allSelectedDays.current = [dateRange.start];
|
|
|
|
|
+
|
|
|
|
|
+ isSelected = true;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
let isDisabled = false;
|
|
let isDisabled = false;
|
|
@@ -153,6 +177,7 @@ const DateSelector = ({
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
return {
|
|
|
|
|
+ originalIndex: allSelectedDays.current.findIndex((day) => moment(currentDay).isSame(day, "day")),
|
|
|
isCurrentMonth: currentDay.isSame(targetDate, "month"),
|
|
isCurrentMonth: currentDay.isSame(targetDate, "month"),
|
|
|
isToday: currentDay.isSame(moment(), "day"),
|
|
isToday: currentDay.isSame(moment(), "day"),
|
|
|
dayOfWeek: currentDay.weekday(),
|
|
dayOfWeek: currentDay.weekday(),
|
|
@@ -163,56 +188,43 @@ const DateSelector = ({
|
|
|
};
|
|
};
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- const weeks: CalendarDay[][] = [];
|
|
|
|
|
-
|
|
|
|
|
- allDays.forEach((day, index) => {
|
|
|
|
|
- const weekIndex = Math.floor(index / 7);
|
|
|
|
|
- if (!weeks[weekIndex]) {
|
|
|
|
|
- weeks[weekIndex] = [];
|
|
|
|
|
- }
|
|
|
|
|
- weeks[weekIndex].push(day);
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
return allDays;
|
|
return allDays;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const renderDay = ({
|
|
const renderDay = ({
|
|
|
weekIndex,
|
|
weekIndex,
|
|
|
- nextItem,
|
|
|
|
|
- prevItem,
|
|
|
|
|
dayIndex,
|
|
dayIndex,
|
|
|
dayItem
|
|
dayItem
|
|
|
}: {
|
|
}: {
|
|
|
- nextItem?: CalendarDay;
|
|
|
|
|
- prevItem?: CalendarDay;
|
|
|
|
|
dayItem: CalendarDay;
|
|
dayItem: CalendarDay;
|
|
|
weekIndex: number;
|
|
weekIndex: number;
|
|
|
dayIndex: number;
|
|
dayIndex: number;
|
|
|
}) => {
|
|
}) => {
|
|
|
- const isNextItemSelected = nextItem && nextItem.isSelected && dayItem.isSelected;
|
|
|
|
|
- const isPrevItemSelected = prevItem && prevItem.isSelected && dayItem.isSelected;
|
|
|
|
|
|
|
+ const isLastItemSelected = dayItem.isSelected && dayItem.originalIndex === allSelectedDays.current.length - 1;
|
|
|
|
|
+ const isFirstItemSelected = dayItem.isSelected && dayItem.originalIndex === 0;
|
|
|
|
|
|
|
|
- const selectionStyle = [
|
|
|
|
|
- isNextItemSelected ? {
|
|
|
|
|
|
|
+ const selectionStyle: Array<Mutable<ViewStyle> | null> = [
|
|
|
|
|
+ isFirstItemSelected && allSelectedDays.current.length > 1 ? {
|
|
|
borderBottomRightRadius: 0,
|
|
borderBottomRightRadius: 0,
|
|
|
borderTopRightRadius: 0
|
|
borderTopRightRadius: 0
|
|
|
} : null,
|
|
} : null,
|
|
|
- isPrevItemSelected ? {
|
|
|
|
|
|
|
+ isLastItemSelected && allSelectedDays.current.length > 1 ? {
|
|
|
borderBottomLeftRadius: 0,
|
|
borderBottomLeftRadius: 0,
|
|
|
borderTopLeftRadius: 0
|
|
borderTopLeftRadius: 0
|
|
|
- } : null,
|
|
|
|
|
- isNextItemSelected && isPrevItemSelected ? {
|
|
|
|
|
- borderBottomRightRadius: 0,
|
|
|
|
|
- borderBottomLeftRadius: 0,
|
|
|
|
|
- borderTopRightRadius: 0,
|
|
|
|
|
- borderTopLeftRadius: 0
|
|
|
|
|
} : null
|
|
} : null
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
let dayTitleColor: keyof NCoreUIKit.TextContentColors = "mid";
|
|
let dayTitleColor: keyof NCoreUIKit.TextContentColors = "mid";
|
|
|
|
|
|
|
|
- if(isPrevItemSelected && isNextItemSelected) {
|
|
|
|
|
|
|
+ if(dayItem.isSelected && !isLastItemSelected && !isFirstItemSelected) {
|
|
|
dayTitleColor = "emphasized";
|
|
dayTitleColor = "emphasized";
|
|
|
|
|
+
|
|
|
|
|
+ selectionStyle.push({
|
|
|
|
|
+ borderBottomRightRadius: 0,
|
|
|
|
|
+ borderBottomLeftRadius: 0,
|
|
|
|
|
+ borderTopRightRadius: 0,
|
|
|
|
|
+ borderTopLeftRadius: 0
|
|
|
|
|
+ });
|
|
|
} else if(dayItem.isSelected) {
|
|
} else if(dayItem.isSelected) {
|
|
|
dayTitleColor = "onPrimary";
|
|
dayTitleColor = "onPrimary";
|
|
|
}
|
|
}
|
|
@@ -232,7 +244,41 @@ const DateSelector = ({
|
|
|
if(variant === "single") {
|
|
if(variant === "single") {
|
|
|
selectObject(dayItem.date.toDate());
|
|
selectObject(dayItem.date.toDate());
|
|
|
} else if(variant === "range") {
|
|
} else if(variant === "range") {
|
|
|
- console.log("range");
|
|
|
|
|
|
|
+ if(!dateRange || !dateRange.start) {
|
|
|
|
|
+ selectMultipleObject({
|
|
|
|
|
+ start: new Date(dayItem.date.toDate().setHours(0, 0, 0)),
|
|
|
|
|
+ end: undefined
|
|
|
|
|
+ });
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if(dateRange && moment(dateRange.start).isSame(dayItem.date, "day")) {
|
|
|
|
|
+ selectMultipleObject({
|
|
|
|
|
+ start: undefined,
|
|
|
|
|
+ end: undefined
|
|
|
|
|
+ });
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if(dateRange && !dateRange.end) {
|
|
|
|
|
+ if(moment(dayItem.date).isBefore(dateRange.start)) {
|
|
|
|
|
+ selectMultipleObject({
|
|
|
|
|
+ start: new Date(dayItem.date.toDate().setHours(0, 0, 0)),
|
|
|
|
|
+ end: undefined
|
|
|
|
|
+ });
|
|
|
|
|
+ } else {
|
|
|
|
|
+ selectMultipleObject({
|
|
|
|
|
+ end: new Date(dayItem.date.toDate().setHours(23, 59, 59)),
|
|
|
|
|
+ start: dateRange?.start
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ selectMultipleObject({
|
|
|
|
|
+ start: dayItem.date.toDate(),
|
|
|
|
|
+ end: undefined
|
|
|
|
|
+ });
|
|
|
} else {
|
|
} else {
|
|
|
console.log("rrule");
|
|
console.log("rrule");
|
|
|
}
|
|
}
|
|
@@ -244,10 +290,13 @@ const DateSelector = ({
|
|
|
backgroundColor: colors.content.container.primary,
|
|
backgroundColor: colors.content.container.primary,
|
|
|
borderColor: colors.content.container.primary
|
|
borderColor: colors.content.container.primary
|
|
|
} : null,
|
|
} : null,
|
|
|
- isNextItemSelected && isPrevItemSelected ? {
|
|
|
|
|
|
|
+ dayItem.isSelected && !isLastItemSelected && !isFirstItemSelected ? {
|
|
|
backgroundColor: colors.content.container.emphasized,
|
|
backgroundColor: colors.content.container.emphasized,
|
|
|
borderColor: colors.content.container.emphasized
|
|
borderColor: colors.content.container.emphasized
|
|
|
} : null,
|
|
} : null,
|
|
|
|
|
+ dayItem.isSelected && (dayItem.isDisabled || !dayItem.isCurrentMonth) ? {
|
|
|
|
|
+ opacity: 0.33
|
|
|
|
|
+ } : null,
|
|
|
...selectionStyle
|
|
...selectionStyle
|
|
|
]}
|
|
]}
|
|
|
>
|
|
>
|
|
@@ -336,10 +385,7 @@ const DateSelector = ({
|
|
|
]}
|
|
]}
|
|
|
>
|
|
>
|
|
|
{weekDays.map((weekItem, weekIndex) => {
|
|
{weekDays.map((weekItem, weekIndex) => {
|
|
|
- const days = monthDays.map((day, dayI) => ({
|
|
|
|
|
- ...day,
|
|
|
|
|
- originalIndex: dayI
|
|
|
|
|
- })).filter((dayItem) => dayItem.dayOfWeek === weekIndex);
|
|
|
|
|
|
|
+ const days = monthDays.filter((dayItem) => dayItem.dayOfWeek === weekIndex);
|
|
|
|
|
|
|
|
return <View
|
|
return <View
|
|
|
key={`day-column-${weekIndex}`}
|
|
key={`day-column-${weekIndex}`}
|
|
@@ -358,8 +404,6 @@ const DateSelector = ({
|
|
|
</Text>
|
|
</Text>
|
|
|
{days.map((dayItem, dayIndex) => {
|
|
{days.map((dayItem, dayIndex) => {
|
|
|
return renderDay({
|
|
return renderDay({
|
|
|
- nextItem: monthDays[dayItem.originalIndex + 1] ?? undefined,
|
|
|
|
|
- prevItem: monthDays[dayItem.originalIndex - 1] ?? undefined,
|
|
|
|
|
weekIndex,
|
|
weekIndex,
|
|
|
dayIndex,
|
|
dayIndex,
|
|
|
dayItem
|
|
dayItem
|