@@ -64,18 +64,32 @@ const baseStyle = css`
64
64
}
65
65
`
66
66
67
- const CardWrap = styled ( 'a' ) . attrs ( props => ( {
68
- rel : props . as === 'a' ? 'noopener noreferrer' : undefined ,
69
- target : props . as === 'a' ? '_blank' : undefined
70
- } ) ) (
71
- baseStyle ,
72
- ( { loading, contrast } ) => ! loading && ! contrast && hoverStyle ,
73
- ( { cardSize } ) => isLarge ( cardSize ) && largeStyle ,
74
- ( { reverse } ) => reverse && reverseStyle ,
75
- ( { backgroundColor, color, contrast } ) =>
76
- contrast && color && backgroundColor && contrastStyle ,
77
- ( { backgroundColor, color, contrast } ) =>
78
- contrast && ( ! color || ! backgroundColor ) && hoverStyle
79
- )
67
+ const createEl = ( { as } ) =>
68
+ styled ( as ) (
69
+ baseStyle ,
70
+ ( { loading, contrast } ) => ! loading && ! contrast && hoverStyle ,
71
+ ( { cardSize } ) => isLarge ( cardSize ) && largeStyle ,
72
+ ( { reverse } ) => reverse && reverseStyle ,
73
+ ( { backgroundColor, color, contrast } ) =>
74
+ contrast && color && backgroundColor && contrastStyle ,
75
+ ( { backgroundColor, color, contrast } ) =>
76
+ contrast && ( ! color || ! backgroundColor ) && hoverStyle
77
+ )
78
+
79
+ const CACHE = { }
80
+
81
+ const CardWrap = ( { rel, href, target, ...props } ) => {
82
+ const key = JSON . stringify ( props )
83
+ return createElement (
84
+ CACHE [ key ] || ( CACHE [ key ] = createEl ( props ) ) ,
85
+ props . as === 'a' ? { ...props , href, rel, target } : props
86
+ )
87
+ }
88
+
89
+ CardWrap . defaultProps = {
90
+ as : 'a' ,
91
+ rel : 'noopener noreferrer' ,
92
+ target : '_blank'
93
+ }
80
94
81
95
export default CardWrap
0 commit comments