-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathTextField.tsx
60 lines (55 loc) · 1.81 KB
/
TextField.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import React from 'react';
import { Controller, useFormContext } from 'react-hook-form';
import { Input, Label } from 'reactstrap';
import 'bootstrap/dist/css/bootstrap.min.css';
import '../../styles/lightMode.scss';
/**
* Types for the Text Field Props.
*/
interface TextFieldProps {
/**
* Type of the field name to be registered in Controller. Required.
*/
name: string,
/**
* ClassName. Optional.
*/
className?: string,
/**
* Types of Any other Props. Optional.
*/
[x: string]: any
}
/**
* Text Field for the User's additional comment/remarks on the Feedback page.
* @param name - Name of the registered Input
* @param props - Other props
* @returns - Registered Text Input component (via {@link https://react-hook-form.com/api/usecontroller/controller | Controller})
*/
export default function TextField({ name, ...props }: TextFieldProps) {
/**
* Form context passed via {@link https://react-hook-form.com/api/useformcontext | Form Context Hook}.
*/
const context = useFormContext();
return(
<Controller
control={context.control}
name={name}
render={({ field: { onChange, onBlur, value, ref } }) => (
<Label check className={"w-100 responsiveText"}>
<Input
className={`${props.className} textFieldStyle`}
type={"text"}
innerRef={ref}
onChange={onChange}
onBlur={onBlur}
name={name}
value={value}
rows={4}
placeholder={"Other..."}
{...props} />
</Label>
)}
></Controller>
);
}