MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / DateTimePicker

Function DateTimePicker

apps/start/src/components/ui/date-time.tsx:15–119  ·  view source on GitHub ↗
({
  value,
  onChange,
}: { value: Date; onChange: (date: Date) => void })

Source from the content-addressed store, hash-verified

13import { CalendarIcon } from 'lucide-react';
14
15export function DateTimePicker({
16 value,
17 onChange,
18}: { value: Date; onChange: (date: Date) => void }) {
19 function handleDateSelect(date: Date | undefined) {
20 if (date) {
21 onChange(date);
22 }
23 }
24
25 function handleTimeChange(type: 'hour' | 'minute', value: string) {
26 const currentDate = value || new Date();
27 const newDate = new Date(currentDate);
28
29 if (type === 'hour') {
30 const hour = Number.parseInt(value, 10);
31 newDate.setHours(hour);
32 } else if (type === 'minute') {
33 newDate.setMinutes(Number.parseInt(value, 10));
34 }
35
36 onChange(newDate);
37 }
38
39 return (
40 <Popover>
41 <PopoverTrigger asChild>
42 <Button
43 variant={'outline'}
44 className={cn(
45 'w-full pl-3 text-left font-normal',
46 !value && 'text-muted-foreground',
47 )}
48 >
49 {value ? (
50 format(value, 'MM/dd/yyyy HH:mm')
51 ) : (
52 <span>MM/DD/YYYY HH:mm</span>
53 )}
54 <CalendarIcon className="ml-auto h-4 w-4 opacity-50" />
55 </Button>
56 </PopoverTrigger>
57 <PopoverPortal>
58 <PopoverContent className="w-auto p-0">
59 <div className="sm:flex">
60 <Calendar
61 mode="single"
62 selected={value}
63 onSelect={handleDateSelect}
64 initialFocus
65 />
66 <div className="flex flex-col sm:flex-row sm:h-[300px] divide-y sm:divide-y-0 sm:divide-x">
67 <ScrollArea className="w-64 sm:w-auto">
68 <div className="flex sm:flex-col p-2">
69 {Array.from({ length: 24 }, (_, i) => i)
70 .reverse()
71 .map((hour) => (
72 <Button

Callers

nothing calls this directly

Calls 6

cnFunction · 0.90
formatFunction · 0.85
handleTimeChangeFunction · 0.85
mapMethod · 0.45
fromMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected