x-ui-design 1.0.30 → 1.0.31-gamma.1
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/README.md +1 -22
- package/dist/{esm/types/components → components}/DatePicker/DatePicker.d.ts +1 -2
- package/dist/{esm/types/components → components}/DatePicker/RangePicker/RangePicker.d.ts +1 -2
- package/dist/{esm/types/components → components}/Dropdown/Dropdown.d.ts +1 -2
- package/dist/{esm/types/components → components}/Empty/Empty.d.ts +1 -2
- package/dist/{esm/types/components → components}/Form/Item/Item.d.ts +1 -2
- package/dist/components/Icons/Icons.d.ts +18 -0
- package/dist/components/Input/Input.d.ts +11 -0
- package/dist/{esm/types/components → components}/Input/Textarea/Textarea.d.ts +1 -2
- package/dist/{esm/types/components → components}/Popover/Popover.d.ts +1 -2
- package/dist/{esm/types/components → components}/Radio/Button/Button.d.ts +1 -2
- package/dist/{esm/types/components → components}/Radio/Group/Group.d.ts +1 -2
- package/dist/{esm/types/components → components}/Radio/Radio.d.ts +1 -2
- package/dist/{esm/types/components → components}/Result/Result.d.ts +1 -2
- package/dist/{esm/types/components → components}/Switch/Switch.d.ts +1 -2
- package/dist/{esm/types/components → components}/Upload/Upload.d.ts +1 -2
- package/dist/esm/types/index.d.ts +0 -56
- package/dist/index.d.ts +1 -150
- package/dist/index.esm.js +3433 -3863
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +3395 -3825
- package/dist/index.js.map +1 -1
- package/package.json +22 -20
- package/.github/workflows/x-ui-design.yml +0 -14
- package/compile.sh +0 -15
- package/dist/esm/types/components/Icons/Icons.d.ts +0 -19
- package/dist/esm/types/components/Input/Input.d.ts +0 -16
- package/eslint.config.mjs +0 -16
- package/lib/components/Button/Button.tsx +0 -136
- package/lib/components/Button/index.ts +0 -1
- package/lib/components/Button/style.css +0 -197
- package/lib/components/Checkbox/Checkbox.tsx +0 -131
- package/lib/components/Checkbox/index.ts +0 -1
- package/lib/components/Checkbox/style.css +0 -95
- package/lib/components/ConditionalWrapper/index.tsx +0 -12
- package/lib/components/DatePicker/DatePicker.tsx +0 -526
- package/lib/components/DatePicker/RangePicker/RangePicker.tsx +0 -500
- package/lib/components/DatePicker/RangePicker/index.ts +0 -1
- package/lib/components/DatePicker/RangePicker/style.css +0 -434
- package/lib/components/DatePicker/TimePicker/TimePicker.tsx +0 -497
- package/lib/components/DatePicker/TimePicker/index.ts +0 -1
- package/lib/components/DatePicker/TimePicker/style.css +0 -197
- package/lib/components/DatePicker/index.ts +0 -1
- package/lib/components/DatePicker/style.css +0 -318
- package/lib/components/Dropdown/Dropdown.tsx +0 -234
- package/lib/components/Dropdown/index.ts +0 -1
- package/lib/components/Dropdown/style.css +0 -124
- package/lib/components/Empty/Empty.tsx +0 -45
- package/lib/components/Empty/index.ts +0 -1
- package/lib/components/Empty/style.css +0 -13
- package/lib/components/Form/Form.tsx +0 -130
- package/lib/components/Form/Item/Item.tsx +0 -294
- package/lib/components/Form/Item/index.ts +0 -1
- package/lib/components/Form/Item/style.css +0 -61
- package/lib/components/Form/index.ts +0 -1
- package/lib/components/Icons/Icons.tsx +0 -433
- package/lib/components/Icons/index.ts +0 -15
- package/lib/components/Input/Input.tsx +0 -228
- package/lib/components/Input/Textarea/Textarea.tsx +0 -110
- package/lib/components/Input/Textarea/index.ts +0 -1
- package/lib/components/Input/Textarea/style.css +0 -104
- package/lib/components/Input/index.ts +0 -1
- package/lib/components/Input/style.css +0 -137
- package/lib/components/Menu/Item/Item.tsx +0 -65
- package/lib/components/Menu/Menu.tsx +0 -261
- package/lib/components/Menu/SubMenu/SubMenu.tsx +0 -68
- package/lib/components/Menu/index.css +0 -145
- package/lib/components/Menu/index.ts +0 -1
- package/lib/components/Popover/Popover.tsx +0 -135
- package/lib/components/Popover/index.ts +0 -1
- package/lib/components/Popover/style.css +0 -82
- package/lib/components/Radio/Button/Button.tsx +0 -42
- package/lib/components/Radio/Button/index.ts +0 -1
- package/lib/components/Radio/Button/style.css +0 -43
- package/lib/components/Radio/Group/Group.tsx +0 -105
- package/lib/components/Radio/Group/index.ts +0 -1
- package/lib/components/Radio/Group/style.css +0 -53
- package/lib/components/Radio/Radio.tsx +0 -83
- package/lib/components/Radio/index.ts +0 -1
- package/lib/components/Radio/style.css +0 -73
- package/lib/components/Result/Result.tsx +0 -39
- package/lib/components/Result/index.ts +0 -1
- package/lib/components/Result/style.css +0 -173
- package/lib/components/Select/Option/Option.tsx +0 -49
- package/lib/components/Select/Option/index.ts +0 -1
- package/lib/components/Select/Option/style.css +0 -50
- package/lib/components/Select/Select.tsx +0 -935
- package/lib/components/Select/Tag/Tag.tsx +0 -43
- package/lib/components/Select/Tag/index.ts +0 -1
- package/lib/components/Select/Tag/style.css +0 -87
- package/lib/components/Select/index.ts +0 -1
- package/lib/components/Select/style.css +0 -186
- package/lib/components/Skeleton/Avatar/Avatar.tsx +0 -61
- package/lib/components/Skeleton/Avatar/index.ts +0 -1
- package/lib/components/Skeleton/Avatar/style.css +0 -27
- package/lib/components/Skeleton/Button/Button.tsx +0 -44
- package/lib/components/Skeleton/Button/index.ts +0 -1
- package/lib/components/Skeleton/Button/style.css +0 -50
- package/lib/components/Skeleton/Image/Image.tsx +0 -45
- package/lib/components/Skeleton/Image/index.ts +0 -1
- package/lib/components/Skeleton/Image/style.css +0 -23
- package/lib/components/Skeleton/Input/Input.tsx +0 -42
- package/lib/components/Skeleton/Input/index.ts +0 -1
- package/lib/components/Skeleton/Input/style.css +0 -56
- package/lib/components/Skeleton/Skeleton.tsx +0 -97
- package/lib/components/Skeleton/index.ts +0 -1
- package/lib/components/Skeleton/style.css +0 -84
- package/lib/components/Switch/Switch.tsx +0 -68
- package/lib/components/Switch/index.css +0 -50
- package/lib/components/Switch/index.ts +0 -1
- package/lib/components/Upload/Upload.tsx +0 -291
- package/lib/components/Upload/index.ts +0 -1
- package/lib/components/Upload/style.css +0 -151
- package/lib/global.d.ts +0 -1
- package/lib/helpers/flatten.ts +0 -26
- package/lib/helpers/index.ts +0 -52
- package/lib/helpers/mask.ts +0 -52
- package/lib/hooks/useForm.ts +0 -548
- package/lib/hooks/usePosition.ts +0 -206
- package/lib/hooks/useWatch.ts +0 -41
- package/lib/hooks/useWatchError.ts +0 -20
- package/lib/index.ts +0 -184
- package/lib/styles/global.css +0 -57
- package/lib/types/button.ts +0 -83
- package/lib/types/checkbox.ts +0 -32
- package/lib/types/datepicker.ts +0 -165
- package/lib/types/dropdown.ts +0 -41
- package/lib/types/empty.ts +0 -8
- package/lib/types/form.ts +0 -179
- package/lib/types/index.ts +0 -38
- package/lib/types/input.ts +0 -72
- package/lib/types/menu.ts +0 -55
- package/lib/types/popover.ts +0 -16
- package/lib/types/radio.ts +0 -69
- package/lib/types/result.ts +0 -22
- package/lib/types/select.ts +0 -126
- package/lib/types/skeleton.ts +0 -62
- package/lib/types/switch.ts +0 -22
- package/lib/types/upload.ts +0 -67
- package/lib/utils/index.ts +0 -37
- package/lib/utils/lazy.ts +0 -17
- package/next.config.ts +0 -7
- package/rollup.config.js +0 -71
- package/src/app/favicon.ico +0 -0
- package/src/app/globals.css +0 -48
- package/src/app/layout.d.ts +0 -5
- package/src/app/layout.tsx +0 -16
- package/src/app/page.d.ts +0 -1
- package/src/app/page.tsx +0 -21
- package/tsconfig.json +0 -46
- /package/dist/{esm/types/components → components}/Button/Button.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Button/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Checkbox/Checkbox.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Checkbox/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/ConditionalWrapper/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/DatePicker/RangePicker/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/DatePicker/TimePicker/TimePicker.d.ts +0 -0
- /package/dist/{esm/types/components → components}/DatePicker/TimePicker/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/DatePicker/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Dropdown/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Empty/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Form/Form.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Form/Item/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Form/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Icons/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Input/Textarea/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Input/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Menu/Item/Item.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Menu/Menu.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Menu/SubMenu/SubMenu.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Menu/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Popover/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Radio/Button/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Radio/Group/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Radio/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Result/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Select/Option/Option.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Select/Option/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Select/Select.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Select/Tag/Tag.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Select/Tag/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Select/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Skeleton/Avatar/Avatar.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Skeleton/Avatar/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Skeleton/Button/Button.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Skeleton/Button/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Skeleton/Image/Image.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Skeleton/Image/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Skeleton/Input/Input.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Skeleton/Input/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Skeleton/Skeleton.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Skeleton/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Switch/index.d.ts +0 -0
- /package/dist/{esm/types/components → components}/Upload/index.d.ts +0 -0
- /package/dist/{esm/types/helpers → helpers}/flatten.d.ts +0 -0
- /package/dist/{esm/types/helpers → helpers}/index.d.ts +0 -0
- /package/dist/{esm/types/helpers → helpers}/mask.d.ts +0 -0
- /package/dist/{esm/types/hooks → hooks}/useForm.d.ts +0 -0
- /package/dist/{esm/types/hooks → hooks}/usePosition.d.ts +0 -0
- /package/dist/{esm/types/hooks → hooks}/useWatch.d.ts +0 -0
- /package/dist/{esm/types/hooks → hooks}/useWatchError.d.ts +0 -0
- /package/dist/{esm/types/types → types}/button.d.ts +0 -0
- /package/dist/{esm/types/types → types}/checkbox.d.ts +0 -0
- /package/dist/{esm/types/types → types}/datepicker.d.ts +0 -0
- /package/dist/{esm/types/types → types}/dropdown.d.ts +0 -0
- /package/dist/{esm/types/types → types}/empty.d.ts +0 -0
- /package/dist/{esm/types/types → types}/form.d.ts +0 -0
- /package/dist/{esm/types/types → types}/index.d.ts +0 -0
- /package/dist/{esm/types/types → types}/input.d.ts +0 -0
- /package/dist/{esm/types/types → types}/menu.d.ts +0 -0
- /package/dist/{esm/types/types → types}/popover.d.ts +0 -0
- /package/dist/{esm/types/types → types}/radio.d.ts +0 -0
- /package/dist/{esm/types/types → types}/result.d.ts +0 -0
- /package/dist/{esm/types/types → types}/select.d.ts +0 -0
- /package/dist/{esm/types/types → types}/skeleton.d.ts +0 -0
- /package/dist/{esm/types/types → types}/switch.d.ts +0 -0
- /package/dist/{esm/types/types → types}/upload.d.ts +0 -0
- /package/dist/{esm/types/utils → utils}/index.d.ts +0 -0
- /package/dist/{esm/types/utils → utils}/lazy.d.ts +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default as Empty } from '../Empty/Empty'
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import React, {
|
|
4
|
-
Children,
|
|
5
|
-
createContext,
|
|
6
|
-
FC,
|
|
7
|
-
isValidElement,
|
|
8
|
-
ReactElement,
|
|
9
|
-
ReactNode,
|
|
10
|
-
SyntheticEvent,
|
|
11
|
-
useCallback,
|
|
12
|
-
useEffect,
|
|
13
|
-
useMemo,
|
|
14
|
-
useRef
|
|
15
|
-
} from 'react';
|
|
16
|
-
import { useForm } from '../../hooks/useForm';
|
|
17
|
-
import { FormInstance, FormItemProps, FormLayoutTypes, FormProps } from '../../types/form';
|
|
18
|
-
import { prefixClsForm, prefixClsFormV3 } from '../../utils';
|
|
19
|
-
import FormItem from './Item/Item';
|
|
20
|
-
import { flattenChildren } from '../../helpers/flatten';
|
|
21
|
-
import { SizeType } from '../../types';
|
|
22
|
-
|
|
23
|
-
export const FormContext = createContext<FormInstance | null>(null);
|
|
24
|
-
|
|
25
|
-
const Form: FC<FormProps> & { Item: FC<FormItemProps> } = ({
|
|
26
|
-
children,
|
|
27
|
-
form,
|
|
28
|
-
style = {},
|
|
29
|
-
prefixCls = prefixClsForm,
|
|
30
|
-
prefixClsV3 = prefixClsFormV3,
|
|
31
|
-
className = '',
|
|
32
|
-
onFinish,
|
|
33
|
-
onFinishFailed,
|
|
34
|
-
initialValues = {},
|
|
35
|
-
onValuesChange,
|
|
36
|
-
onFieldsChange,
|
|
37
|
-
layout = 'horizontal',
|
|
38
|
-
scrollToFirstError = false,
|
|
39
|
-
...rest
|
|
40
|
-
}) => {
|
|
41
|
-
const internalForm = useForm({ initialValues, onFieldsChange, onValuesChange, onFinishFailed });
|
|
42
|
-
const formRef = useRef<HTMLFormElement>(null);
|
|
43
|
-
|
|
44
|
-
const formInstance = useMemo(() => {
|
|
45
|
-
const _form = form || internalForm;
|
|
46
|
-
|
|
47
|
-
if (_form && Object.keys(initialValues).length) {
|
|
48
|
-
Object.keys(initialValues).forEach((name) => {
|
|
49
|
-
if (_form.getFieldValue(name) === undefined) {
|
|
50
|
-
_form.setFieldValue(name, initialValues[name]);
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return _form;
|
|
56
|
-
}, [form, internalForm, initialValues]);
|
|
57
|
-
const childrenList = useMemo(() => flattenChildren(children), [children])
|
|
58
|
-
|
|
59
|
-
const handleSubmit = useCallback(async (e: SyntheticEvent) => {
|
|
60
|
-
e.preventDefault();
|
|
61
|
-
e.stopPropagation();
|
|
62
|
-
|
|
63
|
-
await formInstance.submit();
|
|
64
|
-
}, []);
|
|
65
|
-
|
|
66
|
-
useEffect(() => {
|
|
67
|
-
if (onFinish) { formInstance.setOnFinish?.(onFinish) }
|
|
68
|
-
if (onFieldsChange) { formInstance.setOnFieldsChange?.(onFieldsChange) }
|
|
69
|
-
if (onValuesChange) { formInstance.setOnValuesChange?.(onValuesChange) }
|
|
70
|
-
if (onFinishFailed) { formInstance.setOnFinishFailed?.(onFinishFailed) }
|
|
71
|
-
|
|
72
|
-
if (scrollToFirstError) { formInstance.setScrollToFirstError(scrollToFirstError) }
|
|
73
|
-
}, [formInstance, onFieldsChange, onValuesChange, onFinishFailed, onFinish, scrollToFirstError]);
|
|
74
|
-
|
|
75
|
-
const injectPropsIntoFinalLeaf = useCallback((child: ReactNode): ReactNode => {
|
|
76
|
-
if (!isValidElement(child)) {
|
|
77
|
-
return child;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const childProps = child.props as ReactElement & {
|
|
81
|
-
children: ReactElement[],
|
|
82
|
-
__injected: boolean;
|
|
83
|
-
size?: SizeType;
|
|
84
|
-
layout?: FormLayoutTypes;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const isWrapper =
|
|
88
|
-
typeof child.type === 'string' &&
|
|
89
|
-
!('dangerouslySetInnerHTML' in childProps) &&
|
|
90
|
-
['div', 'span', 'label'].includes(child.type);
|
|
91
|
-
|
|
92
|
-
if (isWrapper) {
|
|
93
|
-
return (
|
|
94
|
-
<child.type {...childProps}>
|
|
95
|
-
{Children.map(flattenChildren(childProps.children), injectPropsIntoFinalLeaf)}
|
|
96
|
-
</child.type>
|
|
97
|
-
)
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (childProps?.__injected) {
|
|
101
|
-
return child;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return <child.type
|
|
105
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
106
|
-
// @ts-expect-error
|
|
107
|
-
{...child.props}
|
|
108
|
-
child={child}
|
|
109
|
-
size={childProps.size || rest.size}
|
|
110
|
-
layout={childProps.layout || layout}
|
|
111
|
-
/>
|
|
112
|
-
}, [rest.size, layout]);
|
|
113
|
-
|
|
114
|
-
return (
|
|
115
|
-
<FormContext.Provider value={formInstance}>
|
|
116
|
-
<form
|
|
117
|
-
style={style}
|
|
118
|
-
ref={formRef}
|
|
119
|
-
onSubmit={handleSubmit}
|
|
120
|
-
className={`${prefixCls} ${prefixClsV3} ${className}`}
|
|
121
|
-
>
|
|
122
|
-
{Children.map(childrenList, injectPropsIntoFinalLeaf)}
|
|
123
|
-
</form>
|
|
124
|
-
</FormContext.Provider>
|
|
125
|
-
);
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
Form.Item = FormItem;
|
|
129
|
-
|
|
130
|
-
export default Form;
|
|
@@ -1,294 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import React, {
|
|
4
|
-
Children,
|
|
5
|
-
isValidElement,
|
|
6
|
-
ReactElement,
|
|
7
|
-
useCallback,
|
|
8
|
-
useContext,
|
|
9
|
-
useEffect,
|
|
10
|
-
useMemo,
|
|
11
|
-
useRef,
|
|
12
|
-
useState
|
|
13
|
-
} from 'react';
|
|
14
|
-
import { clsx } from '../../../helpers';
|
|
15
|
-
import { RuleType, SyntheticBaseEvent } from '../../../types';
|
|
16
|
-
import { flattenChildren } from '../../../helpers/flatten';
|
|
17
|
-
import {
|
|
18
|
-
FieldInstancesRef,
|
|
19
|
-
FormItemChildComponentProps,
|
|
20
|
-
FormItemProps
|
|
21
|
-
} from '../../../types/form';
|
|
22
|
-
import { OptionProps } from '../../../types/select';
|
|
23
|
-
import { prefixClsFormItem, prefixClsFormItemV3 } from '../../../utils';
|
|
24
|
-
import { FormContext } from '../Form';
|
|
25
|
-
import { useWatchError } from '../../../hooks/useWatchError';
|
|
26
|
-
import './style.css';
|
|
27
|
-
|
|
28
|
-
const FormItem = ({
|
|
29
|
-
prefixCls = prefixClsFormItem,
|
|
30
|
-
prefixClsV3 = prefixClsFormItemV3,
|
|
31
|
-
name,
|
|
32
|
-
label,
|
|
33
|
-
rules = [],
|
|
34
|
-
children,
|
|
35
|
-
className = '',
|
|
36
|
-
layout = 'vertical',
|
|
37
|
-
style = {},
|
|
38
|
-
dependencies = [],
|
|
39
|
-
initialValue,
|
|
40
|
-
feedbackIcons,
|
|
41
|
-
extra,
|
|
42
|
-
hideLabel = false,
|
|
43
|
-
removeErrorMessageHeight = false,
|
|
44
|
-
...props
|
|
45
|
-
}: FormItemProps) => {
|
|
46
|
-
const formContext = useContext(FormContext);
|
|
47
|
-
|
|
48
|
-
const errorRef = useRef<HTMLSpanElement>(null);
|
|
49
|
-
const fieldRef = useRef<FieldInstancesRef | null>(null);
|
|
50
|
-
|
|
51
|
-
if (!formContext) {
|
|
52
|
-
throw new Error('FormItem must be used within a Form');
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const errors = useWatchError(formContext, name)?.[0];
|
|
56
|
-
|
|
57
|
-
const {
|
|
58
|
-
isReseting,
|
|
59
|
-
registerField,
|
|
60
|
-
getFieldValue,
|
|
61
|
-
setFieldValue,
|
|
62
|
-
getFieldInstance,
|
|
63
|
-
setFieldInstance,
|
|
64
|
-
subscribeToFields,
|
|
65
|
-
validateFields
|
|
66
|
-
} = formContext;
|
|
67
|
-
|
|
68
|
-
const childrenList = useMemo(() => flattenChildren(children), [children]);
|
|
69
|
-
|
|
70
|
-
useEffect(() => {
|
|
71
|
-
if (name && !getFieldInstance(name)) {
|
|
72
|
-
registerField(name, rules);
|
|
73
|
-
}
|
|
74
|
-
}, [name, rules]);
|
|
75
|
-
|
|
76
|
-
useEffect(() => {
|
|
77
|
-
setFieldInstance(name, fieldRef.current);
|
|
78
|
-
}, [name, fieldRef.current])
|
|
79
|
-
|
|
80
|
-
useEffect(() => () => registerField(name, undefined, true), [name])
|
|
81
|
-
|
|
82
|
-
useEffect(() => {
|
|
83
|
-
if (initialValue && getFieldValue(name) === undefined) {
|
|
84
|
-
setFieldValue(name, initialValue);
|
|
85
|
-
}
|
|
86
|
-
}, [name]);
|
|
87
|
-
|
|
88
|
-
useEffect(() => {
|
|
89
|
-
if (name && dependencies.length > 0) {
|
|
90
|
-
const unsubscribe = subscribeToFields(dependencies, () => {
|
|
91
|
-
validateFields([name]);
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
return () => {
|
|
95
|
-
unsubscribe();
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
}, [dependencies, name]);
|
|
99
|
-
|
|
100
|
-
const isRequired = useMemo(
|
|
101
|
-
() => rules.some((rule: RuleType) => rule.required),
|
|
102
|
-
[rules]
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
return (
|
|
106
|
-
<div
|
|
107
|
-
style={style}
|
|
108
|
-
data-instance={name}
|
|
109
|
-
className={clsx([
|
|
110
|
-
`${prefixCls} ${prefixClsV3}`,
|
|
111
|
-
{
|
|
112
|
-
[layout]: layout,
|
|
113
|
-
[className]: className,
|
|
114
|
-
noStyle: props.noStyle
|
|
115
|
-
}
|
|
116
|
-
])}
|
|
117
|
-
>
|
|
118
|
-
{!props.noStyle && (label || name) && !hideLabel && (
|
|
119
|
-
<label className={`${prefixCls}-label ${prefixClsV3}-label`} htmlFor={name}>
|
|
120
|
-
{label || name}
|
|
121
|
-
{isRequired && <span className={`${prefixCls}-required ${prefixClsV3}-required`}>*</span>}
|
|
122
|
-
{/* @Todo need to add Tooltip like Ant design */}
|
|
123
|
-
</label>
|
|
124
|
-
)}
|
|
125
|
-
|
|
126
|
-
{Children.map(childrenList, (child, key) => {
|
|
127
|
-
if (isValidElement(child)) {
|
|
128
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
129
|
-
// @ts-expect-error
|
|
130
|
-
const { onChange, value, ...childProps } = child.props;
|
|
131
|
-
const fieldValue = value ?? getFieldValue(name) ?? initialValue;
|
|
132
|
-
|
|
133
|
-
return (
|
|
134
|
-
<div className={`${prefixCls}-content`}>
|
|
135
|
-
<FormItemChildComponent
|
|
136
|
-
{...props}
|
|
137
|
-
key={`${key}_${name}_${isReseting}`}
|
|
138
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
139
|
-
// @ts-expect-error
|
|
140
|
-
ref={fieldRef}
|
|
141
|
-
name={name}
|
|
142
|
-
child={child}
|
|
143
|
-
value={value}
|
|
144
|
-
error={!!errors}
|
|
145
|
-
fieldValue={fieldValue}
|
|
146
|
-
setFieldValue={setFieldValue}
|
|
147
|
-
feedbackIcons={feedbackIcons}
|
|
148
|
-
onChange={onChange}
|
|
149
|
-
noStyle={props.noStyle}
|
|
150
|
-
normalize={props.normalize}
|
|
151
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
152
|
-
// @ts-expect-error
|
|
153
|
-
size={childProps.size || props.size}
|
|
154
|
-
/>
|
|
155
|
-
|
|
156
|
-
{extra
|
|
157
|
-
? <div className={`${prefixCls}-extra ${prefixClsV3}-extra`}>
|
|
158
|
-
{extra || ''}
|
|
159
|
-
</div>
|
|
160
|
-
: null}
|
|
161
|
-
|
|
162
|
-
{!props.noStyle && (
|
|
163
|
-
<span
|
|
164
|
-
ref={errorRef}
|
|
165
|
-
className={clsx([
|
|
166
|
-
`${prefixCls}-error ${prefixClsV3}-error`,
|
|
167
|
-
{ [`${prefixCls}-has-error ${prefixClsV3}-has-error`]: errors?.length }
|
|
168
|
-
])}
|
|
169
|
-
style={{
|
|
170
|
-
...removeErrorMessageHeight ? { minHeight: 0 } : {},
|
|
171
|
-
...extra ? { marginBottom: 0 } : {}
|
|
172
|
-
}}
|
|
173
|
-
>
|
|
174
|
-
{errors || ''}
|
|
175
|
-
</span>
|
|
176
|
-
)}
|
|
177
|
-
</div>
|
|
178
|
-
)
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
return child;
|
|
182
|
-
})}
|
|
183
|
-
</div>
|
|
184
|
-
);
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
const FormItemChildComponent = ({
|
|
188
|
-
child,
|
|
189
|
-
name,
|
|
190
|
-
error,
|
|
191
|
-
fieldValue,
|
|
192
|
-
setFieldValue,
|
|
193
|
-
onChange,
|
|
194
|
-
normalize,
|
|
195
|
-
noStyle,
|
|
196
|
-
feedbackIcons,
|
|
197
|
-
ref,
|
|
198
|
-
...props
|
|
199
|
-
}: FormItemChildComponentProps) => {
|
|
200
|
-
const formContext = useContext(FormContext);
|
|
201
|
-
|
|
202
|
-
const [wasNormalize, setWasNormalize] = useState(false);
|
|
203
|
-
|
|
204
|
-
const { getFieldsValue } = formContext || {};
|
|
205
|
-
|
|
206
|
-
const handleChange = (e: SyntheticBaseEvent) => {
|
|
207
|
-
let rawValue: RuleType | SyntheticBaseEvent = e?.target
|
|
208
|
-
? e.target.value
|
|
209
|
-
: e;
|
|
210
|
-
|
|
211
|
-
if (normalize) {
|
|
212
|
-
const prevValue = fieldValue ?? props.value;
|
|
213
|
-
const allValues = getFieldsValue?.();
|
|
214
|
-
|
|
215
|
-
rawValue = normalize(rawValue, prevValue, allValues);
|
|
216
|
-
|
|
217
|
-
if (rawValue === prevValue) {
|
|
218
|
-
e.target.value = rawValue;
|
|
219
|
-
setWasNormalize(prev => !prev);
|
|
220
|
-
|
|
221
|
-
const timeout = setTimeout(() => {
|
|
222
|
-
(
|
|
223
|
-
document.querySelector(`[name='${name}']`) as HTMLInputElement
|
|
224
|
-
)?.focus();
|
|
225
|
-
|
|
226
|
-
clearTimeout(timeout);
|
|
227
|
-
}, 0);
|
|
228
|
-
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
setFieldValue(name, rawValue, undefined, undefined, true);
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
const injectPropsIntoFinalLeaf = (child: ReactElement): ReactElement => {
|
|
237
|
-
if (!isValidElement(child)) {
|
|
238
|
-
return child;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
const childProps = child.props as ReactElement & {
|
|
242
|
-
children: ReactElement[],
|
|
243
|
-
__injected: boolean,
|
|
244
|
-
onChange?: (e: SyntheticBaseEvent, option?: OptionProps) => void
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
const isWrapper =
|
|
248
|
-
typeof child.type === 'string' &&
|
|
249
|
-
!('dangerouslySetInnerHTML' in childProps) &&
|
|
250
|
-
['div', 'span', 'label'].includes(child.type);
|
|
251
|
-
|
|
252
|
-
if (isWrapper) {
|
|
253
|
-
return (
|
|
254
|
-
<child.type {...childProps}>
|
|
255
|
-
{Children.map(flattenChildren(childProps.children), injectPropsIntoFinalLeaf)}
|
|
256
|
-
</child.type>
|
|
257
|
-
)
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
const _onChange = useCallback((e: SyntheticBaseEvent, option?: OptionProps) => {
|
|
261
|
-
handleChange(e);
|
|
262
|
-
|
|
263
|
-
childProps?.onChange?.(e, option)
|
|
264
|
-
}, [handleChange, childProps?.onChange])
|
|
265
|
-
|
|
266
|
-
if (childProps?.__injected) {
|
|
267
|
-
return child;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
return <child.type
|
|
271
|
-
{...props}
|
|
272
|
-
ref={ref}
|
|
273
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
274
|
-
// @ts-expect-error
|
|
275
|
-
{...child.props}
|
|
276
|
-
name={name}
|
|
277
|
-
child={child}
|
|
278
|
-
onChange={_onChange}
|
|
279
|
-
key={`${name}_${wasNormalize}`}
|
|
280
|
-
value={fieldValue ?? props.value}
|
|
281
|
-
{...('dangerouslySetInnerHTML' in childProps ? {} : {
|
|
282
|
-
__injected: true,
|
|
283
|
-
...(error ? { error } : {}),
|
|
284
|
-
})
|
|
285
|
-
}
|
|
286
|
-
/>
|
|
287
|
-
};
|
|
288
|
-
|
|
289
|
-
return injectPropsIntoFinalLeaf(child)
|
|
290
|
-
};
|
|
291
|
-
|
|
292
|
-
FormItem.displayName = 'FormItem';
|
|
293
|
-
|
|
294
|
-
export default FormItem;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default as Item } from './Item'
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
.xUi-form-item {
|
|
2
|
-
display: flex;
|
|
3
|
-
position: relative;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
.xUi-form-item.noStyle {
|
|
7
|
-
display: inline-flex;
|
|
8
|
-
margin-bottom: 0;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
.xUi-form-item-label {
|
|
12
|
-
font-weight: 500;
|
|
13
|
-
margin-bottom: 4px;
|
|
14
|
-
display: flex;
|
|
15
|
-
line-height: 20px;
|
|
16
|
-
align-items: center;
|
|
17
|
-
font-size: var(--xui-font-size-md);
|
|
18
|
-
color: var(--xui-text-color);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
.xUi-form-item-error {
|
|
22
|
-
right: 0;
|
|
23
|
-
margin-top: 4px;
|
|
24
|
-
margin-bottom: 8px;
|
|
25
|
-
display: block;
|
|
26
|
-
min-height: 16px;
|
|
27
|
-
font-size: var(--xui-font-size-xs);
|
|
28
|
-
position: relative;
|
|
29
|
-
color: var(--xui-error-color);
|
|
30
|
-
user-select: none;
|
|
31
|
-
line-height: 16px;
|
|
32
|
-
text-align: end;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
.xUi-form-item-required {
|
|
36
|
-
line-height: 1;
|
|
37
|
-
font-size: var(--xui-font-size-md);
|
|
38
|
-
margin-left: 4px;
|
|
39
|
-
margin-right: 4px;
|
|
40
|
-
display: inline-block;
|
|
41
|
-
color: var(--xui-error-color);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
.xUi-form-item.horizontal {
|
|
45
|
-
gap: 4px;
|
|
46
|
-
flex-direction: row;
|
|
47
|
-
align-items: center;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
.xUi-form-item.vertical {
|
|
51
|
-
flex-direction: column;
|
|
52
|
-
align-self: flex-start;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
.xUi-form-item .xUi-input-container {
|
|
56
|
-
width: -webkit-fill-available;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
.xUi-form-item-content {
|
|
60
|
-
width: -webkit-fill-available;
|
|
61
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default as Form } from './Form'
|