nej-react-utils/Form/Core/DateFields.js
2026-06-03 15:34:54 +02:00

20 lines
690 B
JavaScript

import tw, { styled } from "twin.macro";
import "styled-components/macro";
import dayjs from "dayjs";
import Input, { useField } from "@shared/nej-react-components/Parts/Input";
export default function DateField(props) {
const [{onChange, value, ...field}, meta, helpers] = useField(props);
const parsedDate = dayjs(value);
const isValid = value && parsedDate.isValid();
const {value: _x, onChange: _y, ...restProps} = props;
return <Input type="date"
value={isValid ? parsedDate.format("YYYY-MM-DD") : ""}
onChange={(e)=>onChange({ target: { value: e.target.value ? dayjs(e.target.value).toDate() : null, name: field.name } })} {...field} {...restProps} />;
}