-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add DateRangePickerField (#257)
* feat: add DateRangePickerField * refactor: Apply eslint fix --------- Co-authored-by: Christian Seidel <[email protected]> Co-authored-by: Quis90 <[email protected]>
- Loading branch information
1 parent
af70f60
commit 4296cac
Showing
3 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { DatePicker } from 'antd'; | ||
import { RangePickerProps } from 'antd/es/date-picker'; | ||
import React from 'react'; | ||
import { | ||
FieldPath, | ||
FieldValues, | ||
useController, | ||
UseControllerProps, | ||
} from 'react-hook-form'; | ||
|
||
import { FieldWrapper, FieldWrapperProps } from './FieldWrapper'; | ||
|
||
const { RangePicker } = DatePicker; | ||
|
||
type DateRangePickerFieldProps< | ||
TFieldValues extends FieldValues, | ||
TName extends FieldPath<TFieldValues>, | ||
> = UseControllerProps<TFieldValues, TName> & | ||
Pick<FieldWrapperProps<TFieldValues, TName>, 'formItem'> & { | ||
component?: RangePickerProps; | ||
}; | ||
|
||
export function DateRangePickerField< | ||
TFieldValues extends FieldValues = FieldValues, | ||
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>, | ||
>({ | ||
formItem, | ||
component, | ||
...controller | ||
}: DateRangePickerFieldProps<TFieldValues, TName>) { | ||
const { | ||
field: { ref, ...fieldProps }, | ||
} = useController<TFieldValues, TName>(controller); | ||
return ( | ||
<FieldWrapper controller={controller} formItem={formItem}> | ||
<RangePicker format="DD.MM.YYYY" {...fieldProps} {...component} /> | ||
</FieldWrapper> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters