Skip to content

Commit 7ede7bf

Browse files
feat: modal in portal
1 parent f90f984 commit 7ede7bf

File tree

5 files changed

+29
-18
lines changed

5 files changed

+29
-18
lines changed

packages/field-plugin/src/createFieldPlugin/createFieldPlugin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export type CreateFieldPluginOptions<Content> = {
1212
onUpdateState: (state: FieldPluginResponse<Content>) => void
1313
validateContent?: ValidateContent<Content>
1414
targetOrigin?: string
15+
// TODO add enablePortalModal
1516
}
1617

1718
export type CreateFieldPlugin = <Content = unknown>(

packages/field-plugin/src/messaging/pluginMessage/pluginToContainerMessage/PluginLoadedMessage.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ describe('PluginLoadedMessage', () => {
120120
).toEqual(false)
121121
})
122122
})
123-
describe('usePortalModal', () => {
123+
describe('enablePortalModal', () => {
124124
it('is optional', () => {
125125
expect(
126126
isPluginLoadedMessage({
@@ -184,9 +184,9 @@ describe('PluginLoadedMessage', () => {
184184
true,
185185
)
186186
})
187-
it('sets usePortalModal to true', () => {
187+
it('sets enablePortalModal to true', () => {
188188
expect(pluginLoadedMessage({ uid, callbackId })).toHaveProperty(
189-
'usePortalModal',
189+
'enablePortalModal',
190190
true,
191191
)
192192
})

packages/field-plugin/src/messaging/pluginMessage/pluginToContainerMessage/PluginLoadedMessage.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export type PluginLoadedMessage = MessageToContainer<'loaded'> & {
55
// signals that the field plugin is responsible for its own scrolling in modal mode
66
fullHeight?: boolean
77
subscribeState?: boolean
8-
usePortalModal?: boolean
8+
enablePortalModal?: boolean
99
}
1010
export const isPluginLoadedMessage = (
1111
obj: unknown,
@@ -18,9 +18,9 @@ export const isPluginLoadedMessage = (
1818
(!hasKey(obj, 'subscribeState') ||
1919
typeof obj.subscribeState === 'undefined' ||
2020
typeof obj.subscribeState === 'boolean') &&
21-
(!hasKey(obj, 'usePortalModal') ||
22-
typeof obj.usePortalModal === 'undefined' ||
23-
typeof obj.usePortalModal === 'boolean')
21+
(!hasKey(obj, 'enablePortalModal') ||
22+
typeof obj.enablePortalModal === 'undefined' ||
23+
typeof obj.enablePortalModal === 'boolean')
2424

2525
export const pluginLoadedMessage = (
2626
options: Pick<PluginLoadedMessage, 'uid' | 'callbackId'>,
@@ -29,6 +29,6 @@ export const pluginLoadedMessage = (
2929
event: 'loaded',
3030
fullHeight: true,
3131
subscribeState: true,
32-
usePortalModal: true,
32+
enablePortalModal: true,
3333
...options,
3434
})

packages/sandbox/src/components/FieldPluginSandbox.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ const useSandbox = (
108108
const [isModalOpen, setModalOpen] = useState(false)
109109
const [height, setHeight] = useState(initialHeight)
110110
const [fullHeight, setFullHeight] = useState(false)
111+
const [enablePortalModal, setEnablePortalModal] = useState(false)
111112
const [schema, setSchema] = useState<FieldPluginSchema>({
112113
field_type: 'preview',
113114
options: manifest.options,
@@ -218,6 +219,7 @@ const useSandbox = (
218219
(message: PluginLoadedMessage) => {
219220
setSubscribeState(Boolean(message.subscribeState))
220221
setFullHeight(Boolean(message.fullHeight))
222+
setEnablePortalModal(Boolean(message.enablePortalModal))
221223
dispatchLoadedChanged({
222224
...stateChangedData,
223225
action: 'loaded',
@@ -309,6 +311,7 @@ const useSandbox = (
309311
isModalOpen,
310312
height,
311313
fullHeight,
314+
enablePortalModal,
312315
schema,
313316
url,
314317
fieldTypeIframe,
@@ -332,6 +335,7 @@ export const FieldPluginSandbox: FunctionComponent = () => {
332335
language,
333336
isModalOpen,
334337
fullHeight,
338+
enablePortalModal,
335339
height,
336340
schema,
337341
url,
@@ -371,6 +375,7 @@ export const FieldPluginSandbox: FunctionComponent = () => {
371375
src={iframeSrc}
372376
height={height}
373377
isModal={isModalOpen}
378+
enablePortalModal={enablePortalModal}
374379
fullHeight={fullHeight}
375380
ref={fieldTypeIframe}
376381
/>

packages/sandbox/src/components/FieldTypePreview.tsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import {
99
} from '@mui/material'
1010
import { DisableShieldsNotification } from './DisableShieldsNotification'
1111

12-
const FieldTypeModal: FunctionComponent<
12+
const NonPortalModal: FunctionComponent<
1313
PropsWithChildren<{
14-
isModal: boolean
14+
isNonPortalModalOpen: boolean
1515
}>
1616
> = (props) => (
1717
<Box
1818
sx={
19-
props.isModal
19+
props.isNonPortalModalOpen
2020
? {
2121
position: 'fixed',
2222
left: 0,
@@ -38,12 +38,12 @@ const FieldTypeModal: FunctionComponent<
3838

3939
const FieldTypeSandbox: FunctionComponent<
4040
PropsWithChildren<{
41-
isModal: boolean
41+
isNonPortalModalOpen: boolean
4242
}>
4343
> = (props) => (
4444
<Box
4545
sx={
46-
props.isModal
46+
props.isNonPortalModalOpen
4747
? {
4848
bgcolor: 'background.paper',
4949
p: 6,
@@ -61,7 +61,7 @@ const FieldTypeSandbox: FunctionComponent<
6161
style={{
6262
display: 'flex',
6363
margin: 'auto',
64-
width: props.isModal ? '90%' : '100%',
64+
width: props.isNonPortalModalOpen ? '90%' : '100%',
6565
}}
6666
>
6767
{props.children}
@@ -74,22 +74,27 @@ export const FieldTypePreview = forwardRef<
7474
src: string | undefined
7575
height: number
7676
isModal: boolean
77+
enablePortalModal: boolean
7778
fullHeight: boolean
7879
// Allows the iframe to be refreshed
7980
iframeKey?: number
8081
sx?: SxProps
8182
}
8283
>(function FieldTypePreview(props, ref) {
83-
const { height, isModal, fullHeight } = props
84+
const { height, isModal, fullHeight, enablePortalModal } = props
85+
86+
const isNonPortalModalOpen = !enablePortalModal && isModal
87+
const isPortalModalOpen = enablePortalModal && isModal
88+
8489
return (
8590
<Box sx={props.sx}>
8691
<DisableShieldsNotification />
8792
<Backdrop
8893
open={props.isModal}
8994
sx={{ zIndex: ({ zIndex }) => zIndex.drawer }}
9095
/>
91-
<FieldTypeModal isModal={props.isModal}>
92-
<FieldTypeSandbox isModal={props.isModal}>
96+
<NonPortalModal isNonPortalModalOpen={isNonPortalModalOpen}>
97+
<FieldTypeSandbox isNonPortalModalOpen={isNonPortalModalOpen}>
9398
{typeof props.src !== 'undefined' ? (
9499
<Box
95100
ref={ref}
@@ -116,7 +121,7 @@ export const FieldTypePreview = forwardRef<
116121
</Alert>
117122
)}
118123
</FieldTypeSandbox>
119-
</FieldTypeModal>
124+
</NonPortalModal>
120125
</Box>
121126
)
122127
})

0 commit comments

Comments
 (0)