1
1
import type { DSize } from '../../utils/types' ;
2
2
import type { DBreakpoints } from '../grid' ;
3
- import type { DFormInstance } from './hooks' ;
4
3
5
4
import { isUndefined } from 'lodash' ;
6
- import React , { useMemo } from 'react' ;
5
+ import React from 'react' ;
7
6
8
7
import { getClassName } from '@react-devui/utils' ;
9
8
10
9
import { usePrefixConfig , useComponentConfig , useMediaQuery } from '../../hooks' ;
11
10
import { registerComponentMate } from '../../utils' ;
12
- import { DFormGroup , DFormGroupContext } from './FormGroup' ;
11
+ import { DFormGroup } from './FormGroup' ;
13
12
import { DFormItem } from './FormItem' ;
13
+ import { DFormUpdateContext } from './hooks' ;
14
14
15
15
export interface DFormContextData {
16
- gInstance : DFormInstance ;
17
- gBreakpointsMatched : DBreakpoints [ ] ;
18
16
gLabelWidth : NonNullable < DFormProps [ 'dLabelWidth' ] > ;
19
17
gLabelColon : NonNullable < DFormProps [ 'dLabelColon' ] > ;
20
18
gRequiredType : NonNullable < DFormProps [ 'dRequiredType' ] > ;
21
19
gLayout : NonNullable < DFormProps [ 'dLayout' ] > ;
22
20
gInlineSpan : NonNullable < DFormProps [ 'dInlineSpan' ] > ;
23
21
gFeedbackIcon : NonNullable < DFormProps [ 'dFeedbackIcon' ] > ;
24
22
gSize ?: DSize ;
23
+ gBreakpointsMatched : DBreakpoints [ ] ;
25
24
}
26
25
export const DFormContext = React . createContext < DFormContextData | null > ( null ) ;
27
26
28
27
export interface DFormProps extends React . FormHTMLAttributes < HTMLFormElement > {
29
- dForm : DFormInstance ;
28
+ dUpdate : ( ) => void ;
30
29
dLabelWidth ?: number | string ;
31
30
dLabelColon ?: boolean ;
32
31
dRequiredType ?: 'required' | 'optional' | 'hidden' ;
@@ -52,7 +51,7 @@ export const DForm: {
52
51
} = ( props ) => {
53
52
const {
54
53
children,
55
- dForm ,
54
+ dUpdate ,
56
55
dLabelWidth,
57
56
dLabelColon,
58
57
dRequiredType = 'required' ,
@@ -71,17 +70,16 @@ export const DForm: {
71
70
72
71
const breakpointsMatched = useMediaQuery ( ) ;
73
72
74
- const contextValue = useMemo < DFormContextData > ( ( ) => {
75
- const contextValue = {
76
- gInstance : dForm ,
77
- gBreakpointsMatched : breakpointsMatched ,
73
+ const contextValue = ( ( ) => {
74
+ const contextValue : DFormContextData = {
78
75
gLabelWidth : dLabelWidth ?? 150 ,
79
76
gLabelColon : dLabelColon ?? true ,
80
77
gRequiredType : dRequiredType ,
81
78
gLayout : dLayout ,
82
79
gInlineSpan : dInlineSpan ,
83
80
gFeedbackIcon : dFeedbackIcon ,
84
81
gSize : dSize ,
82
+ gBreakpointsMatched : breakpointsMatched ,
85
83
} ;
86
84
if ( dResponsiveProps ) {
87
85
const mergeProps = ( point : string , targetKey : string , sourceKey : string ) => {
@@ -103,11 +101,11 @@ export const DForm: {
103
101
contextValue . gLabelColon = dLabelColon ?? ( contextValue . gLayout === 'vertical' ? false : true ) ;
104
102
105
103
return contextValue ;
106
- } , [ dForm , breakpointsMatched , dLabelWidth , dLabelColon , dRequiredType , dLayout , dInlineSpan , dFeedbackIcon , dSize , dResponsiveProps ] ) ;
104
+ } ) ( ) ;
107
105
108
106
return (
109
107
< DFormContext . Provider value = { contextValue } >
110
- < DFormGroupContext . Provider value = { dForm . form } >
108
+ < DFormUpdateContext . Provider value = { dUpdate } >
111
109
< form
112
110
{ ...restProps }
113
111
className = { getClassName ( restProps . className , `${ dPrefix } form` , {
@@ -124,7 +122,7 @@ export const DForm: {
124
122
>
125
123
{ children }
126
124
</ form >
127
- </ DFormGroupContext . Provider >
125
+ </ DFormUpdateContext . Provider >
128
126
</ DFormContext . Provider >
129
127
) ;
130
128
} ;
0 commit comments