How to use the react-dnd-html5-backend.NativeTypes.FILE function in react-dnd-html5-backend

To help you get started, we’ve selected a few react-dnd-html5-backend examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github edtr-io / edtr-io / packages / plugin-rows / src / editor / dnd-hoc.ts View on Github external
export function connectDnD(
  Comp: React.ComponentType
) {
  return DropTarget<
    {
      index: number
      moveRow: (from: number, to: number) => void
      insert: (index: number, data: DocumentState) => void
      plugins: Record
    },
    TargetProps
  >(
    ['row', NativeTypes.FILE, NativeTypes.URL],
    {
      hover(props, monitor, component) {
        if (!component) {
          return null
        }
        const node = component.getNode()
        if (!node) {
          return null
        }
        // set the boundingRect for later use (see isDraggingAbove)
        monitor.getItem().boundingRect = node.getBoundingClientRect()

        if (monitor.getItemType() === 'row') {
          const dragIndex = monitor.getItem().index
          const hoverIndex = props.index
          if (dragIndex === hoverIndex) {
github react-dnd / react-dnd / examples_decorators_ts / 01-dustbin / stress-test / src / example.tsx View on Github external
const Container: React.FC = () => {
  const [dustbins, setDustbins] = useState([
    { accepts: [ItemTypes.GLASS], lastDroppedItem: null },
    { accepts: [ItemTypes.FOOD], lastDroppedItem: null },
    {
      accepts: [ItemTypes.PAPER, ItemTypes.GLASS, NativeTypes.URL],
      lastDroppedItem: null,
    },
    { accepts: [ItemTypes.PAPER, NativeTypes.FILE], lastDroppedItem: null },
  ])
  const [boxes, setBoxes] = useState([
    { name: 'Bottle', type: ItemTypes.GLASS },
    { name: 'Banana', type: ItemTypes.FOOD },
    { name: 'Magazine', type: ItemTypes.PAPER },
  ])
  const [droppedBoxNames, setDroppedBoxNames] = useState([])

  useEffect(() => {
    const interval = setInterval(() => {
      setBoxes(shuffle(boxes))
      setDustbins(shuffle(dustbins))
    }, 1000)
    return () => clearInterval(interval)
  })
github react-dnd / react-dnd / examples_js / 01-dustbin / multiple-targets / src / example.jsx View on Github external
const Container = () => {
  const [dustbins, setDustbins] = useState([
    { accepts: [ItemTypes.GLASS], lastDroppedItem: null },
    { accepts: [ItemTypes.FOOD], lastDroppedItem: null },
    {
      accepts: [ItemTypes.PAPER, ItemTypes.GLASS, NativeTypes.URL],
      lastDroppedItem: null,
    },
    { accepts: [ItemTypes.PAPER, NativeTypes.FILE], lastDroppedItem: null },
  ])
  const [boxes] = useState([
    { name: 'Bottle', type: ItemTypes.GLASS },
    { name: 'Banana', type: ItemTypes.FOOD },
    { name: 'Magazine', type: ItemTypes.PAPER },
  ])
  const [droppedBoxNames, setDroppedBoxNames] = useState([])
  function isDropped(boxName) {
    return droppedBoxNames.indexOf(boxName) > -1
  }
  const handleDrop = useCallback(
    (index, item) => {
      const { name } = item
      setDroppedBoxNames(
        update(droppedBoxNames, name ? { $push: [name] } : { $push: [] }),
      )
github react-dnd / react-dnd / examples_decorators_ts / 01-dustbin / multiple-targets / src / example.tsx View on Github external
const Container: React.FC = () => {
  const [dustbins, setDustbins] = useState([
    { accepts: [ItemTypes.GLASS], lastDroppedItem: null },
    { accepts: [ItemTypes.FOOD], lastDroppedItem: null },
    {
      accepts: [ItemTypes.PAPER, ItemTypes.GLASS, NativeTypes.URL],
      lastDroppedItem: null,
    },
    { accepts: [ItemTypes.PAPER, NativeTypes.FILE], lastDroppedItem: null },
  ])

  const [boxes] = useState([
    { name: 'Bottle', type: ItemTypes.GLASS },
    { name: 'Banana', type: ItemTypes.FOOD },
    { name: 'Magazine', type: ItemTypes.PAPER },
  ])

  const [droppedBoxNames, setDroppedBoxNames] = useState([])

  function isDropped(boxName: string) {
    return droppedBoxNames.indexOf(boxName) > -1
  }

  const handleDrop = useCallback(
    (index: number, item: { name: string }) => {
github mydraft-cc / ui / src / wireframes / components / EditorView.tsx View on Github external
export const EditorView = ({ spacing }: EditorViewProps) => {
    const dispatch = useDispatch();
    const selectedDiagramId = useStore(s => getDiagramId(s));
    const editor = useStore(s => getEditor(s));
    const editorSize = editor.size;
    const zoom = useStore(s => s.ui.zoom);
    const zoomedWidth = editorSize.x * zoom;
    const zoomedHeight = editorSize.y * zoom;
    const renderer = React.useContext(RendererContext);

    const ref = React.useRef();

    const [, drop] = useDrop({
        accept: [
            NativeTypes.URL,
            NativeTypes.FILE,
            NativeTypes.TEXT,
            'DND_ASSET',
            'DND_ICON'
        ],
        drop: (item: any, monitor: DropTargetMonitor) => {
            if (!monitor || !ref.current) {
                return;
            }

            const offset = monitor.getSourceClientOffset() || monitor.getClientOffset()!;

            const componentRect = (findDOMNode(ref.current) as HTMLElement)!.getBoundingClientRect();

            let x = (offset.x - spacing - componentRect.left) / zoom;
            let y = (offset.y - spacing - componentRect.top) / zoom;
github uptick / react-keyed-file-browser / src / folders / table.js View on Github external
<div style="{{">
            {draggable}
          </div>
        
        
        
      
    )

    return this.connectDND(folder)
  }
}

@DragSource('folder', BaseFolderConnectors.dragSource, BaseFolderConnectors.dragCollect)
@DropTarget(
  ['file', 'folder', NativeTypes.FILE],
  BaseFileConnectors.targetSource,
  BaseFileConnectors.targetCollect,
)
class TableFolder extends RawTableFolder {}

export default TableFolder
export { RawTableFolder }
github react-dnd / react-dnd / examples_hooks_ts / 06-other / native-files / src / TargetBox.tsx View on Github external
const TargetBox: React.FC = props =&gt; {
  const { onDrop } = props
  const [{ canDrop, isOver }, drop] = useDrop({
    accept: [NativeTypes.FILE],
    drop(item, monitor) {
      if (onDrop) {
        onDrop(props, monitor)
      }
    },
    collect: monitor =&gt; ({
      isOver: monitor.isOver(),
      canDrop: monitor.canDrop(),
    }),
  })

  const isActive = canDrop &amp;&amp; isOver
  return (
    <div style="{style}">
      {isActive ? 'Release to drop' : 'Drag file here'}
    </div>
github Caltech-IPAC / firefly / src / firefly / js / externalSource / FilePicker / react-keyed-file-browser / files / table.js View on Github external
{typeof this.props.modified === 'undefined' ? '-' : this.props.modified}
        
      
    );

    return this.connectDND(row);
  }
}

export default DragSource(
  'file',
  BaseFileConnectors.dragSource,
  BaseFileConnectors.dragCollect
)(
  DropTarget(
    ['file', 'folder', NativeTypes.FILE],
    BaseFileConnectors.targetSource,
    BaseFileConnectors.targetCollect
  )(
    TableFile
  )
);
github bakdata / conquery / frontend / lib / js / form-components / DropzoneWithFileInput.js View on Github external
export default ({
  children,
  onSelectFile,
  acceptedDropTypes,
  disableClick,
  showFileSelectButton,
  ...props
}: PropsT) =&gt; {
  const fileInputRef = React.useRef(null);

  const dropTypes = [...(acceptedDropTypes || []), NativeTypes.FILE];

  function onOpenFileDialog() {
    fileInputRef.current.click();
  }

  return (
     {
        if (disableClick) return;

        onOpenFileDialog();
      }}
      {...props}
    &gt;
      {showFileSelectButton &amp;&amp; (