25 lines
534 B
TypeScript
25 lines
534 B
TypeScript
import { formatDate } from "date-fns";
|
|
|
|
export const DateInput = ({
|
|
value,
|
|
onChange,
|
|
...props
|
|
}: Omit<React.InputHTMLAttributes<HTMLInputElement>, "value" | "onChange"> & {
|
|
value?: Date | null;
|
|
onChange?: (date: Date) => void;
|
|
}) => {
|
|
return (
|
|
<input
|
|
type="datetime-local"
|
|
className="input"
|
|
value={formatDate(value || new Date(), "yyyy-MM-dd hh:mm")}
|
|
onChange={(e) => {
|
|
const date = e.target.value ? new Date(e.target.value) : null;
|
|
if (!date) return;
|
|
onChange?.(date);
|
|
}}
|
|
{...props}
|
|
/>
|
|
);
|
|
};
|