@simoncomputing/mui-bueno-v3 0.1.13 → 0.1.15

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.
Files changed (33) hide show
  1. package/README.md +70 -1
  2. package/dist/@types/index.d.ts +2 -0
  3. package/dist/components/Form/Inputs/Autocomplete/Autocomplete.d.ts +6 -6
  4. package/dist/components/Form/Inputs/Checkbox/Checkbox.d.ts +2 -2
  5. package/dist/components/Form/Inputs/CheckboxGroup/CheckboxGroup.d.ts +1 -1
  6. package/dist/components/Form/Inputs/FileUpload/FileUpload.d.ts +1 -1
  7. package/dist/components/Form/Inputs/RadioGroup/RadioGroup.d.ts +1 -1
  8. package/dist/components/Form/Inputs/RangeSlider/RangeSlider.d.ts +1 -1
  9. package/dist/components/Form/Inputs/Select/Select.d.ts +1 -1
  10. package/dist/components/Form/Inputs/TextField/TextField.d.ts +1 -1
  11. package/dist/components/Form/MForm/MForm.d.ts +12 -7
  12. package/dist/components/Form/MForm/MFormContext.d.ts +8 -0
  13. package/dist/components/Form/RepeatableFormGroup/RepeatableFormGroup.d.ts +3 -3
  14. package/dist/index.cjs.js +129 -131
  15. package/dist/index.css +1 -1
  16. package/dist/index.d.ts +0 -6
  17. package/dist/index.es.js +25144 -25907
  18. package/dist/index.umd.js +130 -132
  19. package/package.json +9 -10
  20. package/dist/components/Form/Inputs/CitationField/CitationBubbleMenuHandler.d.ts +0 -43
  21. package/dist/components/Form/Inputs/CitationField/CitationField.d.ts +0 -78
  22. package/dist/components/Form/Inputs/CitationField/CitationMenu/AttachmentForm.d.ts +0 -13
  23. package/dist/components/Form/Inputs/CitationField/CitationMenu/CitationBubbleMenu.d.ts +0 -25
  24. package/dist/components/Form/Inputs/CitationField/CitationMenu/CitationForm.d.ts +0 -12
  25. package/dist/components/Form/Inputs/CitationField/CitationMenu/CitationMenu.d.ts +0 -62
  26. package/dist/components/Form/Inputs/CitationField/CitationMenu/CitationTable.d.ts +0 -16
  27. package/dist/components/Form/Inputs/CitationField/CitationNode.d.ts +0 -2
  28. package/dist/components/Form/Inputs/CitationField/CitationNodeComponent.d.ts +0 -7
  29. package/dist/components/Form/Inputs/CitationField/CitationRefreshContext/CitationRefreshContext.d.ts +0 -29
  30. package/dist/components/Form/Inputs/CitationField/MenuButtonEditCitation.d.ts +0 -3
  31. package/dist/components/Form/Inputs/Location/Location.d.ts +0 -69
  32. package/dist/components/Form/Inputs/Location/Location.types.d.ts +0 -85
  33. package/dist/components/Form/Inputs/Location/LocationOption.d.ts +0 -38
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # MUI Bueno v3
2
2
 
