mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-05-12 13:49:22 -05:00
52 lines
996 B
TypeScript
52 lines
996 B
TypeScript
import { useIsMounted } from "~/hooks/useIsMounted";
|
|
import { dateToYearMonthDayHourMinuteString } from "~/utils/dates";
|
|
|
|
export function DateInput({
|
|
id,
|
|
name,
|
|
defaultValue,
|
|
min,
|
|
max,
|
|
required,
|
|
"data-cy": dataCy,
|
|
}: {
|
|
id?: string;
|
|
name?: string;
|
|
defaultValue?: Date;
|
|
min?: Date;
|
|
max?: Date;
|
|
"data-cy": string;
|
|
required?: boolean;
|
|
}) {
|
|
const isMounted = useIsMounted();
|
|
|
|
if (!isMounted) {
|
|
return (
|
|
<input
|
|
id={id}
|
|
type="datetime-local"
|
|
name={name}
|
|
required={required}
|
|
disabled
|
|
/>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<input
|
|
id={id}
|
|
type="datetime-local"
|
|
name={name}
|
|
defaultValue={
|
|
defaultValue
|
|
? dateToYearMonthDayHourMinuteString(defaultValue)
|
|
: undefined
|
|
}
|
|
min={min ? dateToYearMonthDayHourMinuteString(min) : undefined}
|
|
max={max ? dateToYearMonthDayHourMinuteString(max) : undefined}
|
|
data-cy={dataCy}
|
|
required={required}
|
|
/>
|
|
);
|
|
}
|