-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Container.tsx
44 lines (42 loc) · 1.38 KB
/
Container.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import type { FC, ReactNode } from 'react'
import { DndProvider } from 'react-dnd'
import { HTML5Backend } from 'react-dnd-html5-backend'
import { Dustbin } from './Dustbin'
import { Box } from './Box'
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import Frame, { FrameContextConsumer } from 'react-frame-component'
const FrameBindingContext: FC<{ children?: ReactNode }> = ({ children }) => (
<FrameContextConsumer>
{({ window }: any) => (
<DndProvider backend={HTML5Backend} context={window}>
{children}
</DndProvider>
)}
</FrameContextConsumer>
)
// Don't use the decorator, embed the DnD context within the iframe
export const Container: FC = () => {
// The react-frame-component will pass the iframe's 'window' global as a context value
// to the DragDropContext provider. You could also directly inject it in via a prop.
// If neither the prop or the context value for 'window' are present, the DndProvider
// will just use the global window.
return (
<>
<Frame style={{ width: '100%', height: 400 }}>
<FrameBindingContext>
<div>
<div style={{ overflow: 'hidden', clear: 'both' }}>
<Dustbin />
</div>
<div style={{ overflow: 'hidden', clear: 'both' }}>
<Box name="Glass" />
<Box name="Banana" />
<Box name="Paper" />
</div>
</div>
</FrameBindingContext>
</Frame>
</>
)
}