3
- A React component library based on [Material UI](https://mui.com/material-ui) components with built-in support for [Formik](https://formik.org/). Rebuilt & redesigned based on the original [mui-bueno](https://www.npmjs.com/package/mui-bueno) library, and expanded to provide additional components beyond form components.
3
+ A React component library based on [Material UI](https://mui.com/material-ui) components with built-in support for [React Hook Form](https://react-hook-form.com/). Rebuilt & redesigned based on the original [mui-bueno](https://www.npmjs.com/package/@simoncomputing/mui-bueno-v3) library, and expanded to provide additional components beyond form components.
4
4
 
5
5
  ![SimonComputing Logo](https://simoncomputing.com/staging/img/sc-logo/SC_logo_scratched_bluer_mobile.png)
6
6
 
@@ -24,6 +24,75 @@ npm install mui-bueno-v3
24
24
  </MForm>
25
25
  ```
26
26
 
27
+ ## Running the Library Locally
28
+
29
+ To test locally before submitting to NPM, perform the following:
30
+
31
+ ```shell
32
+
33
+ rm -rf dist
34
+ npm run build:lib
35
+ npm pack
36
+
37
+ # will output something like: simoncomputing-mui-bueno-v3-0.1.14.tgz
38
+ ```
39
+
40
+ In the application repo:
41
+
42
+ ```shell
43
+ # Update package to look for this file in the proper directory.
44
+ npm i ~/git/mui-bueno-v3/simoncomputing-mui-bueno-v3-0.1.15.tgz
45
+
46
+ # Install
47
+ npm install
48
+
49
+ ## If you want a clean reinstall
50
+ rm -rf node_modules package-lock.json
51
+ npm install
52
+ ```
53
+
54
+ ## Deploying to NPM
55
+
56
+ #### Get an NPM Account
57
+
58
+ 1. Request an account from Simon, indicate you want to deploy mui-bueno-v3.
59
+
60
+ #### Log into NPM
61
+
62
+ 1. At command line, type: `npm login`
63
+ 1. You'll be prompted to press enter to open the browser.
64
+ 1. Finish your login process.
65
+ 1. You can now confirm you're logged in:
66
+
67
+ ```shell
68
+
69
+ # This should identify your user ID
70
+ npm whoami
71
+
72
+ # Logout
73
+ npm logout
74
+
75
+ # Running whoami again should return an error
76
+ npm whoami
77
+
78
+ # Log back in
79
+ npm login
80
+ ```
81
+
82
+ #### Run the build
83
+
84
+ Go into `package.json` and set `private` to `false`. Don't check this in as this is safety against accidental deployment.
85
+
86
+ ```shell
87
+ # Test with dry run
88
+ npm run publishLib:dryrun
89
+
90
+ # Run actual deployment
91
+ npm run publishLib
92
+ ```
93
+
94
+ Undo your change to `package.json`
95
+
27
96
  ## Documentation & Demo
28
97
 
29
98
  This project uses Storybook to document and demonstrate the components. _URL COMING SOON._
@@ -190,3 +190,5 @@ export type UnsavedCitation = {
190
190
  export type UnsavedAttachment = {
191
191
  file?: File;
192
192
  } & UnsavedCitation;
193
+
194
+ export type StoryFormValues = Record<string, any>;
@@ -1,7 +1,7 @@
1
1
  import { AutocompleteProps as MuiAutocompleteProps, TypographyProps } from '@mui/material';
2
2
  export type BaseAutocompleteProps<T> = {
3
3
  /**
4
- * Name of the component. Must match a key from initialValues in Formik.
4
+ * Name of the component. Must match a key from initialValues in react-hook-form.
5
5
  * @required
6
6
  */
7
7
  name: string;
@@ -38,7 +38,7 @@ export type BaseAutocompleteProps<T> = {
38
38
  /**
39
39
  * If true, an asterisk will be displayed next to the label
40
40
  * Most browsers will automatically validate this, but it's recommended to also
41
- * have Formik also validate as well so that `Error` displays for consistency.
41
+ * have react-hook-form also validate as well so that `Error` displays for consistency.
42
42
  * @default false
43
43
  */
44
44
  required?: boolean;
@@ -48,13 +48,13 @@ export type BaseAutocompleteProps<T> = {
48
48
  */
49
49
  clearOnSelect?: boolean;
50
50
  /**
51
- * When using Autocomplete with objects, this prop can be used to store only a property of that object in formik.
51
+ * When using Autocomplete with objects, this prop can be used to store only a property of that object in react-hook-form.
52
52
  *
53
53
  * For example, if you have `type User = { id: number; firstName: string; lastName: string; ... }`, you can
54
- * set useFieldAsValue="id" if you want formik to only store the user's id rather than the whole user object.
54
+ * set useFieldAsValue="id" if you want react-hook-form to only store the user's id rather than the whole user object.
55
55
  *
56
- * NOTE: This will require extra processing on the client-side compared to just using the object for the formik value
57
- * because the Autocomplete will have to search `options` for the object with the property matching formik's initial value.
56
+ * NOTE: This will require extra processing on the client-side compared to just using the object for the react-hook-form value
57
+ * because the Autocomplete will have to search `options` for the object with the property matching react-hook-form's initial value.
58
58
  *
59
59
  */
60
60
  useFieldAsValue?: string;
@@ -2,7 +2,7 @@ import { CheckboxProps as MuiCheckboxProps, TypographyProps } from '@mui/materia
2
2
  import * as React from "react";
3
3
  type BaseCheckboxProps = {
4
4
  /**
5
- * Must match a key from initialValues in Formik.
5
+ * Must match a key from initialValues in react-hook-form.
6
6
  * @required
7
7
  */
8
8
  name: string;
@@ -36,7 +36,7 @@ type BaseCheckboxProps = {
36
36
  /**
37
37
  * If true, an asterisk will be displayed next to the label
38
38
  * Most browsers will automatically validate this, but it's recommended to also
39
- * have Formik also validate as well so that `Error` displays for consistency.
39
+ * have react-hook-form also validate as well so that `Error` displays for consistency.
40
40
  * @default false
41
41
  */
42
42
  required?: boolean;
@@ -59,7 +59,7 @@ export type CheckboxGroupProps = {
59
59
  /**
60
60
  * If true, an asterisk will be displayed next to the label
61
61
  * Most browsers will automatically validate this, but it's recommended to also
62
- * have Formik also validate as well so that `Error` displays for consistency.
62
+ * have react-hook-form also validate as well so that `Error` displays for consistency.
63
63
  * @default false
64
64
  */
65
65
  required?: boolean;
@@ -2,7 +2,7 @@ import { TypographyProps } from '@mui/material';
2
2
  import * as React from 'react';
3
3
  export type FileUploadProps = {
4
4
  /**
5
- * Must match a key from initialValues in Formik.
5
+ * Must match a key from initialValues in react-hook-form.
6
6
  * @required
7
7
  */
8
8
  name: string;
@@ -86,7 +86,7 @@ type BaseRadioGroupProps<T> = {
86
86
  /**
87
87
  * If true, an asterisk will be displayed next to the label
88
88
  * Most browsers will automatically validate this, but it's recommended to also
89
- * have ( NOT Formik) also validate as well so that `Error` displays for consistency.
89
+ * have ( NOT react-hook-form) also validate as well so that `Error` displays for consistency.
90
90
  * @default false
91
91
  */
92
92
  required?: boolean;
@@ -2,7 +2,7 @@ import { SliderProps, TypographyProps } from '@mui/material';
2
2
  import * as React from 'react';
3
3
  type BaseRangeSliderProps = {
4
4
  /**
5
- * Must match a key from initialValues in Formik.
5
+ * Must match a key from initialValues in react-hook-form.
6
6
  * @required
7
7
  */
8
8
  name: string;
@@ -35,7 +35,7 @@ export interface SelectOption<T> {
35
35
  /**
36
36
  * If true, an asterisk will be displayed next to the label
37
37
  * Most browsers will automatically validate this, but it's recommended to also
38
- * have Formik also validate as well so that `Error` displays for consistency.
38
+ * have react-hook-form also validate as well so that `Error` displays for consistency.
39
39
  * @default false
40
40
  */
41
41
  required?: boolean;
@@ -2,7 +2,7 @@ import { TypographyProps, TextFieldProps as MuiTextFieldProps } from '@mui/mater
2
2
  import * as React from "react";
3
3
  type BaseTextFieldProps = {
4
4
  /**
5
- * Name and ID of the component. Must match a key from initialValues in Formik.
5
+ * Name and ID of the component. Must match a key from initialValues in react-hook-form.
6
6
  * @required
7
7
  */
8
8
  name: string;
@@ -1,19 +1,24 @@
1
+ import { default as React } from 'react';
1
2
  import { SubmitHandler, FieldValues, DefaultValues, FieldErrors, UseFormSetValue, UseFormReturn } from 'react-hook-form';
2
3
  import { AnyObjectSchema } from 'yup';
4
+ type MFormChildProps<T extends FieldValues> = {
5
+ values: T;
6
+ setValue: UseFormSetValue<T>;
7
+ methods: UseFormReturn<T>;
8
+ };
3
9
  type MFormProps<T extends FieldValues> = Readonly<{
4
10
  initialValues: DefaultValues<T>;
5
11
  initialErrors?: FieldErrors<T>;
6
- onSubmit: SubmitHandler<T>;
7
- children: React.ReactNode | ((props: {
8
- values: T;
9
- setValue: UseFormSetValue<T>;
10
- methods: UseFormReturn<T>;
11
- }) => React.ReactNode);
12
+ onSubmit: SubmitHandler<T> | ((values: T) => Promise<void>);
13
+ children: React.ReactNode | ((props: MFormChildProps<T>) => React.ReactNode);
12
14
  validationSchema?: AnyObjectSchema;
13
15
  shouldValidateOption?: boolean;
14
16
  shouldDirtyOption?: boolean;
15
17
  validationOnMount?: boolean;
16
18
  enableReinitialize?: boolean;
19
+ /** Automatically catch and apply 422 server errors (Axios-style). */
20
+ applyAxios422Errors?: boolean;
21
+ submitRef?: React.RefObject<(() => Promise<void>) | null>;
17
22
  }>;
18
- export declare function MForm<T extends FieldValues>({ initialValues, onSubmit, children, initialErrors, validationSchema, shouldValidateOption, shouldDirtyOption, validationOnMount, enableReinitialize }: MFormProps<T>): import("react/jsx-runtime").JSX.Element;
23
+ export declare function MForm<T extends FieldValues>({ initialValues, onSubmit, children, initialErrors, validationSchema, shouldValidateOption, shouldDirtyOption, validationOnMount, enableReinitialize, applyAxios422Errors, submitRef, }: MFormProps<T>): import("react/jsx-runtime").JSX.Element;
19
24
  export default MForm;
@@ -0,0 +1,8 @@
1
+ import * as React from 'react';
2
+ export type ServerErrorMap = Record<string, string>;
3
+ type MFormCtx = {
4
+ applyServerErrors: (errors: ServerErrorMap, focusFirst?: boolean) => void;
5
+ };
6
+ export declare const MFormContext: React.Context<MFormCtx | null>;
7
+ export declare function useMForm(): MFormCtx;
8
+ export {};
@@ -4,12 +4,12 @@ type RepeatableGroupWrapperType = 'card' | 'elevatedCard' | 'none';
4
4
  type RepeatableRemovePosition = 'bottom' | 'right';
5
5
  export type RepeatableFormGroupProps<T> = {
6
6
  /**
7
- * Name of field. Must match the name of the array in Formik.
7
+ * Name of field. Must match the name of the array in react-hook-form.
8
8
  */
9
9
  name: string;
10
10
  /**
11
11
  * An "empty" object of type T.
12
- * This is what you would normally pass to initialState for Formik for a single object of type T
12
+ * This is what you would normally pass to initialState for react-hook-form for a single object of type T
13
13
  */
14
14
  initialState: T;
15
15
  /**
@@ -83,7 +83,7 @@ export type RepeatableFormGroupProps<T> = {
83
83
  };
84
84
  /**
85
85
  * Repeatable Form Group is used for handling arrays in forms. It automatically handles adding & removing
86
- * field groups (components containing one or multiple fields) using Formik.
86
+ * field groups (components containing one or multiple fields) using react-hook-form.
87
87
  */
88
88
  export declare const RepeatableFormGroup: <T>(props: RepeatableFormGroupProps<T>) => import("react/jsx-runtime").JSX.Element;
89
89
  export default RepeatableFormGroup;