mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 23:16:03 +01:00
feat(web/input): date input
This commit is contained in:
38
web/src/features/dialog/components/fields/date.tsx
Normal file
38
web/src/features/dialog/components/fields/date.tsx
Normal file
@@ -0,0 +1,38 @@
|
||||
import { IDateInput } from '../../../../interfaces/dialog';
|
||||
import { Control, useController } from 'react-hook-form';
|
||||
import { FormValues } from '../../InputDialog';
|
||||
import { DatePicker } from '@mantine/dates';
|
||||
|
||||
interface Props {
|
||||
row: IDateInput;
|
||||
index: number;
|
||||
control: Control<FormValues>;
|
||||
}
|
||||
|
||||
const DateField: React.FC<Props> = (props) => {
|
||||
const controller = useController({
|
||||
name: `test.${props.index}.value`,
|
||||
control: props.control,
|
||||
defaultValue: props.row.default && new Date(props.row.default),
|
||||
rules: { required: props.row.required },
|
||||
});
|
||||
|
||||
return (
|
||||
<DatePicker
|
||||
value={controller.field.value}
|
||||
name={controller.field.name}
|
||||
ref={controller.field.ref}
|
||||
onBlur={controller.field.onBlur}
|
||||
onChange={controller.field.onChange}
|
||||
label={props.row.label}
|
||||
description={props.row.description}
|
||||
placeholder={props.row.placeholder}
|
||||
disabled={props.row.disabled}
|
||||
inputFormat="DD/MM/YYYY"
|
||||
withAsterisk={props.row.required}
|
||||
clearable={props.row.clearable}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default DateField;
|
||||
Reference in New Issue
Block a user