@iress-oss/ids-components 6.0.0-alpha.4 → 6.0.0-alpha.5
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/constants.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useContext as
|
|
3
|
-
import { a as
|
|
4
|
-
import { getErrorTypeMessage as
|
|
5
|
-
import { FormContext as
|
|
6
|
-
import { transformCustomRulesToValidateRule as
|
|
7
|
-
import { IressField as
|
|
1
|
+
import { jsx as I } from "react/jsx-runtime";
|
|
2
|
+
import { useContext as M, useRef as E, useMemo as f, useEffect as x } from "react";
|
|
3
|
+
import { a as _ } from "../../../index.esm-BiUTGNH8.js";
|
|
4
|
+
import { getErrorTypeMessage as $ } from "./helpers/getErrorTypeMessage.js";
|
|
5
|
+
import { FormContext as v } from "../FormContext.js";
|
|
6
|
+
import { transformCustomRulesToValidateRule as q } from "./helpers/transformCustomRulesToValidateRule.js";
|
|
7
|
+
import { IressField as S } from "../../../components/Field/Field.js";
|
|
8
8
|
import "../../../components/Field/Field.styles.js";
|
|
9
9
|
import "../../../components/Icon/Icon.styles.js";
|
|
10
10
|
import "../../../components/Field/FieldGroup/FieldGroup.styles.js";
|
|
11
11
|
import "../../../components/Label/Label.styles.js";
|
|
12
12
|
import { useFieldRenderProps as T } from "./hooks/useFieldRenderProps.js";
|
|
13
|
-
const
|
|
14
|
-
control:
|
|
13
|
+
const H = ({
|
|
14
|
+
control: d,
|
|
15
15
|
defaultValue: p,
|
|
16
16
|
name: r,
|
|
17
17
|
render: n,
|
|
@@ -20,47 +20,53 @@ const G = ({
|
|
|
20
20
|
readOnly: e,
|
|
21
21
|
...u
|
|
22
22
|
}) => {
|
|
23
|
-
const o =
|
|
23
|
+
const o = M(v), F = E(null);
|
|
24
24
|
if (!o)
|
|
25
25
|
throw new Error(
|
|
26
26
|
"IressFormField must be used inside an IressForm. If you need a standalone field, use IressField instead."
|
|
27
27
|
);
|
|
28
|
-
const m =
|
|
28
|
+
const m = f(() => {
|
|
29
29
|
if (!e)
|
|
30
|
-
return s ?
|
|
31
|
-
}, [e, s]), { field: c, fieldState: t } =
|
|
32
|
-
control:
|
|
30
|
+
return s ? q(s) : void 0;
|
|
31
|
+
}, [e, s]), { field: a, formState: c, fieldState: t } = _({
|
|
32
|
+
control: d,
|
|
33
33
|
defaultValue: p,
|
|
34
34
|
name: r,
|
|
35
35
|
rules: m,
|
|
36
36
|
shouldUnregister: l
|
|
37
|
-
}), i =
|
|
38
|
-
() => t.error ?
|
|
37
|
+
}), i = f(
|
|
38
|
+
() => t.error ? $(
|
|
39
39
|
t.error?.message,
|
|
40
40
|
t.error?.type,
|
|
41
41
|
s
|
|
42
42
|
) : "",
|
|
43
43
|
[t.error, s]
|
|
44
44
|
);
|
|
45
|
-
|
|
45
|
+
x(() => {
|
|
46
46
|
e ? o.setErrorMessage(r, "") : o.setErrorMessage(r, i);
|
|
47
47
|
}, [i, o, r, e]);
|
|
48
|
-
const
|
|
49
|
-
return /* @__PURE__ */
|
|
50
|
-
|
|
48
|
+
const g = T(a, F);
|
|
49
|
+
return /* @__PURE__ */ I(
|
|
50
|
+
S,
|
|
51
51
|
{
|
|
52
52
|
errorMessages: i && !e ? [{ message: i }] : void 0,
|
|
53
53
|
readOnly: e,
|
|
54
54
|
required: !!m?.required,
|
|
55
55
|
htmlFor: `${o.id}__${r}`,
|
|
56
56
|
...u,
|
|
57
|
-
children: n(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
children: n(
|
|
58
|
+
{
|
|
59
|
+
...g,
|
|
60
|
+
id: `${o.id}__${r}`
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
formState: c,
|
|
64
|
+
fieldState: t
|
|
65
|
+
}
|
|
66
|
+
)
|
|
61
67
|
}
|
|
62
68
|
);
|
|
63
69
|
};
|
|
64
70
|
export {
|
|
65
|
-
|
|
71
|
+
H as IressFormField
|
|
66
72
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
import { Control, ControllerRenderProps, FieldPath, FieldPathValue, FieldValues, UseControllerProps } from 'react-hook-form';
|
|
2
|
+
import { Control, ControllerFieldState, ControllerRenderProps, FieldPath, FieldPathValue, FieldValues, UseControllerProps, UseFormStateReturn } from 'react-hook-form';
|
|
3
3
|
import { CustomRules } from './helpers/transformCustomRulesToValidateRule';
|
|
4
4
|
import { IressFieldProps } from '../../../components/Field';
|
|
5
5
|
export interface IressFormFieldProps<T extends FieldValues = FieldValues, TName extends FieldPath<T> = FieldPath<T>> extends Omit<IressFieldProps, 'children' | 'htmlFor' | 'required'>, Omit<UseControllerProps<T, FieldPath<T>>, 'disabled'> {
|
|
@@ -22,7 +22,7 @@ export interface IressFormFieldProps<T extends FieldValues = FieldValues, TName
|
|
|
22
22
|
* To ensure the field is correctly registered with the form, the control must be passed as props to the rendered component.
|
|
23
23
|
* (eg. `render={field => <IressInput {...field} />}`)
|
|
24
24
|
*/
|
|
25
|
-
render: (field: FormFieldRenderProps<T>) => ReactNode;
|
|
25
|
+
render: (field: FormFieldRenderProps<T>, state: FormFieldRenderState<T>) => ReactNode;
|
|
26
26
|
/**
|
|
27
27
|
* Validation rules, including: required, min, max, minLength, maxLength, pattern, validate
|
|
28
28
|
* @see https://react-hook-form.com/api/useform/register)
|
|
@@ -47,6 +47,19 @@ export interface FormFieldRenderProps<T extends FieldValues> extends ControllerR
|
|
|
47
47
|
*/
|
|
48
48
|
id: string;
|
|
49
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Props for the `IressFormField` `render` prop, second argument.
|
|
52
|
+
*/
|
|
53
|
+
export interface FormFieldRenderState<T extends FieldValues> {
|
|
54
|
+
/**
|
|
55
|
+
* State of the field.
|
|
56
|
+
*/
|
|
57
|
+
fieldState?: ControllerFieldState;
|
|
58
|
+
/**
|
|
59
|
+
* State of the form.
|
|
60
|
+
*/
|
|
61
|
+
formState?: UseFormStateReturn<T>;
|
|
62
|
+
}
|
|
50
63
|
/**
|
|
51
64
|
* A `IressField` wrapper that can show error message and label automatically inside an `IressForm`.
|
|
52
65
|
* It uses the `useController` hook from `react-hook-form` for form management.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iress-oss/ids-components",
|
|
3
|
-
"version": "6.0.0-alpha.
|
|
3
|
+
"version": "6.0.0-alpha.5",
|
|
4
4
|
"description": "Iress React Component Library",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -99,5 +99,6 @@
|
|
|
99
99
|
"repository": {
|
|
100
100
|
"type": "git",
|
|
101
101
|
"url": "https://github.com/iress/design-system"
|
|
102
|
-
}
|
|
102
|
+
},
|
|
103
|
+
"stableVersion": "6.0.0-alpha.4"
|
|
103
104
|
}
|