mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 10:56:28 +00:00
fb2d746fc0
Introduce a set of reusable UI primitives and integrate tooltip provider in the app layout. Adds: Combobox (with virtualized and non-virtualized variants), Command palette components (cmdk wrapper and related subcomponents), DatePicker and DateTimePicker (popover-based date/time selection with time pickers and Done footer), LazyImage (progressive image with blur/scale transition), and Tooltip (Radix wrapper and provider). Also imports TooltipProvider in app/layout.tsx and wraps the app content so tooltips are available globally.
68 lines
2.5 KiB
TypeScript
68 lines
2.5 KiB
TypeScript
"use client"
|
|
|
|
import { useMemo, useState } from "react";
|
|
import { CalendarIcon } from "@radix-ui/react-icons";
|
|
import { format } from "date-fns";
|
|
import { cn } from "@/lib/utils";
|
|
import { Button } from "@/components/ui/button";
|
|
import { Calendar } from "@/components/ui/calendar";
|
|
import {
|
|
Popover,
|
|
PopoverContent,
|
|
PopoverTrigger,
|
|
} from "@/components/ui/popover";
|
|
import type { Matcher } from "react-day-picker";
|
|
|
|
interface DatePickerProps {
|
|
date: Date | undefined;
|
|
setDate: (date: Date | undefined) => void;
|
|
placeholder?: string;
|
|
disabled?: boolean;
|
|
disabledDate?: Matcher | Matcher[] | undefined;
|
|
captionLayout?: "label" | "dropdown" | "dropdown-months" | "dropdown-years";
|
|
formatDate?: string;
|
|
className?: string
|
|
}
|
|
|
|
export function DatePicker({ date, setDate, placeholder, disabled, disabledDate, captionLayout, formatDate, className }: DatePickerProps) {
|
|
const [open, setOpen] = useState(false);
|
|
|
|
// Safety check to ensure we always work with a Date object
|
|
const parsedDate = useMemo(() => {
|
|
if (!date) return undefined;
|
|
if (typeof date === "string") return new Date(date);
|
|
return date;
|
|
}, [date]);
|
|
|
|
return (
|
|
<Popover open={open} onOpenChange={setOpen}>
|
|
<PopoverTrigger asChild>
|
|
<Button
|
|
variant={"outline"} disabled={disabled}
|
|
className={cn(
|
|
"w-full justify-start text-left font-normal",
|
|
!parsedDate && "text-muted-foreground", className
|
|
)}
|
|
>
|
|
<CalendarIcon className="mr-2 h-4 w-4" />
|
|
{parsedDate ? format(parsedDate, formatDate || "PPP") : <span>{placeholder || "Pick a date"}</span>}
|
|
</Button>
|
|
</PopoverTrigger>
|
|
<PopoverContent className="w-auto p-0" align="start">
|
|
<Calendar
|
|
mode="single"
|
|
captionLayout={captionLayout || 'dropdown'}
|
|
disabled={disabledDate}
|
|
selected={parsedDate}
|
|
defaultMonth={parsedDate}
|
|
onSelect={(selectedDate) => {
|
|
setDate(selectedDate);
|
|
setOpen(false); // Close popover immediately after selection
|
|
}}
|
|
initialFocus
|
|
endMonth={new Date(2050, 11)}
|
|
/>
|
|
</PopoverContent>
|
|
</Popover>
|
|
);
|
|
} |