import { Calendar } from '@/components/originui/calendar'; import { Input } from '@/components/ui/input'; import { Popover, PopoverContent, PopoverTrigger, } from '@/components/ui/popover'; import { cn } from '@/lib/utils'; import { Locale } from 'date-fns'; import dayjs from 'dayjs'; import { Calendar as CalendarIcon } from 'lucide-react'; import * as React from 'react'; interface DateInputProps extends Omit< React.InputHTMLAttributes, 'value' | 'onChange' > { value?: Date; onChange?: (date: Date | undefined) => void; showTimeSelect?: boolean; dateFormat?: string; timeFormat?: string; showTimeSelectOnly?: boolean; showTimeInput?: boolean; timeInputLabel?: string; locale?: Locale; // Support for internationalization } const DateInput = React.forwardRef( ( { className, value, onChange, dateFormat = 'DD/MM/YYYY', timeFormat = 'HH:mm:ss', showTimeSelect = false, showTimeSelectOnly = false, showTimeInput = false, timeInputLabel = '', ...props }, ref, ) => { const [open, setOpen] = React.useState(false); const handleDateSelect = (date: Date | undefined) => { onChange?.(date); setOpen(false); }; // Determine display format based on the type of date picker let displayFormat = dateFormat; if (showTimeSelect) { displayFormat = `${dateFormat} ${timeFormat}`; } else if (showTimeSelectOnly) { displayFormat = timeFormat; } // Format the date according to the specified format const formattedValue = React.useMemo(() => { return value && !isNaN(value.getTime()) ? dayjs(value).format(displayFormat) : ''; }, [value, displayFormat]); return (
); }, ); DateInput.displayName = 'DateInput'; export { DateInput };