Add drag and drop provider

This commit is contained in:
dannyrb authored and James A. Petts committed 2020-05-15 14:05:55 +02:00
1 parent fe57becb2c
commit 599204176c
8 files changed
+57 -6

No files matched your search

+2
View File
@@ -4,6 +4,7 @@ export { utils };
/** CONTEXT/HOOKS */
export {
DragAndDropContext,
ModalProvider,
ModalConsumer,
useModal,
@@ -60,6 +61,7 @@ export {
Viewport,
ViewportActionBar,
ViewportGrid,
ViewportPane,
} from './src/components';
/** VIEWS */
+2
View File
@@ -38,6 +38,8 @@
"react": "16.11.0",
"react-dates": "^21.8.0",
"react-dnd": "^10.0.2",
"react-dnd-html5-backend": "^10.0.2",
"react-dnd-touch-backend": "^10.0.2",
"react-dom": "16.11.0",
"react-powerplug": "1.0.0",
"react-select": "^3.0.8",
@@ -3,6 +3,9 @@ import PropTypes from 'prop-types';
import classnames from 'classnames';
import { useDrop } from 'react-dnd';
// NOTE: If we found a way to make `useDrop` conditional,
// Or we provided a HOC of this component, we could provide
// this UI without the DragAndDropContext dependency.
function ViewportPane({ children, isActive, onDrop }) {
const [{ isHovered, isHighlighted }, drop] = useDrop({
accept: 'displayset',
@@ -5,7 +5,7 @@ route: components/viewport-pane
---
import { Playground, Props } from 'docz';
import { ViewportGrid, ViewportPane } from '@ohif/ui';
import { DragAndDropContext, ViewportGrid, ViewportPane } from '@ohif/ui';
# ViewportPane
@@ -21,10 +21,12 @@ import { ViewportPane } from '@ohif/ui';
<Playground>
<div className="p-4 h-56">
<ViewportGrid>
<ViewportPane><h3>Hello</h3></ViewportPane>
<ViewportPane><h3>World</h3></ViewportPane>
</ViewportGrid>
<DragAndDropContext>
<ViewportGrid numRows={1} numCols={2}>
<ViewportPane onDrop={() => {}} isActive={true}><h3>Hello</h3></ViewportPane>
<ViewportPane onDrop={() => {}} isActive={false}><h3>World</h3></ViewportPane>
</ViewportGrid>
</DragAndDropContext>
</div>
</Playground>
@@ -1,2 +1,2 @@
import ViewportPane from './ViewportPane.jsx';
import ViewportPane from './ViewportPane';
export default ViewportPane;
@@ -0,0 +1,25 @@
import React from 'react';
import { DndProvider } from "react-dnd";
import HTML5Backend from 'react-dnd-html5-backend';
import TouchBackend from 'react-dnd-touch-backend';
const isTouchDevice = typeof window !== `undefined` && !!('ontouchstart' in window || navigator.maxTouchPoints);
/**
* Relevant:
* https://github.com/react-dnd/react-dnd/issues/186#issuecomment-335429067
* https://github.com/react-dnd/react-dnd/issues/186#issuecomment-282789420
*
* Docs:
* http://react-dnd.github.io/react-dnd/docs/api/drag-drop-context
*/
export default function DragAndDropContext({children}) {
const backend = isTouchDevice ? TouchBackend : HTML5Backend;
const opts = isTouchDevice ? { enableMouseEvents: true } : {};
return (
<DndProvider backend={backend} opts={opts}>
{children}
</DndProvider>
);
}
@@ -9,3 +9,5 @@ export {
default as ViewportDialogProvider,
useViewportDialog,
} from './ViewportDialogProvider';
export { default as DragAndDropContext } from './DragAndDropContext';