11import type { DSize } from '../../utils/types' ;
22import type { DBreakpoints } from '../grid' ;
3- import type { DFormInstance } from './hooks' ;
43
54import { isUndefined } from 'lodash' ;
6- import React , { useMemo } from 'react' ;
5+ import React from 'react' ;
76
87import { getClassName } from '@react-devui/utils' ;
98
109import { usePrefixConfig , useComponentConfig , useMediaQuery } from '../../hooks' ;
1110import { registerComponentMate } from '../../utils' ;
12- import { DFormGroup , DFormGroupContext } from './FormGroup' ;
11+ import { DFormGroup } from './FormGroup' ;
1312import { DFormItem } from './FormItem' ;
13+ import { DFormUpdateContext } from './hooks' ;
1414
1515export interface DFormContextData {
16- gInstance : DFormInstance ;
17- gBreakpointsMatched : DBreakpoints [ ] ;
1816 gLabelWidth : NonNullable < DFormProps [ 'dLabelWidth' ] > ;
1917 gLabelColon : NonNullable < DFormProps [ 'dLabelColon' ] > ;
2018 gRequiredType : NonNullable < DFormProps [ 'dRequiredType' ] > ;
2119 gLayout : NonNullable < DFormProps [ 'dLayout' ] > ;
2220 gInlineSpan : NonNullable < DFormProps [ 'dInlineSpan' ] > ;
2321 gFeedbackIcon : NonNullable < DFormProps [ 'dFeedbackIcon' ] > ;
2422 gSize ?: DSize ;
23+ gBreakpointsMatched : DBreakpoints [ ] ;
2524}
2625export const DFormContext = React . createContext < DFormContextData | null > ( null ) ;
2726
2827export interface DFormProps extends React . FormHTMLAttributes < HTMLFormElement > {
29- dForm : DFormInstance ;
28+ dUpdate : ( ) => void ;
3029 dLabelWidth ?: number | string ;
3130 dLabelColon ?: boolean ;
3231 dRequiredType ?: 'required' | 'optional' | 'hidden' ;
@@ -52,7 +51,7 @@ export const DForm: {
5251} = ( props ) => {
5352 const {
5453 children,
55- dForm ,
54+ dUpdate ,
5655 dLabelWidth,
5756 dLabelColon,
5857 dRequiredType = 'required' ,
@@ -71,17 +70,16 @@ export const DForm: {
7170
7271 const breakpointsMatched = useMediaQuery ( ) ;
7372
74- const contextValue = useMemo < DFormContextData > ( ( ) => {
75- const contextValue = {
76- gInstance : dForm ,
77- gBreakpointsMatched : breakpointsMatched ,
73+ const contextValue = ( ( ) => {
74+ const contextValue : DFormContextData = {
7875 gLabelWidth : dLabelWidth ?? 150 ,
7976 gLabelColon : dLabelColon ?? true ,
8077 gRequiredType : dRequiredType ,
8178 gLayout : dLayout ,
8279 gInlineSpan : dInlineSpan ,
8380 gFeedbackIcon : dFeedbackIcon ,
8481 gSize : dSize ,
82+ gBreakpointsMatched : breakpointsMatched ,
8583 } ;
8684 if ( dResponsiveProps ) {
8785 const mergeProps = ( point : string , targetKey : string , sourceKey : string ) => {
@@ -103,11 +101,11 @@ export const DForm: {
103101 contextValue . gLabelColon = dLabelColon ?? ( contextValue . gLayout === 'vertical' ? false : true ) ;
104102
105103 return contextValue ;
106- } , [ dForm , breakpointsMatched , dLabelWidth , dLabelColon , dRequiredType , dLayout , dInlineSpan , dFeedbackIcon , dSize , dResponsiveProps ] ) ;
104+ } ) ( ) ;
107105
108106 return (
109107 < DFormContext . Provider value = { contextValue } >
110- < DFormGroupContext . Provider value = { dForm . form } >
108+ < DFormUpdateContext . Provider value = { dUpdate } >
111109 < form
112110 { ...restProps }
113111 className = { getClassName ( restProps . className , `${ dPrefix } form` , {
@@ -124,7 +122,7 @@ export const DForm: {
124122 >
125123 { children }
126124 </ form >
127- </ DFormGroupContext . Provider >
125+ </ DFormUpdateContext . Provider >
128126 </ DFormContext . Provider >
129127 ) ;
130128} ;
0 commit comments