x-ui-design 0.6.14 → 0.6.15
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/esm/types/components/Form/Item/Item.d.ts +1 -1
- package/dist/esm/types/types/form.d.ts +1 -1
- package/dist/index.esm.js +18 -37
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +18 -37
- package/dist/index.js.map +1 -1
- package/lib/components/Form/Item/Item.tsx +20 -27
- package/lib/components/Input/Input.tsx +1 -0
- package/lib/hooks/useForm.ts +4 -20
- package/lib/types/form.ts +2 -2
- package/package.json +1 -1
- package/src/app/page.tsx +3 -4
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { FormItemProps } from '../../../types/form';
|
|
3
3
|
import './style.css';
|
|
4
4
|
declare const FormItem: {
|
|
5
|
-
({ prefixCls, name, label, rules, children, className, layout, style,
|
|
5
|
+
({ prefixCls, name, label, rules, children, className, layout, style, extra, hideLabel, removeErrorMessageHeight, ...props }: FormItemProps): React.JSX.Element;
|
|
6
6
|
displayName: string;
|
|
7
7
|
};
|
|
8
8
|
export default FormItem;
|
|
@@ -81,6 +81,7 @@ export interface FormItemChildComponentProps {
|
|
|
81
81
|
noStyle?: boolean;
|
|
82
82
|
feedbackIcons?: boolean;
|
|
83
83
|
ref?: FieldInstancesRef | null;
|
|
84
|
+
dependencies?: string[];
|
|
84
85
|
}
|
|
85
86
|
export interface FormInstance {
|
|
86
87
|
submit: () => Promise<Record<string, RuleTypes> | undefined>;
|
|
@@ -112,5 +113,4 @@ export interface FormInstance {
|
|
|
112
113
|
setOnFinish?: (onFinish?: ((values: Record<string, RuleTypes>) => void) | undefined) => void;
|
|
113
114
|
setOnValuesChange?: (onValuesChange?: (changedValues: Record<string, RuleTypes>, allValues: Record<string, RuleTypes>) => void) => void;
|
|
114
115
|
changeStep: (step: number) => void;
|
|
115
|
-
subscribeToErrors?: (callback: (errors: FieldError[]) => void) => () => void;
|
|
116
116
|
}
|
package/dist/index.esm.js
CHANGED
|
@@ -620,7 +620,6 @@ const useForm = (initialValues = {}, onFieldsChange, onValuesChange, scrollToFir
|
|
|
620
620
|
const fieldInstancesRef = useRef({});
|
|
621
621
|
const [isReseting, setIsReseting] = useState(false);
|
|
622
622
|
const errorsRef = useRef({});
|
|
623
|
-
const errorSubscribers = useRef([]);
|
|
624
623
|
const fieldSubscribers = useRef({});
|
|
625
624
|
const formSubscribers = useRef([]);
|
|
626
625
|
function getFormFields() {
|
|
@@ -766,8 +765,6 @@ const useForm = (initialValues = {}, onFieldsChange, onValuesChange, scrollToFir
|
|
|
766
765
|
[name]: fieldErrors
|
|
767
766
|
};
|
|
768
767
|
warningsRef.current[name] = fieldWarnings;
|
|
769
|
-
const currentErrors = getFieldsError();
|
|
770
|
-
errorSubscribers.current.forEach(callback => callback(currentErrors));
|
|
771
768
|
return fieldErrors.length === 0;
|
|
772
769
|
}
|
|
773
770
|
async function validateFields(nameList) {
|
|
@@ -775,6 +772,7 @@ const useForm = (initialValues = {}, onFieldsChange, onValuesChange, scrollToFir
|
|
|
775
772
|
const results = await Promise.all(fieldsToValidate.map(name => validateField(name)));
|
|
776
773
|
if (_scrollToFirstError.current) {
|
|
777
774
|
const firstErrorContent = document.querySelectorAll('.xUi-form-item-has-error')?.[0];
|
|
775
|
+
console.log(firstErrorContent);
|
|
778
776
|
if (firstErrorContent) {
|
|
779
777
|
firstErrorContent.closest('.xUi-form-item')?.scrollIntoView({
|
|
780
778
|
behavior: 'smooth'
|
|
@@ -806,8 +804,6 @@ const useForm = (initialValues = {}, onFieldsChange, onValuesChange, scrollToFir
|
|
|
806
804
|
});
|
|
807
805
|
}
|
|
808
806
|
formSubscribers.current.forEach(callback => callback(getFieldsValue()));
|
|
809
|
-
const currentErrors = getFieldsError();
|
|
810
|
-
errorSubscribers.current.forEach(callback => callback(currentErrors));
|
|
811
807
|
setIsReseting(prev => !prev);
|
|
812
808
|
}
|
|
813
809
|
async function submit() {
|
|
@@ -841,12 +837,6 @@ const useForm = (initialValues = {}, onFieldsChange, onValuesChange, scrollToFir
|
|
|
841
837
|
fieldCallbacks.forEach(unsubscribe => unsubscribe());
|
|
842
838
|
};
|
|
843
839
|
}
|
|
844
|
-
function subscribeToErrors(callback) {
|
|
845
|
-
errorSubscribers.current.push(callback);
|
|
846
|
-
return () => {
|
|
847
|
-
errorSubscribers.current = errorSubscribers.current.filter(cb => cb !== callback);
|
|
848
|
-
};
|
|
849
|
-
}
|
|
850
840
|
function setScrollToFirstError(value) {
|
|
851
841
|
_scrollToFirstError.current = value;
|
|
852
842
|
}
|
|
@@ -894,8 +884,7 @@ const useForm = (initialValues = {}, onFieldsChange, onValuesChange, scrollToFir
|
|
|
894
884
|
setOnFinish,
|
|
895
885
|
setOnFieldsChange,
|
|
896
886
|
setOnValuesChange,
|
|
897
|
-
changeStep
|
|
898
|
-
subscribeToErrors
|
|
887
|
+
changeStep
|
|
899
888
|
};
|
|
900
889
|
return formInstance;
|
|
901
890
|
};
|
|
@@ -991,8 +980,6 @@ const FormItem$1 = ({
|
|
|
991
980
|
className = '',
|
|
992
981
|
layout = 'vertical',
|
|
993
982
|
style = {},
|
|
994
|
-
dependencies = [],
|
|
995
|
-
feedbackIcons,
|
|
996
983
|
extra,
|
|
997
984
|
hideLabel = false,
|
|
998
985
|
removeErrorMessageHeight = false,
|
|
@@ -1009,10 +996,7 @@ const FormItem$1 = ({
|
|
|
1009
996
|
isReseting,
|
|
1010
997
|
registerField,
|
|
1011
998
|
getFieldInstance,
|
|
1012
|
-
setFieldInstance
|
|
1013
|
-
subscribeToFields,
|
|
1014
|
-
validateFields,
|
|
1015
|
-
subscribeToErrors
|
|
999
|
+
setFieldInstance
|
|
1016
1000
|
} = formContext;
|
|
1017
1001
|
const childrenList = useMemo(() => flattenChildren(children), [children]);
|
|
1018
1002
|
useEffect(() => {
|
|
@@ -1024,22 +1008,6 @@ const FormItem$1 = ({
|
|
|
1024
1008
|
setFieldInstance(name, fieldRef.current);
|
|
1025
1009
|
}, [name, fieldRef.current]);
|
|
1026
1010
|
useEffect(() => () => registerField(name, undefined, true), [name]);
|
|
1027
|
-
useEffect(() => {
|
|
1028
|
-
if (name && dependencies.length > 0) {
|
|
1029
|
-
const unsubscribe = subscribeToFields(dependencies, () => {
|
|
1030
|
-
validateFields([name]);
|
|
1031
|
-
});
|
|
1032
|
-
return () => {
|
|
1033
|
-
unsubscribe();
|
|
1034
|
-
};
|
|
1035
|
-
}
|
|
1036
|
-
}, [dependencies, name]);
|
|
1037
|
-
useEffect(() => {
|
|
1038
|
-
const unsubscribe = subscribeToErrors?.(errors => {
|
|
1039
|
-
setErrorMessage(errors.find(error => error.name === name)?.errors?.[0] || '');
|
|
1040
|
-
});
|
|
1041
|
-
return () => unsubscribe?.();
|
|
1042
|
-
}, []);
|
|
1043
1011
|
const isRequired = useMemo(() => rules.some(rule => rule.required), [rules]);
|
|
1044
1012
|
return /*#__PURE__*/React.createElement("div", {
|
|
1045
1013
|
style: style,
|
|
@@ -1092,8 +1060,8 @@ const FormItemChildComponent = ({
|
|
|
1092
1060
|
initialValue,
|
|
1093
1061
|
normalize,
|
|
1094
1062
|
noStyle,
|
|
1095
|
-
feedbackIcons,
|
|
1096
1063
|
ref,
|
|
1064
|
+
dependencies = [],
|
|
1097
1065
|
...props
|
|
1098
1066
|
}) => {
|
|
1099
1067
|
const formContext = useContext(FormContext);
|
|
@@ -1101,7 +1069,9 @@ const FormItemChildComponent = ({
|
|
|
1101
1069
|
const {
|
|
1102
1070
|
getFieldsValue,
|
|
1103
1071
|
getFieldValue,
|
|
1104
|
-
setFieldValue
|
|
1072
|
+
setFieldValue,
|
|
1073
|
+
subscribeToFields,
|
|
1074
|
+
validateFields
|
|
1105
1075
|
} = formContext || {};
|
|
1106
1076
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1107
1077
|
// @ts-expect-error
|
|
@@ -1115,6 +1085,16 @@ const FormItemChildComponent = ({
|
|
|
1115
1085
|
setFieldValue?.(name, initialValue);
|
|
1116
1086
|
}
|
|
1117
1087
|
}, []);
|
|
1088
|
+
useEffect(() => {
|
|
1089
|
+
if (name && dependencies.length > 0) {
|
|
1090
|
+
const unsubscribe = subscribeToFields?.(dependencies, () => {
|
|
1091
|
+
validateFields?.([name]);
|
|
1092
|
+
});
|
|
1093
|
+
return () => {
|
|
1094
|
+
unsubscribe?.();
|
|
1095
|
+
};
|
|
1096
|
+
}
|
|
1097
|
+
}, [dependencies, name]);
|
|
1118
1098
|
const handleChange = (e, option) => {
|
|
1119
1099
|
let rawValue = e?.target ? e.target.value : e;
|
|
1120
1100
|
if (normalize) {
|
|
@@ -3036,6 +3016,7 @@ const InputComponent = ({
|
|
|
3036
3016
|
}, prefix && /*#__PURE__*/React.createElement("span", {
|
|
3037
3017
|
className: `${prefixCls}-prefix`
|
|
3038
3018
|
}, prefix), /*#__PURE__*/React.createElement("input", _extends({}, props, {
|
|
3019
|
+
suppressHydrationWarning: true,
|
|
3039
3020
|
ref: inputRef
|
|
3040
3021
|
}, props.type === 'password' && iconRender ? {
|
|
3041
3022
|
type: iconRenderVisible ? 'text' : 'password'
|