@availity/mui-controlled-form 0.2.6 → 0.3.1
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 +14 -0
- package/README.md +2 -2
- package/dist/index.d.mts +122 -26
- package/dist/index.d.ts +122 -26
- package/dist/index.js +175 -132
- package/dist/index.mjs +175 -131
- package/package.json +2 -2
- package/src/index.ts +47 -0
- package/src/lib/AsyncAutocomplete.stories.tsx +21 -36
- package/src/lib/AsyncAutocomplete.test.tsx +17 -53
- package/src/lib/AsyncAutocomplete.tsx +13 -6
- package/src/lib/Autocomplete.stories.tsx +20 -33
- package/src/lib/Autocomplete.test.tsx +7 -37
- package/src/lib/Autocomplete.tsx +21 -16
- package/src/lib/Checkbox.stories.tsx +48 -46
- package/src/lib/Checkbox.test.tsx +14 -46
- package/src/lib/Checkbox.tsx +19 -16
- package/src/lib/CodesAutocomplete.stories.tsx +21 -35
- package/src/lib/CodesAutocomplete.test.tsx +20 -54
- package/src/lib/CodesAutocomplete.tsx +13 -6
- package/src/lib/ControlledForm.stories.tsx +1 -0
- package/src/lib/ControlledForm.tsx +7 -3
- package/src/lib/Datepicker.stories.tsx +19 -32
- package/src/lib/Datepicker.test.tsx +3 -35
- package/src/lib/Datepicker.tsx +18 -8
- package/src/lib/Input.stories.tsx +32 -38
- package/src/lib/Input.test.tsx +71 -7
- package/src/lib/Input.tsx +30 -15
- package/src/lib/OrganizationAutocomplete.stories.tsx +30 -35
- package/src/lib/OrganizationAutocomplete.test.tsx +23 -57
- package/src/lib/OrganizationAutocomplete.tsx +14 -9
- package/src/lib/ProviderAutocomplete.stories.tsx +20 -35
- package/src/lib/ProviderAutocomplete.test.tsx +29 -63
- package/src/lib/ProviderAutocomplete.tsx +11 -5
- package/src/lib/RadioGroup.stories.tsx +41 -36
- package/src/lib/RadioGroup.test.tsx +3 -35
- package/src/lib/RadioGroup.tsx +31 -20
- package/src/lib/Select.stories.tsx +66 -93
- package/src/lib/Select.test.tsx +8 -36
- package/src/lib/Select.tsx +30 -15
- package/src/lib/TextField.stories.tsx +26 -39
- package/src/lib/TextField.test.tsx +71 -5
- package/src/lib/TextField.tsx +33 -17
- package/src/lib/Types.tsx +2489 -0
- package/src/lib/UtilComponents.tsx +52 -0
- package/docs/propDefinitions.tsx +0 -31
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { FormHTMLAttributes } from "react";
|
|
2
|
+
import { Paper } from "@availity/mui-paper";
|
|
3
|
+
import { Typography } from "@availity/mui-typography";
|
|
4
|
+
import { Grid } from "@availity/mui-layout";
|
|
5
|
+
import { Button } from "@availity/mui-button";
|
|
6
|
+
import { useFormContext, FormProvider, UseFormProps, useForm, SubmitHandler } from "..";
|
|
7
|
+
|
|
8
|
+
export const SubmittedValues = () => {
|
|
9
|
+
const {
|
|
10
|
+
getValues,
|
|
11
|
+
formState: { isSubmitSuccessful },
|
|
12
|
+
} = useFormContext();
|
|
13
|
+
|
|
14
|
+
return isSubmitSuccessful ? (
|
|
15
|
+
<Paper sx={{ padding: '1.5rem', marginTop: '1.5rem' }}>
|
|
16
|
+
<Typography variant="h2">Submitted Values</Typography>
|
|
17
|
+
<pre data-testid="result">{JSON.stringify(getValues(), null, 2)}</pre>
|
|
18
|
+
</Paper>
|
|
19
|
+
) : null;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const Actions = () => {
|
|
23
|
+
const {
|
|
24
|
+
formState: { isSubmitSuccessful },
|
|
25
|
+
} = useFormContext();
|
|
26
|
+
return (
|
|
27
|
+
<Grid container direction="row" justifyContent="space-between">
|
|
28
|
+
<Button type="submit" disabled={isSubmitSuccessful} children="Submit" />
|
|
29
|
+
</Grid>
|
|
30
|
+
);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
type TestFormProviderProps = {
|
|
34
|
+
UseFormOptions?: UseFormProps;
|
|
35
|
+
/** This function will receive the form data if form validation is successful. */
|
|
36
|
+
onSubmit?: SubmitHandler<any>;
|
|
37
|
+
} & FormHTMLAttributes<HTMLFormElement>;
|
|
38
|
+
|
|
39
|
+
/** `FormProvider` and `form`, also adds `Actions` and `SubmittedValues` components */
|
|
40
|
+
export const TestForm = ({UseFormOptions, children, onSubmit = (data) => data, ...rest }: TestFormProviderProps) => {
|
|
41
|
+
const methods = useForm(UseFormOptions);
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<FormProvider {...methods}>
|
|
45
|
+
<form onSubmit={methods.handleSubmit(onSubmit)} noValidate {...rest}>
|
|
46
|
+
{children}
|
|
47
|
+
<Actions />
|
|
48
|
+
<SubmittedValues />
|
|
49
|
+
</form>
|
|
50
|
+
</FormProvider>
|
|
51
|
+
);
|
|
52
|
+
};
|
package/docs/propDefinitions.tsx
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
export const missingRHFprops = {
|
|
2
|
-
name: {
|
|
3
|
-
description: 'Unique name of your input.',
|
|
4
|
-
},
|
|
5
|
-
deps: {
|
|
6
|
-
description: 'Validation will be triggered for the dependent inputs, it only limited to register api not trigger.',
|
|
7
|
-
},
|
|
8
|
-
max: {
|
|
9
|
-
description: 'The maximum value to accept for this input.',
|
|
10
|
-
},
|
|
11
|
-
maxLength: {
|
|
12
|
-
description: 'The maximum length of the value to accept for this input.',
|
|
13
|
-
},
|
|
14
|
-
min: {
|
|
15
|
-
description: 'The minimum value to accept for this input.',
|
|
16
|
-
},
|
|
17
|
-
minLength: {
|
|
18
|
-
description: 'The minimum length of the value to accept for this input.',
|
|
19
|
-
},
|
|
20
|
-
pattern: {
|
|
21
|
-
description: 'The regex pattern for the input.',
|
|
22
|
-
},
|
|
23
|
-
shouldUnregister: {
|
|
24
|
-
description:
|
|
25
|
-
'Input will be unregistered after unmount and defaultValues will be removed as well. Note: this prop should be avoided when using with useFieldArray as unregister function gets called after input unmount/remount and reorder.',
|
|
26
|
-
},
|
|
27
|
-
required: {
|
|
28
|
-
description:
|
|
29
|
-
'A Boolean which, if true, indicates that the input must have a value before the form can be submitted. You can assign a string to return an error message in the errors object. Note: This config aligns with web constrained API for required input validation, for object or array type of input use validate function instead.',
|
|
30
|
-
},
|
|
31
|
-
};
|