mirror of
https://github.com/BrenBroZAYT/gameyfin.git
synced 2026-06-13 16:40:01 +00:00
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import {useField} from "formik";
|
|
import {DatePicker, DateValue} from "@heroui/react";
|
|
import {parseDate} from "@internationalized/date";
|
|
import {useState} from "react";
|
|
|
|
// @ts-ignore
|
|
export default function DatePickerInput({label, showErrorUntouched = false, ...props}) {
|
|
// @ts-ignore
|
|
const [field, meta] = useField(props);
|
|
const [value, setValue] = useState<DateValue | null>(field.value ? parseDate(field.value) : null);
|
|
|
|
return (
|
|
<DatePicker
|
|
className="min-h-20 flex-grow"
|
|
showMonthAndYearPickers
|
|
fullWidth={false}
|
|
{...props}
|
|
{...field}
|
|
value={value}
|
|
onChange={(date) => {
|
|
setValue(date);
|
|
field.onChange({
|
|
target: {
|
|
name: field.name,
|
|
value: date ? date.toString() : ''
|
|
}
|
|
});
|
|
}}
|
|
id={label}
|
|
label={label}
|
|
isInvalid={(meta.touched || showErrorUntouched) && !!meta.error}
|
|
errorMessage={meta.initialError || meta.error}
|
|
/>
|
|
);
|
|
} |