@@ -10,72 +10,82 @@ export interface OpenIntConnectEmbedProps
10
10
11
11
const DEFAULT_HEIGHT = 500
12
12
const DEFAULT_WIDTH = 350
13
- export const OpenIntConnectEmbed = React . forwardRef (
14
- (
15
- { baseUrl , params , onReady , ... iframeProps } : OpenIntConnectEmbedProps ,
16
- forwardedRef : React . ForwardedRef < HTMLIFrameElement > ,
17
- ) => {
18
- const url = getIFrameUrl ( { baseUrl , params } )
19
- const [ loading , setLoading ] = React . useState ( true )
13
+ export const OpenIntConnectEmbed = React . memo (
14
+ React . forwardRef (
15
+ (
16
+ props : OpenIntConnectEmbedProps ,
17
+ forwardedRef : React . ForwardedRef < HTMLIFrameElement > ,
18
+ ) => {
19
+ const { baseUrl , params , onReady , ... iframeProps } = props
20
20
21
- React . useEffect ( ( ) => {
22
- if (
23
- typeof iframeProps . height === 'number' &&
24
- iframeProps . height < DEFAULT_HEIGHT
25
- ) {
26
- console . warn (
27
- 'Optimal height for Connect is 500px. Using 500px instead.' ,
28
- )
29
- }
30
- if ( typeof iframeProps . width === 'number' && iframeProps . width < 350 ) {
31
- console . warn ( 'Minimum width for Connect is 350px. Using 350px instead.' )
32
- }
33
- } , [ iframeProps . height , iframeProps . width ] )
21
+ const url = React . useMemo (
22
+ ( ) => getIFrameUrl ( { baseUrl, params} ) ,
23
+ [ baseUrl , params ] ,
24
+ )
34
25
35
- const height =
36
- typeof iframeProps . height === 'number'
37
- ? iframeProps . height > DEFAULT_HEIGHT
38
- ? iframeProps . height
39
- : DEFAULT_HEIGHT
40
- : iframeProps . height
26
+ const [ loading , setLoading ] = React . useState ( true )
41
27
42
- const width =
43
- typeof iframeProps . width === 'number'
44
- ? iframeProps . width > DEFAULT_WIDTH
45
- ? iframeProps . width
46
- : DEFAULT_WIDTH
47
- : iframeProps . width || DEFAULT_WIDTH
28
+ React . useEffect ( ( ) => {
29
+ if (
30
+ typeof iframeProps . height === 'number' &&
31
+ iframeProps . height < DEFAULT_HEIGHT
32
+ ) {
33
+ console . warn (
34
+ 'Optimal height for Connect is 500px. Using 500px instead.' ,
35
+ )
36
+ }
37
+ if ( typeof iframeProps . width === 'number' && iframeProps . width < 350 ) {
38
+ console . warn (
39
+ 'Minimum width for Connect is 350px. Using 350px instead.' ,
40
+ )
41
+ }
42
+ } , [ iframeProps . height , iframeProps . width ] )
48
43
49
- // Add a more reliable way to know iframe has fully finished loading
50
- // by sending message from iframe to parent when ready
51
- return (
52
- < div className = "connect-embed-wrapper" >
53
- < div className = { `spinner-container ${ loading ? 'loading' : 'loaded' } ` } >
54
- < svg className = "spinner" viewBox = "0 0 50 50" >
55
- < circle
56
- className = "path"
57
- cx = "25"
58
- cy = "25"
59
- r = "20"
60
- fill = "none"
61
- strokeWidth = "5" > </ circle >
62
- </ svg >
63
- </ div >
64
- < iframe
65
- name = "openint-connect-frame"
66
- id = "openint-connect-frame"
67
- { ...iframeProps }
68
- ref = { forwardedRef }
69
- onLoad = { ( ) => {
70
- setLoading ( false )
71
- onReady ?.( )
72
- } }
73
- src = { url }
74
- width = { width }
75
- height = { height }
76
- />
44
+ const height =
45
+ typeof iframeProps . height === 'number'
46
+ ? iframeProps . height > DEFAULT_HEIGHT
47
+ ? iframeProps . height
48
+ : DEFAULT_HEIGHT
49
+ : iframeProps . height
50
+
51
+ const width =
52
+ typeof iframeProps . width === 'number'
53
+ ? iframeProps . width > DEFAULT_WIDTH
54
+ ? iframeProps . width
55
+ : DEFAULT_WIDTH
56
+ : iframeProps . width || DEFAULT_WIDTH
77
57
78
- < style > { `
58
+ // Add a more reliable way to know iframe has fully finished loading
59
+ // by sending message from iframe to parent when ready
60
+ return (
61
+ < div className = "connect-embed-wrapper" >
62
+ < div
63
+ className = { `spinner-container ${ loading ? 'loading' : 'loaded' } ` } >
64
+ < svg className = "spinner" viewBox = "0 0 50 50" >
65
+ < circle
66
+ className = "path"
67
+ cx = "25"
68
+ cy = "25"
69
+ r = "20"
70
+ fill = "none"
71
+ strokeWidth = "5" > </ circle >
72
+ </ svg >
73
+ </ div >
74
+ < iframe
75
+ name = "openint-connect-frame"
76
+ id = "openint-connect-frame"
77
+ { ...iframeProps }
78
+ ref = { forwardedRef }
79
+ onLoad = { ( ) => {
80
+ setLoading ( false )
81
+ onReady ?.( )
82
+ } }
83
+ src = { url }
84
+ width = { width }
85
+ height = { height }
86
+ />
87
+
88
+ < style > { `
79
89
.connect-embed-wrapper {
80
90
display: flex;
81
91
height: ${ height } px;
@@ -91,7 +101,7 @@ export const OpenIntConnectEmbed = React.forwardRef(
91
101
justify-content: center;
92
102
align-items: center;
93
103
height: 100%;
94
- background: white;
104
+ background: ${ params ?. theme === 'dark' ? '#1C1C1C' : ' white' } ;
95
105
transition: opacity 0.3s ease;
96
106
max-width: ${ width } px;
97
107
max-height: ${ height } px;
@@ -130,8 +140,10 @@ export const OpenIntConnectEmbed = React.forwardRef(
130
140
}
131
141
}
132
142
` } </ style >
133
- </ div >
134
- )
135
- } ,
143
+ </ div >
144
+ )
145
+ } ,
146
+ ) ,
136
147
)
148
+
137
149
OpenIntConnectEmbed . displayName = 'OpenIntConnectEmbed'
0 commit comments