Skip to content

Commit e1c420f

Browse files
committed
chore: add calendar
1 parent f5c2f19 commit e1c420f

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

package-lock.json

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"lucide-react": "^0.479.0",
4646
"next-themes": "^0.4.6",
4747
"react": "^19.0.0",
48+
"react-day-picker": "^8.10.1",
4849
"react-dom": "^19.0.0",
4950
"react-hook-form": "^7.54.2",
5051
"react-router": "^7.3.0",

src/components/ui/calendar.tsx

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import * as React from "react"
2+
import { ChevronLeft, ChevronRight } from "lucide-react"
3+
import { DayPicker } from "react-day-picker"
4+
5+
import { cn } from "@/lib/utils"
6+
import { buttonVariants } from "@/components/ui/button"
7+
8+
function Calendar({
9+
className,
10+
classNames,
11+
showOutsideDays = true,
12+
...props
13+
}: React.ComponentProps<typeof DayPicker>) {
14+
return (
15+
<DayPicker
16+
showOutsideDays={showOutsideDays}
17+
className={cn("p-3", className)}
18+
classNames={{
19+
months: "flex flex-col sm:flex-row gap-2",
20+
month: "flex flex-col gap-4",
21+
caption: "flex justify-center pt-1 relative items-center w-full",
22+
caption_label: "text-sm font-medium",
23+
nav: "flex items-center gap-1",
24+
nav_button: cn(
25+
buttonVariants({ variant: "outline" }),
26+
"size-7 bg-transparent p-0 opacity-50 hover:opacity-100"
27+
),
28+
nav_button_previous: "absolute left-1",
29+
nav_button_next: "absolute right-1",
30+
table: "w-full border-collapse space-x-1",
31+
head_row: "flex",
32+
head_cell:
33+
"text-muted-foreground rounded-md w-8 font-normal text-[0.8rem]",
34+
row: "flex w-full mt-2",
35+
cell: cn(
36+
"relative p-0 text-center text-sm focus-within:relative focus-within:z-20 [&:has([aria-selected])]:bg-accent [&:has([aria-selected].day-range-end)]:rounded-r-md",
37+
props.mode === "range"
38+
? "[&:has(>.day-range-end)]:rounded-r-md [&:has(>.day-range-start)]:rounded-l-md first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-r-md"
39+
: "[&:has([aria-selected])]:rounded-md"
40+
),
41+
day: cn(
42+
buttonVariants({ variant: "ghost" }),
43+
"size-8 p-0 font-normal aria-selected:opacity-100"
44+
),
45+
day_range_start:
46+
"day-range-start aria-selected:bg-primary aria-selected:text-primary-foreground",
47+
day_range_end:
48+
"day-range-end aria-selected:bg-primary aria-selected:text-primary-foreground",
49+
day_selected:
50+
"bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground focus:bg-primary focus:text-primary-foreground",
51+
day_today: "bg-accent text-accent-foreground",
52+
day_outside:
53+
"day-outside text-muted-foreground aria-selected:text-muted-foreground",
54+
day_disabled: "text-muted-foreground opacity-50",
55+
day_range_middle:
56+
"aria-selected:bg-accent aria-selected:text-accent-foreground",
57+
day_hidden: "invisible",
58+
...classNames,
59+
}}
60+
components={{
61+
IconLeft: ({ className, ...props }) => (
62+
<ChevronLeft className={cn("size-4", className)} {...props} />
63+
),
64+
IconRight: ({ className, ...props }) => (
65+
<ChevronRight className={cn("size-4", className)} {...props} />
66+
),
67+
}}
68+
{...props}
69+
/>
70+
)
71+
}
72+
73+
export { Calendar }

0 commit comments

Comments
 (0)