@public-ui/react-hook-form-adapter 4.0.0-alpha.0 → 4.0.0-alpha.10
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/README.md +8 -13
- package/dist/index.cjs +29 -37
- package/dist/index.d.cts +626 -111
- package/dist/index.d.mts +626 -111
- package/dist/index.d.ts +626 -111
- package/dist/index.mjs +30 -37
- package/package.json +14 -13
package/README.md
CHANGED
|
@@ -18,18 +18,13 @@ import { useForm } from 'react-hook-form';
|
|
|
18
18
|
import { KolInputTextController } from '@public-ui/react-hook-form-adapter';
|
|
19
19
|
|
|
20
20
|
const MyForm = () => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
rules={{ required: 'Please enter your name' }}
|
|
30
|
-
_label="First name"
|
|
31
|
-
/>
|
|
32
|
-
</form>
|
|
33
|
-
);
|
|
21
|
+
const { control, handleSubmit } = useForm({
|
|
22
|
+
defaultValues: { firstName: '' },
|
|
23
|
+
});
|
|
24
|
+
return (
|
|
25
|
+
<form onSubmit={handleSubmit(console.log)}>
|
|
26
|
+
<KolInputTextController name="firstName" control={control} rules={{ required: 'Please enter your name' }} _label="First name" />
|
|
27
|
+
</form>
|
|
28
|
+
);
|
|
34
29
|
};
|
|
35
30
|
```
|
package/dist/index.cjs
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const reactV19 = require('@public-ui/react-v19');
|
|
3
4
|
const React = require('react');
|
|
4
5
|
const reactHookForm = require('react-hook-form');
|
|
5
|
-
const reactV19 = require('@public-ui/react-v19');
|
|
6
6
|
|
|
7
7
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
8
8
|
|
|
9
9
|
const React__default = /*#__PURE__*/_interopDefaultCompat(React);
|
|
10
10
|
|
|
11
11
|
function withController(Component, valueProp) {
|
|
12
|
-
|
|
13
|
-
const { name, control, rules, defaultValue, ...
|
|
14
|
-
const userEventHandlers = props._on || {};
|
|
12
|
+
const ControllerWrapper = React__default.forwardRef((props, ref) => {
|
|
13
|
+
const { name, control, rules, defaultValue, shouldUnregister, disabled, ...componentProps } = props;
|
|
15
14
|
return /* @__PURE__ */ React__default.createElement(
|
|
16
15
|
reactHookForm.Controller,
|
|
17
16
|
{
|
|
@@ -19,58 +18,52 @@ function withController(Component, valueProp) {
|
|
|
19
18
|
control,
|
|
20
19
|
rules,
|
|
21
20
|
defaultValue,
|
|
21
|
+
shouldUnregister,
|
|
22
|
+
disabled,
|
|
22
23
|
render: ({ field, fieldState }) => {
|
|
23
|
-
const
|
|
24
|
-
|
|
24
|
+
const userHandlers = componentProps._on;
|
|
25
|
+
const mergedProps = {
|
|
26
|
+
...componentProps,
|
|
27
|
+
ref: (element) => {
|
|
28
|
+
if (ref) {
|
|
29
|
+
if (typeof ref === "function") ref(element);
|
|
30
|
+
else ref.current = element;
|
|
31
|
+
}
|
|
32
|
+
if (element) field.ref(element);
|
|
33
|
+
},
|
|
25
34
|
_name: name,
|
|
26
35
|
_touched: fieldState.isTouched,
|
|
27
|
-
_disabled:
|
|
36
|
+
_disabled: componentProps._disabled || disabled || field.disabled,
|
|
28
37
|
_msg: fieldState.error ? {
|
|
29
38
|
_type: "error",
|
|
30
|
-
_description:
|
|
39
|
+
_description: fieldState.error.message || String(fieldState.error)
|
|
31
40
|
} : void 0,
|
|
32
41
|
_on: {
|
|
33
|
-
...
|
|
34
|
-
onInput: (
|
|
42
|
+
...userHandlers || {},
|
|
43
|
+
onInput: (event, value) => {
|
|
35
44
|
field.onChange(value);
|
|
36
|
-
|
|
37
|
-
userEventHandlers.onInput(e, value);
|
|
38
|
-
}
|
|
45
|
+
userHandlers?.onInput?.(event, value);
|
|
39
46
|
},
|
|
40
|
-
onChange: (
|
|
47
|
+
onChange: (event, value) => {
|
|
41
48
|
field.onChange(value);
|
|
42
|
-
|
|
43
|
-
userEventHandlers.onChange(e, value);
|
|
44
|
-
}
|
|
49
|
+
userHandlers?.onChange?.(event, value);
|
|
45
50
|
},
|
|
46
|
-
onBlur: (
|
|
51
|
+
onBlur: (event) => {
|
|
47
52
|
field.onBlur();
|
|
48
|
-
|
|
49
|
-
userEventHandlers.onBlur(e);
|
|
50
|
-
}
|
|
53
|
+
userHandlers?.onBlur?.(event);
|
|
51
54
|
}
|
|
52
55
|
}
|
|
53
56
|
};
|
|
54
57
|
if (valueProp) {
|
|
55
|
-
|
|
58
|
+
mergedProps[valueProp] = field.value;
|
|
56
59
|
}
|
|
57
|
-
return /* @__PURE__ */ React__default.createElement(
|
|
58
|
-
Component,
|
|
59
|
-
{
|
|
60
|
-
ref: (e) => {
|
|
61
|
-
if (ref) {
|
|
62
|
-
if (typeof ref === "function") ref(e);
|
|
63
|
-
else ref.current = e;
|
|
64
|
-
}
|
|
65
|
-
if (e && field.ref) field.ref(e);
|
|
66
|
-
},
|
|
67
|
-
...componentProps
|
|
68
|
-
}
|
|
69
|
-
);
|
|
60
|
+
return /* @__PURE__ */ React__default.createElement(Component, { ...mergedProps });
|
|
70
61
|
}
|
|
71
62
|
}
|
|
72
63
|
);
|
|
73
64
|
});
|
|
65
|
+
ControllerWrapper.displayName = `withController(${Component.displayName || Component.name || "Component"})`;
|
|
66
|
+
return ControllerWrapper;
|
|
74
67
|
}
|
|
75
68
|
const KolInputTextController = withController(reactV19.KolInputText, "_value");
|
|
76
69
|
const KolInputPasswordController = withController(reactV19.KolInputPassword, "_value");
|
|
@@ -79,7 +72,7 @@ const KolInputNumberController = withController(reactV19.KolInputNumber, "_value
|
|
|
79
72
|
const KolInputRangeController = withController(reactV19.KolInputRange, "_value");
|
|
80
73
|
const KolInputDateController = withController(reactV19.KolInputDate, "_value");
|
|
81
74
|
const KolInputColorController = withController(reactV19.KolInputColor, "_value");
|
|
82
|
-
const KolInputFileController = withController(reactV19.KolInputFile
|
|
75
|
+
const KolInputFileController = withController(reactV19.KolInputFile);
|
|
83
76
|
const KolTextareaController = withController(reactV19.KolTextarea, "_value");
|
|
84
77
|
const KolComboboxController = withController(reactV19.KolCombobox, "_value");
|
|
85
78
|
const KolSelectController = withController(reactV19.KolSelect, "_value");
|
|
@@ -101,4 +94,3 @@ exports.KolInputTextController = KolInputTextController;
|
|
|
101
94
|
exports.KolSelectController = KolSelectController;
|
|
102
95
|
exports.KolSingleSelectController = KolSingleSelectController;
|
|
103
96
|
exports.KolTextareaController = KolTextareaController;
|
|
104
|
-
exports.withController = withController;
|