-
Notifications
You must be signed in to change notification settings - Fork 0
/
with-dropdown.tsx
63 lines (59 loc) · 1.8 KB
/
with-dropdown.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"use client"
import { format } from "date-fns"
import { CalendarIcon, ChevronLeft, ChevronRight } from "lucide-react"
import { useState } from "react"
import {
Button,
FormItem,
Label,
Popover,
PopoverContent,
PopoverTrigger,
} from "@/app/components/ui"
import { cn } from "@/app/lib/utils"
import { Calendar } from "./calendar"
import MonthAndYearDropdown from "./month-year-dropdown"
export function DatePickerWithDropdown() {
const [date, setDate] = useState<Date | undefined>()
return (
<FormItem className="flex flex-col">
<Label id="datepicker-month-year-dropdown-v9">
Datepicker With Month and Year Dropdown
</Label>
<Popover>
<PopoverTrigger asChild>
<Button
variant="outline"
className={cn(
"w-[280px] justify-start text-left font-normal",
!date && "text-muted-foreground",
)}
aria-labelledby="datepicker-month-year-dropdown-v9"
>
<CalendarIcon className="mr-2 size-4" />
{date ? format(date, "PPP") : <span>Pick a date</span>}
</Button>
</PopoverTrigger>
<PopoverContent className="w-auto p-0" align="start">
<Calendar
mode="single"
captionLayout="dropdown"
selected={date}
onSelect={setDate}
showOutsideDays={true}
endMonth={new Date(2099, 11)}
components={{
Dropdown: MonthAndYearDropdown,
Chevron: ({ orientation }) =>
orientation === "left" ? (
<ChevronLeft className="size-4" />
) : (
<ChevronRight className="size-4" />
),
}}
/>
</PopoverContent>
</Popover>
</FormItem>
)
}