@@ -10,17 +10,21 @@ import { copyRefs } from './utils';
1010
1111import type { ThemeProviderType } from './createThemeProvider' ;
1212
13+ type $DeepShape < O : Object > = $Shape <
14+ $ObjMap < O , ( < V : Object > (V) => $DeepShape < V > ) & ( < V > (V) => V ) >
15+ > ;
16+
1317const isClassComponent = ( Component : any ) =>
1418 Boolean ( Component . prototype && Component . prototype . isReactComponent ) ;
1519
16- export type WithThemeType < T , S > = < P , C : React . ComponentType < P >> (
20+ export type WithThemeType < T > = < P , C : React . ComponentType < P >> (
1721 Comp : C
1822) => C &
1923 React . ComponentType <
20- $Diff < React . ElementConfig < C > , { theme : T } > & { theme ?: S }
24+ $Diff < React . ElementConfig < C > , { theme : T } > & { theme ?: $DeepShape < T > }
2125 > ;
2226
23- const createWithTheme = < T , S > (
27+ const createWithTheme = < T : Object , S : $DeepShape < T > > (
2428 ThemeProvider : ThemeProviderType < T > ,
2529 ThemeContext : Context < T >
2630) =>
@@ -47,7 +51,6 @@ const createWithTheme = <T, S>(
4751 _root: any ;
4852
4953 render ( ) {
50- const { forwardedRef, ...rest } = this . props ;
5154 return (
5255 < ThemeContext . Consumer >
5356 { theme => {
@@ -59,15 +62,15 @@ const createWithTheme = <T, S>(
5962 // It's needed to support use cases which need access to the underlying node
6063 element = (
6164 < Comp
62- { ...rest }
65+ { ...this . props }
6366 ref = { c => {
6467 this . _root = c ;
6568 } }
6669 theme = { merged }
6770 />
6871 ) ;
6972 } else {
70- element = < Comp { ...rest } theme = { merged } /> ;
73+ element = < Comp { ...this . props } theme = { merged } /> ;
7174 }
7275
7376 if ( merged !== this . props . theme ) {
@@ -82,24 +85,23 @@ const createWithTheme = <T, S>(
8285 }
8386 }
8487
85- let ComponentWithMethods = ThemedComponent ;
8688 if ( isClassComponent ( Comp ) ) {
8789 // getWrappedInstance is exposed by some HOCs like react-redux's connect
8890 // Use it to get the ref to the underlying element
8991 // Also expose it to access the underlying element after wrapping
9092 // $FlowFixMe
91- ComponentWithMethods . prototype . getWrappedInstance = function getWrappedInstance ( ) {
92- return this . _root . getWrappedInstance
93+ ThemedComponent . prototype . getWrappedInstance = function getWrappedInstance ( ) {
94+ return this . _root && this . _root . getWrappedInstance
9395 ? this . _root . getWrappedInstance ( )
9496 : this . _root ;
9597 } ;
9698
97- ComponentWithMethods = copyRefs ( ComponentWithMethods , Comp ) ;
99+ ThemedComponent = copyRefs ( ThemedComponent , Comp ) ;
98100 }
99101
100- hoistNonReactStatics ( ComponentWithMethods , Comp ) ;
102+ hoistNonReactStatics ( ThemedComponent , Comp ) ;
101103
102- return ( ComponentWithMethods : any ) ;
104+ return ( ThemedComponent : any ) ;
103105 } ;
104106
105107export default createWithTheme ;
0 commit comments