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

ray-hoc-sortable

v1.0.9

Published

sortable list

Downloads

19

Readme

ray-hoc-sortable (HOC)

install

npm install ray-hoc-sortable --save

Usage

// Using an ES6 transpiler like Babel
import { withSortableView, withSortableItem, withSortableBar, exchangeData } from 'ray-hoc-sortable';

// Not using an ES6 transpiler
const Sortable = require('ray-hoc-sortable');
const withSortableView = Sortable.withSortableView;
const withSortableItem = Sortable.withSortableItem;
const withSortableBar = Sortable.withSortableBar;
const exchangeData = Sortable.exchangeData;

Basic Example

import React, { Component } from 'react';
import { render } from 'react-dom';
import { withSortableView, withSortableItem, exchangeData } from 'ray-hoc-sortable';

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

const SortableList = withSortableView(({items}) => {
  return (
    <ul>
      {items.map((value, index) => (
        <SortableItem key={`item-${index}`} 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: exchangeData(this.state.items, oldIndex, newIndex),
    });
  };

  render() {
    return <SortableList items={this.state.items} onSortEnd={this.onSortEnd} />;
  }
}

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

Prop Types

withSortableView HOC

| Property | Type | Default | Description | | ------ | ------ | ------ | ------ | | axis | String | y | 在网格中的排序方式,可以是 x, y or xy | | lockAxis | String | - | 锁定排序移动的轴,可选值为 xy. 这是 HTML5 Drag & Drop 不具备的功能。 | | helperClass | String | - | 自定义样式名 | | transitionDuration | Number | 300 | 元素移动位置时持续时间。设置为 0 则禁用缓动时间 | | pressDelay| Number | 0 | 按下一定时间后执行排序,移动设备设置 200 最佳,不能与“distance”属性一起使用。 | | pressThreshold | Number | 5 | 忽略移动的像素值,默认为 5px . | | distance | Number | 0 | 移动一定距离之后进行排序,不能与 pressDelay 一同使用.| | shouldCancelStart | Function | Function | 执行排序之前调用,常用作取消排序,例如,默认情况下当事件目标是 input, textarea, select or option 时,将取消排序. | | onSortStart | Function | | 开始排序时的回调函数. function({node, index, collection}, event) | | onSortMove | Function| - | 移动过程中的回调. function(event) | | onSortEnd | Function | | 排序结束时回调. function({oldIndex, newIndex, collection}, e) | | useDragHandle | Boolean| false | 使用 headerBar 进行拖拽。当使用 withSortableBar 时,需要设置为 true | | useWindowAsScrollContainer | Boolean| false | 将 window 设置为滚动容器 | | hideSortableGhost | Boolean| true| 是否隐藏重影元素,默认情况自动隐藏当前正在排序的元素,使用自定义样式时,设置为 false | | lockToContainerEdges | Boolean| false | 将排序区域锁定为父元素,父元需要使用 withSortableView 进行包裹 | | lockOffset| OffsetValue or [OffsetValue, OffsetValue] | "50%" | 当 lockToContainerEdgestrue 时,可以设置与父元素上下编边距,百分比值相对于当前正在排序项的高度,如果顶部与底部不同,则传入数组 ["0%", "100%"] 实现。| | getContainer | Function | - | 指定自定义容器对象,需要返回滚动容器元素(DOM Element),默认为 withSortableView 元素自身,如果 useWindowAsScrollContainer 为 true,则为 window。 | | getHelperDimensions | Function | Function | function({node, index, collection}) 返回计算维度 | | helperContainer | HTMLElement or Function | document.body | 默认情况下,克隆的可排序 helper 附加到页面中。该 props 为 helper 指定一个不同的容器。可以是一个 HTMLElement 或一个返回 HTMLElement 的函数,该函数将在排序开始之前调用 | | disableAutoscroll | Boolean | false | 拖动时是否禁用自动滚动 |

OffsetValue String类型或者 Number类型,单位为: (px or %). Examples: 10"10px", "50%" 等。

withSortableItem HOC

| Property | Type | Default | Required? | Description | | ------ | ------ | ------ | ------ | ------ | | index | Number| | ✓ | 元素集合的 index 值 | | collection | Number or String | 0 | - | 元素所属集合. 同一个 withSortableView 中有多组可排序元素时使用。 | | disabled | Boolean | false | - | 禁用元素排序 | | getNode | func: (tarNode: HTMLElement) => HTMLElement | - | - | 调整指定的排序 node 节点 |

changlog

2022-2-21 v1.0.9

修改 onSortStart 回调中,collectionundefined bug

2020-6-22 v1.0.6

添加 zindex 值,以防外部容器设置 zindex 时,导致无法显示 item