x-ui-design 0.6.33 → 0.6.34
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/Select/Select.d.ts +3 -5
- package/dist/esm/types/hooks/useForm.d.ts +4 -3
- package/dist/esm/types/index.d.ts +50 -1
- package/dist/index.d.ts +50 -1
- package/dist/index.esm.js +58 -50
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +57 -49
- package/dist/index.js.map +1 -1
- package/lib/components/Form/Form.tsx +5 -1
- package/lib/components/Form/Item/Item.tsx +13 -20
- package/lib/components/Select/Select.tsx +42 -28
- package/lib/hooks/useForm.ts +36 -29
- package/package.json +1 -1
- package/src/app/page.tsx +53 -41
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import React, { ReactElement } from 'react';
|
|
2
2
|
import { SelectProps } from '../../types/select';
|
|
3
3
|
import './style.css';
|
|
4
|
-
declare const
|
|
4
|
+
declare const _default: React.MemoExoticComponent<{
|
|
5
5
|
({ prefixCls, id, searchValue, autoClearSearchValue, filterOption, optionFilterProp, children, options, listHeight, menuItemSelectedIcon, mode, value, defaultValue, maxCount, disabled, loading, placeholder, allowClear, filterable, defaultOpen, size, error, dropdownClassName, className, suffixIcon, searchIcon, style, showSearch, open, closeFromParent, showArrow, notFoundContent, noStyle, feedbackIcons, placement, removeIcon, maxTagCount, onSearch, onSelect, onDeselect, onClear, onChange, onClose, tagRender, getPopupContainer, dropdownRender, onDropdownVisibleChange, ref }: SelectProps): ReactElement;
|
|
6
6
|
displayName: string;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
};
|
|
10
|
-
export default Select;
|
|
7
|
+
}>;
|
|
8
|
+
export default _default;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RuleTypes } from '../types';
|
|
2
2
|
import type { FieldData, FieldError, FormInstance } from '../types/form';
|
|
3
|
-
|
|
3
|
+
type TUseForm = {
|
|
4
4
|
initialValues?: Record<string, RuleTypes>;
|
|
5
5
|
onFieldsChange?: (changedFields: FieldData[]) => void;
|
|
6
6
|
onValuesChange?: (changedValues: Record<string, RuleTypes>, allValues: Record<string, RuleTypes>) => void;
|
|
@@ -8,7 +8,8 @@ declare const useForm: ({ initialValues, onFieldsChange, onValuesChange, scrollT
|
|
|
8
8
|
onFinish?: ((values: Record<string, RuleTypes>) => void) | undefined;
|
|
9
9
|
onFinishFailed?: (errorInfo: {
|
|
10
10
|
values: Record<string, RuleTypes>;
|
|
11
|
-
errorFields: Pick<FieldError,
|
|
11
|
+
errorFields: Pick<FieldError, 'errors' | 'name'>[];
|
|
12
12
|
}) => void;
|
|
13
|
-
}
|
|
13
|
+
};
|
|
14
|
+
declare const useForm: ({ initialValues, onFieldsChange, onValuesChange, scrollToFirstError, onFinish, onFinishFailed }: TUseForm) => FormInstance;
|
|
14
15
|
export { useForm };
|
|
@@ -35,7 +35,56 @@ declare const Textarea: import("react").ComponentType<import("@/types/input").Te
|
|
|
35
35
|
declare const Radio: import("react").ComponentType<import("@/types/radio").RadioProps>;
|
|
36
36
|
declare const RadioButton: import("react").ComponentType<import("@/types/radio").RadioButtonProps>;
|
|
37
37
|
declare const RadioGroup: import("react").ComponentType<import("@/types/radio").RadioGroupProps>;
|
|
38
|
-
declare const Select: import("react").ComponentType<import("@/types
|
|
38
|
+
declare const Select: import("react").ComponentType<import("@/types").DefaultProps & {
|
|
39
|
+
id?: string;
|
|
40
|
+
searchValue?: string;
|
|
41
|
+
onSearch?: (value: string) => void;
|
|
42
|
+
autoClearSearchValue?: boolean;
|
|
43
|
+
onSelect?: (value: import("@/types").RuleTypes, option?: import("@/types/select").OptionType) => void;
|
|
44
|
+
onDeselect?: (value: string, option?: import("@/types/select").OptionType) => void;
|
|
45
|
+
filterOption?: boolean | ((input: string, option: import("@/types/select").OptionType) => boolean);
|
|
46
|
+
optionFilterProp?: string;
|
|
47
|
+
options?: import("@/types/select").OptionType[];
|
|
48
|
+
children?: import("react").ReactNode;
|
|
49
|
+
defaultActiveFirstOption?: boolean;
|
|
50
|
+
listHeight?: number;
|
|
51
|
+
menuItemSelectedIcon?: import("react").ReactNode;
|
|
52
|
+
mode?: "default" | "multiple" | "tags";
|
|
53
|
+
value?: import("@/types").RuleTypes;
|
|
54
|
+
defaultValue?: import("@/types").RuleTypes;
|
|
55
|
+
maxCount?: number;
|
|
56
|
+
onChange?: (e: import("@/types").RuleTypes, option?: import("@/types/select").OptionType) => void;
|
|
57
|
+
onClose?: () => void;
|
|
58
|
+
disabled?: boolean;
|
|
59
|
+
loading?: boolean;
|
|
60
|
+
placeholder?: string;
|
|
61
|
+
allowClear?: boolean;
|
|
62
|
+
filterable?: boolean;
|
|
63
|
+
defaultOpen?: boolean;
|
|
64
|
+
size?: "small" | "middle" | "large";
|
|
65
|
+
onClear?: () => void;
|
|
66
|
+
error?: boolean;
|
|
67
|
+
showSearch?: boolean;
|
|
68
|
+
tagRender?: ((props: import("@/types/select").CustomTagProps) => import("react").ReactElement) | undefined;
|
|
69
|
+
maxTagPlaceholder?: import("react").ReactNode | ((omittedValues: import("@/types/select").DisplayValueType[]) => import("react").ReactNode);
|
|
70
|
+
dropdownClassName?: string;
|
|
71
|
+
showArrow?: boolean;
|
|
72
|
+
onBlur?: import("react").FocusEventHandler<HTMLElement> | undefined;
|
|
73
|
+
onDropdownVisibleChange?: ((open: boolean, selected: import("@/types").RuleType) => void) | undefined;
|
|
74
|
+
showAction?: ("click" | "focus")[] | undefined;
|
|
75
|
+
suffixIcon?: import("react").ReactNode;
|
|
76
|
+
searchIcon?: import("react").ReactNode;
|
|
77
|
+
open?: boolean;
|
|
78
|
+
notFoundContent?: import("react").ReactNode;
|
|
79
|
+
getPopupContainer?: (triggerNode: HTMLElement) => HTMLElement;
|
|
80
|
+
dropdownRender?: (menu: import("react").ReactNode) => import("react").ReactNode;
|
|
81
|
+
feedbackIcons?: boolean;
|
|
82
|
+
placement?: "bottomLeft" | "bottomRight" | "topLeft" | "topRight";
|
|
83
|
+
removeIcon?: import("react").ReactNode;
|
|
84
|
+
maxTagCount?: number | "responsive";
|
|
85
|
+
ref?: import("react").ForwardedRef<HTMLDivElement>;
|
|
86
|
+
closeFromParent?: boolean;
|
|
87
|
+
}>;
|
|
39
88
|
declare const Option: import("react").ComponentType<import("@/types/select").OptionProps>;
|
|
40
89
|
declare const Tag: import("react").ComponentType<import("@/types/select").CustomTagProps>;
|
|
41
90
|
declare const Skeleton: import("react").ComponentType<import("./types/skeleton").SkeletonProps>;
|
package/dist/index.d.ts
CHANGED
|
@@ -139,7 +139,56 @@ declare const Textarea: react.ComponentType<__types_input.TextareaProps>;
|
|
|
139
139
|
declare const Radio: react.ComponentType<__types_radio.RadioProps>;
|
|
140
140
|
declare const RadioButton: react.ComponentType<__types_radio.RadioButtonProps>;
|
|
141
141
|
declare const RadioGroup: react.ComponentType<__types_radio.RadioGroupProps>;
|
|
142
|
-
declare const Select: react.ComponentType<
|
|
142
|
+
declare const Select: react.ComponentType<__types.DefaultProps & {
|
|
143
|
+
id?: string;
|
|
144
|
+
searchValue?: string;
|
|
145
|
+
onSearch?: (value: string) => void;
|
|
146
|
+
autoClearSearchValue?: boolean;
|
|
147
|
+
onSelect?: (value: __types.RuleTypes, option?: __types_select.OptionType) => void;
|
|
148
|
+
onDeselect?: (value: string, option?: __types_select.OptionType) => void;
|
|
149
|
+
filterOption?: boolean | ((input: string, option: __types_select.OptionType) => boolean);
|
|
150
|
+
optionFilterProp?: string;
|
|
151
|
+
options?: __types_select.OptionType[];
|
|
152
|
+
children?: react.ReactNode;
|
|
153
|
+
defaultActiveFirstOption?: boolean;
|
|
154
|
+
listHeight?: number;
|
|
155
|
+
menuItemSelectedIcon?: react.ReactNode;
|
|
156
|
+
mode?: "default" | "multiple" | "tags";
|
|
157
|
+
value?: __types.RuleTypes;
|
|
158
|
+
defaultValue?: __types.RuleTypes;
|
|
159
|
+
maxCount?: number;
|
|
160
|
+
onChange?: (e: __types.RuleTypes, option?: __types_select.OptionType) => void;
|
|
161
|
+
onClose?: () => void;
|
|
162
|
+
disabled?: boolean;
|
|
163
|
+
loading?: boolean;
|
|
164
|
+
placeholder?: string;
|
|
165
|
+
allowClear?: boolean;
|
|
166
|
+
filterable?: boolean;
|
|
167
|
+
defaultOpen?: boolean;
|
|
168
|
+
size?: "small" | "middle" | "large";
|
|
169
|
+
onClear?: () => void;
|
|
170
|
+
error?: boolean;
|
|
171
|
+
showSearch?: boolean;
|
|
172
|
+
tagRender?: ((props: __types_select.CustomTagProps) => react.ReactElement) | undefined;
|
|
173
|
+
maxTagPlaceholder?: react.ReactNode | ((omittedValues: __types_select.DisplayValueType[]) => react.ReactNode);
|
|
174
|
+
dropdownClassName?: string;
|
|
175
|
+
showArrow?: boolean;
|
|
176
|
+
onBlur?: react.FocusEventHandler<HTMLElement> | undefined;
|
|
177
|
+
onDropdownVisibleChange?: ((open: boolean, selected: __types.RuleType) => void) | undefined;
|
|
178
|
+
showAction?: ("click" | "focus")[] | undefined;
|
|
179
|
+
suffixIcon?: react.ReactNode;
|
|
180
|
+
searchIcon?: react.ReactNode;
|
|
181
|
+
open?: boolean;
|
|
182
|
+
notFoundContent?: react.ReactNode;
|
|
183
|
+
getPopupContainer?: (triggerNode: HTMLElement) => HTMLElement;
|
|
184
|
+
dropdownRender?: (menu: react.ReactNode) => react.ReactNode;
|
|
185
|
+
feedbackIcons?: boolean;
|
|
186
|
+
placement?: "bottomLeft" | "bottomRight" | "topLeft" | "topRight";
|
|
187
|
+
removeIcon?: react.ReactNode;
|
|
188
|
+
maxTagCount?: number | "responsive";
|
|
189
|
+
ref?: react.ForwardedRef<HTMLDivElement>;
|
|
190
|
+
closeFromParent?: boolean;
|
|
191
|
+
}>;
|
|
143
192
|
declare const Option: react.ComponentType<__types_select.OptionProps>;
|
|
144
193
|
declare const Tag: react.ComponentType<__types_select.CustomTagProps>;
|
|
145
194
|
declare const Skeleton: react.ComponentType<SkeletonProps>;
|
package/dist/index.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import require$$1 from 'react/jsx-runtime';
|
|
2
|
-
import React, { useRef, useState, Children, isValidElement, Fragment, Suspense, memo, useContext, useMemo, useEffect,
|
|
2
|
+
import React, { useRef, useState, Children, isValidElement, Fragment, Suspense, memo, useContext, useMemo, useEffect, createContext, useCallback, useImperativeHandle, useLayoutEffect } from 'react';
|
|
3
3
|
import { createPortal } from 'react-dom';
|
|
4
4
|
import ReactDOMServer from 'react-dom/server';
|
|
5
5
|
|
|
@@ -886,40 +886,44 @@ const useForm = ({
|
|
|
886
886
|
formRef.current[stepRef.current] = {};
|
|
887
887
|
}
|
|
888
888
|
}
|
|
889
|
+
const formInstanceRef = useRef(null);
|
|
889
890
|
const formInstance = {
|
|
890
|
-
submit,
|
|
891
891
|
setFields,
|
|
892
|
-
|
|
893
|
-
getFieldError,
|
|
894
|
-
registerField,
|
|
892
|
+
setOnFinish,
|
|
895
893
|
setFieldValue,
|
|
896
|
-
getFieldValue,
|
|
897
|
-
validateFields,
|
|
898
894
|
setFieldsValue,
|
|
895
|
+
setFieldInstance,
|
|
896
|
+
setOnFieldsChange,
|
|
897
|
+
setOnValuesChange,
|
|
898
|
+
setOnFinishFailed,
|
|
899
|
+
setScrollToFirstError,
|
|
899
900
|
getFieldsValue,
|
|
900
|
-
|
|
901
|
+
getFieldError,
|
|
902
|
+
getFieldValue,
|
|
901
903
|
getFieldsError,
|
|
902
|
-
isFieldsTouched,
|
|
903
904
|
getFieldWarning,
|
|
905
|
+
getFieldInstance,
|
|
906
|
+
isFieldTouched,
|
|
907
|
+
isFieldsTouched,
|
|
904
908
|
isFieldValidating,
|
|
905
909
|
subscribeToField,
|
|
906
910
|
subscribeToForm,
|
|
907
911
|
subscribeToFieldError,
|
|
912
|
+
subscribeToFields,
|
|
908
913
|
onFieldsChange,
|
|
909
914
|
onValuesChange,
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
915
|
+
submit,
|
|
916
|
+
resetFields,
|
|
917
|
+
registerField,
|
|
918
|
+
validateFields,
|
|
919
|
+
changeStep,
|
|
914
920
|
scrollToFirstError,
|
|
915
|
-
isReseting
|
|
916
|
-
setOnFinish,
|
|
917
|
-
setOnFieldsChange,
|
|
918
|
-
setOnValuesChange,
|
|
919
|
-
setOnFinishFailed,
|
|
920
|
-
changeStep
|
|
921
|
+
isReseting
|
|
921
922
|
};
|
|
922
|
-
|
|
923
|
+
if (!formInstanceRef.current) {
|
|
924
|
+
formInstanceRef.current = formInstance;
|
|
925
|
+
}
|
|
926
|
+
return formInstanceRef.current;
|
|
923
927
|
};
|
|
924
928
|
|
|
925
929
|
function _extends() {
|
|
@@ -1140,7 +1144,7 @@ const FormItemChildComponent = /*#__PURE__*/memo(({
|
|
|
1140
1144
|
};
|
|
1141
1145
|
}
|
|
1142
1146
|
}, [dependencies, name]);
|
|
1143
|
-
const handleChange =
|
|
1147
|
+
const handleChange = e => {
|
|
1144
1148
|
let rawValue = e?.target ? e.target.value : e;
|
|
1145
1149
|
if (normalize) {
|
|
1146
1150
|
const prevValue = fieldValue;
|
|
@@ -1157,9 +1161,8 @@ const FormItemChildComponent = /*#__PURE__*/memo(({
|
|
|
1157
1161
|
}
|
|
1158
1162
|
}
|
|
1159
1163
|
setFieldValue?.(name, rawValue, undefined, undefined, true);
|
|
1160
|
-
onChange?.(e, option);
|
|
1161
1164
|
};
|
|
1162
|
-
const injectPropsIntoFinalLeaf =
|
|
1165
|
+
const injectPropsIntoFinalLeaf = child => {
|
|
1163
1166
|
if (! /*#__PURE__*/isValidElement(child)) {
|
|
1164
1167
|
return child;
|
|
1165
1168
|
}
|
|
@@ -1174,15 +1177,16 @@ const FormItemChildComponent = /*#__PURE__*/memo(({
|
|
|
1174
1177
|
return /*#__PURE__*/React.createElement(child.type, _extends({}, props, {
|
|
1175
1178
|
ref: ref,
|
|
1176
1179
|
name: name
|
|
1177
|
-
|
|
1178
|
-
// @ts-expect-error
|
|
1179
|
-
}, child.props, {
|
|
1180
|
+
}, childProps, {
|
|
1180
1181
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1181
1182
|
// @ts-expect-error
|
|
1182
1183
|
size: childProps.size || props.size,
|
|
1183
1184
|
child: child,
|
|
1184
1185
|
value: fieldValue,
|
|
1185
|
-
onChange:
|
|
1186
|
+
onChange: (e, option) => {
|
|
1187
|
+
handleChange?.(e);
|
|
1188
|
+
childProps.onChange?.(e, option);
|
|
1189
|
+
},
|
|
1186
1190
|
key: `${name}_${wasNormalize}`
|
|
1187
1191
|
}, 'dangerouslySetInnerHTML' in childProps ? {} : {
|
|
1188
1192
|
__injected: true,
|
|
@@ -1190,7 +1194,7 @@ const FormItemChildComponent = /*#__PURE__*/memo(({
|
|
|
1190
1194
|
error
|
|
1191
1195
|
} : {})
|
|
1192
1196
|
}));
|
|
1193
|
-
}
|
|
1197
|
+
};
|
|
1194
1198
|
return injectPropsIntoFinalLeaf(child);
|
|
1195
1199
|
});
|
|
1196
1200
|
FormItem$1.displayName = 'FormItem';
|
|
@@ -1274,6 +1278,9 @@ const Form$1 = ({
|
|
|
1274
1278
|
}));
|
|
1275
1279
|
}, [rest.size, layout]);
|
|
1276
1280
|
const injectedChildren = useMemo(() => Children.map(childrenList, child => injectPropsIntoFinalLeaf(child)), [childrenList, injectPropsIntoFinalLeaf]);
|
|
1281
|
+
useEffect(() => {
|
|
1282
|
+
console.log('formInstance', formInstance);
|
|
1283
|
+
}, [formInstance]);
|
|
1277
1284
|
return /*#__PURE__*/React.createElement(FormContext.Provider, {
|
|
1278
1285
|
value: formInstance
|
|
1279
1286
|
}, /*#__PURE__*/React.createElement("form", {
|
|
@@ -1283,7 +1290,7 @@ const Form$1 = ({
|
|
|
1283
1290
|
className: formClassName
|
|
1284
1291
|
}, injectedChildren));
|
|
1285
1292
|
};
|
|
1286
|
-
Form$1.Item =
|
|
1293
|
+
Form$1.Item = FormItem$1;
|
|
1287
1294
|
var Form$2 = /*#__PURE__*/memo(Form$1);
|
|
1288
1295
|
|
|
1289
1296
|
var Form$3 = /*#__PURE__*/Object.freeze({
|
|
@@ -3694,23 +3701,27 @@ const SelectComponent = ({
|
|
|
3694
3701
|
}
|
|
3695
3702
|
return options || [];
|
|
3696
3703
|
}, []);
|
|
3697
|
-
const extractedOptions =
|
|
3704
|
+
const extractedOptions = useMemo(() => {
|
|
3705
|
+
return children ? extractOptions(children) : Array.isArray(options) ? options : [];
|
|
3706
|
+
}, [children, options]);
|
|
3698
3707
|
const triggerNode = useMemo(() => {
|
|
3699
3708
|
return selectRef.current?.querySelector(`.${prefixCls}-trigger`);
|
|
3700
3709
|
}, [prefixCls]);
|
|
3701
|
-
const filteredOptions =
|
|
3702
|
-
|
|
3703
|
-
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
|
|
3711
|
-
|
|
3712
|
-
|
|
3713
|
-
|
|
3710
|
+
const filteredOptions = useMemo(() => {
|
|
3711
|
+
return extractedOptions.filter(option => {
|
|
3712
|
+
if (typeof filterOption === 'function') {
|
|
3713
|
+
return filterOption(searchQuery, option);
|
|
3714
|
+
}
|
|
3715
|
+
if (filterOption === false) {
|
|
3716
|
+
return true;
|
|
3717
|
+
}
|
|
3718
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
3719
|
+
// @ts-expect-error
|
|
3720
|
+
const optionFilterPropValue = option[optionFilterProp];
|
|
3721
|
+
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);
|
|
3722
|
+
return valueToCheck.toLowerCase().includes(searchQuery.toLowerCase());
|
|
3723
|
+
});
|
|
3724
|
+
}, [extractedOptions, filterOption, searchQuery, optionFilterProp, getTextFromNode]);
|
|
3714
3725
|
const handleTriggerClick = () => {
|
|
3715
3726
|
if (!disabled) {
|
|
3716
3727
|
setIsOpen(!isOpen);
|
|
@@ -3721,8 +3732,8 @@ const SelectComponent = ({
|
|
|
3721
3732
|
setSearchInputWidth(searchContent.clientWidth - PADDING_TAG_INPUT);
|
|
3722
3733
|
}
|
|
3723
3734
|
};
|
|
3724
|
-
const dataRender = (() => {
|
|
3725
|
-
|
|
3735
|
+
const dataRender = useMemo(() => {
|
|
3736
|
+
return filteredOptions.map(({
|
|
3726
3737
|
children,
|
|
3727
3738
|
className = '',
|
|
3728
3739
|
...props
|
|
@@ -3751,8 +3762,7 @@ const SelectComponent = ({
|
|
|
3751
3762
|
className: `${prefixCls}-selected-icon`
|
|
3752
3763
|
}, menuItemSelectedIcon === true ? /*#__PURE__*/React.createElement(CheckIcon, null) : menuItemSelectedIcon));
|
|
3753
3764
|
});
|
|
3754
|
-
|
|
3755
|
-
})();
|
|
3765
|
+
}, [filteredOptions, hasMode, selected, maxCount, menuItemSelectedIcon]);
|
|
3756
3766
|
const dropdownContent = !loading && open && isOpen && /*#__PURE__*/React.createElement("div", {
|
|
3757
3767
|
className: clsx([`${prefixCls}-dropdown`, {
|
|
3758
3768
|
[placement]: placement,
|
|
@@ -3934,9 +3944,7 @@ const SelectComponent = ({
|
|
|
3934
3944
|
}, /*#__PURE__*/React.createElement(LoadingIcon, null)))), getPopupContainer?.(triggerNode) ? /*#__PURE__*/createPortal(dropdownContent, getPopupContainer(triggerNode)) : dropdownContent);
|
|
3935
3945
|
};
|
|
3936
3946
|
SelectComponent.displayName = 'Select';
|
|
3937
|
-
|
|
3938
|
-
Option
|
|
3939
|
-
});
|
|
3947
|
+
var Select = /*#__PURE__*/memo(SelectComponent);
|
|
3940
3948
|
|
|
3941
3949
|
var Select$1 = /*#__PURE__*/Object.freeze({
|
|
3942
3950
|
__proto__: null,
|