@@ -76,38 +76,33 @@ interface FoundationStyledInterface extends FoundationStyledComponentFactories {
76
76
) : ThemedStyledFunction < C , Foundation , { foundation ?: Foundation } >
77
77
}
78
78
79
+ function templateFunctionGenerator ( BaseComponentGenerator : ThemedStyledFunction < any , any , object , string | number | symbol > ) {
80
+ const customTemplateFn = ( ...args : TemplateStringsArray ) => {
81
+ // @ts -ignore
82
+ const BaseComponent = BaseComponentGenerator ( ...args )
83
+ const BaseRefComponent = forwardRef ( ( props , ref ) => {
84
+ const currentFoundation = useContext ( FoundationContext )
85
+ return (
86
+ < BaseComponent
87
+ ref = { ref }
88
+ key = { args . toString ( ) }
89
+ foundation = { currentFoundation }
90
+ { ...props }
91
+ />
92
+ )
93
+ } )
94
+ BaseRefComponent . toString = BaseComponent . toString
95
+ return BaseRefComponent
96
+ }
97
+ customTemplateFn . attrs = ( attrs ) => templateFunctionGenerator ( BaseComponentGenerator . attrs ( attrs ) )
98
+ customTemplateFn . withConfig = ( config ) => templateFunctionGenerator ( BaseComponentGenerator . withConfig ( config ) )
99
+ return customTemplateFn
100
+ }
101
+
79
102
/* eslint-disable-next-line func-names */ /* @ts -ignore */
80
103
const FoundationStyled : FoundationStyledInterface = ( tag ) => {
81
104
const tagTemplate = styled ( tag )
82
-
83
- function templateFunctionGenerator ( BaseComponentGenerator ) {
84
- return function customTemplateFunction ( ...args : TemplateStringsArray ) {
85
- const BaseComponent = BaseComponentGenerator ( ...args )
86
-
87
- const BaseRefComponent = forwardRef ( ( props , ref ) => {
88
- const currentFoundation = useContext ( FoundationContext )
89
- return (
90
- < BaseComponent
91
- ref = { ref }
92
- key = { args . toString ( ) }
93
- foundation = { currentFoundation }
94
- { ...props }
95
- />
96
- )
97
- } )
98
- BaseRefComponent . toString = BaseComponent . toString
99
-
100
- return BaseRefComponent
101
- }
102
- }
103
-
104
- const wrappedTemplateFunction = templateFunctionGenerator ( tagTemplate )
105
- // @ts -ignore
106
- wrappedTemplateFunction . attrs = attrs => templateFunctionGenerator ( tagTemplate . attrs ( attrs ) )
107
- // @ts -ignore
108
- wrappedTemplateFunction . withConfig = config => templateFunctionGenerator ( tagTemplate . withConfig ( config ) )
109
-
110
- return wrappedTemplateFunction
105
+ return templateFunctionGenerator ( tagTemplate )
111
106
} ;
112
107
113
108
( domElements as Array < AnyStyledComponent > ) . forEach ( element => {
0 commit comments