x-ui-design 0.3.62 → 0.3.64
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/types/form.d.ts +2 -3
- package/dist/index.esm.js +80 -50
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +79 -49
- package/dist/index.js.map +1 -1
- package/lib/components/Form/Form.tsx +44 -20
- package/lib/components/Form/Item/Item.tsx +60 -37
- package/lib/helpers/flatten.ts +1 -1
- package/lib/types/form.ts +2 -2
- package/package.json +1 -1
- package/src/app/page.tsx +8 -5
|
@@ -26,7 +26,7 @@ export interface FieldError {
|
|
|
26
26
|
name: string;
|
|
27
27
|
errors: string[];
|
|
28
28
|
}
|
|
29
|
-
type FormLayoutTypes = 'horizontal' | 'vertical' | 'inline';
|
|
29
|
+
export type FormLayoutTypes = 'horizontal' | 'vertical' | 'inline';
|
|
30
30
|
export type FormProps = DefaultProps & {
|
|
31
31
|
colon?: boolean;
|
|
32
32
|
name?: string;
|
|
@@ -67,7 +67,7 @@ export type FormItemProps = DefaultProps & {
|
|
|
67
67
|
feedbackIcons?: boolean;
|
|
68
68
|
};
|
|
69
69
|
export interface FormItemChildComponentProps {
|
|
70
|
-
child:
|
|
70
|
+
child: ReactElement;
|
|
71
71
|
name: string;
|
|
72
72
|
error: boolean;
|
|
73
73
|
fieldValue: RuleTypes;
|
|
@@ -103,4 +103,3 @@ export interface FormInstance {
|
|
|
103
103
|
getFieldInstance: (fieldName: string) => FieldInstancesRef;
|
|
104
104
|
isReseting: boolean;
|
|
105
105
|
}
|
|
106
|
-
export {};
|
package/dist/index.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import require$$1 from 'react/jsx-runtime';
|
|
2
|
-
import React$1, { useRef, useState, Children, isValidElement, Fragment, Suspense, useContext, useMemo, useEffect, createContext, forwardRef, useImperativeHandle, useCallback } from 'react';
|
|
2
|
+
import React$1, { useRef, useState, Children, isValidElement, Fragment, Suspense, useContext, useMemo, useEffect, cloneElement, createContext, forwardRef, useImperativeHandle, useCallback } from 'react';
|
|
3
3
|
import { createPortal } from 'react-dom';
|
|
4
4
|
import ReactDOMServer from 'react-dom/server';
|
|
5
5
|
|
|
@@ -820,16 +820,6 @@ const useForm = (initialValues = {}, onFieldsChange, onValuesChange) => {
|
|
|
820
820
|
return formInstance;
|
|
821
821
|
};
|
|
822
822
|
|
|
823
|
-
function _extends() {
|
|
824
|
-
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
825
|
-
for (var e = 1; e < arguments.length; e++) {
|
|
826
|
-
var t = arguments[e];
|
|
827
|
-
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
828
|
-
}
|
|
829
|
-
return n;
|
|
830
|
-
}, _extends.apply(null, arguments);
|
|
831
|
-
}
|
|
832
|
-
|
|
833
823
|
const prefixClsForm = 'xUi-form';
|
|
834
824
|
const prefixClsFormItem = 'xUi-form-item';
|
|
835
825
|
const prefixClsEmpty = 'xUi-empty';
|
|
@@ -845,6 +835,16 @@ const prefixClsTimePicker = 'xUi-timepicker';
|
|
|
845
835
|
const prefixClsButton = 'xUi-button';
|
|
846
836
|
const prefixClsSkeleton = 'xUi-skeleton';
|
|
847
837
|
|
|
838
|
+
function _extends() {
|
|
839
|
+
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
840
|
+
for (var e = 1; e < arguments.length; e++) {
|
|
841
|
+
var t = arguments[e];
|
|
842
|
+
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
843
|
+
}
|
|
844
|
+
return n;
|
|
845
|
+
}, _extends.apply(null, arguments);
|
|
846
|
+
}
|
|
847
|
+
|
|
848
848
|
const parseValue = value => {
|
|
849
849
|
if (value === 'true') {
|
|
850
850
|
return true;
|
|
@@ -887,7 +887,7 @@ function flattenChildren(children) {
|
|
|
887
887
|
const result = [];
|
|
888
888
|
Children.forEach(children, child => {
|
|
889
889
|
if (! /*#__PURE__*/isValidElement(child)) return;
|
|
890
|
-
if (child.type ===
|
|
890
|
+
if (child.type === Fragment || child.type === Suspense) {
|
|
891
891
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
892
892
|
// @ts-expect-error
|
|
893
893
|
result.push(...flattenChildren(child.props.children));
|
|
@@ -973,7 +973,7 @@ const FormItem$1 = ({
|
|
|
973
973
|
}, label || name, ":", isRequired && /*#__PURE__*/React$1.createElement("span", {
|
|
974
974
|
className: `${prefixCls}-required`
|
|
975
975
|
}, "*")), Children.map(childrenList, (child, key) => {
|
|
976
|
-
if (/*#__PURE__*/isValidElement(child)
|
|
976
|
+
if (/*#__PURE__*/isValidElement(child)) {
|
|
977
977
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
978
978
|
// @ts-expect-error
|
|
979
979
|
const {
|
|
@@ -982,23 +982,23 @@ const FormItem$1 = ({
|
|
|
982
982
|
...childProps
|
|
983
983
|
} = child.props;
|
|
984
984
|
const fieldValue = getFieldValue(name) ?? initialValue;
|
|
985
|
-
return /*#__PURE__*/React$1.createElement(FormItemChildComponent, _extends({},
|
|
985
|
+
return /*#__PURE__*/React$1.createElement(FormItemChildComponent, _extends({}, props, {
|
|
986
|
+
key: `${key}_${isReseting}`,
|
|
986
987
|
name: name,
|
|
987
988
|
child: child,
|
|
988
989
|
value: value,
|
|
990
|
+
error: !!errorMessage,
|
|
989
991
|
fieldValue: fieldValue,
|
|
990
|
-
noStyle: props.noStyle,
|
|
991
|
-
normalize: props.normalize,
|
|
992
|
-
key: `${key}_${isReseting}`,
|
|
993
|
-
error: Boolean(errorMessage),
|
|
994
992
|
setFieldValue: setFieldValue,
|
|
995
|
-
feedbackIcons: feedbackIcons
|
|
993
|
+
feedbackIcons: feedbackIcons,
|
|
994
|
+
onChange: onChange,
|
|
995
|
+
noStyle: props.noStyle,
|
|
996
|
+
normalize: props.normalize
|
|
996
997
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
997
998
|
// @ts-expect-error
|
|
998
999
|
,
|
|
999
|
-
size: childProps.size || props.size
|
|
1000
|
-
|
|
1001
|
-
}, childProps));
|
|
1000
|
+
size: childProps.size || props.size
|
|
1001
|
+
}));
|
|
1002
1002
|
}
|
|
1003
1003
|
return child;
|
|
1004
1004
|
}), !props.noStyle && errorMessage && /*#__PURE__*/React$1.createElement("span", {
|
|
@@ -1044,19 +1044,38 @@ const FormItemChildComponent = ({
|
|
|
1044
1044
|
setFieldValue(name, rawValue);
|
|
1045
1045
|
onChange?.(e, option);
|
|
1046
1046
|
};
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1047
|
+
const injectPropsIntoFinalLeaf = child => {
|
|
1048
|
+
if (! /*#__PURE__*/isValidElement(child)) {
|
|
1049
|
+
return child;
|
|
1050
|
+
}
|
|
1051
|
+
const childProps = child.props;
|
|
1052
|
+
const isWrapper = typeof child.type === 'string' && ['div', 'span', 'label'].includes(child.type);
|
|
1053
|
+
if (isWrapper) {
|
|
1054
|
+
return /*#__PURE__*/cloneElement(child, {
|
|
1055
|
+
...childProps,
|
|
1056
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1057
|
+
// @ts-expect-error
|
|
1058
|
+
children: Children.map(childProps.children, injectPropsIntoFinalLeaf)
|
|
1059
|
+
});
|
|
1060
|
+
}
|
|
1061
|
+
if (childProps?.__injected) {
|
|
1062
|
+
return child;
|
|
1063
|
+
}
|
|
1064
|
+
return /*#__PURE__*/cloneElement(child, {
|
|
1065
|
+
...props,
|
|
1066
|
+
name,
|
|
1067
|
+
onChange: handleChange,
|
|
1068
|
+
key: `${name}_${wasNormalize}`,
|
|
1069
|
+
value: fieldValue ?? props.value,
|
|
1070
|
+
...(error ? {
|
|
1071
|
+
error
|
|
1072
|
+
} : {}),
|
|
1073
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1074
|
+
// @ts-expect-error
|
|
1075
|
+
__injected: true
|
|
1076
|
+
});
|
|
1077
|
+
};
|
|
1078
|
+
return injectPropsIntoFinalLeaf(child);
|
|
1060
1079
|
};
|
|
1061
1080
|
FormItem$1.displayName = 'FormItem';
|
|
1062
1081
|
|
|
@@ -1104,6 +1123,31 @@ const Form$1 = ({
|
|
|
1104
1123
|
formInstance.onValuesChange = onValuesChange;
|
|
1105
1124
|
}
|
|
1106
1125
|
}, [formInstance, onFieldsChange, onValuesChange]);
|
|
1126
|
+
const injectPropsIntoFinalLeaf = child => {
|
|
1127
|
+
if (! /*#__PURE__*/isValidElement(child)) {
|
|
1128
|
+
return child;
|
|
1129
|
+
}
|
|
1130
|
+
const childProps = child.props;
|
|
1131
|
+
const isWrapper = typeof child.type === 'string' && ['div', 'span', 'label'].includes(child.type);
|
|
1132
|
+
if (isWrapper) {
|
|
1133
|
+
return /*#__PURE__*/cloneElement(child, {
|
|
1134
|
+
...childProps,
|
|
1135
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1136
|
+
// @ts-expect-error
|
|
1137
|
+
children: Children.map(childProps.children, injectPropsIntoFinalLeaf)
|
|
1138
|
+
});
|
|
1139
|
+
}
|
|
1140
|
+
if (childProps?.__injected) {
|
|
1141
|
+
return child;
|
|
1142
|
+
}
|
|
1143
|
+
return /*#__PURE__*/cloneElement(child, {
|
|
1144
|
+
...childProps,
|
|
1145
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1146
|
+
// @ts-expect-error
|
|
1147
|
+
size: childProps.size || rest.size,
|
|
1148
|
+
layout: childProps.layout || layout
|
|
1149
|
+
});
|
|
1150
|
+
};
|
|
1107
1151
|
return /*#__PURE__*/React$1.createElement(FormContext.Provider, {
|
|
1108
1152
|
value: formInstance
|
|
1109
1153
|
}, /*#__PURE__*/React$1.createElement("form", {
|
|
@@ -1111,21 +1155,7 @@ const Form$1 = ({
|
|
|
1111
1155
|
ref: formRef,
|
|
1112
1156
|
onSubmit: handleSubmit,
|
|
1113
1157
|
className: `${prefixCls} ${className}`
|
|
1114
|
-
}, Children.map(childrenList, child =>
|
|
1115
|
-
if (/*#__PURE__*/isValidElement(child) && child.type !== Fragment) {
|
|
1116
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1117
|
-
// @ts-expect-error
|
|
1118
|
-
const {
|
|
1119
|
-
...childProps
|
|
1120
|
-
} = child.props;
|
|
1121
|
-
return /*#__PURE__*/React$1.createElement(child.type, _extends({}, childProps, {
|
|
1122
|
-
child: child,
|
|
1123
|
-
size: childProps.size || rest.size,
|
|
1124
|
-
layout: childProps.layout || layout
|
|
1125
|
-
}));
|
|
1126
|
-
}
|
|
1127
|
-
return child;
|
|
1128
|
-
})));
|
|
1158
|
+
}, Children.map(childrenList, child => injectPropsIntoFinalLeaf(child))));
|
|
1129
1159
|
};
|
|
1130
1160
|
Form$1.Item = FormItem$1;
|
|
1131
1161
|
|