"react drag & drop"
Bootstrap 3.0.0 Snippet by evarevirus

<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script> <script src="//code.jquery.com/jquery-1.11.1.min.js"></script> <!------ Include the above in your HEAD tag ----------> <!DOCTYPE html><html class=''> <head><script src='//production-assets.codepen.io/assets/editor/live/console_runner-079c09a0e3b9ff743e39ee2d5637b9216b3545af0de366d4b9aad9dc87e26bfd.js'></script><script src='//production-assets.codepen.io/assets/editor/live/events_runner-73716630c22bbc8cff4bd0f07b135f00a0bdc5d14629260c3ec49e5606f98fdd.js'></script><script src='//production-assets.codepen.io/assets/editor/live/css_live_reload_init-2c0dc5167d60a5af3ee189d570b1835129687ea2a61bee3513dee3a50c115a77.js'></script><meta charset='UTF-8'><meta name="robots" content="noindex"><link rel="shortcut icon" type="image/x-icon" href="//production-assets.codepen.io/assets/favicon/favicon-8ea04875e70c4b0bb41da869e81236e54394d63638a1ef12fa558a4a835f1164.ico" /><link rel="mask-icon" type="" href="//production-assets.codepen.io/assets/favicon/logo-pin-f2d2b6d2c61838f7e76325261b7195c27224080bc099486ddd6dccb469b8e8e6.svg" color="#111" /><link rel="canonical" href="https://codepen.io/adamaoc/pen/GoKZKE?depth=everything&order=popularity&page=2&q=react&show_forks=false" /> <link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css'><script src='https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js'></script> <style class="cp-pen-styles">body { width: 100%; max-width: 380px; margin: 0 auto; } h1 { border-left: 5px solid #e1e1e1; padding-left: 5px; } ul { list-style: none; margin: 0; padding: 0; border: 5px solid #e1e1e1; box-shadow: 1px 3px 8px #888; } li { padding: 10px 15px; background: #eee; } li:hover { background: #e1e1e1; } .placeholder { background: #fff078; } .placeholder:before { content: "Drop here"; color: #e1d25a; } </style></head><body> <h1>React Drag & Drop</h1> <div id="app"></div> <script src='//production-assets.codepen.io/assets/common/stopExecutionOnTimeout-b2a7b3fe212eaa732349046d8416e00a9dec26eb7fd347590fbced3ab38af52e.js'></script><script src='//cdnjs.cloudflare.com/ajax/libs/react/0.14.3/react.min.js'></script><script src='https://cdnjs.cloudflare.com/ajax/libs/react/0.14.3/react-dom.js'></script> <script >"use strict"; var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) {if (window.CP.shouldStopExecution(2)){break;} var source = arguments[i]; for (var key in source) {if (window.CP.shouldStopExecution(1)){break;} if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } window.CP.exitedLoop(1); } window.CP.exitedLoop(2); return target; }; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var placeholder = document.createElement("li"); placeholder.className = "placeholder"; var List = function (_React$Component) { _inherits(List, _React$Component); function List(props) { _classCallCheck(this, List); var _this = _possibleConstructorReturn(this, _React$Component.call(this, props)); _this.state = _extends({}, props); return _this; } List.prototype.dragStart = function dragStart(e) { this.dragged = e.currentTarget; e.dataTransfer.effectAllowed = 'move'; e.dataTransfer.setData('text/html', this.dragged); }; List.prototype.dragEnd = function dragEnd(e) { this.dragged.style.display = 'block'; this.dragged.parentNode.removeChild(placeholder); // update state var data = this.state.colors; var from = Number(this.dragged.dataset.id); var to = Number(this.over.dataset.id); if (from < to) to--; data.splice(to, 0, data.splice(from, 1)[0]); this.setState({ colors: data }); }; List.prototype.dragOver = function dragOver(e) { e.preventDefault(); this.dragged.style.display = "none"; if (e.target.className === 'placeholder') return; this.over = e.target; e.target.parentNode.insertBefore(placeholder, e.target); }; List.prototype.render = function render() { var _this2 = this; var listItems = this.state.colors.map(function (item, i) { return React.createElement( "li", { "data-id": i, key: i, draggable: "true", onDragEnd: _this2.dragEnd.bind(_this2), onDragStart: _this2.dragStart.bind(_this2) }, item ); }); return React.createElement( "ul", { onDragOver: this.dragOver.bind(this) }, listItems ); }; return List; }(React.Component); var App = function (_React$Component2) { _inherits(App, _React$Component2); function App(props) { _classCallCheck(this, App); var _this3 = _possibleConstructorReturn(this, _React$Component2.call(this, props)); _this3.state = { colors: ['Red', 'Green', 'Blue', 'Yellow', 'Black', 'White', 'Orange'] }; return _this3; } App.prototype.render = function render() { return React.createElement( "div", null, React.createElement(List, { colors: this.state.colors }) ); }; return App; }(React.Component); ReactDOM.render(React.createElement(App, null), document.getElementById('app')); //# sourceURL=pen.js </script> </body></html>

Related: See More


Questions / Comments: