@gridsuite/commons-ui 0.53.0 → 0.54.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/dist/components/react-hook-form/ExpandingTextField.d.ts +1 -1
- package/dist/components/react-hook-form/ExpandingTextField.js +4 -2
- package/dist/components/react-hook-form/autocomplete-input.js +3 -2
- package/dist/components/react-hook-form/directory-items-input.js +7 -6
- package/dist/components/react-hook-form/provider/custom-form-provider.d.ts +13 -0
- package/dist/components/react-hook-form/provider/custom-form-provider.js +25 -0
- package/dist/components/react-hook-form/provider/use-custom-form-context.d.ts +3 -0
- package/dist/components/react-hook-form/provider/use-custom-form-context.js +11 -0
- package/dist/components/react-hook-form/text-input.js +3 -2
- package/dist/components/react-hook-form/utils/functions.d.ts +0 -1
- package/dist/components/react-hook-form/utils/functions.js +0 -5
- package/dist/index.d.ts +3 -1
- package/dist/index.js +42 -38
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useState } from "react";
|
|
3
3
|
import { Typography } from "@mui/material";
|
|
4
|
-
import {
|
|
4
|
+
import { useWatch } from "react-hook-form";
|
|
5
5
|
import "../TreeViewFinder/TreeViewFinder.js";
|
|
6
6
|
import "../TopBar/TopBar.js";
|
|
7
7
|
import "../TopBar/GridLogo.js";
|
|
@@ -25,6 +25,8 @@ import "autosuggest-highlight/parse";
|
|
|
25
25
|
import "clsx";
|
|
26
26
|
import "../CardErrorBoundary/card-error-boundary.js";
|
|
27
27
|
import "notistack";
|
|
28
|
+
import { useCustomFormContext } from "./provider/use-custom-form-context.js";
|
|
29
|
+
import "./provider/custom-form-provider.js";
|
|
28
30
|
import "./autocomplete-input.js";
|
|
29
31
|
import TextInput from "./text-input.js";
|
|
30
32
|
import "./radio-input.js";
|
|
@@ -50,7 +52,7 @@ const ExpandingTextField = ({
|
|
|
50
52
|
...otherTexFieldProps
|
|
51
53
|
}) => {
|
|
52
54
|
const [isFocused, setIsFocused] = useState(false);
|
|
53
|
-
const { control } =
|
|
55
|
+
const { control } = useCustomFormContext();
|
|
54
56
|
const descriptionWatch = useWatch({
|
|
55
57
|
name,
|
|
56
58
|
control
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import PropTypes from "prop-types";
|
|
3
3
|
import { Autocomplete, TextField } from "@mui/material";
|
|
4
|
-
import {
|
|
4
|
+
import { useController } from "react-hook-form";
|
|
5
5
|
import { isFieldRequired, genHelperPreviousValue, genHelperError, identity } from "./utils/functions.js";
|
|
6
6
|
import FieldLabel from "./utils/field-label.js";
|
|
7
|
+
import { useCustomFormContext } from "./provider/use-custom-form-context.js";
|
|
7
8
|
const AutocompleteInput = ({
|
|
8
9
|
name,
|
|
9
10
|
label,
|
|
@@ -20,7 +21,7 @@ const AutocompleteInput = ({
|
|
|
20
21
|
formProps,
|
|
21
22
|
...props
|
|
22
23
|
}) => {
|
|
23
|
-
const { validationSchema, getValues, removeOptional } =
|
|
24
|
+
const { validationSchema, getValues, removeOptional } = useCustomFormContext();
|
|
24
25
|
const {
|
|
25
26
|
field: { onChange, value, ref },
|
|
26
27
|
fieldState: { error }
|
|
@@ -5,14 +5,15 @@ import { useSnackMessage } from "../../hooks/useSnackMessage.js";
|
|
|
5
5
|
import FieldLabel from "./utils/field-label.js";
|
|
6
6
|
import FolderIcon from "@mui/icons-material/Folder";
|
|
7
7
|
import { useMemo, useState, useCallback } from "react";
|
|
8
|
-
import { useFieldArray,
|
|
8
|
+
import { useFieldArray, useController } from "react-hook-form";
|
|
9
9
|
import { useIntl } from "react-intl";
|
|
10
10
|
import ErrorInput from "./error-management/error-input.js";
|
|
11
11
|
import MidFormError from "./error-management/mid-form-error.js";
|
|
12
12
|
import { RawReadOnlyInput } from "./raw-read-only-input.js";
|
|
13
13
|
import { mergeSx } from "../../utils/styles.js";
|
|
14
14
|
import DirectoryItemSelector from "../DirectoryItemSelector/directory-item-selector.js";
|
|
15
|
-
import {
|
|
15
|
+
import { useCustomFormContext } from "./provider/use-custom-form-context.js";
|
|
16
|
+
import { isFieldRequired } from "./utils/functions.js";
|
|
16
17
|
const NAME = "name";
|
|
17
18
|
const styles = {
|
|
18
19
|
formDirectoryElements1: {
|
|
@@ -72,8 +73,8 @@ const DirectoryItemsInput = ({
|
|
|
72
73
|
} = useFieldArray({
|
|
73
74
|
name
|
|
74
75
|
});
|
|
75
|
-
const formContext =
|
|
76
|
-
const { getValues } = formContext;
|
|
76
|
+
const formContext = useCustomFormContext();
|
|
77
|
+
const { getValues, validationSchema } = formContext;
|
|
77
78
|
const {
|
|
78
79
|
fieldState: { error }
|
|
79
80
|
} = useController({
|
|
@@ -122,9 +123,9 @@ const DirectoryItemsInput = ({
|
|
|
122
123
|
FieldLabel,
|
|
123
124
|
{
|
|
124
125
|
label,
|
|
125
|
-
optional: labelRequiredFromContext && !
|
|
126
|
+
optional: labelRequiredFromContext && !isFieldRequired(
|
|
126
127
|
name,
|
|
127
|
-
|
|
128
|
+
validationSchema,
|
|
128
129
|
getValues()
|
|
129
130
|
)
|
|
130
131
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { UseFormReturn } from 'react-hook-form';
|
|
2
|
+
import { default as React, PropsWithChildren } from 'react';
|
|
3
|
+
|
|
4
|
+
import * as yup from 'yup';
|
|
5
|
+
type CustomFormContextProps = {
|
|
6
|
+
removeOptional?: boolean;
|
|
7
|
+
validationSchema: yup.AnySchema;
|
|
8
|
+
};
|
|
9
|
+
export type MergedFormContextProps = UseFormReturn<any> & CustomFormContextProps;
|
|
10
|
+
type CustomFormProviderProps = PropsWithChildren<MergedFormContextProps>;
|
|
11
|
+
export declare const CustomFormContext: React.Context<CustomFormContextProps>;
|
|
12
|
+
declare const CustomFormProvider: (props: CustomFormProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
export default CustomFormProvider;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext } from "react";
|
|
3
|
+
import { FormProvider } from "react-hook-form";
|
|
4
|
+
import * as yup from "yup";
|
|
5
|
+
const CustomFormContext = createContext({
|
|
6
|
+
removeOptional: false,
|
|
7
|
+
validationSchema: yup.object()
|
|
8
|
+
});
|
|
9
|
+
const CustomFormProvider = (props) => {
|
|
10
|
+
const { validationSchema, removeOptional, children, ...formMethods } = props;
|
|
11
|
+
return /* @__PURE__ */ jsx(FormProvider, { ...formMethods, children: /* @__PURE__ */ jsx(
|
|
12
|
+
CustomFormContext.Provider,
|
|
13
|
+
{
|
|
14
|
+
value: {
|
|
15
|
+
validationSchema,
|
|
16
|
+
removeOptional
|
|
17
|
+
},
|
|
18
|
+
children
|
|
19
|
+
}
|
|
20
|
+
) });
|
|
21
|
+
};
|
|
22
|
+
export {
|
|
23
|
+
CustomFormContext,
|
|
24
|
+
CustomFormProvider as default
|
|
25
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useFormContext } from "react-hook-form";
|
|
2
|
+
import { useContext } from "react";
|
|
3
|
+
import { CustomFormContext } from "./custom-form-provider.js";
|
|
4
|
+
const useCustomFormContext = () => {
|
|
5
|
+
const formMethods = useFormContext();
|
|
6
|
+
const customFormMethods = useContext(CustomFormContext);
|
|
7
|
+
return { ...formMethods, ...customFormMethods };
|
|
8
|
+
};
|
|
9
|
+
export {
|
|
10
|
+
useCustomFormContext
|
|
11
|
+
};
|
|
@@ -2,10 +2,11 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import PropTypes from "prop-types";
|
|
3
3
|
import { InputAdornment, IconButton, TextField } from "@mui/material";
|
|
4
4
|
import { Clear } from "@mui/icons-material";
|
|
5
|
-
import {
|
|
5
|
+
import { useController } from "react-hook-form";
|
|
6
6
|
import TextFieldWithAdornment from "./utils/text-field-with-adornment.js";
|
|
7
7
|
import FieldLabel from "./utils/field-label.js";
|
|
8
8
|
import { isFieldRequired, genHelperPreviousValue, genHelperError, identity } from "./utils/functions.js";
|
|
9
|
+
import { useCustomFormContext } from "./provider/use-custom-form-context.js";
|
|
9
10
|
const TextInput = ({
|
|
10
11
|
name,
|
|
11
12
|
label,
|
|
@@ -24,7 +25,7 @@ const TextInput = ({
|
|
|
24
25
|
clearable,
|
|
25
26
|
formProps
|
|
26
27
|
}) => {
|
|
27
|
-
const { validationSchema, getValues, removeOptional } =
|
|
28
|
+
const { validationSchema, getValues, removeOptional } = useCustomFormContext();
|
|
28
29
|
const {
|
|
29
30
|
field: { onChange, value, ref },
|
|
30
31
|
fieldState: { error }
|
|
@@ -7,5 +7,4 @@ export function genHelperError(...errors: any[]): {
|
|
|
7
7
|
helperText?: undefined;
|
|
8
8
|
};
|
|
9
9
|
export function identity(x: any): any;
|
|
10
|
-
export function isFieldFromContextRequired(fieldName: any, formContext: any, values: any): boolean;
|
|
11
10
|
export function isFieldRequired(fieldName: any, schema: any, values: any): boolean;
|
|
@@ -22,10 +22,6 @@ function genHelperError(...errors) {
|
|
|
22
22
|
function identity(x) {
|
|
23
23
|
return x;
|
|
24
24
|
}
|
|
25
|
-
const isFieldFromContextRequired = (fieldName, formContext, values) => {
|
|
26
|
-
const { validationSchema } = formContext;
|
|
27
|
-
return isFieldRequired(fieldName, validationSchema, values);
|
|
28
|
-
};
|
|
29
25
|
const isFieldRequired = (fieldName, schema, values) => {
|
|
30
26
|
var _a;
|
|
31
27
|
const { schema: fieldSchema, parent: parentValues } = getIn(schema, fieldName, values) || {};
|
|
@@ -35,6 +31,5 @@ export {
|
|
|
35
31
|
genHelperError,
|
|
36
32
|
genHelperPreviousValue,
|
|
37
33
|
identity,
|
|
38
|
-
isFieldFromContextRequired,
|
|
39
34
|
isFieldRequired
|
|
40
35
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ButtonProps,
|
|
1
|
+
import { ButtonProps, CheckboxProps, RadioGroupProps, SwitchProps, SxProps, TextFieldProps } from '@mui/material';
|
|
2
2
|
import { AutocompleteProps } from '@mui/material/Autocomplete/Autocomplete';
|
|
3
3
|
import { FunctionComponent, ReactElement } from 'react';
|
|
4
4
|
|
|
@@ -91,6 +91,8 @@ export { default as directory_items_input_fr } from './components/translations/d
|
|
|
91
91
|
export { TagRenderer } from './components/ElementSearchDialog';
|
|
92
92
|
export { EquipmentItem } from './components/ElementSearchDialog/equipment-item';
|
|
93
93
|
export { useIntlRef } from './hooks/useIntlRef';
|
|
94
|
+
export { useCustomFormContext } from './components/react-hook-form/provider/use-custom-form-context';
|
|
95
|
+
export { default as CustomFormProvider } from './components/react-hook-form/provider/custom-form-provider';
|
|
94
96
|
export { default as SliderInput } from './components/react-hook-form/slider-input';
|
|
95
97
|
export { default as TextFieldWithAdornment } from './components/react-hook-form/utils/text-field-with-adornment';
|
|
96
98
|
export {
|
package/dist/index.js
CHANGED
|
@@ -47,79 +47,82 @@ import { default as default36 } from "./components/CardErrorBoundary/card-error-
|
|
|
47
47
|
import { useIntlRef } from "./hooks/useIntlRef.js";
|
|
48
48
|
import { useSnackMessage } from "./hooks/useSnackMessage.js";
|
|
49
49
|
import { useDebounce } from "./hooks/useDebounce.js";
|
|
50
|
-
import {
|
|
51
|
-
import { default as
|
|
52
|
-
import { default as
|
|
53
|
-
import { default as
|
|
54
|
-
import { default as
|
|
55
|
-
import { default as
|
|
56
|
-
import { default as
|
|
57
|
-
import { default as
|
|
58
|
-
import { default as
|
|
59
|
-
import { default as
|
|
60
|
-
import { default as
|
|
61
|
-
import { default as
|
|
62
|
-
import { default as
|
|
63
|
-
import { default as
|
|
64
|
-
import { default as
|
|
65
|
-
import { default as
|
|
66
|
-
import { default as
|
|
50
|
+
import { useCustomFormContext } from "./components/react-hook-form/provider/use-custom-form-context.js";
|
|
51
|
+
import { default as default37 } from "./components/react-hook-form/provider/custom-form-provider.js";
|
|
52
|
+
import { default as default38 } from "./components/react-hook-form/autocomplete-input.js";
|
|
53
|
+
import { default as default39 } from "./components/react-hook-form/text-input.js";
|
|
54
|
+
import { default as default40 } from "./components/react-hook-form/ExpandingTextField.js";
|
|
55
|
+
import { default as default41 } from "./components/react-hook-form/radio-input.js";
|
|
56
|
+
import { default as default42 } from "./components/react-hook-form/slider-input.js";
|
|
57
|
+
import { default as default43 } from "./components/react-hook-form/numbers/float-input.js";
|
|
58
|
+
import { default as default44 } from "./components/react-hook-form/numbers/integer-input.js";
|
|
59
|
+
import { default as default45 } from "./components/react-hook-form/select-input.js";
|
|
60
|
+
import { default as default46 } from "./components/react-hook-form/booleans/checkbox-input.js";
|
|
61
|
+
import { default as default47 } from "./components/react-hook-form/booleans/switch-input.js";
|
|
62
|
+
import { default as default48 } from "./components/react-hook-form/error-management/error-input.js";
|
|
63
|
+
import { default as default49 } from "./components/react-hook-form/error-management/field-error-alert.js";
|
|
64
|
+
import { default as default50 } from "./components/react-hook-form/error-management/mid-form-error.js";
|
|
65
|
+
import { default as default51 } from "./components/react-hook-form/utils/text-field-with-adornment.js";
|
|
66
|
+
import { default as default52 } from "./components/react-hook-form/utils/field-label.js";
|
|
67
|
+
import { default as default53 } from "./components/react-hook-form/utils/submit-button.js";
|
|
68
|
+
import { default as default54 } from "./components/react-hook-form/utils/cancel-button.js";
|
|
67
69
|
import { genHelperError, genHelperPreviousValue, identity, isFieldRequired } from "./components/react-hook-form/utils/functions.js";
|
|
68
|
-
import { default as
|
|
69
|
-
import { default as
|
|
70
|
+
import { default as default55 } from "./components/react-hook-form/directory-items-input.js";
|
|
71
|
+
import { default as default56 } from "./components/DirectoryItemSelector/directory-item-selector.js";
|
|
70
72
|
import { RawReadOnlyInput } from "./components/react-hook-form/raw-read-only-input.js";
|
|
71
73
|
import { UserManagerMock } from "./utils/UserManagerMock.js";
|
|
72
74
|
export {
|
|
73
75
|
default4 as AboutDialog,
|
|
74
76
|
default6 as AuthenticationRouter,
|
|
75
|
-
|
|
77
|
+
default38 as AutocompleteInput,
|
|
76
78
|
CHANGE_WAYS,
|
|
77
|
-
|
|
79
|
+
default54 as CancelButton,
|
|
78
80
|
default36 as CardErrorBoundary,
|
|
79
|
-
|
|
81
|
+
default46 as CheckboxInput,
|
|
82
|
+
default37 as CustomFormProvider,
|
|
80
83
|
DARK_THEME,
|
|
81
84
|
DEFAULT_CELL_PADDING,
|
|
82
85
|
DEFAULT_HEADER_HEIGHT,
|
|
83
86
|
DEFAULT_ROW_HEIGHT,
|
|
84
|
-
|
|
85
|
-
|
|
87
|
+
default56 as DirectoryItemSelector,
|
|
88
|
+
default55 as DirectoryItemsInput,
|
|
86
89
|
EQUIPMENT_TYPE,
|
|
87
90
|
default10 as ElementSearchDialog,
|
|
88
91
|
ElementType,
|
|
89
92
|
EquipmentItem,
|
|
90
93
|
EquipmentType,
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
94
|
+
default48 as ErrorInput,
|
|
95
|
+
default40 as ExpandingTextField,
|
|
96
|
+
default49 as FieldErrorAlert,
|
|
97
|
+
default52 as FieldLabel,
|
|
95
98
|
FlatParameters,
|
|
96
|
-
|
|
97
|
-
|
|
99
|
+
default43 as FloatInput,
|
|
100
|
+
default44 as IntegerInput,
|
|
98
101
|
KeyedColumnsRowIndexer,
|
|
99
102
|
LANG_ENGLISH,
|
|
100
103
|
LANG_FRENCH,
|
|
101
104
|
LANG_SYSTEM,
|
|
102
105
|
LIGHT_THEME,
|
|
103
106
|
LOGOUT_ERROR,
|
|
104
|
-
|
|
107
|
+
default50 as MidFormError,
|
|
105
108
|
default7 as MuiVirtualizedTable,
|
|
106
109
|
default11 as MultipleSelectionDialog,
|
|
107
110
|
OverflowableText,
|
|
108
111
|
RESET_AUTHENTICATION_ROUTER_ERROR,
|
|
109
|
-
|
|
112
|
+
default41 as RadioInput,
|
|
110
113
|
RawReadOnlyInput,
|
|
111
114
|
default8 as ReportViewer,
|
|
112
115
|
default9 as ReportViewerDialog,
|
|
113
116
|
SHOW_AUTH_INFO_LOGIN,
|
|
114
117
|
SIGNIN_CALLBACK_ERROR,
|
|
115
|
-
|
|
116
|
-
|
|
118
|
+
default45 as SelectInput,
|
|
119
|
+
default42 as SliderInput,
|
|
117
120
|
default5 as SnackbarProvider,
|
|
118
|
-
|
|
119
|
-
|
|
121
|
+
default53 as SubmitButton,
|
|
122
|
+
default47 as SwitchInput,
|
|
120
123
|
TagRenderer,
|
|
121
|
-
|
|
122
|
-
|
|
124
|
+
default51 as TextFieldWithAdornment,
|
|
125
|
+
default39 as TextInput,
|
|
123
126
|
default3 as TopBar,
|
|
124
127
|
default2 as TreeViewFinder,
|
|
125
128
|
UNAUTHORIZED_USER_INFO,
|
|
@@ -164,6 +167,7 @@ export {
|
|
|
164
167
|
default17 as top_bar_fr,
|
|
165
168
|
default20 as treeview_finder_en,
|
|
166
169
|
default21 as treeview_finder_fr,
|
|
170
|
+
useCustomFormContext,
|
|
167
171
|
useDebounce,
|
|
168
172
|
useIntlRef,
|
|
169
173
|
useSnackMessage
|