Skip to content

Commit c4f98a6

Browse files
fix(sandbox): close modal from the parent app
1 parent c603fcb commit c4f98a6

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

packages/sandbox/src/components/FieldPluginSandbox.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ const useSandbox = (
323323
setSchema,
324324
setUrl,
325325
randomizeUid,
326+
setModalOpen,
326327
},
327328
] as const
328329
}
@@ -342,7 +343,7 @@ export const FieldPluginSandbox: FunctionComponent = () => {
342343
fieldTypeIframe,
343344
iframeSrc,
344345
},
345-
{ setContent, setLanguage, setSchema, setUrl, randomizeUid },
346+
{ setModalOpen, setContent, setLanguage, setSchema, setUrl, randomizeUid },
346347
] = useSandbox(error)
347348

348349
return (
@@ -378,6 +379,7 @@ export const FieldPluginSandbox: FunctionComponent = () => {
378379
enablePortalModal={enablePortalModal}
379380
fullHeight={fullHeight}
380381
ref={fieldTypeIframe}
382+
onModalChange={setModalOpen}
381383
/>
382384
</CenteredContent>
383385
<Stack alignSelf="flex-start">

packages/sandbox/src/components/FieldTypePreview.tsx

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ import {
1010
Backdrop,
1111
Box,
1212
Dialog,
13+
IconButton,
1314
SxProps,
1415
Typography,
1516
} from '@mui/material'
1617
import { DisableShieldsNotification } from './DisableShieldsNotification'
18+
import { CloseIcon } from '@storyblok/mui'
1719

1820
const NonPortalModal: FunctionComponent<
1921
PropsWithChildren<{
@@ -136,9 +138,11 @@ export const FieldTypePreview = forwardRef<
136138
// Allows the iframe to be refreshed
137139
iframeKey?: number
138140
sx?: SxProps
141+
onModalChange: (isModal: boolean) => void
139142
}
140143
>(function FieldTypePreview(props, ref) {
141-
const { height, isModal, fullHeight, enablePortalModal } = props
144+
const { height, isModal, fullHeight, enablePortalModal, onModalChange } =
145+
props
142146

143147
const isNonPortalModalOpen = !enablePortalModal && isModal
144148
const isPortalModalOpen = enablePortalModal && isModal
@@ -154,6 +158,10 @@ export const FieldTypePreview = forwardRef<
154158
}
155159
}
156160

161+
const handleClose = () => {
162+
onModalChange(false)
163+
}
164+
157165
return (
158166
<Box sx={props.sx}>
159167
<DisableShieldsNotification />
@@ -169,7 +177,21 @@ export const FieldTypePreview = forwardRef<
169177
overflow: 'hidden',
170178
},
171179
}}
180+
onClose={handleClose}
172181
>
182+
<Box
183+
width="100%"
184+
display="flex"
185+
justifyContent="flex-end"
186+
padding={1}
187+
>
188+
<IconButton
189+
onClick={handleClose}
190+
color="secondary"
191+
>
192+
<CloseIcon />
193+
</IconButton>
194+
</Box>
173195
<FieldPluginIframe
174196
key={props.iframeKey}
175197
src={props.src}

0 commit comments

Comments
 (0)