1.0.3 • Published 1 year ago

reactjs-table-dnd v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

reactjs-table-dnd

npm version npm npm All Contributors

Installation

NPM

To install the latest stable version:

npm install --save reactjs-table-dnd

Basic usage:

import React, { Component } from 'react';
import { render } from 'react-dom';
import { SortableContainer, SortableElement } from 'reactjs-table-dnd';
import arrayMove from 'array-move';

const SortableItem = SortableElement(({ value }) => <li>{value}</li>);

const SortableList = SortableContainer(({ items }) => {
  return (
    <ul>
      {items.map((value, index) => (
        <SortableItem key={`item-${value}`} index={index} value={value} />
      ))}
    </ul>
  );
});

class SortableComponent extends Component {
  state = {
    items: ['Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item 5', 'Item 6'],
  };
  onSortEnd = ({ oldIndex, newIndex }) => {
    this.setState(({ items }) => ({
      items: arrayMove(items, oldIndex, newIndex),
    }));
  };
  render() {
    return <SortableList items={this.state.items} onSortEnd={this.onSortEnd} />;
  }
}

render(<SortableComponent />, document.getElementById('root'));
1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago