@availity/mui-controlled-form 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/README.md +65 -0
- package/dist/index.d.mts +20 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +71 -0
- package/dist/index.mjs +47 -0
- package/docs/propDefinitions.tsx +31 -0
- package/introduction.stories.mdx +7 -0
- package/jest.config.js +7 -0
- package/package.json +66 -0
- package/project.json +41 -0
- package/src/index.ts +1 -0
- package/src/lib/AsyncAutocomplete.stories.tsx +113 -0
- package/src/lib/AsyncAutocomplete.test.tsx +162 -0
- package/src/lib/AsyncAutocomplete.tsx +92 -0
- package/src/lib/Autocomplete.stories.tsx +60 -0
- package/src/lib/Autocomplete.test.tsx +70 -0
- package/src/lib/Autocomplete.tsx +96 -0
- package/src/lib/Checkbox.stories.tsx +67 -0
- package/src/lib/Checkbox.test.tsx +73 -0
- package/src/lib/Checkbox.tsx +37 -0
- package/src/lib/CodesAutocomplete.stories.tsx +79 -0
- package/src/lib/CodesAutocomplete.test.tsx +128 -0
- package/src/lib/CodesAutocomplete.tsx +76 -0
- package/src/lib/ControlledForm.stories.tsx +74 -0
- package/src/lib/ControlledForm.test.tsx +77 -0
- package/src/lib/ControlledForm.tsx +35 -0
- package/src/lib/Datepicker.stories.tsx +63 -0
- package/src/lib/Datepicker.test.tsx +73 -0
- package/src/lib/Datepicker.tsx +49 -0
- package/src/lib/Input.stories.tsx +60 -0
- package/src/lib/Input.test.tsx +98 -0
- package/src/lib/Input.tsx +54 -0
- package/src/lib/OrganizationAutocomplete.stories.tsx +77 -0
- package/src/lib/OrganizationAutocomplete.test.tsx +125 -0
- package/src/lib/OrganizationAutocomplete.tsx +75 -0
- package/src/lib/ProviderAutocomplete.stories.tsx +79 -0
- package/src/lib/ProviderAutocomplete.test.tsx +128 -0
- package/src/lib/ProviderAutocomplete.tsx +80 -0
- package/src/lib/RadioGroup.stories.tsx +63 -0
- package/src/lib/RadioGroup.test.tsx +66 -0
- package/src/lib/RadioGroup.tsx +68 -0
- package/src/lib/Select.stories.tsx +74 -0
- package/src/lib/Select.test.tsx +68 -0
- package/src/lib/Select.tsx +55 -0
- package/src/lib/TextField.stories.tsx +67 -0
- package/src/lib/TextField.test.tsx +99 -0
- package/src/lib/TextField.tsx +67 -0
- package/tsconfig.json +5 -0
- package/tsconfig.spec.json +10 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { TextField, TextFieldProps } from '@availity/mui-textfield';
|
|
2
|
+
import { useFormContext, RegisterOptions, FieldValues } from 'react-hook-form';
|
|
3
|
+
|
|
4
|
+
export type ControlledTextFieldProps = Omit<TextFieldProps, 'required'> & {
|
|
5
|
+
name: string;
|
|
6
|
+
} & RegisterOptions<FieldValues, string>;
|
|
7
|
+
|
|
8
|
+
export const ControlledTextField = ({
|
|
9
|
+
name,
|
|
10
|
+
helperText,
|
|
11
|
+
required,
|
|
12
|
+
maxLength,
|
|
13
|
+
minLength,
|
|
14
|
+
max,
|
|
15
|
+
min,
|
|
16
|
+
pattern,
|
|
17
|
+
validate,
|
|
18
|
+
setValueAs,
|
|
19
|
+
disabled,
|
|
20
|
+
onChange,
|
|
21
|
+
onBlur,
|
|
22
|
+
value,
|
|
23
|
+
shouldUnregister,
|
|
24
|
+
deps,
|
|
25
|
+
...rest
|
|
26
|
+
}: ControlledTextFieldProps) => {
|
|
27
|
+
const {
|
|
28
|
+
register,
|
|
29
|
+
formState: { errors },
|
|
30
|
+
} = useFormContext();
|
|
31
|
+
|
|
32
|
+
const errorMessage = errors[name]?.message;
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<TextField
|
|
36
|
+
{...rest}
|
|
37
|
+
{...register(name, {
|
|
38
|
+
required,
|
|
39
|
+
maxLength,
|
|
40
|
+
minLength,
|
|
41
|
+
max,
|
|
42
|
+
min,
|
|
43
|
+
pattern,
|
|
44
|
+
validate,
|
|
45
|
+
setValueAs,
|
|
46
|
+
disabled,
|
|
47
|
+
onChange,
|
|
48
|
+
onBlur,
|
|
49
|
+
value,
|
|
50
|
+
shouldUnregister,
|
|
51
|
+
deps,
|
|
52
|
+
})}
|
|
53
|
+
error={!!errors[name]}
|
|
54
|
+
helperText={
|
|
55
|
+
errorMessage && typeof errorMessage === 'string' ? (
|
|
56
|
+
<>
|
|
57
|
+
{errorMessage}
|
|
58
|
+
<br />
|
|
59
|
+
{helperText}
|
|
60
|
+
</>
|
|
61
|
+
) : (
|
|
62
|
+
helperText
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
/>
|
|
66
|
+
);
|
|
67
|
+
};
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "../../dist/out-tsc",
|
|
5
|
+
"module": "commonjs",
|
|
6
|
+
"types": ["jest", "node", "@testing-library/jest-dom"],
|
|
7
|
+
"allowJs": true
|
|
8
|
+
},
|
|
9
|
+
"include": ["**/*.test.js", "**/*.test.ts", "**/*.test.tsx", "**/*.d.ts"]
|
|
10
|
+
}
|