RoyLee1224 commented on code in PR #56173: URL: https://github.com/apache/airflow/pull/56173#discussion_r2399467046
########## airflow-core/src/airflow/ui/src/components/FilterBar/filters/DateRangeCalendar.tsx: ########## @@ -0,0 +1,182 @@ +/*! + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import { Button, Grid, HStack, Text, VStack, Box } from "@chakra-ui/react"; +import dayjs, { type Dayjs } from "dayjs"; +import { useMemo } from "react"; +import { MdChevronLeft, MdChevronRight } from "react-icons/md"; + +import { useCalendarGrid } from "src/hooks/useCalendarGrid"; + +import type { DateRangeValue } from "../types"; +import { isValidDateValue } from "../utils"; + +type DateRangeCalendarProps = { + readonly currentMonth: Dayjs; + readonly onDateClick: (date: Dayjs) => void; + readonly onMonthChange: (month: Dayjs) => void; + readonly value: DateRangeValue; +}; + +const getDayState = (day: Dayjs, currentMonth: Dayjs, dateRange: { endDate?: Dayjs; startDate?: Dayjs }) => { + const isCurrentMonth = day.isSame(currentMonth, "month"); + const isEnd = Boolean(dateRange.endDate?.isSame(day, "day")); + const isInRange = Boolean( + dateRange.startDate && + dateRange.endDate && + day.isAfter(dateRange.startDate, "day") && + day.isBefore(dateRange.endDate, "day"), + ); + const isStart = Boolean(dateRange.startDate?.isSame(day, "day")); + const isToday = day.isSame(dayjs(), "day"); + + return { isCurrentMonth, isEnd, isInRange, isStart, isToday }; +}; + +export const DateRangeCalendar = ({ + currentMonth, + onDateClick, + onMonthChange, + value, +}: DateRangeCalendarProps) => { + const { days } = useCalendarGrid(currentMonth); + + const startDateValue = isValidDateValue(value.startDate) ? dayjs(value.startDate) : undefined; + const endDateValue = isValidDateValue(value.endDate) ? dayjs(value.endDate) : undefined; + + const weekdayHeaders = useMemo(() => days.slice(0, 7).map((day) => day.format("dd")), [days]); + + const getDateStyles = useMemo( + () => (day: Dayjs) => { + const state = getDayState(day, currentMonth, { endDate: endDateValue, startDate: startDateValue }); + + const getBgColor = () => { + if (state.isStart) { + return "blue.500"; + } + if (state.isEnd) { + return "blue.300"; + } + if (state.isInRange) { + return "blue.50"; Review Comment: Sure, I'm working on the dark mode. I'll provide screenshots once they are ready -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
