Application
Date Picker
A button that opens the Calendar in a popover and shows the formatted date.
Motionpopover scale/opacity on tween.quick
Install
Install Kineto and follow the theme setup once in your app.
bash
npm install kinetotsx
import { DatePicker } from "kineto/date-picker";Preview
tsx
"use client";
import * as React from "react";
import { Calendar as CalendarIcon } from "lucide-react";
import { cn } from "@/lib/cn";
import { Button } from "@/components/ui/button";
import { Calendar } from "@/components/ui/calendar";
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
export interface DatePickerProps {
value?: Date;
defaultValue?: Date;
onValueChange?: (date: Date | undefined) => void;
placeholder?: string;
className?: string;
}
export function DatePicker({
value,
defaultValue,
onValueChange,
placeholder = "Pick a date",
className,
}: DatePickerProps) {
const [internal, setInternal] = React.useState<Date | undefined>(defaultValue);
const [open, setOpen] = React.useState(false);
const date = value ?? internal;
const set = (next: Date | undefined) => {
if (value === undefined) setInternal(next);
onValueChange?.(next);
setOpen(false);
};
return (
<Popover open={open} onOpenChange={setOpen}>
<PopoverTrigger asChild>
<Button
variant="outline"
className={cn(
"w-64 justify-start gap-2 font-normal",
!date && "text-muted-foreground",
className
)}
>
<CalendarIcon className="size-4" />
{date
? date.toLocaleDateString(undefined, {
year: "numeric",
month: "long",
day: "numeric",
})
: placeholder}
</Button>
</PopoverTrigger>
<PopoverContent className="w-auto p-2" align="start">
<Calendar mode="single" selected={date} onSelect={set} autoFocus />
</PopoverContent>
</Popover>
);
}src/components/ui/date-picker.tsx
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| value / defaultValue | Date | — | Controlled or uncontrolled date. |
| onValueChange | (date?) => void | — | Fires on selection. |