rsuite 5.59.3-alpha.1 → 5.60.1
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 +27 -0
- package/DateRangePicker/styles/index.css +2 -3
- package/DateRangePicker/styles/index.less +6 -5
- package/TagInput/styles/index.css +24 -24
- package/TagPicker/styles/index.css +24 -24
- package/TagPicker/styles/index.less +11 -10
- package/Toggle/styles/index.css +2 -1
- package/Toggle/styles/index.less +2 -1
- package/cjs/DateRangePicker/DateRangePicker.js +17 -9
- package/cjs/DateRangePicker/utils.d.ts +2 -2
- package/cjs/DateRangePicker/utils.js +2 -2
- 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 +29 -29
- 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 +29 -29
- package/dist/rsuite-no-reset.min.css +1 -1
- package/dist/rsuite-no-reset.min.css.map +1 -1
- package/dist/rsuite-rtl.css +29 -29
- package/dist/rsuite-rtl.min.css +1 -1
- package/dist/rsuite-rtl.min.css.map +1 -1
- package/dist/rsuite.css +29 -29
- package/dist/rsuite.js +55 -11
- 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/DateRangePicker/DateRangePicker.js +17 -9
- package/esm/DateRangePicker/utils.d.ts +2 -2
- package/esm/DateRangePicker/utils.js +2 -2
- 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/styles/variables.less +0 -1
|
@@ -102,7 +102,8 @@ var DateRangePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
102
102
|
prefix = _useClassNames.prefix;
|
|
103
103
|
var _useCustom = useCustom('DateRangePicker', overrideLocale),
|
|
104
104
|
locale = _useCustom.locale,
|
|
105
|
-
formatDate = _useCustom.formatDate;
|
|
105
|
+
formatDate = _useCustom.formatDate; // Default gap between two calendars, if `showOneCalendar` is set, the gap is 0
|
|
106
|
+
var calendarGap = showOneCalendar ? 0 : 1;
|
|
106
107
|
var rangeFormatStr = "" + formatStr + character + formatStr;
|
|
107
108
|
var _useControlled = useControlled(valueProp, defaultValue !== null && defaultValue !== void 0 ? defaultValue : null),
|
|
108
109
|
value = _useControlled[0],
|
|
@@ -129,7 +130,7 @@ var DateRangePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
129
130
|
var _useState2 = useState((_ref = valueProp !== null && valueProp !== void 0 ? valueProp : defaultValue) !== null && _ref !== void 0 ? _ref : []),
|
|
130
131
|
selectedDates = _useState2[0],
|
|
131
132
|
setSelectedDates = _useState2[1]; // The date of the current hover, used to reduce the calculation of `handleMouseMove`
|
|
132
|
-
var _useState3 = useState(
|
|
133
|
+
var _useState3 = useState(value),
|
|
133
134
|
hoverDateRange = _useState3[0],
|
|
134
135
|
setHoverDateRange = _useState3[1]; // The displayed calendar panel is rendered based on this value.
|
|
135
136
|
var _useState4 = useState(getSafeCalendarDate({
|
|
@@ -165,14 +166,14 @@ var DateRangePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
165
166
|
var nextValue = dateRange;
|
|
166
167
|
|
|
167
168
|
// The time should remain the same when the dates in the date range are changed.
|
|
168
|
-
if (shouldRenderTime(formatStr) && dateRange !== null && dateRange !== void 0 && dateRange.length && eventName
|
|
169
|
+
if (shouldRenderTime(formatStr) && dateRange !== null && dateRange !== void 0 && dateRange.length && (eventName === 'changeDate' || eventName === 'changeMonth')) {
|
|
169
170
|
var _startDate = copyTime({
|
|
170
171
|
from: getCalendarDatetime('start'),
|
|
171
172
|
to: dateRange[0]
|
|
172
173
|
});
|
|
173
174
|
var _endDate = copyTime({
|
|
174
175
|
from: getCalendarDatetime('end'),
|
|
175
|
-
to: dateRange.length === 1 ? addMonths(_startDate,
|
|
176
|
+
to: dateRange.length === 1 ? addMonths(_startDate, calendarGap) : dateRange[1]
|
|
176
177
|
});
|
|
177
178
|
nextValue = [_startDate, _endDate];
|
|
178
179
|
} else if (dateRange === null && typeof defaultCalendarValue !== 'undefined') {
|
|
@@ -182,7 +183,9 @@ var DateRangePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
182
183
|
var nextCalendarDate = getSafeCalendarDate({
|
|
183
184
|
value: nextValue,
|
|
184
185
|
calendarKey: calendarKey,
|
|
185
|
-
|
|
186
|
+
// When only the month is displayed and only one calendar is displayed,
|
|
187
|
+
// there is no need to add a month and two calendar panels are allowed to display the same month
|
|
188
|
+
allowSameMonth: onlyShowMonth || showOneCalendar
|
|
186
189
|
});
|
|
187
190
|
setCalendarDate(nextCalendarDate);
|
|
188
191
|
if (onlyShowMonth && eventName === 'changeMonth') {
|
|
@@ -331,6 +334,11 @@ var DateRangePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
331
334
|
} else {
|
|
332
335
|
setHoverDateRange([nextSelectDates[0], nextSelectDates[0]]);
|
|
333
336
|
}
|
|
337
|
+
if (isSelectedIdle) {
|
|
338
|
+
setActiveCalendarKey('end');
|
|
339
|
+
} else {
|
|
340
|
+
setActiveCalendarKey('start');
|
|
341
|
+
}
|
|
334
342
|
setSelectedDates(nextSelectDates);
|
|
335
343
|
setCalendarDateRange({
|
|
336
344
|
dateRange: nextSelectDates,
|
|
@@ -402,7 +410,7 @@ var DateRangePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
402
410
|
if (value && value.length) {
|
|
403
411
|
var _startDate3 = value[0],
|
|
404
412
|
endData = value[1];
|
|
405
|
-
nextCalendarDate = [_startDate3, isSameMonth(_startDate3, endData) ? addMonths(endData,
|
|
413
|
+
nextCalendarDate = [_startDate3, isSameMonth(_startDate3, endData) ? addMonths(endData, calendarGap) : endData];
|
|
406
414
|
} else {
|
|
407
415
|
// Reset the date on the calendar to the default date
|
|
408
416
|
nextCalendarDate = getSafeCalendarDate({
|
|
@@ -731,11 +739,11 @@ var DateRangePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
731
739
|
format: formatStr,
|
|
732
740
|
placeholder: placeholder ? placeholder : rangeFormatStr,
|
|
733
741
|
disabled: disabled,
|
|
734
|
-
onChange: handleInputChange,
|
|
735
742
|
readOnly: readOnly || !editable || loading,
|
|
736
743
|
plaintext: plaintext,
|
|
737
|
-
|
|
738
|
-
|
|
744
|
+
htmlSize: getInputHtmlSize(),
|
|
745
|
+
onChange: handleInputChange,
|
|
746
|
+
onKeyDown: handleInputKeyDown
|
|
739
747
|
})), /*#__PURE__*/React.createElement(PickerIndicator, {
|
|
740
748
|
loading: loading,
|
|
741
749
|
caretAs: caretAs,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { DateRange } from './types';
|
|
2
|
-
export declare function getSafeCalendarDate({ value, calendarKey,
|
|
2
|
+
export declare function getSafeCalendarDate({ value, calendarKey, allowSameMonth }: {
|
|
3
3
|
value: [] | [Date] | [Date, Date] | null;
|
|
4
4
|
calendarKey?: 'start' | 'end';
|
|
5
|
-
|
|
5
|
+
allowSameMonth?: boolean;
|
|
6
6
|
}): DateRange;
|
|
7
7
|
export declare const isSameRange: (source: DateRange | null, dest: DateRange | null, format: string) => boolean;
|
|
8
8
|
export declare const getMonthHoverRange: (date: Date) => DateRange;
|
|
@@ -5,10 +5,10 @@ export function getSafeCalendarDate(_ref) {
|
|
|
5
5
|
var value = _ref.value,
|
|
6
6
|
_ref$calendarKey = _ref.calendarKey,
|
|
7
7
|
calendarKey = _ref$calendarKey === void 0 ? 'start' : _ref$calendarKey,
|
|
8
|
-
|
|
8
|
+
allowSameMonth = _ref.allowSameMonth;
|
|
9
9
|
// Update calendarDate if the value is not null
|
|
10
10
|
value = (_value = value) !== null && _value !== void 0 ? _value : [];
|
|
11
|
-
var gap =
|
|
11
|
+
var gap = allowSameMonth ? 0 : 1;
|
|
12
12
|
if (value[0] && value[1]) {
|
|
13
13
|
var diffMonth = differenceInCalendarMonths(value[1], value[0]);
|
|
14
14
|
if (calendarKey === 'start') {
|
package/esm/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/esm/Form/Form.js
CHANGED
|
@@ -16,6 +16,7 @@ import useSchemaModel from './hooks/useSchemaModel';
|
|
|
16
16
|
import useFormValidate from './hooks/useFormValidate';
|
|
17
17
|
import useFormValue from './hooks/useFormValue';
|
|
18
18
|
import useFormClassNames from './hooks/useFormClassNames';
|
|
19
|
+
import useFormRef from './hooks/useFormRef';
|
|
19
20
|
var defaultSchema = SchemaModel({});
|
|
20
21
|
|
|
21
22
|
/**
|
|
@@ -46,10 +47,11 @@ var Form = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
46
47
|
children = props.children,
|
|
47
48
|
disabled = props.disabled,
|
|
48
49
|
onSubmit = props.onSubmit,
|
|
50
|
+
onReset = props.onReset,
|
|
49
51
|
onCheck = props.onCheck,
|
|
50
52
|
onError = props.onError,
|
|
51
53
|
onChange = props.onChange,
|
|
52
|
-
rest = _objectWithoutPropertiesLoose(props, ["checkTrigger", "classPrefix", "errorFromContext", "formDefaultValue", "formValue", "formError", "fluid", "nestedField", "layout", "model", "readOnly", "plaintext", "className", "children", "disabled", "onSubmit", "onCheck", "onError", "onChange"]);
|
|
54
|
+
rest = _objectWithoutPropertiesLoose(props, ["checkTrigger", "classPrefix", "errorFromContext", "formDefaultValue", "formValue", "formError", "fluid", "nestedField", "layout", "model", "readOnly", "plaintext", "className", "children", "disabled", "onSubmit", "onReset", "onCheck", "onError", "onChange"]);
|
|
53
55
|
var _useSchemaModel = useSchemaModel(formModel),
|
|
54
56
|
getCombinedModel = _useSchemaModel.getCombinedModel,
|
|
55
57
|
pushFieldRule = _useSchemaModel.pushFieldRule,
|
|
@@ -60,9 +62,9 @@ var Form = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
60
62
|
}),
|
|
61
63
|
formValue = _useFormValue.formValue,
|
|
62
64
|
onRemoveValue = _useFormValue.onRemoveValue,
|
|
63
|
-
setFieldValue = _useFormValue.setFieldValue
|
|
65
|
+
setFieldValue = _useFormValue.setFieldValue,
|
|
66
|
+
resetFormValue = _useFormValue.resetFormValue;
|
|
64
67
|
var formValidateProps = {
|
|
65
|
-
ref: ref,
|
|
66
68
|
formValue: formValue,
|
|
67
69
|
getCombinedModel: getCombinedModel,
|
|
68
70
|
onCheck: onCheck,
|
|
@@ -74,7 +76,12 @@ var Form = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
74
76
|
setFieldError = _useFormValidate.setFieldError,
|
|
75
77
|
onRemoveError = _useFormValidate.onRemoveError,
|
|
76
78
|
check = _useFormValidate.check,
|
|
77
|
-
|
|
79
|
+
checkAsync = _useFormValidate.checkAsync,
|
|
80
|
+
checkForField = _useFormValidate.checkForField,
|
|
81
|
+
checkForFieldAsync = _useFormValidate.checkForFieldAsync,
|
|
82
|
+
cleanErrors = _useFormValidate.cleanErrors,
|
|
83
|
+
resetErrors = _useFormValidate.resetErrors,
|
|
84
|
+
cleanErrorForField = _useFormValidate.cleanErrorForField;
|
|
78
85
|
var classes = useFormClassNames({
|
|
79
86
|
classPrefix: classPrefix,
|
|
80
87
|
className: className,
|
|
@@ -84,22 +91,58 @@ var Form = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
84
91
|
plaintext: plaintext,
|
|
85
92
|
disabled: disabled
|
|
86
93
|
});
|
|
87
|
-
var
|
|
88
|
-
|
|
89
|
-
|
|
94
|
+
var submit = useEventCallback(function (event) {
|
|
95
|
+
// Check the form before submitting
|
|
96
|
+
if (check()) {
|
|
97
|
+
onSubmit === null || onSubmit === void 0 ? void 0 : onSubmit(formValue, event);
|
|
98
|
+
}
|
|
90
99
|
});
|
|
91
|
-
var
|
|
92
|
-
|
|
100
|
+
var reset = useEventCallback(function (event) {
|
|
101
|
+
resetErrors();
|
|
102
|
+
onReset === null || onReset === void 0 ? void 0 : onReset(resetFormValue(), event);
|
|
93
103
|
});
|
|
94
104
|
var handleSubmit = useEventCallback(function (event) {
|
|
95
105
|
var _event$preventDefault, _event$stopPropagatio;
|
|
96
106
|
event === null || event === void 0 ? void 0 : (_event$preventDefault = event.preventDefault) === null || _event$preventDefault === void 0 ? void 0 : _event$preventDefault.call(event);
|
|
97
107
|
event === null || event === void 0 ? void 0 : (_event$stopPropagatio = event.stopPropagation) === null || _event$stopPropagatio === void 0 ? void 0 : _event$stopPropagatio.call(event);
|
|
108
|
+
|
|
109
|
+
// Prevent submission when the form is disabled, readOnly, or plaintext
|
|
98
110
|
if (disabled || readOnly || plaintext) {
|
|
99
111
|
return;
|
|
100
112
|
}
|
|
101
|
-
|
|
102
|
-
|
|
113
|
+
submit();
|
|
114
|
+
});
|
|
115
|
+
var handleReset = useEventCallback(function (event) {
|
|
116
|
+
var _event$preventDefault2, _event$stopPropagatio2;
|
|
117
|
+
event === null || event === void 0 ? void 0 : (_event$preventDefault2 = event.preventDefault) === null || _event$preventDefault2 === void 0 ? void 0 : _event$preventDefault2.call(event);
|
|
118
|
+
event === null || event === void 0 ? void 0 : (_event$stopPropagatio2 = event.stopPropagation) === null || _event$stopPropagatio2 === void 0 ? void 0 : _event$stopPropagatio2.call(event);
|
|
119
|
+
|
|
120
|
+
// Prevent reset when the form is disabled, readOnly, or plaintext
|
|
121
|
+
if (disabled || readOnly || plaintext) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
reset(event);
|
|
125
|
+
});
|
|
126
|
+
var imperativeMethods = {
|
|
127
|
+
check: check,
|
|
128
|
+
checkForField: checkForField,
|
|
129
|
+
checkAsync: checkAsync,
|
|
130
|
+
checkForFieldAsync: checkForFieldAsync,
|
|
131
|
+
cleanErrors: cleanErrors,
|
|
132
|
+
cleanErrorForField: cleanErrorForField,
|
|
133
|
+
reset: reset,
|
|
134
|
+
resetErrors: resetErrors,
|
|
135
|
+
submit: submit
|
|
136
|
+
};
|
|
137
|
+
var formRef = useFormRef(ref, {
|
|
138
|
+
imperativeMethods: imperativeMethods
|
|
139
|
+
});
|
|
140
|
+
var removeFieldValue = useEventCallback(function (name) {
|
|
141
|
+
var formValue = onRemoveValue(name);
|
|
142
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(formValue);
|
|
143
|
+
});
|
|
144
|
+
var removeFieldError = useEventCallback(function (name) {
|
|
145
|
+
onRemoveError(name);
|
|
103
146
|
});
|
|
104
147
|
var onFieldError = useEventCallback(function (name, checkResult) {
|
|
105
148
|
setFieldError(name, checkResult);
|
|
@@ -131,6 +174,7 @@ var Form = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
131
174
|
return /*#__PURE__*/React.createElement("form", _extends({}, rest, {
|
|
132
175
|
ref: formRef,
|
|
133
176
|
onSubmit: handleSubmit,
|
|
177
|
+
onReset: handleReset,
|
|
134
178
|
className: classes
|
|
135
179
|
}), /*#__PURE__*/React.createElement(FormProvider, {
|
|
136
180
|
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 {};
|
|
@@ -1,40 +1,13 @@
|
|
|
1
1
|
'use client';
|
|
2
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
3
|
import { useRef, useImperativeHandle } from 'react';
|
|
3
|
-
import omit from 'lodash/omit';
|
|
4
|
-
import useEventCallback from '../../utils/useEventCallback';
|
|
5
|
-
import { nameToPath } from '../../FormControl/utils';
|
|
6
4
|
export default function useFormRef(ref, props) {
|
|
7
5
|
var rootRef = useRef(null);
|
|
8
|
-
var
|
|
9
|
-
setFormError = props.setFormError,
|
|
10
|
-
nestedField = props.nestedField,
|
|
11
|
-
check = props.check,
|
|
12
|
-
checkForField = props.checkForField,
|
|
13
|
-
checkAsync = props.checkAsync,
|
|
14
|
-
checkForFieldAsync = props.checkForFieldAsync;
|
|
15
|
-
var cleanErrors = useEventCallback(function () {
|
|
16
|
-
setFormError({});
|
|
17
|
-
});
|
|
18
|
-
var resetErrors = useEventCallback(function (formError) {
|
|
19
|
-
if (formError === void 0) {
|
|
20
|
-
formError = {};
|
|
21
|
-
}
|
|
22
|
-
setFormError(formError);
|
|
23
|
-
});
|
|
24
|
-
var cleanErrorForField = useEventCallback(function (fieldName) {
|
|
25
|
-
setFormError(omit(formError, [nestedField ? nameToPath(fieldName) : fieldName]));
|
|
26
|
-
});
|
|
6
|
+
var imperativeMethods = props.imperativeMethods;
|
|
27
7
|
useImperativeHandle(ref, function () {
|
|
28
|
-
return {
|
|
29
|
-
root: rootRef.current
|
|
30
|
-
|
|
31
|
-
checkForField: checkForField,
|
|
32
|
-
checkAsync: checkAsync,
|
|
33
|
-
checkForFieldAsync: checkForFieldAsync,
|
|
34
|
-
cleanErrors: cleanErrors,
|
|
35
|
-
cleanErrorForField: cleanErrorForField,
|
|
36
|
-
resetErrors: resetErrors
|
|
37
|
-
};
|
|
8
|
+
return _extends({
|
|
9
|
+
root: rootRef.current
|
|
10
|
+
}, imperativeMethods);
|
|
38
11
|
});
|
|
39
12
|
return rootRef;
|
|
40
13
|
}
|
|
@@ -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
|
};
|
|
@@ -6,10 +6,8 @@ import set from 'lodash/set';
|
|
|
6
6
|
import { useControlled } from '../../utils';
|
|
7
7
|
import { nameToPath } from '../../FormControl/utils';
|
|
8
8
|
import useEventCallback from '../../utils/useEventCallback';
|
|
9
|
-
import useFormRef from './useFormRef';
|
|
10
9
|
export default function useFormValidate(formError, props) {
|
|
11
|
-
var
|
|
12
|
-
formValue = props.formValue,
|
|
10
|
+
var formValue = props.formValue,
|
|
13
11
|
getCombinedModel = props.getCombinedModel,
|
|
14
12
|
onCheck = props.onCheck,
|
|
15
13
|
onError = props.onError,
|
|
@@ -133,19 +131,27 @@ export default function useFormValidate(formError, props) {
|
|
|
133
131
|
onCheck === null || onCheck === void 0 ? void 0 : onCheck(nextFormError);
|
|
134
132
|
return nextFormError;
|
|
135
133
|
}, [formError, nestedField, onCheck, onError, setFormError]);
|
|
136
|
-
var
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
134
|
+
var cleanErrors = useEventCallback(function () {
|
|
135
|
+
setFormError({});
|
|
136
|
+
});
|
|
137
|
+
var resetErrors = useEventCallback(function (formError) {
|
|
138
|
+
if (formError === void 0) {
|
|
139
|
+
formError = {};
|
|
140
|
+
}
|
|
141
|
+
setFormError(formError);
|
|
142
|
+
});
|
|
143
|
+
var cleanErrorForField = useEventCallback(function (fieldName) {
|
|
144
|
+
setFormError(omit(formError, [nestedField ? nameToPath(fieldName) : fieldName]));
|
|
144
145
|
});
|
|
145
146
|
return {
|
|
146
|
-
formRef: formRef,
|
|
147
147
|
formError: realFormError,
|
|
148
148
|
check: check,
|
|
149
|
+
checkForField: checkForField,
|
|
150
|
+
checkAsync: checkAsync,
|
|
151
|
+
checkForFieldAsync: checkForFieldAsync,
|
|
152
|
+
cleanErrors: cleanErrors,
|
|
153
|
+
resetErrors: resetErrors,
|
|
154
|
+
cleanErrorForField: cleanErrorForField,
|
|
149
155
|
setFieldError: setFieldError,
|
|
150
156
|
onRemoveError: onRemoveError
|
|
151
157
|
};
|
|
@@ -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 {};
|
|
@@ -28,10 +28,16 @@ export default function useFormValue(controlledValue, props) {
|
|
|
28
28
|
setFormValue(formValue);
|
|
29
29
|
return formValue;
|
|
30
30
|
}, [setFormValue]);
|
|
31
|
+
var resetFormValue = useCallback(function (nextValue) {
|
|
32
|
+
var value = nextValue || formDefaultValue;
|
|
33
|
+
setFormValue(value);
|
|
34
|
+
return value;
|
|
35
|
+
}, [formDefaultValue, setFormValue]);
|
|
31
36
|
return {
|
|
32
37
|
formValue: formValue,
|
|
33
38
|
setFormValue: setFormValue,
|
|
34
39
|
setFieldValue: setFieldValue,
|
|
35
|
-
onRemoveValue: onRemoveValue
|
|
40
|
+
onRemoveValue: onRemoveValue,
|
|
41
|
+
resetFormValue: resetFormValue
|
|
36
42
|
};
|
|
37
43
|
}
|
|
@@ -42,9 +42,9 @@ var useInputWidth = function useInputWidth(props, sizerRef, placeholderRef) {
|
|
|
42
42
|
}
|
|
43
43
|
var width;
|
|
44
44
|
if (placeholder && !value && placeholderRef.current) {
|
|
45
|
-
width = Math.max(sizerRef.current.scrollWidth, placeholderRef.current.scrollWidth) +
|
|
45
|
+
width = Math.max(sizerRef.current.scrollWidth, placeholderRef.current.scrollWidth) + 10;
|
|
46
46
|
} else {
|
|
47
|
-
width = sizerRef.current.scrollWidth +
|
|
47
|
+
width = sizerRef.current.scrollWidth + 10;
|
|
48
48
|
}
|
|
49
49
|
if (width < minWidth) {
|
|
50
50
|
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.
|