nej-react-utils/Form/Core/DateFields.js
honzapatCZ 16a81d9eb7 dates
2026-06-03 17:01:55 +02:00

25 lines
721 B
JavaScript

import tw, { styled } from "twin.macro";
import "styled-components/macro";
import dayjs from "dayjs";
import { DatePickerInput } from '@mantine/dates';
import '@mantine/dates/styles.css';
import { 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 <DatePickerInput
value={isValid ? parsedDate.toDate() : null}
onChange={(val)=>onChange({ target: { value: val, name: field.name } })}
{...field}
{...restProps}
/>;
}