How to use the react-dnd.DragLayer function in react-dnd

To help you get started, we’ve selected a few react-dnd 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 flow-typed / flow-typed / definitions / npm / react-dnd_v2.x.x / flow_v0.53.x- / test_react-dnd-v2.js View on Github external
static defaultProps: CustomDragLayerProps = {
    isDragging: false,
    title: ""
  };

  render() {
    const { title, isDragging } = this.props;
    if (!isDragging) {
      return null;
    }

    return <div>this.props.title</div>;
  }
}

const DndCustomDragLayer = DragLayer(dragLayerCollect)(CustomDragLayer);

(DndCustomDragLayer.DecoratedComponent: typeof CustomDragLayer);

// Test Drag Drop Context
// ----------------------------------------------------------------------

type BoardProps = {
  width: number,
  height: number
};

class Board extends React.Component {
  static defaultProps: BoardProps = {
    width: 400,
    height: 400
  };
github streetmix / streetmix / assets / scripts / segments / SegmentDragLayer.jsx View on Github external
)}
      
    )
  }
}

function collect (monitor) {
  return {
    item: monitor.getItem(),
    type: monitor.getItemType(),
    currentOffset: monitor.getSourceClientOffset(),
    isDragging: monitor.isDragging()
  }
}

export default DragLayer(collect)(SegmentDragLayer)
github stipsan / epic / client / components / Setup / ItemPreview.js View on Github external
render() {
    
    
    
    return <div style="{layerStyles}">
        <div style="{getItemStyles(this.props.currentOffset)}">
            {this.props.id} {this.props.name}
        </div>
    </div>;
  }
}

export default DragLayer(collect)(ItemPreview)
github Radarr / Radarr / frontend / src / Components / Table / TableOptions / TableOptionsColumnDragPreview.js View on Github external
);
  }
}

TableOptionsColumnDragPreview.propTypes = {
  item: PropTypes.object,
  itemType: PropTypes.string,
  currentOffset: PropTypes.shape({
    x: PropTypes.number.isRequired,
    y: PropTypes.number.isRequired
  })
};

export default DragLayer(collectDragLayer)(TableOptionsColumnDragPreview);
github Bandwidth / shared-components / packages / shared-components / src / components / DragLayer / DragLayer.js View on Github external
<div style="{previewPositionStyles}">
            {this.renderPreviewContent()}
          </div>
        
      
    );
  }
}

const collect = monitor =&gt; ({
  item: monitor.getItem(),
  clientOffset: monitor.getClientOffset(),
});

export default LibDragLayer(collect)(DragLayer);
github plone / volto / src / components / mosaic / Column / ColumnResizeHelper.jsx View on Github external
/**
 * Column resize helper.
 * @module components/mosaic/ColumnResizeHelper
 */

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { DragLayer } from 'react-dnd';
import { map } from 'lodash';

@DragLayer(monitor => ({
  item: monitor.getItem(),
  itemType: monitor.getItemType(),
  initialOffset: monitor.getInitialSourceClientOffset(),
  currentOffset: monitor.getSourceClientOffset(),
  isDragging: monitor.isDragging(),
}))
/**
 * ColumnResizeHelper component class.
 * @function ColumnResizeHelper
 * @param {Object} props Component properties.
 * @param {Object} props.item Item to be dragged.
 * @param {string} props.itemType Item type to be dragged.
 * @param {Object} props.initialOffset Initial offset.
 * @param {Object} props.currentOffset Current offset.
 * @param {bool} props.isDragging Is dragging.
 * @returns {string} Markup of the component.
github allangomessl / kanban-react / src / components / card / Card.Item.Drag.jsx View on Github external
function getItemStyles(x, y) {
  if (!x) {
    return { display: 'none' }
  }

  return {
    pointerEvents: 'none',
    transform: `translate(${x}px, ${y}px) rotate(0.01turn)`,
  };
}


export const CardItemPreview = compose(
  DragLayer((monitor) => {
    const item = monitor.getItem()
    const offset = monitor.getSourceClientOffset() || {}
    return {
        ...item,
        x: offset.x,
        y: offset.y
    }
  }),
  mapProps(({ x, y, ...props }) => ({
    ...props,
    style: getItemStyles(x, y)
  }))
)(class Preview extends React.PureComponent {

  render() {
    const { currentOffset, boundingRect, style, ...props } = this.props
github GiraffeTools / GiraffeTools / frontend / porcupine / components / canvas / itemPreview.js View on Github external
const ItemPreview = (props) =&gt; {
  if (!props.isDragging) {
    return <div style="{{display:">;
  } else if (props.itemType === 'paneElement') {
    return (
      <div style="{[styles.nodePreview,">
        {props.name}
      </div>
    );
  } else if (props.itemType === 'node') {
    return <div style="{{display:">;
  }
};

export default DragLayer(collect)(ItemPreview);
</div></div>
github web-pal / react-trello-board / src / containers / Board / CustomDragLayer.js View on Github external
if (props.snapToGrid) {
    x -= initialOffset.x;
    y -= initialOffset.y;
    [x, y] = snapToGrid(x, y);
    x += initialOffset.x;
    y += initialOffset.y;
  }

  const transform = `translate(${x}px, ${y}px)`;
  return {
    WebkitTransform: transform,
    transform
  };
}

@DragLayer((monitor) => ({
  item: monitor.getItem(),
  itemType: monitor.getItemType(),
  initialOffset: monitor.getInitialSourceClientOffset(),
  currentOffset: monitor.getSourceClientOffset(),
  isDragging: monitor.isDragging()
}))
export default class CustomDragLayer extends Component {
  static propTypes = {
    item: PropTypes.object,
    itemType: PropTypes.string,
    initialOffset: PropTypes.shape({
      x: PropTypes.number.isRequired,
      y: PropTypes.number.isRequired
    }),
    currentOffset: PropTypes.shape({
      x: PropTypes.number.isRequired,
github Parrit / Parrit / frontend / src / project / components / CustomDragLayer.js View on Github external
currentOffset: PropTypes.shape({
        x: PropTypes.number.isRequired,
        y: PropTypes.number.isRequired
    })
})

const dragCollect = (monitor) => {
    return {
        item: monitor.getItem(),
        itemType: monitor.getItemType(),
        isDragging: monitor.isDragging(),
        currentOffset: monitor.getSourceClientOffset()
    }
}

export default DragLayer(dragCollect)(CustomDragLayer)