rsuite 5.59.3-alpha.1 → 5.60.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/Animation/styles/fade.less +1 -1
- package/Animation/styles/index.css +1 -1
- package/CHANGELOG.md +16 -0
- package/TagInput/styles/index.css +24 -24
- package/TagPicker/styles/index.css +24 -24
- package/TagPicker/styles/index.less +11 -10
- package/cjs/Form/Form.d.ts +13 -9
- package/cjs/Form/Form.js +55 -11
- package/cjs/Form/FormContext.d.ts +2 -2
- package/cjs/Form/hooks/useFormRef.d.ts +9 -7
- package/cjs/Form/hooks/useFormRef.js +5 -32
- package/cjs/Form/hooks/useFormValidate.d.ts +6 -4
- package/cjs/Form/hooks/useFormValidate.js +18 -12
- package/cjs/Form/hooks/useFormValue.d.ts +8 -1
- package/cjs/Form/hooks/useFormValue.js +7 -1
- package/cjs/InputPicker/InputAutosize.js +2 -2
- package/cjs/InputPicker/InputPicker.d.ts +5 -7
- package/cjs/InputPicker/InputPicker.js +119 -151
- package/cjs/InputPicker/InputPickerContext.d.ts +11 -3
- package/cjs/InputPicker/InputPickerContext.js +7 -1
- package/cjs/InputPicker/hooks/useData.d.ts +17 -0
- package/cjs/InputPicker/hooks/useData.js +44 -0
- package/cjs/InputPicker/hooks/useInput.d.ts +21 -0
- package/cjs/InputPicker/hooks/useInput.js +46 -0
- package/cjs/InputPicker/hooks/useMaxWidth.d.ts +4 -0
- package/cjs/InputPicker/hooks/useMaxWidth.js +25 -0
- package/cjs/InputPicker/index.d.ts +2 -1
- package/cjs/InputPicker/utils.d.ts +1 -0
- package/cjs/InputPicker/utils.js +17 -0
- package/cjs/TagInput/index.js +2 -2
- package/cjs/TagPicker/index.js +2 -2
- package/dist/rsuite-no-reset-rtl.css +25 -25
- package/dist/rsuite-no-reset-rtl.min.css +1 -1
- package/dist/rsuite-no-reset-rtl.min.css.map +1 -1
- package/dist/rsuite-no-reset.css +25 -25
- package/dist/rsuite-no-reset.min.css +1 -1
- package/dist/rsuite-no-reset.min.css.map +1 -1
- package/dist/rsuite-rtl.css +25 -25
- package/dist/rsuite-rtl.min.css +1 -1
- package/dist/rsuite-rtl.min.css.map +1 -1
- package/dist/rsuite.css +25 -25
- package/dist/rsuite.js +53 -9
- package/dist/rsuite.js.map +1 -1
- package/dist/rsuite.min.css +1 -1
- package/dist/rsuite.min.css.map +1 -1
- package/dist/rsuite.min.js +1 -1
- package/dist/rsuite.min.js.map +1 -1
- package/esm/Form/Form.d.ts +13 -9
- package/esm/Form/Form.js +55 -11
- package/esm/Form/FormContext.d.ts +2 -2
- package/esm/Form/hooks/useFormRef.d.ts +9 -7
- package/esm/Form/hooks/useFormRef.js +5 -32
- package/esm/Form/hooks/useFormValidate.d.ts +6 -4
- package/esm/Form/hooks/useFormValidate.js +18 -12
- package/esm/Form/hooks/useFormValue.d.ts +8 -1
- package/esm/Form/hooks/useFormValue.js +7 -1
- package/esm/InputPicker/InputAutosize.js +2 -2
- package/esm/InputPicker/InputPicker.d.ts +5 -7
- package/esm/InputPicker/InputPicker.js +111 -143
- package/esm/InputPicker/InputPickerContext.d.ts +11 -3
- package/esm/InputPicker/InputPickerContext.js +4 -0
- package/esm/InputPicker/hooks/useData.d.ts +17 -0
- package/esm/InputPicker/hooks/useData.js +38 -0
- package/esm/InputPicker/hooks/useInput.d.ts +21 -0
- package/esm/InputPicker/hooks/useInput.js +40 -0
- package/esm/InputPicker/hooks/useMaxWidth.d.ts +4 -0
- package/esm/InputPicker/hooks/useMaxWidth.js +19 -0
- package/esm/InputPicker/index.d.ts +2 -1
- package/esm/InputPicker/utils.d.ts +1 -0
- package/esm/InputPicker/utils.js +12 -0
- package/esm/TagInput/index.js +2 -2
- package/esm/TagPicker/index.js +2 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
# [5.60.0](https://github.com/rsuite/rsuite/compare/v5.59.2...v5.60.0) (2024-04-26)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **Fade:** fix Picker not working in Drawer without backdrop ([#3759](https://github.com/rsuite/rsuite/issues/3759)) ([930a321](https://github.com/rsuite/rsuite/commit/930a3212b58202f4d0bf05a8bb191195944d589c))
|
|
7
|
+
* **TagPicker:** fix misalignment of large size tag with textbox ([#3755](https://github.com/rsuite/rsuite/issues/3755)) ([2bcd793](https://github.com/rsuite/rsuite/commit/2bcd793cd7cf1b181643125fe92f4ffb0e18f771))
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
* **Form:** add support for onSubmit and onReset ([#3750](https://github.com/rsuite/rsuite/issues/3750)) ([d9b747e](https://github.com/rsuite/rsuite/commit/d9b747e97f3aaaa1d0b047ab81150d2a01764ed1))
|
|
13
|
+
* **TagPicker:** fix text flicker when entering ([#3758](https://github.com/rsuite/rsuite/issues/3758)) ([f7058d1](https://github.com/rsuite/rsuite/commit/f7058d1e9234e43c9f8d7884636a09d83f40fcb9))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
1
17
|
## [5.59.2](https://github.com/rsuite/rsuite/compare/v5.59.1...v5.59.2) (2024-04-19)
|
|
2
18
|
|
|
3
19
|
|
|
@@ -3610,30 +3610,6 @@ textarea.rs-picker-search-input {
|
|
|
3610
3610
|
.rs-plaintext .rs-tag {
|
|
3611
3611
|
margin: 0;
|
|
3612
3612
|
}
|
|
3613
|
-
.rs-picker-tag-lg .rs-picker-textbox {
|
|
3614
|
-
padding-bottom: 6px;
|
|
3615
|
-
}
|
|
3616
|
-
.rs-picker-tag-lg .rs-picker-textbox .rs-picker-search-input {
|
|
3617
|
-
padding-left: 16px;
|
|
3618
|
-
margin-top: 6px;
|
|
3619
|
-
font-size: 16px;
|
|
3620
|
-
}
|
|
3621
|
-
.rs-picker-tag-lg .rs-picker-textbox input {
|
|
3622
|
-
height: 20px;
|
|
3623
|
-
}
|
|
3624
|
-
.rs-picker-tag-lg .rs-picker-toggle {
|
|
3625
|
-
padding-top: 8px;
|
|
3626
|
-
padding-bottom: 8px;
|
|
3627
|
-
-webkit-box-shadow: none;
|
|
3628
|
-
box-shadow: none;
|
|
3629
|
-
}
|
|
3630
|
-
.rs-picker-tag-lg .rs-picker-textbox {
|
|
3631
|
-
min-height: 40px;
|
|
3632
|
-
}
|
|
3633
|
-
.rs-picker-tag-lg .rs-picker-tag-list .rs-tag-lg {
|
|
3634
|
-
margin-top: 6px;
|
|
3635
|
-
margin-left: 6px;
|
|
3636
|
-
}
|
|
3637
3613
|
.rs-picker-tag .rs-picker-textbox,
|
|
3638
3614
|
.rs-picker-tag-md .rs-picker-textbox {
|
|
3639
3615
|
padding-bottom: 5px;
|
|
@@ -3660,6 +3636,30 @@ textarea.rs-picker-search-input {
|
|
|
3660
3636
|
margin-top: 5px;
|
|
3661
3637
|
margin-left: 5px;
|
|
3662
3638
|
}
|
|
3639
|
+
.rs-picker-tag-lg .rs-picker-textbox {
|
|
3640
|
+
padding-bottom: 7px;
|
|
3641
|
+
}
|
|
3642
|
+
.rs-picker-tag-lg .rs-picker-textbox .rs-picker-search-input {
|
|
3643
|
+
padding-left: 16px;
|
|
3644
|
+
margin-top: 7px;
|
|
3645
|
+
font-size: 16px;
|
|
3646
|
+
}
|
|
3647
|
+
.rs-picker-tag-lg .rs-picker-textbox input {
|
|
3648
|
+
height: 20px;
|
|
3649
|
+
}
|
|
3650
|
+
.rs-picker-tag-lg .rs-picker-toggle {
|
|
3651
|
+
padding-top: 9px;
|
|
3652
|
+
padding-bottom: 9px;
|
|
3653
|
+
-webkit-box-shadow: none;
|
|
3654
|
+
box-shadow: none;
|
|
3655
|
+
}
|
|
3656
|
+
.rs-picker-tag-lg .rs-picker-textbox {
|
|
3657
|
+
min-height: 40px;
|
|
3658
|
+
}
|
|
3659
|
+
.rs-picker-tag-lg .rs-picker-tag-list .rs-tag-lg {
|
|
3660
|
+
margin-top: 6px;
|
|
3661
|
+
margin-left: 6px;
|
|
3662
|
+
}
|
|
3663
3663
|
.rs-picker-tag-sm .rs-picker-textbox {
|
|
3664
3664
|
padding-bottom: 2px;
|
|
3665
3665
|
}
|
|
@@ -3610,30 +3610,6 @@ textarea.rs-picker-search-input {
|
|
|
3610
3610
|
.rs-plaintext .rs-tag {
|
|
3611
3611
|
margin: 0;
|
|
3612
3612
|
}
|
|
3613
|
-
.rs-picker-tag-lg .rs-picker-textbox {
|
|
3614
|
-
padding-bottom: 6px;
|
|
3615
|
-
}
|
|
3616
|
-
.rs-picker-tag-lg .rs-picker-textbox .rs-picker-search-input {
|
|
3617
|
-
padding-left: 16px;
|
|
3618
|
-
margin-top: 6px;
|
|
3619
|
-
font-size: 16px;
|
|
3620
|
-
}
|
|
3621
|
-
.rs-picker-tag-lg .rs-picker-textbox input {
|
|
3622
|
-
height: 20px;
|
|
3623
|
-
}
|
|
3624
|
-
.rs-picker-tag-lg .rs-picker-toggle {
|
|
3625
|
-
padding-top: 8px;
|
|
3626
|
-
padding-bottom: 8px;
|
|
3627
|
-
-webkit-box-shadow: none;
|
|
3628
|
-
box-shadow: none;
|
|
3629
|
-
}
|
|
3630
|
-
.rs-picker-tag-lg .rs-picker-textbox {
|
|
3631
|
-
min-height: 40px;
|
|
3632
|
-
}
|
|
3633
|
-
.rs-picker-tag-lg .rs-picker-tag-list .rs-tag-lg {
|
|
3634
|
-
margin-top: 6px;
|
|
3635
|
-
margin-left: 6px;
|
|
3636
|
-
}
|
|
3637
3613
|
.rs-picker-tag .rs-picker-textbox,
|
|
3638
3614
|
.rs-picker-tag-md .rs-picker-textbox {
|
|
3639
3615
|
padding-bottom: 5px;
|
|
@@ -3660,6 +3636,30 @@ textarea.rs-picker-search-input {
|
|
|
3660
3636
|
margin-top: 5px;
|
|
3661
3637
|
margin-left: 5px;
|
|
3662
3638
|
}
|
|
3639
|
+
.rs-picker-tag-lg .rs-picker-textbox {
|
|
3640
|
+
padding-bottom: 7px;
|
|
3641
|
+
}
|
|
3642
|
+
.rs-picker-tag-lg .rs-picker-textbox .rs-picker-search-input {
|
|
3643
|
+
padding-left: 16px;
|
|
3644
|
+
margin-top: 7px;
|
|
3645
|
+
font-size: 16px;
|
|
3646
|
+
}
|
|
3647
|
+
.rs-picker-tag-lg .rs-picker-textbox input {
|
|
3648
|
+
height: 20px;
|
|
3649
|
+
}
|
|
3650
|
+
.rs-picker-tag-lg .rs-picker-toggle {
|
|
3651
|
+
padding-top: 9px;
|
|
3652
|
+
padding-bottom: 9px;
|
|
3653
|
+
-webkit-box-shadow: none;
|
|
3654
|
+
box-shadow: none;
|
|
3655
|
+
}
|
|
3656
|
+
.rs-picker-tag-lg .rs-picker-textbox {
|
|
3657
|
+
min-height: 40px;
|
|
3658
|
+
}
|
|
3659
|
+
.rs-picker-tag-lg .rs-picker-tag-list .rs-tag-lg {
|
|
3660
|
+
margin-top: 6px;
|
|
3661
|
+
margin-left: 6px;
|
|
3662
|
+
}
|
|
3663
3663
|
.rs-picker-tag-sm .rs-picker-textbox {
|
|
3664
3664
|
padding-bottom: 2px;
|
|
3665
3665
|
}
|
|
@@ -67,16 +67,6 @@
|
|
|
67
67
|
|
|
68
68
|
// Tag Picker Size
|
|
69
69
|
// --------------------------------------------------
|
|
70
|
-
.rs-picker-tag-lg {
|
|
71
|
-
.rs-tag-picker-size(@padding-y-lg - 1; @padding-x-lg; @font-size-large; @line-height-large);
|
|
72
|
-
.rs-picker-textbox {
|
|
73
|
-
min-height: 40px;
|
|
74
|
-
}
|
|
75
|
-
.rs-picker-tag-list .rs-tag-lg {
|
|
76
|
-
margin-top: 6px;
|
|
77
|
-
margin-left: 6px;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
70
|
|
|
81
71
|
// Default size
|
|
82
72
|
.rs-picker-tag,
|
|
@@ -88,6 +78,17 @@
|
|
|
88
78
|
}
|
|
89
79
|
}
|
|
90
80
|
|
|
81
|
+
.rs-picker-tag-lg {
|
|
82
|
+
.rs-tag-picker-size(@padding-y-lg; @padding-x-lg; @font-size-large; @line-height-large);
|
|
83
|
+
.rs-picker-textbox {
|
|
84
|
+
min-height: 40px;
|
|
85
|
+
}
|
|
86
|
+
.rs-picker-tag-list .rs-tag-lg {
|
|
87
|
+
margin-top: 6px;
|
|
88
|
+
margin-left: 6px;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
91
92
|
.rs-picker-tag-sm {
|
|
92
93
|
.rs-tag-picker-size(@padding-y-sm; @padding-x-sm; @font-size-base; @line-height-base);
|
|
93
94
|
.rs-picker-textbox {
|
package/cjs/Form/Form.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { FormHTMLAttributes } from 'react';
|
|
2
2
|
import { Schema } from 'schema-typed';
|
|
3
3
|
import FormControl from '../FormControl';
|
|
4
4
|
import FormControlLabel from '../FormControlLabel';
|
|
@@ -7,9 +7,9 @@ import FormGroup from '../FormGroup';
|
|
|
7
7
|
import FormHelpText from '../FormHelpText';
|
|
8
8
|
import { WithAsProps, TypeAttributes, RsRefForwardingComponent } from '../@types/common';
|
|
9
9
|
import { FormInstance } from './hooks/useFormRef';
|
|
10
|
-
export interface FormProps<
|
|
11
|
-
[P in keyof
|
|
12
|
-
}> extends WithAsProps, Omit<
|
|
10
|
+
export interface FormProps<V = Record<string, any>, M = any, E = {
|
|
11
|
+
[P in keyof V]?: M;
|
|
12
|
+
}> extends WithAsProps, Omit<FormHTMLAttributes<HTMLFormElement>, 'onChange' | 'onSubmit' | 'onError' | 'onReset'> {
|
|
13
13
|
/**
|
|
14
14
|
* Set the left and right columns of the layout of the elements within the form。
|
|
15
15
|
*
|
|
@@ -23,11 +23,11 @@ export interface FormProps<T = Record<string, any>, errorMsgType = any, E = {
|
|
|
23
23
|
/**
|
|
24
24
|
* Current value of the input. Creates a controlled component
|
|
25
25
|
*/
|
|
26
|
-
formValue?:
|
|
26
|
+
formValue?: V | null;
|
|
27
27
|
/**
|
|
28
28
|
* Initial value
|
|
29
29
|
*/
|
|
30
|
-
formDefaultValue?:
|
|
30
|
+
formDefaultValue?: V | null;
|
|
31
31
|
/**
|
|
32
32
|
* Error message of form
|
|
33
33
|
*/
|
|
@@ -77,7 +77,7 @@ export interface FormProps<T = Record<string, any>, errorMsgType = any, E = {
|
|
|
77
77
|
/**
|
|
78
78
|
* Callback fired when data changing
|
|
79
79
|
*/
|
|
80
|
-
onChange?: (formValue:
|
|
80
|
+
onChange?: (formValue: V, event?: React.SyntheticEvent) => void;
|
|
81
81
|
/**
|
|
82
82
|
* Callback fired when error checking
|
|
83
83
|
*/
|
|
@@ -87,9 +87,13 @@ export interface FormProps<T = Record<string, any>, errorMsgType = any, E = {
|
|
|
87
87
|
*/
|
|
88
88
|
onCheck?: (formError: E) => void;
|
|
89
89
|
/**
|
|
90
|
-
* Callback fired when form submit
|
|
90
|
+
* Callback fired when form submit,only when the form data is validated will trigger
|
|
91
91
|
*/
|
|
92
|
-
onSubmit?: (
|
|
92
|
+
onSubmit?: (formValue: V | null, event?: React.FormEvent<HTMLFormElement>) => void;
|
|
93
|
+
/**
|
|
94
|
+
* Callback fired when form reset
|
|
95
|
+
*/
|
|
96
|
+
onReset?: (formValue: V | null, event?: React.FormEvent<HTMLFormElement>) => void;
|
|
93
97
|
}
|
|
94
98
|
export interface FormComponent extends RsRefForwardingComponent<'form', FormProps & {
|
|
95
99
|
ref?: React.Ref<FormInstance>;
|
package/cjs/Form/Form.js
CHANGED
|
@@ -21,6 +21,7 @@ var _useSchemaModel2 = _interopRequireDefault(require("./hooks/useSchemaModel"))
|
|
|
21
21
|
var _useFormValidate2 = _interopRequireDefault(require("./hooks/useFormValidate"));
|
|
22
22
|
var _useFormValue2 = _interopRequireDefault(require("./hooks/useFormValue"));
|
|
23
23
|
var _useFormClassNames = _interopRequireDefault(require("./hooks/useFormClassNames"));
|
|
24
|
+
var _useFormRef = _interopRequireDefault(require("./hooks/useFormRef"));
|
|
24
25
|
var defaultSchema = (0, _schemaTyped.SchemaModel)({});
|
|
25
26
|
|
|
26
27
|
/**
|
|
@@ -51,10 +52,11 @@ var Form = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
|
|
|
51
52
|
children = props.children,
|
|
52
53
|
disabled = props.disabled,
|
|
53
54
|
onSubmit = props.onSubmit,
|
|
55
|
+
onReset = props.onReset,
|
|
54
56
|
onCheck = props.onCheck,
|
|
55
57
|
onError = props.onError,
|
|
56
58
|
onChange = props.onChange,
|
|
57
|
-
rest = (0, _objectWithoutPropertiesLoose2.default)(props, ["checkTrigger", "classPrefix", "errorFromContext", "formDefaultValue", "formValue", "formError", "fluid", "nestedField", "layout", "model", "readOnly", "plaintext", "className", "children", "disabled", "onSubmit", "onCheck", "onError", "onChange"]);
|
|
59
|
+
rest = (0, _objectWithoutPropertiesLoose2.default)(props, ["checkTrigger", "classPrefix", "errorFromContext", "formDefaultValue", "formValue", "formError", "fluid", "nestedField", "layout", "model", "readOnly", "plaintext", "className", "children", "disabled", "onSubmit", "onReset", "onCheck", "onError", "onChange"]);
|
|
58
60
|
var _useSchemaModel = (0, _useSchemaModel2.default)(formModel),
|
|
59
61
|
getCombinedModel = _useSchemaModel.getCombinedModel,
|
|
60
62
|
pushFieldRule = _useSchemaModel.pushFieldRule,
|
|
@@ -65,9 +67,9 @@ var Form = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
|
|
|
65
67
|
}),
|
|
66
68
|
formValue = _useFormValue.formValue,
|
|
67
69
|
onRemoveValue = _useFormValue.onRemoveValue,
|
|
68
|
-
setFieldValue = _useFormValue.setFieldValue
|
|
70
|
+
setFieldValue = _useFormValue.setFieldValue,
|
|
71
|
+
resetFormValue = _useFormValue.resetFormValue;
|
|
69
72
|
var formValidateProps = {
|
|
70
|
-
ref: ref,
|
|
71
73
|
formValue: formValue,
|
|
72
74
|
getCombinedModel: getCombinedModel,
|
|
73
75
|
onCheck: onCheck,
|
|
@@ -79,7 +81,12 @@ var Form = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
|
|
|
79
81
|
setFieldError = _useFormValidate.setFieldError,
|
|
80
82
|
onRemoveError = _useFormValidate.onRemoveError,
|
|
81
83
|
check = _useFormValidate.check,
|
|
82
|
-
|
|
84
|
+
checkAsync = _useFormValidate.checkAsync,
|
|
85
|
+
checkForField = _useFormValidate.checkForField,
|
|
86
|
+
checkForFieldAsync = _useFormValidate.checkForFieldAsync,
|
|
87
|
+
cleanErrors = _useFormValidate.cleanErrors,
|
|
88
|
+
resetErrors = _useFormValidate.resetErrors,
|
|
89
|
+
cleanErrorForField = _useFormValidate.cleanErrorForField;
|
|
83
90
|
var classes = (0, _useFormClassNames.default)({
|
|
84
91
|
classPrefix: classPrefix,
|
|
85
92
|
className: className,
|
|
@@ -89,22 +96,58 @@ var Form = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
|
|
|
89
96
|
plaintext: plaintext,
|
|
90
97
|
disabled: disabled
|
|
91
98
|
});
|
|
92
|
-
var
|
|
93
|
-
|
|
94
|
-
|
|
99
|
+
var submit = (0, _utils.useEventCallback)(function (event) {
|
|
100
|
+
// Check the form before submitting
|
|
101
|
+
if (check()) {
|
|
102
|
+
onSubmit === null || onSubmit === void 0 ? void 0 : onSubmit(formValue, event);
|
|
103
|
+
}
|
|
95
104
|
});
|
|
96
|
-
var
|
|
97
|
-
|
|
105
|
+
var reset = (0, _utils.useEventCallback)(function (event) {
|
|
106
|
+
resetErrors();
|
|
107
|
+
onReset === null || onReset === void 0 ? void 0 : onReset(resetFormValue(), event);
|
|
98
108
|
});
|
|
99
109
|
var handleSubmit = (0, _utils.useEventCallback)(function (event) {
|
|
100
110
|
var _event$preventDefault, _event$stopPropagatio;
|
|
101
111
|
event === null || event === void 0 ? void 0 : (_event$preventDefault = event.preventDefault) === null || _event$preventDefault === void 0 ? void 0 : _event$preventDefault.call(event);
|
|
102
112
|
event === null || event === void 0 ? void 0 : (_event$stopPropagatio = event.stopPropagation) === null || _event$stopPropagatio === void 0 ? void 0 : _event$stopPropagatio.call(event);
|
|
113
|
+
|
|
114
|
+
// Prevent submission when the form is disabled, readOnly, or plaintext
|
|
103
115
|
if (disabled || readOnly || plaintext) {
|
|
104
116
|
return;
|
|
105
117
|
}
|
|
106
|
-
|
|
107
|
-
|
|
118
|
+
submit();
|
|
119
|
+
});
|
|
120
|
+
var handleReset = (0, _utils.useEventCallback)(function (event) {
|
|
121
|
+
var _event$preventDefault2, _event$stopPropagatio2;
|
|
122
|
+
event === null || event === void 0 ? void 0 : (_event$preventDefault2 = event.preventDefault) === null || _event$preventDefault2 === void 0 ? void 0 : _event$preventDefault2.call(event);
|
|
123
|
+
event === null || event === void 0 ? void 0 : (_event$stopPropagatio2 = event.stopPropagation) === null || _event$stopPropagatio2 === void 0 ? void 0 : _event$stopPropagatio2.call(event);
|
|
124
|
+
|
|
125
|
+
// Prevent reset when the form is disabled, readOnly, or plaintext
|
|
126
|
+
if (disabled || readOnly || plaintext) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
reset(event);
|
|
130
|
+
});
|
|
131
|
+
var imperativeMethods = {
|
|
132
|
+
check: check,
|
|
133
|
+
checkForField: checkForField,
|
|
134
|
+
checkAsync: checkAsync,
|
|
135
|
+
checkForFieldAsync: checkForFieldAsync,
|
|
136
|
+
cleanErrors: cleanErrors,
|
|
137
|
+
cleanErrorForField: cleanErrorForField,
|
|
138
|
+
reset: reset,
|
|
139
|
+
resetErrors: resetErrors,
|
|
140
|
+
submit: submit
|
|
141
|
+
};
|
|
142
|
+
var formRef = (0, _useFormRef.default)(ref, {
|
|
143
|
+
imperativeMethods: imperativeMethods
|
|
144
|
+
});
|
|
145
|
+
var removeFieldValue = (0, _utils.useEventCallback)(function (name) {
|
|
146
|
+
var formValue = onRemoveValue(name);
|
|
147
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(formValue);
|
|
148
|
+
});
|
|
149
|
+
var removeFieldError = (0, _utils.useEventCallback)(function (name) {
|
|
150
|
+
onRemoveError(name);
|
|
108
151
|
});
|
|
109
152
|
var onFieldError = (0, _utils.useEventCallback)(function (name, checkResult) {
|
|
110
153
|
setFieldError(name, checkResult);
|
|
@@ -136,6 +179,7 @@ var Form = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
|
|
|
136
179
|
return /*#__PURE__*/_react.default.createElement("form", (0, _extends2.default)({}, rest, {
|
|
137
180
|
ref: formRef,
|
|
138
181
|
onSubmit: handleSubmit,
|
|
182
|
+
onReset: handleReset,
|
|
139
183
|
className: classes
|
|
140
184
|
}), /*#__PURE__*/_react.default.createElement(_FormContext.FormProvider, {
|
|
141
185
|
value: formContextValue
|
|
@@ -3,8 +3,8 @@ import { TypeAttributes } from '../@types/common';
|
|
|
3
3
|
import type { Schema, CheckResult } from 'schema-typed';
|
|
4
4
|
import type { FieldRuleType } from './hooks/useSchemaModel';
|
|
5
5
|
declare type RecordAny = Record<string, any>;
|
|
6
|
-
interface TrulyFormContextValue<T = RecordAny,
|
|
7
|
-
[P in keyof T]?:
|
|
6
|
+
interface TrulyFormContextValue<T = RecordAny, M = any, E = {
|
|
7
|
+
[P in keyof T]?: M;
|
|
8
8
|
}> {
|
|
9
9
|
formError: E;
|
|
10
10
|
nestedField: boolean;
|
|
@@ -31,6 +31,14 @@ export interface FormImperativeMethods<T = Record<string, any>, M = string, E =
|
|
|
31
31
|
* All error messages are reset, and an initial value can be set
|
|
32
32
|
*/
|
|
33
33
|
resetErrors: (formError?: E) => void;
|
|
34
|
+
/**
|
|
35
|
+
* Reset form data to initial value and clear all error messages
|
|
36
|
+
*/
|
|
37
|
+
reset: () => void;
|
|
38
|
+
/**
|
|
39
|
+
* Submit form data and verify
|
|
40
|
+
*/
|
|
41
|
+
submit: () => void;
|
|
34
42
|
}
|
|
35
43
|
export interface FormInstance<T = Record<string, any>, M = string, E = {
|
|
36
44
|
[P in keyof T]?: M;
|
|
@@ -43,13 +51,7 @@ export interface FormInstance<T = Record<string, any>, M = string, E = {
|
|
|
43
51
|
interface FormRefProps<T = Record<string, any>, M = string, E = {
|
|
44
52
|
[P in keyof T]?: M;
|
|
45
53
|
}> {
|
|
46
|
-
|
|
47
|
-
nestedField?: boolean;
|
|
48
|
-
setFormError: (formError: E) => void;
|
|
49
|
-
check: (callback?: (formError: E) => void) => boolean;
|
|
50
|
-
checkForField: (fieldName: keyof T, callback?: (checkResult: CheckResult<M>) => void) => boolean;
|
|
51
|
-
checkAsync: () => Promise<any>;
|
|
52
|
-
checkForFieldAsync: (fieldName: keyof T) => Promise<CheckResult>;
|
|
54
|
+
imperativeMethods: FormImperativeMethods<T, M, E>;
|
|
53
55
|
}
|
|
54
56
|
export default function useFormRef(ref: React.Ref<FormInstance>, props: FormRefProps): import("react").RefObject<HTMLFormElement>;
|
|
55
57
|
export {};
|
|
@@ -4,42 +4,15 @@
|
|
|
4
4
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
5
5
|
exports.__esModule = true;
|
|
6
6
|
exports.default = useFormRef;
|
|
7
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
7
8
|
var _react = require("react");
|
|
8
|
-
var _omit = _interopRequireDefault(require("lodash/omit"));
|
|
9
|
-
var _useEventCallback = _interopRequireDefault(require("../../utils/useEventCallback"));
|
|
10
|
-
var _utils = require("../../FormControl/utils");
|
|
11
9
|
function useFormRef(ref, props) {
|
|
12
10
|
var rootRef = (0, _react.useRef)(null);
|
|
13
|
-
var
|
|
14
|
-
setFormError = props.setFormError,
|
|
15
|
-
nestedField = props.nestedField,
|
|
16
|
-
check = props.check,
|
|
17
|
-
checkForField = props.checkForField,
|
|
18
|
-
checkAsync = props.checkAsync,
|
|
19
|
-
checkForFieldAsync = props.checkForFieldAsync;
|
|
20
|
-
var cleanErrors = (0, _useEventCallback.default)(function () {
|
|
21
|
-
setFormError({});
|
|
22
|
-
});
|
|
23
|
-
var resetErrors = (0, _useEventCallback.default)(function (formError) {
|
|
24
|
-
if (formError === void 0) {
|
|
25
|
-
formError = {};
|
|
26
|
-
}
|
|
27
|
-
setFormError(formError);
|
|
28
|
-
});
|
|
29
|
-
var cleanErrorForField = (0, _useEventCallback.default)(function (fieldName) {
|
|
30
|
-
setFormError((0, _omit.default)(formError, [nestedField ? (0, _utils.nameToPath)(fieldName) : fieldName]));
|
|
31
|
-
});
|
|
11
|
+
var imperativeMethods = props.imperativeMethods;
|
|
32
12
|
(0, _react.useImperativeHandle)(ref, function () {
|
|
33
|
-
return {
|
|
34
|
-
root: rootRef.current
|
|
35
|
-
|
|
36
|
-
checkForField: checkForField,
|
|
37
|
-
checkAsync: checkAsync,
|
|
38
|
-
checkForFieldAsync: checkForFieldAsync,
|
|
39
|
-
cleanErrors: cleanErrors,
|
|
40
|
-
cleanErrorForField: cleanErrorForField,
|
|
41
|
-
resetErrors: resetErrors
|
|
42
|
-
};
|
|
13
|
+
return (0, _extends2.default)({
|
|
14
|
+
root: rootRef.current
|
|
15
|
+
}, imperativeMethods);
|
|
43
16
|
});
|
|
44
17
|
return rootRef;
|
|
45
18
|
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
/// <reference types="lodash" />
|
|
3
2
|
import type { CheckResult } from 'schema-typed';
|
|
4
|
-
import { FormInstance } from './useFormRef';
|
|
5
3
|
export interface FormErrorProps {
|
|
6
|
-
ref: React.Ref<FormInstance>;
|
|
7
4
|
formValue: any;
|
|
8
5
|
getCombinedModel: () => any;
|
|
9
6
|
onCheck?: (formError: any) => void;
|
|
@@ -11,9 +8,14 @@ export interface FormErrorProps {
|
|
|
11
8
|
nestedField?: boolean;
|
|
12
9
|
}
|
|
13
10
|
export default function useFormValidate(formError: any, props: FormErrorProps): {
|
|
14
|
-
formRef: import("react").RefObject<HTMLFormElement>;
|
|
15
11
|
formError: any;
|
|
16
12
|
check: (...args: any[]) => any;
|
|
13
|
+
checkForField: (...args: any[]) => any;
|
|
14
|
+
checkAsync: (...args: any[]) => any;
|
|
15
|
+
checkForFieldAsync: (...args: any[]) => any;
|
|
16
|
+
cleanErrors: (...args: any[]) => any;
|
|
17
|
+
resetErrors: (...args: any[]) => any;
|
|
18
|
+
cleanErrorForField: (...args: any[]) => any;
|
|
17
19
|
setFieldError: (fieldName: string, checkResult: string | CheckResult) => any;
|
|
18
20
|
onRemoveError: (name: string) => import("lodash").Omit<any, string>;
|
|
19
21
|
};
|
|
@@ -11,10 +11,8 @@ var _set = _interopRequireDefault(require("lodash/set"));
|
|
|
11
11
|
var _utils = require("../../utils");
|
|
12
12
|
var _utils2 = require("../../FormControl/utils");
|
|
13
13
|
var _useEventCallback = _interopRequireDefault(require("../../utils/useEventCallback"));
|
|
14
|
-
var _useFormRef = _interopRequireDefault(require("./useFormRef"));
|
|
15
14
|
function useFormValidate(formError, props) {
|
|
16
|
-
var
|
|
17
|
-
formValue = props.formValue,
|
|
15
|
+
var formValue = props.formValue,
|
|
18
16
|
getCombinedModel = props.getCombinedModel,
|
|
19
17
|
onCheck = props.onCheck,
|
|
20
18
|
onError = props.onError,
|
|
@@ -138,19 +136,27 @@ function useFormValidate(formError, props) {
|
|
|
138
136
|
onCheck === null || onCheck === void 0 ? void 0 : onCheck(nextFormError);
|
|
139
137
|
return nextFormError;
|
|
140
138
|
}, [formError, nestedField, onCheck, onError, setFormError]);
|
|
141
|
-
var
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
139
|
+
var cleanErrors = (0, _useEventCallback.default)(function () {
|
|
140
|
+
setFormError({});
|
|
141
|
+
});
|
|
142
|
+
var resetErrors = (0, _useEventCallback.default)(function (formError) {
|
|
143
|
+
if (formError === void 0) {
|
|
144
|
+
formError = {};
|
|
145
|
+
}
|
|
146
|
+
setFormError(formError);
|
|
147
|
+
});
|
|
148
|
+
var cleanErrorForField = (0, _useEventCallback.default)(function (fieldName) {
|
|
149
|
+
setFormError((0, _omit.default)(formError, [nestedField ? (0, _utils2.nameToPath)(fieldName) : fieldName]));
|
|
149
150
|
});
|
|
150
151
|
return {
|
|
151
|
-
formRef: formRef,
|
|
152
152
|
formError: realFormError,
|
|
153
153
|
check: check,
|
|
154
|
+
checkForField: checkForField,
|
|
155
|
+
checkAsync: checkAsync,
|
|
156
|
+
checkForFieldAsync: checkForFieldAsync,
|
|
157
|
+
cleanErrors: cleanErrors,
|
|
158
|
+
resetErrors: resetErrors,
|
|
159
|
+
cleanErrorForField: cleanErrorForField,
|
|
154
160
|
setFieldError: setFieldError,
|
|
155
161
|
onRemoveError: onRemoveError
|
|
156
162
|
};
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
/// <reference types="lodash" />
|
|
2
|
-
|
|
2
|
+
declare type RecordAny = Record<string, any>;
|
|
3
|
+
interface UseFormValueProps<V = RecordAny> {
|
|
4
|
+
formDefaultValue: V;
|
|
5
|
+
nestedField: boolean;
|
|
6
|
+
}
|
|
7
|
+
export default function useFormValue<V>(controlledValue: any, props: UseFormValueProps<V>): {
|
|
3
8
|
formValue: any;
|
|
4
9
|
setFormValue: (value: any) => void;
|
|
5
10
|
setFieldValue: (fieldName: string, fieldValue: any) => any;
|
|
6
11
|
onRemoveValue: (name: string) => import("lodash").Omit<any, string>;
|
|
12
|
+
resetFormValue: (nextValue?: V) => V;
|
|
7
13
|
};
|
|
14
|
+
export {};
|
|
@@ -33,10 +33,16 @@ function useFormValue(controlledValue, props) {
|
|
|
33
33
|
setFormValue(formValue);
|
|
34
34
|
return formValue;
|
|
35
35
|
}, [setFormValue]);
|
|
36
|
+
var resetFormValue = (0, _react.useCallback)(function (nextValue) {
|
|
37
|
+
var value = nextValue || formDefaultValue;
|
|
38
|
+
setFormValue(value);
|
|
39
|
+
return value;
|
|
40
|
+
}, [formDefaultValue, setFormValue]);
|
|
36
41
|
return {
|
|
37
42
|
formValue: formValue,
|
|
38
43
|
setFormValue: setFormValue,
|
|
39
44
|
setFieldValue: setFieldValue,
|
|
40
|
-
onRemoveValue: onRemoveValue
|
|
45
|
+
onRemoveValue: onRemoveValue,
|
|
46
|
+
resetFormValue: resetFormValue
|
|
41
47
|
};
|
|
42
48
|
}
|
|
@@ -48,9 +48,9 @@ var useInputWidth = function useInputWidth(props, sizerRef, placeholderRef) {
|
|
|
48
48
|
}
|
|
49
49
|
var width;
|
|
50
50
|
if (placeholder && !value && placeholderRef.current) {
|
|
51
|
-
width = Math.max(sizerRef.current.scrollWidth, placeholderRef.current.scrollWidth) +
|
|
51
|
+
width = Math.max(sizerRef.current.scrollWidth, placeholderRef.current.scrollWidth) + 10;
|
|
52
52
|
} else {
|
|
53
|
-
width = sizerRef.current.scrollWidth +
|
|
53
|
+
width = sizerRef.current.scrollWidth + 10;
|
|
54
54
|
}
|
|
55
55
|
if (width < minWidth) {
|
|
56
56
|
width = minWidth;
|
|
@@ -1,24 +1,22 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { PickerComponent, PickerToggleProps } from '../internals/Picker';
|
|
3
|
+
import { type InputItemDataType } from './hooks/useData';
|
|
3
4
|
import type { ItemDataType, FormControlPickerProps } from '../@types/common';
|
|
4
5
|
import type { InputPickerLocale } from '../locales';
|
|
5
6
|
import type { SelectProps } from '../SelectPicker';
|
|
6
|
-
export interface InputItemDataType extends ItemDataType {
|
|
7
|
-
create?: boolean;
|
|
8
|
-
}
|
|
9
7
|
export declare type ValueType = any;
|
|
10
|
-
export interface InputPickerProps<
|
|
8
|
+
export interface InputPickerProps<V = ValueType> extends FormControlPickerProps<V, InputPickerLocale, InputItemDataType>, SelectProps<V>, Pick<PickerToggleProps, 'caretAs' | 'loading'> {
|
|
11
9
|
tabIndex?: number;
|
|
12
10
|
/** Settings can create new options */
|
|
13
11
|
creatable?: boolean;
|
|
14
12
|
/** Option to cache value when searching asynchronously */
|
|
15
|
-
cacheData?: InputItemDataType[];
|
|
13
|
+
cacheData?: InputItemDataType<V>[];
|
|
16
14
|
/** The `onBlur` attribute for the `input` element. */
|
|
17
15
|
onBlur?: React.FocusEventHandler;
|
|
18
16
|
/** The `onFocus` attribute for the `input` element. */
|
|
19
17
|
onFocus?: React.FocusEventHandler;
|
|
20
18
|
/** Called when the option is created */
|
|
21
|
-
onCreate?: (value:
|
|
19
|
+
onCreate?: (value: V, item: ItemDataType, event: React.SyntheticEvent) => void;
|
|
22
20
|
/**
|
|
23
21
|
* Customize whether to display "Create option" action with given textbox value
|
|
24
22
|
*
|
|
@@ -27,7 +25,7 @@ export interface InputPickerProps<T = ValueType> extends FormControlPickerProps<
|
|
|
27
25
|
* @param searchKeyword Value of the textbox
|
|
28
26
|
* @param filteredData The items filtered by the searchKeyword
|
|
29
27
|
*/
|
|
30
|
-
shouldDisplayCreateOption?: (searchKeyword: string, filteredData: InputItemDataType[]) => boolean;
|
|
28
|
+
shouldDisplayCreateOption?: (searchKeyword: string, filteredData: InputItemDataType<V>[]) => boolean;
|
|
31
29
|
}
|
|
32
30
|
/**
|
|
33
31
|
* Single item selector with text box input.
|