-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
julian-wasmeier-titanom
committed
May 24, 2024
1 parent
2fd9e46
commit 934c42e
Showing
1 changed file
with
53 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,53 @@ | ||
import React from "react"; | ||
import { | ||
Control, | ||
Controller, | ||
FieldErrors, | ||
FieldValues, | ||
InputValidationRules, | ||
Path, | ||
RegisterOptions, | ||
} from "react-hook-form"; | ||
import { View, Text, TextInput, TextInputProps } from "react-native"; | ||
|
||
type Props<T extends FieldValues> = { | ||
name: Path<T>; | ||
labelText: string; | ||
textInputProps: Omit<TextInputProps, "onChangeText" | "value">; | ||
control: Control<T>; | ||
errors: FieldErrors<T>; | ||
rules?: RegisterOptions<T>; | ||
}; | ||
|
||
function FormTextInput<T extends FieldValues>({ | ||
name, | ||
labelText, | ||
textInputProps, | ||
control, | ||
errors, | ||
rules, | ||
}: Props<T>) { | ||
return ( | ||
<View> | ||
<Text className="text-white mb-2"> | ||
{labelText} {rules?.required && "*"} | ||
</Text> | ||
<Controller | ||
control={control} | ||
rules={rules} | ||
render={({ field: { onChange, value } }) => ( | ||
<TextInput | ||
{...textInputProps} | ||
onChangeText={onChange} | ||
value={value} | ||
className="p-4 rounded-lg bg-white mb-2" | ||
/> | ||
)} | ||
name={name} | ||
/> | ||
{errors[name] && <Text className="text-red-300">Title is required</Text>} | ||
</View> | ||
); | ||
} | ||
|
||
export default FormTextInput; |