npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-html5-sortable

v0.0.1

Published

React mixin for HTML5 drag-and-drop sorting of items in a container

Downloads

15

Readme

react-html5-sortable

React mixin for HTML5 drag-and-drop sorting of items in a container

Demo

Installation

npm install --save react-html5-sortable

Setup

Use this library as a mixin into your list item components. Your list item component should have a reactKey prop which is the unique, unchanging, key for the item. When a list item is dragged over another list item, the onMove(src, dest) event will fire, which you can handle in your list component to change the data and re-render the list. src will be the reactKey prop for the list item being dragged, and dest will be the reactKey prop for the list item that the src item is above.

The example below uses a simple array of strings, but as long as your list item components have a reactKey prop, you can sort arrays of complex data structures with this module.

If your list item component has a dragHandle ref, that element will be the only part of the item that can be grabbed to drag the item. If dragHandle doesn't exist, the entire object can be grabbed.

Example

var Sortable = require("react-html5-sortable");

var MyListItem = React.createClass({
	mixins: [Sortable],
	render: function() {
		return <div>{this.props.text}</div>;
	}
});

var MyList = React.createClass({
	render: function() {
		var items = this.props.items.map(function(item) {
			return <MyListItem key={item} reactKey={item} text={item} onMove={this.props.onMove} />;
		}.bind(this));
		return <div>{items}</div>;
	}
});

var items = ["First Item", "Second Item", "Third Item", "Fourth Item", "Fifth Item"];

// If you're using [Flux](https://facebook.github.io/flux/), this would probably live in your Store
function move(src, dest) {
	var srcIdx = items.indexOf(src);
	var destIdx = items.indexOf(dest);
	if (srcIdx === -1 || destIdx === -1 || srcIdx === destIdx) {
		return;
	}
	var item = items.splice(srcIdx, 1);
	items.splice(destIdx, 0, item[0]);
	render();
}

function render() {
	React.render(<MyList items={items} onMove={move} />, document.getElementById("list-demo"));
}

render();

Code of Conduct

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.