x-ui-design 0.6.47 → 0.6.49
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/index.esm.js +34 -26
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +34 -26
- package/dist/index.js.map +1 -1
- package/lib/components/Select/Select.tsx +26 -23
- package/lib/hooks/useForm.ts +7 -11
- package/package.json +1 -1
- package/src/app/page.tsx +1 -2
package/dist/index.esm.js
CHANGED
|
@@ -620,7 +620,7 @@ const useForm = (initialValues = {}, onFieldsChange, onValuesChange, scrollToFir
|
|
|
620
620
|
});
|
|
621
621
|
const fieldInstancesRef = useRef({});
|
|
622
622
|
const [isReseting, setIsReseting] = useState(false);
|
|
623
|
-
const
|
|
623
|
+
const [errors, setErrors] = useState({});
|
|
624
624
|
const fieldSubscribers = useRef({});
|
|
625
625
|
const formSubscribers = useRef([]);
|
|
626
626
|
function getFormFields() {
|
|
@@ -644,13 +644,13 @@ const useForm = (initialValues = {}, onFieldsChange, onValuesChange, scrollToFir
|
|
|
644
644
|
}, {});
|
|
645
645
|
}
|
|
646
646
|
function getFieldError(name) {
|
|
647
|
-
return
|
|
647
|
+
return errors[name] || [];
|
|
648
648
|
}
|
|
649
649
|
function getFieldWarning(name) {
|
|
650
650
|
return warningsRef.current[name] || [];
|
|
651
651
|
}
|
|
652
652
|
function getFieldsError() {
|
|
653
|
-
return Object.entries(
|
|
653
|
+
return Object.entries(errors).map(([name, err]) => ({
|
|
654
654
|
name,
|
|
655
655
|
errors: err
|
|
656
656
|
}));
|
|
@@ -664,8 +664,9 @@ const useForm = (initialValues = {}, onFieldsChange, onValuesChange, scrollToFir
|
|
|
664
664
|
touchedFieldsRef.current.add(name);
|
|
665
665
|
}
|
|
666
666
|
if (reset === null) {
|
|
667
|
-
|
|
668
|
-
|
|
667
|
+
setErrors({
|
|
668
|
+
[name]: []
|
|
669
|
+
});
|
|
669
670
|
return;
|
|
670
671
|
}
|
|
671
672
|
if (!errors?.length) {
|
|
@@ -686,8 +687,9 @@ const useForm = (initialValues = {}, onFieldsChange, onValuesChange, scrollToFir
|
|
|
686
687
|
}
|
|
687
688
|
});
|
|
688
689
|
} else {
|
|
689
|
-
|
|
690
|
-
|
|
690
|
+
setErrors({
|
|
691
|
+
[name]: errors
|
|
692
|
+
});
|
|
691
693
|
}
|
|
692
694
|
}
|
|
693
695
|
function setFieldsValue(values, reset) {
|
|
@@ -763,8 +765,10 @@ const useForm = (initialValues = {}, onFieldsChange, onValuesChange, scrollToFir
|
|
|
763
765
|
}
|
|
764
766
|
}
|
|
765
767
|
}));
|
|
766
|
-
|
|
767
|
-
|
|
768
|
+
setErrors(prev => ({
|
|
769
|
+
...prev,
|
|
770
|
+
[name]: fieldErrors
|
|
771
|
+
}));
|
|
768
772
|
warningsRef.current[name] = fieldWarnings;
|
|
769
773
|
return fieldErrors.length === 0;
|
|
770
774
|
}
|
|
@@ -795,8 +799,10 @@ const useForm = (initialValues = {}, onFieldsChange, onValuesChange, scrollToFir
|
|
|
795
799
|
formData[name] = initialValues[name];
|
|
796
800
|
touchedFieldsRef.current.delete(name);
|
|
797
801
|
delete warningsRef.current[name];
|
|
798
|
-
|
|
799
|
-
|
|
802
|
+
setErrors(prev => ({
|
|
803
|
+
...prev,
|
|
804
|
+
[name]: []
|
|
805
|
+
}));
|
|
800
806
|
setFieldValue(name, initialValues[name], undefined, showError);
|
|
801
807
|
});
|
|
802
808
|
} else {
|
|
@@ -3678,19 +3684,21 @@ const SelectComponent = ({
|
|
|
3678
3684
|
const triggerNode = useMemo(() => {
|
|
3679
3685
|
return selectRef.current?.querySelector(`.${prefixCls}-trigger`);
|
|
3680
3686
|
}, [prefixCls]);
|
|
3681
|
-
const filteredOptions =
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
|
|
3693
|
-
|
|
3687
|
+
const filteredOptions = useMemo(() => {
|
|
3688
|
+
return extractedOptions.filter(option => {
|
|
3689
|
+
if (typeof filterOption === 'function') {
|
|
3690
|
+
return filterOption(searchQuery, option);
|
|
3691
|
+
}
|
|
3692
|
+
if (filterOption === false) {
|
|
3693
|
+
return true;
|
|
3694
|
+
}
|
|
3695
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
3696
|
+
// @ts-expect-error
|
|
3697
|
+
const optionFilterPropValue = option[optionFilterProp];
|
|
3698
|
+
const valueToCheck = optionFilterProp && typeof optionFilterPropValue === 'string' ? String(optionFilterPropValue) : Array.isArray(option.children) && typeof option.children[0] === 'string' ? option.children[0] : getTextFromNode(option.children) || String(option.label) || String(option.value);
|
|
3699
|
+
return valueToCheck.toLowerCase().includes(searchQuery.toLowerCase());
|
|
3700
|
+
});
|
|
3701
|
+
}, [extractedOptions, filterOption, optionFilterProp, searchQuery]);
|
|
3694
3702
|
const handleTriggerClick = () => {
|
|
3695
3703
|
if (!disabled) {
|
|
3696
3704
|
setIsOpen(!isOpen);
|
|
@@ -3701,10 +3709,10 @@ const SelectComponent = ({
|
|
|
3701
3709
|
setSearchInputWidth(searchContent.clientWidth - PADDING_TAG_INPUT);
|
|
3702
3710
|
}
|
|
3703
3711
|
};
|
|
3704
|
-
const selectedOption = (() => {
|
|
3712
|
+
const selectedOption = useMemo(() => {
|
|
3705
3713
|
const option = extractedOptions.find(e => e.value === selected || e.label === selected || e.children === selected) || selected;
|
|
3706
3714
|
return option?.children || option?.label || option?.value || null;
|
|
3707
|
-
})
|
|
3715
|
+
}, [extractedOptions, selected]) || selected || null;
|
|
3708
3716
|
const hasMaxTagCount = hasMode && (typeof maxTagCount === 'number' || maxTagCount === 'responsive');
|
|
3709
3717
|
const container = tagContainerRef.current;
|
|
3710
3718
|
const selectedTags = hasMode ? selected : [];
|