-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathControlledDateTimePicker.tsx
More file actions
57 lines (55 loc) ยท 1.54 KB
/
ControlledDateTimePicker.tsx
File metadata and controls
57 lines (55 loc) ยท 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { DateTimeInput } from '@/components/DateTimeInput';
import { DateTimePicker } from '@/components/DateTimePicker';
import type { Control, FieldValues, Path } from 'react-hook-form';
import { Controller } from 'react-hook-form';
interface ControlledDateTimePickerProps<T extends FieldValues> {
control: Control<T>;
name: Path<T>;
id?: string;
placeholder?: string;
disabled?: boolean;
onChange?: (date: Date | undefined) => void;
}
export function ControlledDateTimePicker<T extends FieldValues>({
control,
name,
id,
placeholder,
disabled,
onChange: onSideChange,
}: ControlledDateTimePickerProps<T>) {
return (
<Controller
control={control}
name={name}
render={({ field }) => (
<DateTimePicker
id={id || name}
value={field.value}
onChange={(date: Date | undefined) => {
field.onChange(date);
if (onSideChange) onSideChange(date);
}}
placeholder={placeholder}
disabled={disabled}
renderTrigger={({ value, open, setOpen }) => (
<DateTimeInput
value={value}
onChange={(date: Date | undefined) => {
if (date) {
field.onChange(date);
if (onSideChange) onSideChange(date);
}
}}
onCalendarClick={() => {
setOpen(!open);
}}
placeholder={placeholder}
disabled={disabled}
/>
)}
/>
)}
/>
);
}