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

@human-tools/use-sortable

v0.0.5

Published

Simple implementation that allows you to reorder items easily using useSortable hook.

Downloads

15

Readme

useSortable

Simple implementation that allows you to reorder items easily using useSortable hook.

Options

  • [Optional] draggingClassNames: string[] - Default: ['dragging']
  • [Optional] dragoverClassNames: string[] - Default: ['dragover']
  • [Optional] animate: boolean - Default: true
  • [Optional] animationDelayFunction: (index: number) => number - Default: () => 0
  • [Optional] animationDurationFunction: (index: number) => number - Default: () => 0.3
  • [Optional] animationTimingFunction: (index: number) => string - Default: () => 'cubic-bezier(0, 1.28, 1, 1)'

Installing

yarn add @human-tools/use-sortable
# OR
npm install @human-tools/use-sortable

Example

import { useState } from 'react';
import * as ReactDOM from 'react-dom';
import { useSortable } from '@human-tools/use-sortable';
import './index.css';

const App = (): JSX.Element => {
  const [items] = useState<number[]>(
    new Array(30).fill(0).map<number>((_, i) => i)
  );
  const { orderedItems, setItems, setContainerRef, addDraggableNodeRef } = useSortable<number>(
    items,
    {}
  );

  return (
    <div>
      <div className="card-container" ref={setContainerRef}>
        {orderedItems.map(item => (
          <div className="card" key={item} ref={addDraggableNodeRef}>
            {item + 1}
          </div>
        ))}
      </div>
    </div>
  );
};

ReactDOM.render(<App />, document.getElementById('root'));
.card-container {
  display: flex;
  flex-wrap: wrap;
}

.card {
  font-size: 56px;
  color: #ddd;
  background-color: white;
  padding: 30px;
  box-shadow: 1px 1px 5px 0 rgba(0, 0, 0, 0.2);
  margin: 10px;
  cursor: grab;
  width: 150px;
  height: 150px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card:hover {
  background-color: slategrey;
}

.card.dragover {
  box-shadow: 1px 1px 15px 0 rgba(0, 128, 128, 1);
}

.card.dragging {
  cursor: grabbing;
  opacity: 0.2;
}

Contributing

The package uses @pika/pack to build and publish the library. The example directory is a small snowpack react app.

If you want to work on the src of the library while using the example as a scratchpad to see your changes, run:

  • yarn start in the root directory - This will watch the src/ and copy the files to example/src/use-sortable-lib directory
  • yarn start in the example directory - This will start the normal snowpack dev server and watch example files and hmr appropriately.

This setup is mainly because snowpack still doesn't have a good support for yarn/npm link'd packages.

Deploying Updated Example Site

This will happen automatically using Netlify, all you need to do is merge updated files in.

Publishing new version of @human-tools/use-sortable

Currently one of the maintainers have to run npx pika publish and follow the prompts. This will probably eventually be automated anytime master branch is updated.

License

MIT