@@ -16,15 +16,16 @@ import {
16
16
} from '@mui/material'
17
17
import { DisableShieldsNotification } from './DisableShieldsNotification'
18
18
import { CloseIcon } from '@storyblok/mui'
19
+ import { ModalState } from './FieldPluginSandbox'
19
20
20
21
const NonPortalModal : FunctionComponent <
21
22
PropsWithChildren < {
22
- isNonPortalModalOpen : boolean
23
+ isModal : boolean
23
24
} >
24
25
> = ( props ) => (
25
26
< Box
26
27
sx = {
27
- props . isNonPortalModalOpen
28
+ props . isModal
28
29
? {
29
30
position : 'fixed' ,
30
31
left : 0 ,
@@ -46,12 +47,12 @@ const NonPortalModal: FunctionComponent<
46
47
47
48
const FieldTypeSandbox : FunctionComponent <
48
49
PropsWithChildren < {
49
- isNonPortalModalOpen : boolean
50
+ isModal : boolean
50
51
} >
51
52
> = ( props ) => (
52
53
< Box
53
54
sx = {
54
- props . isNonPortalModalOpen
55
+ props . isModal
55
56
? {
56
57
bgcolor : 'background.paper' ,
57
58
p : 6 ,
@@ -69,7 +70,7 @@ const FieldTypeSandbox: FunctionComponent<
69
70
style = { {
70
71
display : 'flex' ,
71
72
margin : 'auto' ,
72
- width : props . isNonPortalModalOpen ? '90%' : '100%' ,
73
+ width : props . isModal ? '90%' : '100%' ,
73
74
} }
74
75
>
75
76
{ props . children }
@@ -132,28 +133,23 @@ export const FieldTypePreview = forwardRef<
132
133
{
133
134
src : string | undefined
134
135
height : number
135
- isModal : boolean
136
- enablePortalModal : boolean
136
+ modalState : ModalState
137
137
fullHeight : boolean
138
138
// Allows the iframe to be refreshed
139
139
iframeKey ?: number
140
140
sx ?: SxProps
141
141
onModalChange : ( isModal : boolean ) => void
142
142
}
143
143
> ( function FieldTypePreview ( props , ref ) {
144
- const { height, isModal, fullHeight, enablePortalModal, onModalChange } =
145
- props
146
-
147
- const isNonPortalModalOpen = ! enablePortalModal && isModal
148
- const isPortalModalOpen = enablePortalModal && isModal
144
+ const { height, fullHeight, modalState, onModalChange } = props
149
145
150
146
const setTeleported = ( el : HTMLIFrameElement | null ) => {
151
- if ( isPortalModalOpen ) {
147
+ if ( modalState === 'modal-with-portal' ) {
152
148
setRef ( ref , el )
153
149
}
154
150
}
155
151
const setNonTeleported = ( el : HTMLIFrameElement | null ) => {
156
- if ( ! isPortalModalOpen ) {
152
+ if ( modalState !== 'modal-with-portal' ) {
157
153
setRef ( ref , el )
158
154
}
159
155
}
@@ -166,7 +162,7 @@ export const FieldTypePreview = forwardRef<
166
162
< Box sx = { props . sx } >
167
163
< DisableShieldsNotification />
168
164
< Dialog
169
- open = { isPortalModalOpen }
165
+ open = { modalState === 'modal-with-portal' }
170
166
fullScreen
171
167
sx = { {
172
168
padding : 10 ,
@@ -197,28 +193,33 @@ export const FieldTypePreview = forwardRef<
197
193
src = { props . src }
198
194
ref = { setTeleported }
199
195
fullHeight = { fullHeight }
200
- modal = { isModal }
196
+ modal = { modalState === 'modal-with-portal' }
201
197
height = { height }
202
198
/>
203
199
</ Dialog >
204
- < Backdrop
205
- open = { isNonPortalModalOpen }
206
- sx = { { zIndex : ( { zIndex } ) => zIndex . drawer } }
207
- />
208
- < NonPortalModal isNonPortalModalOpen = { isNonPortalModalOpen } >
209
- < FieldTypeSandbox isNonPortalModalOpen = { isNonPortalModalOpen } >
210
- { ! isPortalModalOpen && (
211
- < FieldPluginIframe
212
- key = { props . iframeKey }
213
- src = { props . src }
214
- ref = { setNonTeleported }
215
- fullHeight = { fullHeight }
216
- modal = { isModal }
217
- height = { height }
200
+ {
201
+ // Always render it unless the modal with portal is open; then we don't want to render thois
202
+ modalState !== 'modal-with-portal' && (
203
+ < >
204
+ < Backdrop
205
+ open = { modalState === 'modal-without-portal' }
206
+ sx = { { zIndex : ( { zIndex } ) => zIndex . drawer } }
218
207
/>
219
- ) }
220
- </ FieldTypeSandbox >
221
- </ NonPortalModal >
208
+ < NonPortalModal isModal = { modalState === 'modal-without-portal' } >
209
+ < FieldTypeSandbox isModal = { modalState === 'modal-without-portal' } >
210
+ < FieldPluginIframe
211
+ key = { props . iframeKey }
212
+ src = { props . src }
213
+ ref = { setNonTeleported }
214
+ fullHeight = { fullHeight }
215
+ modal = { modalState === 'modal-without-portal' }
216
+ height = { height }
217
+ />
218
+ </ FieldTypeSandbox >
219
+ </ NonPortalModal >
220
+ </ >
221
+ )
222
+ }
222
223
</ Box >
223
224
)
224
225
} )
0 commit comments