* feat: simplify date range picker to Airbnb-style selection Co-Authored-By: [email protected] <[email protected]> * feat: apply Airbnb-style selection to allowPastDates branch Co-Authored-By: [email protected] <[email protected]> * refactor: extract date range selection logic and add unit tests - Extract date range selection logic into pure function (dateRangeLogic.ts) - Remove unused allowPastDates parameter from selection logic - Add comprehensive unit tests (11 test cases covering all scenarios) - Simplify DateRangePicker component (30+ lines -> 5 lines) - Improve separation of concerns: allowPastDates only controls calendar date restrictions * style update * feat: add hover highlighting for date range selection When a start date is selected and user hovers over other dates, the potential range between start and hovered date now shows bg-emphasis background for better visual feedback. Co-Authored-By: [email protected] <[email protected]> * memoize hovering range and update styles --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
76 lines
2.6 KiB
TypeScript
76 lines
2.6 KiB
TypeScript
"use client";
|
|
|
|
import * as React from "react";
|
|
import { DayPicker } from "react-day-picker";
|
|
|
|
import dayjs from "@calcom/dayjs";
|
|
import cn from "@calcom/ui/classNames";
|
|
|
|
import { buttonClasses } from "../../button/Button";
|
|
import { Icon } from "../../icon";
|
|
|
|
export type CalendarProps = React.ComponentProps<typeof DayPicker>;
|
|
|
|
function Calendar({
|
|
className,
|
|
classNames,
|
|
fromDate,
|
|
toDate,
|
|
showOutsideDays = true,
|
|
...props
|
|
}: CalendarProps) {
|
|
return (
|
|
<DayPicker
|
|
fromDate={fromDate}
|
|
toDate={toDate || undefined}
|
|
showOutsideDays={showOutsideDays}
|
|
className={cn("p-3", className)}
|
|
classNames={{
|
|
months: "flex flex-col sm:flex-row stack-y-4 sm:space-x-4 sm:stack-y-0",
|
|
month: "stack-y-4",
|
|
caption: "flex pt-1 relative items-center justify-between",
|
|
caption_label: "text-sm font-medium",
|
|
nav: "flex items-center",
|
|
head: "",
|
|
head_row: "flex w-full items-center justify-between",
|
|
head_cell: "w-8 md:w-11 h-8 text-sm font-medium text-default text-center",
|
|
nav_button: cn(buttonClasses({ color: "minimal", variant: "icon" })),
|
|
table: "w-full border-collapse stack-y-1",
|
|
row: "flex w-full mt-0.5 gap-0.5",
|
|
cell: "w-8 h-8 md:h-11 md:w-11 text-center text-sm p-0 relative focus-within:relative focus-within:z-20",
|
|
day: cn(
|
|
buttonClasses({ color: "minimal" }),
|
|
"w-8 h-8 md:h-11 md:w-11 p-0 text-sm font-medium aria-selected:opacity-100 inline-flex items-center justify-center"
|
|
),
|
|
day_range_end: "hover:bg-inverted! text-inverted!",
|
|
day_range_start: "hover:bg-inverted! text-inverted!",
|
|
day_selected: "bg-inverted text-inverted",
|
|
day_today: "",
|
|
day_outside: "",
|
|
day_disabled: "text-muted opacity-50",
|
|
day_range_middle: "aria-selected:bg-emphasis aria-selected:text-emphasis",
|
|
day_hidden: "invisible",
|
|
...classNames,
|
|
}}
|
|
components={{
|
|
CaptionLabel: (capLabelProps) => (
|
|
<div className="px-2">
|
|
<span className="text-emphasis font-semibold leading-none">
|
|
{dayjs(capLabelProps.displayMonth).format("MMMM")}{" "}
|
|
</span>
|
|
<span className="text-subtle font-medium leading-none">
|
|
{dayjs(capLabelProps.displayMonth).format("YYYY")}
|
|
</span>
|
|
</div>
|
|
),
|
|
IconLeft: () => <Icon name="chevron-left" className="h-4 w-4 stroke-2" />,
|
|
IconRight: () => <Icon name="chevron-right" className="h-4 w-4 stroke-2" />,
|
|
}}
|
|
{...props}
|
|
/>
|
|
);
|
|
}
|
|
Calendar.displayName = "Calendar";
|
|
|
|
export { Calendar };
|