Files
calendar/packages/ui/components/form/datepicker/DatePicker.tsx
T
Nayan BagaleandGitHub 1be002c33c fix: Issues with scheduling timezone change without end time (#19103)
* fix: Issues with scheduling timezone change without end time

* test: remove DatePicker component tests

* feat: implement DatePicker component with tests and update button data-testid
2025-02-20 19:19:55 +00:00

60 lines
1.6 KiB
TypeScript

import * as Popover from "@radix-ui/react-popover";
import { format } from "date-fns";
import { classNames as cn } from "@calcom/lib";
import { Button } from "@calcom/ui";
import { Calendar } from "../date-range-picker/Calendar";
type Props = {
date: Date;
onDatesChange?: ((date: Date) => void) | undefined;
className?: string;
disabled?: boolean;
minDate?: Date;
};
const DatePicker = ({ minDate, disabled, date, onDatesChange, className }: Props) => {
function handleDayClick(newDate: Date) {
onDatesChange?.(newDate ?? new Date());
}
const fromDate = minDate ?? new Date();
const calender = (
<Calendar
initialFocus
fromDate={minDate === null ? undefined : fromDate}
// toDate={maxDate}
mode="single"
defaultMonth={date}
selected={date}
onDayClick={(day) => handleDayClick(day)}
numberOfMonths={1}
disabled={disabled}
/>
);
return (
<div className={cn("grid gap-2", className)}>
<Popover.Root>
<Popover.Trigger asChild>
<Button
data-testid="pick-date"
color="secondary"
EndIcon="calendar"
className={cn("justify-between text-left font-normal", !date && "text-subtle")}>
{date ? <>{format(date, "LLL dd, y")}</> : <span>Pick a date</span>}
</Button>
</Popover.Trigger>
<Popover.Content
className="bg-default text-emphasis z-50 w-auto rounded-md border p-0 outline-none"
align="start"
sideOffset={4}>
{calender}
</Popover.Content>
</Popover.Root>
</div>
);
};
export default DatePicker;