@@ -21,23 +21,30 @@ export interface IFormLayoutProps {
2121 direction ?: 'rtl' | 'ltr'
2222 inset ?: boolean
2323 shallow ?: boolean
24- feedbackLayout ?: 'loose' | 'terse' | 'popover' | 'none'
2524 tooltipLayout ?: 'icon' | 'text'
25+ feedbackLayout ?: 'loose' | 'terse' | 'popover' | 'none'
2626 bordered ?: boolean
2727}
2828
29- export const FormLayoutContext = createContext < IFormLayoutProps > ( null )
29+ export const FormLayoutDeepContext = createContext < IFormLayoutProps > ( null )
3030
3131export const FormLayoutShallowContext = createContext < IFormLayoutProps > ( null )
3232
33- export const useFormLayout = ( ) => useContext ( FormLayoutContext )
33+ export const useFormDeepLayout = ( ) => useContext ( FormLayoutDeepContext )
3434
3535export const useFormShallowLayout = ( ) => useContext ( FormLayoutShallowContext )
3636
37+ export const useFormLayout = ( ) => ( {
38+ ...useFormDeepLayout ( ) ,
39+ ...useFormShallowLayout ( ) ,
40+ } )
41+
3742export const FormLayout : React . FC < IFormLayoutProps > & {
3843 useFormLayout : ( ) => IFormLayoutProps
44+ useFormDeepLayout : ( ) => IFormLayoutProps
3945 useFormShallowLayout : ( ) => IFormLayoutProps
4046} = ( { shallow, children, prefix, className, style, ...props } ) => {
47+ const deepLayout = useFormDeepLayout ( )
4148 const formPrefixCls = usePrefixCls ( 'form' )
4249 const layoutPrefixCls = usePrefixCls ( 'formily-layout' , { prefix } )
4350 const layoutClassName = cls (
@@ -50,19 +57,26 @@ export const FormLayout: React.FC<IFormLayoutProps> & {
5057 className
5158 )
5259 const renderChildren = ( ) => {
53- if ( shallow ) {
54- return (
55- < FormLayoutShallowContext . Provider value = { props } >
56- { children }
57- </ FormLayoutShallowContext . Provider >
58- )
60+ const newDeepLayout = {
61+ ...deepLayout ,
62+ }
63+ if ( ! shallow ) {
64+ Object . assign ( newDeepLayout , props )
5965 } else {
60- return (
61- < FormLayoutContext . Provider value = { props } >
62- { children }
63- </ FormLayoutContext . Provider >
64- )
66+ if ( props . size ) {
67+ newDeepLayout . size = props . size
68+ }
69+ if ( props . colon ) {
70+ newDeepLayout . colon = props . colon
71+ }
6572 }
73+ return (
74+ < FormLayoutDeepContext . Provider value = { newDeepLayout } >
75+ < FormLayoutShallowContext . Provider value = { shallow ? props : undefined } >
76+ { children }
77+ </ FormLayoutShallowContext . Provider >
78+ </ FormLayoutDeepContext . Provider >
79+ )
6680 }
6781 return (
6882 < div className = { layoutClassName } style = { style } >
@@ -75,7 +89,8 @@ FormLayout.defaultProps = {
7589 shallow : true ,
7690}
7791
78- FormLayout . useFormLayout = useFormLayout
92+ FormLayout . useFormDeepLayout = useFormDeepLayout
7993FormLayout . useFormShallowLayout = useFormShallowLayout
94+ FormLayout . useFormLayout = useFormLayout
8095
8196export default FormLayout
0 commit comments