Components
npx shadcn@latest add https://21st.dev/r/originui/calendarLoading preview...
"use client";
import { cn } from "@/lib/utils";
import { Button } from "@/components/ui/button";
import { Calendar } from "@/components/ui/calendar";
import { Label } from "@/components/ui/label";
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
import { format } from "date-fns";
import { CalendarIcon } from "lucide-react";
import { useId, useState } from "react";
import { DateRange } from "react-day-picker";
function Component() {
const id = useId();
const [date, setDate] = useState<DateRange | undefined>();
return (
<div>
<div className="space-y-2">
<Label htmlFor={id}>Date range picker</Label>
<Popover>
<PopoverTrigger asChild>
<Button
id={id}
variant={"outline"}
className={cn(
"group w-full justify-between bg-background px-3 font-normal outline-offset-0 hover:bg-background focus-visible:border-ring focus-visible:outline-[3px] focus-visible:outline-ring/20",
!date && "text-muted-foreground",
)}
>
<span className={cn("truncate", !date && "text-muted-foreground")}>
{date?.from ? (
date.to ? (
<>
{format(date.from, "LLL dd, y")} - {format(date.to, "LLL dd, y")}
</>
) : (
format(date.from, "LLL dd, y")
)
) : (
"Pick a date range"
)}
</span>
<CalendarIcon
size={16}
strokeWidth={2}
className="shrink-0 text-muted-foreground/80 transition-colors group-hover:text-foreground"
aria-hidden="true"
/>
</Button>
</PopoverTrigger>
<PopoverContent className="w-auto p-2" align="start">
<Calendar mode="range" selected={date} onSelect={setDate} />
</PopoverContent>
</Popover>
</div>
<p className="mt-2 text-xs text-muted-foreground" role="region" aria-live="polite">
Built with{" "}
<a
className="underline hover:text-foreground"
href="https://daypicker.dev/"
target="_blank"
rel="noopener nofollow"
>
React DayPicker
</a>
</p>
</div>
);
}
export { Component };
Loading preview...
Loading preview...
Loading preview...
Loading preview...
Loading preview...
Loading preview...
Loading preview...
Loading preview...
Loading preview...
Loading preview...
Loading preview...
Loading preview...
Loading preview...
Loading preview...
Loading preview...
Loading preview...
Loading preview...
Loading preview...
Loading preview...
Loading preview...
Loading preview...