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-dragger

v1.3.0

Published

Simple React Dragger component

Downloads

61

Readme

React Dragger

Tiny React Dragging library - mobile ready and with no dependencies!

Travis npm Coverage Status npm npm Codacy grade

I wrote this library because I couldn't find any existing one to make elements draggable super easily, ignoring where they are dropped.

In some cases you really need an unobtrusive way to make items draggable, this will do just that.

I use React-DnD a lot as well, but sometimes you really just want to make an element draggable :smile:

Installation

$ npm i react-dragger

Or if you prefer yarn

$ yarn add react-dragger

Usage

<Dragger
    target={ this.state.ref }
    onStart={ this.onStart }
    onDrag={ this.onDrag }
    onEnd={ this.onEnd }
    position={ this.state.itemLocation }
    inverted={ this.props.inverted }
/>

Props

Docs on each prop, see them in action in the example below.

target

Element that will be draggable. This is to scope the mouse/touch event handlers and make sure that it doesn't affect your whole web app.

It must be a React ref, it should also exist, so you may want to check if it's already initialized before rendering the Dragger component.

onStart

This will be fired when the element starts being dragged.

onDrag

This will be fired while the element is being dragged. It will receive an object with the top and left coordinates of the element.

onDrag({
  top: number,
  left: number,
});

onEnd

This will be fired when the element stops being dragged.

inverted (Optional)

Whether you want the dragging to be inverted (drag mouse up -> element goes down)

Example

This example was taken from example/app/src/Example.js which you can see running at https://aurbano.eu/react-dragger/

import React from 'react';
import Dragger from 'react-dragger';

import './react-dragger.css';

export default class Example extends React.PureComponent {

  constructor() {
    super();

    this.state = {
      ref: null,
      dragState: 'waiting',
      itemLocation: {
        top: 10,
        left: 260,
      },
    };
  }

  onStart = () => {
    this.setState({
      dragState: 'started',
    });
  };

  onDrag = (itemLocation) => {
    this.setState({
      dragState: 'dragging',
      itemLocation,
    });
  };

  onEnd = () => {
    this.setState({
      dragState: 'ended',
    });
  };

  render() {
    const itemStyle = {
      ...this.state.itemLocation,
    };
    return (
      <div style={ { position: 'relative', marginBottom: '10em' } }>
        <p>State: <code>{ this.state.dragState }</code></p>
        <div className='item' ref={ (ref) => this.setState({ ref }) } style={ itemStyle }>
          Drag me!
        </div>

        { this.state.ref && (
          <Dragger
            target={ this.state.ref }
            onStart={ this.onStart }
            onDrag={ this.onDrag }
            onEnd={ this.onEnd }
            position={ this.state.itemLocation }
            inverted={ this.props.inverted }
          />
        ) }
      </div>
    );
  }
}

Contributing

Only edit the files in the src folder. I'll update dist manually before publishing new versions to npm.

To run the tests simply run npm test. Add tests as you see fit to the test folder, they must be called {string}.test.js.

Meta

Copyright © Alejandro U. Alvarez 2017. MIT Licensed.