-
Notifications
You must be signed in to change notification settings - Fork 0
/
timepicker.tsx
37 lines (31 loc) · 1011 Bytes
/
timepicker.tsx
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
'use client';
import React, { useState } from 'react';
import 'flatpickr/dist/themes/light.css';
import Flatpickr from 'react-flatpickr';
interface ITimePickerProps {
onChange?: (date: string) => void;
}
const TimePicker = ({ onChange }: ITimePickerProps) => {
const [date, setDate] = useState<Date | string | number>(new Date());
const handleChange = (selectedDates: Date[]) => {
const [selectedDate] = selectedDates;
if (selectedDate) {
setDate(selectedDate);
onChange && onChange(`${selectedDate.getHours()}:${selectedDate.getMinutes()}`);
}
};
return (
<Flatpickr
options={{
enableTime: true,
noCalendar: true,
time_24hr: true,
defaultHour: 2,
}}
className="!w-12 inline-flex bg-neutral-200 p-1 rounded text-center"
value={date}
onChange={handleChange}
/>
);
};
export default TimePicker;