import random from 'lodash/random'; import uniqueId from 'lodash/uniqueId'; import uniq from 'lodash/uniq'; import React from 'react'; import ReactDOM from 'react-dom'; import Sortable from '../src'; class App extends React.Component { state = { simpleList: [1, 2, 3, 4, 5, 6], groupLeft: ['Apple', 'Banana', 'Cherry', 'Grape'], groupRight: ['Lemon', 'Orange', 'Pear', 'Peach'], cloneUncontrolled: ['Apple', 'Banana', 'Cherry', 'Guava', 'Grape', 'Kiwi', 'Lemon', 'Melon', 'Orange', 'Pear', 'Peach', 'Strawberry'], cloneControlledSource: ['Apple', 'Banana', 'Cherry', 'Guava', 'Grape', 'Kiwi', 'Lemon', 'Melon', 'Orange', 'Pear', 'Peach', 'Strawberry'], cloneControlledTarget: [] }; simpleList = null; addMoreItems = () => { const items = [ 'Apple', 'Banana', 'Cherry', 'Guava', 'Grape', 'Kiwi', 'Lemon', 'Melon', 'Orange', 'Pear', 'Peach', 'Strawberry' ]; const i = random(0, items.length - 1); this.setState(state => ({ groupLeft: state.groupLeft.concat(items[i]) })); }; render() { const simpleList = this.state.simpleList.map((val, key) => (
  • List Item {val}
  • )); const groupLeft = this.state.groupLeft.map((val, key) => (
    {val}
    )); const groupRight = this.state.groupRight.map((val, key) => (
    {val}
    )); const cloneUncontrolled = this.state.cloneUncontrolled.map((val, key) => (
  • {val}
  • )); const cloneControlledSource = this.state.cloneControlledSource.map((val, key) => (
  • {val}
  • )); const cloneControlledTarget = this.state.cloneControlledTarget.map((val, key) => (
  • {val}
  • )); return (
    Simple List
    { if (c) { this.simpleList = c.sortable; } }} tag="ul" > {simpleList}
    Shared Group
    { this.setState({ groupLeft: items }); }} > {groupLeft}
    { this.setState({ groupRight: items }); }} > {groupRight}
    Uncontrolled Component

    Clone items from left to right. DOM elements are duplicated.

    {cloneUncontrolled}
    Controlled Component

    Clone items from left to right without duplication.

    { this.setState({ cloneControlledSource: items }); }} tag="ul" > {cloneControlledSource}
    { items = uniq(items); // Remove duplicate items this.setState({ cloneControlledTarget: items }); }} tag="ul" > {cloneControlledTarget}
    ); } } ReactDOM.render( , document.getElementById('container') );