x-ui-design 0.6.42 → 0.6.44
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/hooks/useForm.d.ts +4 -11
- package/dist/index.esm.js +41 -63
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +40 -62
- package/dist/index.js.map +1 -1
- package/lib/components/Select/Select.tsx +52 -59
- package/lib/hooks/useForm.ts +22 -35
- package/package.json +1 -1
- package/src/app/page.tsx +20 -15
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
import { RuleTypes } from '../types';
|
|
2
2
|
import type { FieldData, FieldError, FormInstance } from '../types/form';
|
|
3
|
-
declare const useForm: (
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
scrollToFirstError?: boolean;
|
|
8
|
-
onFinish?: ((values: Record<string, RuleTypes>) => void) | undefined;
|
|
9
|
-
onFinishFailed?: (errorInfo: {
|
|
10
|
-
values: Record<string, RuleTypes>;
|
|
11
|
-
errorFields: Pick<FieldError, "errors" | "name">[];
|
|
12
|
-
}) => void;
|
|
13
|
-
}) => FormInstance;
|
|
3
|
+
declare const useForm: (initialValues?: Record<string, RuleTypes>, onFieldsChange?: (changedFields: FieldData[]) => void, onValuesChange?: (changedValues: Record<string, RuleTypes>, allValues: Record<string, RuleTypes>) => void, scrollToFirstError?: boolean, onFinish?: ((values: Record<string, RuleTypes>) => void) | undefined, onFinishFailed?: (errorInfo: {
|
|
4
|
+
values: Record<string, RuleTypes>;
|
|
5
|
+
errorFields: Pick<FieldError, "errors" | "name">[];
|
|
6
|
+
}) => void) => FormInstance;
|
|
14
7
|
export { useForm };
|
package/dist/index.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import require$$1 from 'react/jsx-runtime';
|
|
2
|
-
import React, { useRef, useState,
|
|
2
|
+
import React, { useRef, useState, Children, isValidElement, Fragment, Suspense, useContext, useMemo, useEffect, createContext, useImperativeHandle, useCallback, useLayoutEffect } from 'react';
|
|
3
3
|
import { createPortal } from 'react-dom';
|
|
4
4
|
import ReactDOMServer from 'react-dom/server';
|
|
5
5
|
|
|
@@ -598,14 +598,7 @@ const SpinerIcon = () => /*#__PURE__*/React.createElement("svg", {
|
|
|
598
598
|
d: "M988 548c-19.9 0-36-16.1-36-36 0-59.4-11.6-117-34.6-171.3a440.45 440.45 0 00-94.3-139.9 437.71 437.71 0 00-139.9-94.3C629 83.6 571.4 72 512 72c-19.9 0-36-16.1-36-36s16.1-36 36-36c69.1 0 136.2 13.5 199.3 40.3C772.3 66 827 103 874 150c47 47 83.9 101.8 109.7 162.7 26.7 63.1 40.2 130.2 40.2 199.3.1 19.9-16 36-35.9 36z"
|
|
599
599
|
}));
|
|
600
600
|
|
|
601
|
-
const useForm = ({
|
|
602
|
-
initialValues = {},
|
|
603
|
-
onFieldsChange,
|
|
604
|
-
onValuesChange,
|
|
605
|
-
scrollToFirstError,
|
|
606
|
-
onFinish,
|
|
607
|
-
onFinishFailed
|
|
608
|
-
}) => {
|
|
601
|
+
const useForm = (initialValues = {}, onFieldsChange, onValuesChange, scrollToFirstError, onFinish, onFinishFailed) => {
|
|
609
602
|
const touchedFieldsRef = useRef(new Set());
|
|
610
603
|
const rulesRef = useRef({});
|
|
611
604
|
const warningsRef = useRef({});
|
|
@@ -627,13 +620,9 @@ const useForm = ({
|
|
|
627
620
|
});
|
|
628
621
|
const fieldInstancesRef = useRef({});
|
|
629
622
|
const [isReseting, setIsReseting] = useState(false);
|
|
630
|
-
const
|
|
631
|
-
const errorsRef = useRef(errors);
|
|
623
|
+
const errorsRef = useRef({});
|
|
632
624
|
const fieldSubscribers = useRef({});
|
|
633
625
|
const formSubscribers = useRef([]);
|
|
634
|
-
useEffect(() => {
|
|
635
|
-
errorsRef.current = errors;
|
|
636
|
-
}, [errors]);
|
|
637
626
|
function getFormFields() {
|
|
638
627
|
return Object.assign({}, ...Object.values(formRef.current));
|
|
639
628
|
}
|
|
@@ -675,9 +664,8 @@ const useForm = ({
|
|
|
675
664
|
touchedFieldsRef.current.add(name);
|
|
676
665
|
}
|
|
677
666
|
if (reset === null) {
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
});
|
|
667
|
+
errorsRef.current[name] = [];
|
|
668
|
+
// setErrors({ [name]: [] });
|
|
681
669
|
return;
|
|
682
670
|
}
|
|
683
671
|
if (!errors?.length) {
|
|
@@ -698,9 +686,8 @@ const useForm = ({
|
|
|
698
686
|
}
|
|
699
687
|
});
|
|
700
688
|
} else {
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
});
|
|
689
|
+
errorsRef.current[name] = errors;
|
|
690
|
+
// setErrors({ [name]: errors });
|
|
704
691
|
}
|
|
705
692
|
}
|
|
706
693
|
function setFieldsValue(values, reset) {
|
|
@@ -776,10 +763,8 @@ const useForm = ({
|
|
|
776
763
|
}
|
|
777
764
|
}
|
|
778
765
|
}));
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
[name]: fieldErrors
|
|
782
|
-
}));
|
|
766
|
+
errorsRef.current[name] = fieldErrors;
|
|
767
|
+
// setErrors(prev => ({ ...prev, [name]: fieldErrors }));
|
|
783
768
|
warningsRef.current[name] = fieldWarnings;
|
|
784
769
|
return fieldErrors.length === 0;
|
|
785
770
|
}
|
|
@@ -796,8 +781,7 @@ const useForm = ({
|
|
|
796
781
|
if (_scrollToFirstError.current) {
|
|
797
782
|
const firstErrorContent = document.querySelectorAll('.xUi-form-item-has-error')?.[0];
|
|
798
783
|
if (firstErrorContent) {
|
|
799
|
-
|
|
800
|
-
_firstErrorContent?.scrollIntoView({
|
|
784
|
+
firstErrorContent.closest('.xUi-form-item')?.scrollIntoView({
|
|
801
785
|
behavior: 'smooth'
|
|
802
786
|
});
|
|
803
787
|
}
|
|
@@ -811,10 +795,8 @@ const useForm = ({
|
|
|
811
795
|
formData[name] = initialValues[name];
|
|
812
796
|
touchedFieldsRef.current.delete(name);
|
|
813
797
|
delete warningsRef.current[name];
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
[name]: []
|
|
817
|
-
}));
|
|
798
|
+
errorsRef.current[name] = [];
|
|
799
|
+
// setErrors(prev => ({ ...prev, [name]: [] }));
|
|
818
800
|
setFieldValue(name, initialValues[name], undefined, showError);
|
|
819
801
|
});
|
|
820
802
|
} else {
|
|
@@ -3717,38 +3699,6 @@ const SelectComponent = ({
|
|
|
3717
3699
|
setSearchInputWidth(searchContent.clientWidth - PADDING_TAG_INPUT);
|
|
3718
3700
|
}
|
|
3719
3701
|
};
|
|
3720
|
-
const dataRender = (() => {
|
|
3721
|
-
const options = filteredOptions.map(({
|
|
3722
|
-
children,
|
|
3723
|
-
className = '',
|
|
3724
|
-
...props
|
|
3725
|
-
}, index) => {
|
|
3726
|
-
const isSelected = hasMode ? selected.includes(props.value) : props.value === selected;
|
|
3727
|
-
return /*#__PURE__*/React.createElement(Option, _extends({
|
|
3728
|
-
key: `${props.value}_${index}`
|
|
3729
|
-
}, props, {
|
|
3730
|
-
selected: isSelected,
|
|
3731
|
-
className: clsx([className, {
|
|
3732
|
-
[`${prefixCls}-focused`]: hasMode ? isSelected : props.value === selected,
|
|
3733
|
-
[`${prefixCls}-disabled`]: maxCount && hasMode && !isSelected ? selected.length >= maxCount : false
|
|
3734
|
-
}]),
|
|
3735
|
-
onClick: e => {
|
|
3736
|
-
if (props.disabled) {
|
|
3737
|
-
return;
|
|
3738
|
-
}
|
|
3739
|
-
handleSelect(e, props.value, {
|
|
3740
|
-
children,
|
|
3741
|
-
className,
|
|
3742
|
-
...props
|
|
3743
|
-
});
|
|
3744
|
-
},
|
|
3745
|
-
"data-value": props.value
|
|
3746
|
-
}), children || props.label || props.value, menuItemSelectedIcon && hasMode && isSelected && /*#__PURE__*/React.createElement("span", {
|
|
3747
|
-
className: `${prefixCls}-selected-icon`
|
|
3748
|
-
}, menuItemSelectedIcon === true ? /*#__PURE__*/React.createElement(CheckIcon, null) : menuItemSelectedIcon));
|
|
3749
|
-
});
|
|
3750
|
-
return options;
|
|
3751
|
-
})();
|
|
3752
3702
|
const dropdownContent = !loading && open && isOpen && /*#__PURE__*/React.createElement("div", {
|
|
3753
3703
|
className: clsx([`${prefixCls}-dropdown`, {
|
|
3754
3704
|
[placement]: placement,
|
|
@@ -3790,7 +3740,35 @@ const SelectComponent = ({
|
|
|
3790
3740
|
handleSelect(e, searchQuery);
|
|
3791
3741
|
},
|
|
3792
3742
|
"data-value": searchQuery
|
|
3793
|
-
}, searchQuery), filteredOptions.length ?
|
|
3743
|
+
}, searchQuery), filteredOptions.length ? filteredOptions.map(({
|
|
3744
|
+
children,
|
|
3745
|
+
className = '',
|
|
3746
|
+
...props
|
|
3747
|
+
}, index) => {
|
|
3748
|
+
const isSelected = hasMode ? selected.includes(props.value) : props.value === selected;
|
|
3749
|
+
return /*#__PURE__*/React.createElement(Option, _extends({
|
|
3750
|
+
key: `${props.value}_${index}`
|
|
3751
|
+
}, props, {
|
|
3752
|
+
selected: isSelected,
|
|
3753
|
+
className: clsx([className, {
|
|
3754
|
+
[`${prefixCls}-focused`]: hasMode ? isSelected : props.value === selected,
|
|
3755
|
+
[`${prefixCls}-disabled`]: maxCount && hasMode && !isSelected ? selected.length >= maxCount : false
|
|
3756
|
+
}]),
|
|
3757
|
+
onClick: e => {
|
|
3758
|
+
if (props.disabled) {
|
|
3759
|
+
return;
|
|
3760
|
+
}
|
|
3761
|
+
handleSelect(e, props.value, {
|
|
3762
|
+
children,
|
|
3763
|
+
className,
|
|
3764
|
+
...props
|
|
3765
|
+
});
|
|
3766
|
+
},
|
|
3767
|
+
"data-value": props.value
|
|
3768
|
+
}), children || props.label || props.value, menuItemSelectedIcon && hasMode && isSelected && /*#__PURE__*/React.createElement("span", {
|
|
3769
|
+
className: `${prefixCls}-selected-icon`
|
|
3770
|
+
}, menuItemSelectedIcon === true ? /*#__PURE__*/React.createElement(CheckIcon, null) : menuItemSelectedIcon));
|
|
3771
|
+
}) : !asTag ? notFoundContent || /*#__PURE__*/React.createElement(EmptyContent, null) : null)));
|
|
3794
3772
|
const selectedOption = (() => {
|
|
3795
3773
|
const option = extractedOptions.find(e => e.value === selected || e.label === selected || e.children === selected) || selected;
|
|
3796
3774
|
return option?.children || option?.label || option?.value || null;
|