React Base Fiddle (JSX)

Starting point for creating JSFiddles with React.

by Shuang Zhang

HTML

<script src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<div id="container"></div>

CSS

.App-main {
    padding: 10px 50px 0;
}

.App-main-title {
    text-align: center;
    font-weight: bold;
    font-size: 20px;
}

.Demo-box {
    display: flex;
    flex-direction: row;
}

.Demo {
    flex: 1;
    background-color: #fefefe;
    margin: 0 10px;
    border: 1px solid #333;
    user-select: none;
}

.List-item {
    height: 70px;
    padding: 0 20px;
    border-bottom: 1px solid #ccc;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
}

.List-item-btn {
    padding: 5px 10px;
    background-color: #3385ff;
    color: #fff;
    cursor: pointer;
    font-size: 12px;
    user-select: none;
}

.List-b {
    cursor: pointer;
}

.List-item-desc {
  font-size: 13px;
}

.List-b {
    cursor: pointer;
}

Babel + JSX

class Sortable extends React.Component {
    constructor(props) {
        super(props);
        this.listData = props.value;
        
        this.containerElement = null;
        this.dragItems = [];
        
        this.dragging = false;
        this.draggingIndex = -1;
        this.draggingElement = null;
        this.draggingPlaceholder = null;
        
        this.startPositionY = 0;
        this.startPageY = 0;
        
        this.sorting = false;
        this.sortingStartY = 0;
        
        this.handleMouseDown = this.handleMouseDown.bind(this);
        this.handleMouseMove = this.handleMouseMove.bind(this);
        this.handleMouseUp = this.handleMouseUp.bind(this);
        this.exchangeListItemVertically = this.exchangeListItemVertically.bind(this);
        this.removePlaceholderElement = this.removePlaceholderElement.bind(this);
    }
    
    componentDidMount() {
        document.addEventListener('mousemove', this.handleMouseMove, false);
        document.addEventListener('mouseup', this.handleMouseUp, false);
    }
    
    componentWillReceiveProps(nextProps) {
        if (nextProps.value) {
            this.listData = nextProps.value;
        }
    }
    
    shouldComponentUpdate() {
        if (!this.dragging) {
            this.removePlaceholderElement();
        }
        return !this.dragging;
    }
    
    componentWillUnmount() {
        document.removeEventListener('mousemove', this.handleMouseMove, false);
        document.removeEventListener('mouseup', this.handleMouseUp, false);
    }
    
    removePlaceholderElement() {
        setTimeout(() => {
            let placeholderElement = document.getElementById('drag-placeholder');
            if (placeholderElement && this.containerElement) {
                this.containerElement.removeChild(placeholderElement);
            }
        });
    }
    
    handleMouseDown(e, index) {
        if (this.props.dragbtn && !e.target.className.includes(this.props.dragbtn)) {
           ...