From fb2d746fc01e50c89d9e7c95026c43c206c6381c Mon Sep 17 00:00:00 2001 From: Ichsan Kurniawan Date: Thu, 16 Apr 2026 22:37:45 +0700 Subject: [PATCH] Add UI components and Tooltip provider 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. --- app/layout.tsx | 11 +- components/ui/combobox.tsx | 133 +++++++++++++++++++++ components/ui/command.tsx | 184 +++++++++++++++++++++++++++++ components/ui/date-time-picker.tsx | 139 ++++++++++++++++++++++ components/ui/datepicker.tsx | 68 +++++++++++ components/ui/lazy-image.tsx | 33 ++++++ components/ui/tooltip.tsx | 57 +++++++++ package.json | 5 + 8 files changed, 626 insertions(+), 4 deletions(-) create mode 100644 components/ui/combobox.tsx create mode 100644 components/ui/command.tsx create mode 100644 components/ui/date-time-picker.tsx create mode 100644 components/ui/datepicker.tsx create mode 100644 components/ui/lazy-image.tsx create mode 100644 components/ui/tooltip.tsx diff --git a/app/layout.tsx b/app/layout.tsx index b6f05db..493e8fb 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -12,6 +12,7 @@ import SessionProvider from '@/providers/SessionProvider' import { Toaster } from '@/components/ui/sonner'; import AntdConfigProvider from '@/providers/AntdConfigProvider'; import ProgressBarProviders from '@/providers/ProgressBarProvider'; +import { TooltipProvider } from '@/components/ui/tooltip'; const jakarta = Plus_Jakarta_Sans({ subsets: ['latin'] }) @@ -81,10 +82,12 @@ export default async function RootLayout({ -
- {children} - {modal} -
+ +
+ {children} + {modal} +
+
diff --git a/components/ui/combobox.tsx b/components/ui/combobox.tsx new file mode 100644 index 0000000..597155d --- /dev/null +++ b/components/ui/combobox.tsx @@ -0,0 +1,133 @@ +import { Check, ChevronsUpDown } from "lucide-react" + +import { cn } from "@/lib/utils" +import { Button } from "@/components/ui/button" +import { + Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, +} from "@/components/ui/command" +import { + Popover, PopoverContent, PopoverTrigger, +} from "@/components/ui/popover" +import { Dispatch, SetStateAction, useDeferredValue, useMemo, useState } from "react" +import { VList } from "virtua" + +type Props = { + title?: string + options: { value: any, label: any }[] + value: any + setValue: Dispatch> + onSelectItem?: (item: any) => any + className?: string + disabled?: boolean +}; + +export function Combobox({ value, setValue, onSelectItem, options, title, className, disabled }: Props) { + const [open, setOpen] = useState(false) + const [search, setSearch] = useState("") + + // Deferred state for the heavy filtering + const deferredSearch = useDeferredValue(search) + + const filteredOptions = useMemo(() => { + return options.filter((item) => + item.label.toLowerCase().includes(deferredSearch.toLowerCase()) + ) + }, [deferredSearch, options]) + + return ( + + + + + + + setSearch(val)} /> + + {/* MANUAL SEARCH */} + {filteredOptions.length === 0 ? ( + Data tidak ditemukan. + ) : ( + + + {filteredOptions.map((item) => ( + { + setValue(item.value === value ? "" : item.value); + if (onSelectItem) onSelectItem(item) + setOpen(false) + setSearch('') + }} + // className="h-10" // Fixed height for each item + > + {item.label} + + + ))} + + + )} + + + + + ) +} + +export function ComboboxWithoutVirtua({ value, setValue, onSelectItem, options, title, className, disabled }: Props) { + const [open, setOpen] = useState(false) + const [search, setSearch] = useState("") + + const deferredSearch = useDeferredValue(search) + + const filteredOptions = useMemo(() => { + return options.filter((item) => + item.label.toLowerCase().includes(deferredSearch.toLowerCase()) + ) + }, [deferredSearch, options]) + + return ( + + + + + + + setSearch(val)} /> + + {/* MANUAL SEARCH */} + {filteredOptions.length === 0 ? ( + Data tidak ditemukan. + ) : ( + + {filteredOptions.map((item) => ( + { + setValue(item.value === value ? "" : item.value); + if (onSelectItem) onSelectItem(item) + setOpen(false) + setSearch('') + }} + > + {item.label} + + + ))} + + )} + + + + + ) +} diff --git a/components/ui/command.tsx b/components/ui/command.tsx new file mode 100644 index 0000000..8fe3ccb --- /dev/null +++ b/components/ui/command.tsx @@ -0,0 +1,184 @@ +"use client" + +import * as React from "react" +import { Command as CommandPrimitive } from "cmdk" +import { SearchIcon } from "lucide-react" + +import { cn } from "@/lib/utils" +import { + Dialog, + DialogContent, + DialogDescription, + DialogHeader, + DialogTitle, +} from "@/components/ui/dialog" + +function Command({ + className, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function CommandDialog({ + title = "Command Palette", + description = "Search for a command to run...", + children, + className, + showCloseButton = true, + ...props +}: React.ComponentProps & { + title?: string + description?: string + className?: string + showCloseButton?: boolean +}) { + return ( + + + {title} + {description} + + + + {children} + + + + ) +} + +function CommandInput({ + className, + ...props +}: React.ComponentProps) { + return ( +
+ + +
+ ) +} + +function CommandList({ + className, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function CommandEmpty({ + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function CommandGroup({ + className, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function CommandSeparator({ + className, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function CommandItem({ + className, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function CommandShortcut({ + className, + ...props +}: React.ComponentProps<"span">) { + return ( + + ) +} + +export { + Command, + CommandDialog, + CommandInput, + CommandList, + CommandEmpty, + CommandGroup, + CommandItem, + CommandShortcut, + CommandSeparator, +} diff --git a/components/ui/date-time-picker.tsx b/components/ui/date-time-picker.tsx new file mode 100644 index 0000000..cb001b6 --- /dev/null +++ b/components/ui/date-time-picker.tsx @@ -0,0 +1,139 @@ +"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 { ScrollArea, ScrollBar } from "@/components/ui/scroll-area"; +import type { Matcher } from "react-day-picker"; + +interface DateTimePickerProps { + 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; +} + +export function DateTimePicker({ date, setDate, placeholder, disabled, disabledDate, captionLayout, formatDate }: DateTimePickerProps) { + const [isOpen, setIsOpen] = useState(false); + + const hours = Array.from({ length: 24 }, (_, i) => i).reverse(); + const minutes = Array.from({ length: 12 }, (_, i) => i * 5); + + const parsedDate = useMemo(() => { + if (!date) return undefined; + if (typeof date === "string") return new Date(date); + return date; + }, [date]); + + const handleDateSelect = (selectedDate: Date | undefined) => { + if (selectedDate) { + if (parsedDate) { + selectedDate.setHours(parsedDate.getHours()); + selectedDate.setMinutes(parsedDate.getMinutes()); + } + setDate(selectedDate); + } + }; + + const handleTimeChange = (type: "hour" | "minute", value: string) => { + if (date) { + const current = parsedDate || new Date(); + const newDate = new Date(current); + + if (type === "hour") { + newDate.setHours(parseInt(value)); + } else if (type === "minute") { + newDate.setMinutes(parseInt(value)); + } + setDate(newDate); + } + }; + + return ( + + + + + +
+ +
+ +
+ {hours.map((hour) => ( + + ))} +
+ +
+ +
+ {minutes.map((minute) => ( + + ))} +
+ +
+
+
+ {/* --- ADDED FOOTER HERE --- */} +
+ +
+
+
+ ); +} \ No newline at end of file diff --git a/components/ui/datepicker.tsx b/components/ui/datepicker.tsx new file mode 100644 index 0000000..38fa819 --- /dev/null +++ b/components/ui/datepicker.tsx @@ -0,0 +1,68 @@ +"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 ( + + + + + + { + setDate(selectedDate); + setOpen(false); // Close popover immediately after selection + }} + initialFocus + endMonth={new Date(2050, 11)} + /> + + + ); +} \ No newline at end of file diff --git a/components/ui/lazy-image.tsx b/components/ui/lazy-image.tsx new file mode 100644 index 0000000..d73080c --- /dev/null +++ b/components/ui/lazy-image.tsx @@ -0,0 +1,33 @@ +"use client" + +import { cn } from "@/lib/utils"; +import { useState, useRef, useEffect } from "react"; + +export function LazyImage({ src, alt, className }: { src: string; alt: string; className?: string }) { + const [isLoaded, setIsLoaded] = useState(false); + const imgRef = useRef(null); + + // Check if the image is already loaded from the cache + useEffect(() => { + if (imgRef.current?.complete) { + setIsLoaded(true); + } + }, [src]); // Re-run this check if the src prop changes + + return ( +
+ {alt} setIsLoaded(true)} + className={cn( + "w-full h-full object-cover transition-all duration-700 ease-in-out", + isLoaded ? "blur-0 scale-100 opacity-100" : "blur-xl scale-110 opacity-0" + )} + /> +
+ ); +} \ No newline at end of file diff --git a/components/ui/tooltip.tsx b/components/ui/tooltip.tsx new file mode 100644 index 0000000..ec65c1e --- /dev/null +++ b/components/ui/tooltip.tsx @@ -0,0 +1,57 @@ +"use client" + +import * as React from "react" +import { Tooltip as TooltipPrimitive } from "radix-ui" + +import { cn } from "@/lib/utils" + +function TooltipProvider({ + delayDuration = 0, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function Tooltip({ + ...props +}: React.ComponentProps) { + return +} + +function TooltipTrigger({ + ...props +}: React.ComponentProps) { + return +} + +function TooltipContent({ + className, + sideOffset = 0, + children, + ...props +}: React.ComponentProps) { + return ( + + + {children} + + + + ) +} + +export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider } diff --git a/package.json b/package.json index 495139d..3cbd186 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "axios": "^1.13.2", "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", + "cmdk": "^1.1.1", "date-fns": "^4.1.0", "dayjs": "^1.11.19", "exceljs": "^4.4.0", @@ -50,10 +51,12 @@ "get-orientation": "^1.1.2", "heic2any": "^0.0.4", "lucide-react": "^0.556.0", + "motion": "^12.38.0", "next": "^16.0.10", "next-auth": "^4.24.13", "next-themes": "^0.4.6", "pdf-lib": "^1.17.1", + "radix-ui": "^1.4.3", "react": "^19.2.3", "react-apexcharts": "^1.9.0", "react-day-picker": "^9.12.0", @@ -69,6 +72,8 @@ "swr": "^2.3.7", "tailwind-merge": "^3.4.0", "tailwind-scrollbar-hide": "^4.0.0", + "virtua": "^0.49.1", + "yup": "^1.7.1", "zod": "^4.1.13" }, "devDependencies": {