# @asany/sortable

> 基于 React-Dnd 封装的拖拽排序组件

Latest version **0.1.45** (published 2024-04-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install @asany/sortable
pnpm add @asany/sortable
yarn add @asany/sortable
bun add @asany/sortable
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.45 |
| Published | 2024-04-12 |
| First published | 2021-07-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=10 |
| Dependencies | 4 |
| Unpacked size | 588.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| GitHub stars | 12 |
| Author | 李茂峰 |
| Maintainers | limaofeng |

## Links

- npm: https://www.npmjs.com/package/@asany/sortable
- Repository: https://github.com/limaofeng/asany-sortable
- npm.io page: https://npm.io/package/@asany/sortable

## Dependencies (4)

- [lodash-es](https://npm.io/package/lodash-es.md) ^4.17.21
- [classnames](https://npm.io/package/classnames.md) ^2.3.1
- [react-flip-toolkit](https://npm.io/package/react-flip-toolkit.md) ^7.0.14
- [immutability-helper](https://npm.io/package/immutability-helper.md) ^3.1.1

## Recent versions

- 0.1.45 (latest) — 2024-04-12
- 0.1.44 — 2022-11-04
- 0.1.43 — 2022-11-04
- 0.1.42 — 2022-11-04
- 0.1.41 — 2022-09-15
- 0.1.40 — 2022-09-09
- 0.1.39 — 2022-09-09
- 0.1.38 — 2022-09-09
- 0.1.37 — 2022-09-08
- 0.1.36 — 2022-06-25
- 0.1.35 — 2022-06-25
- 0.1.34 — 2022-06-25
- 0.1.33 — 2022-06-24
- 0.1.32 — 2022-06-23
- 0.1.31 — 2022-06-23
- … 19 more at https://npm.io/package/@asany/sortable/versions

## README

# AsanySortable

基于 React-Dnd 封装的拖拽排序组件

## Install

```bash
npm i @asany/sortable # or yarn add @asany/sortable
```

## Usage

```tsx
const defaultStyle = {
  border: '1px dashed gray',
  padding: '0.5rem 1rem',
  marginBottom: '.5rem',
  marginRight: '.5rem',
  backgroundColor: 'white',
};

const SortItem = forwardRef(({ data, style, className }: SortableItemProps<any>, ref: any) => {
    return (
      <li
        className={className}
        style={{ ...defaultStyle, ...style }}
        ref={drag(ref)}
      >
        {data.name}
      </li>
    );
  }
);

const Example = () => {
  const [items, setItems] = useState([
    { id: '1', name: '小明', type: 'sortable-card' },
    { id: '2', name: '陈二', type: 'sortable-card' },
    { id: '3', name: '张三', type: 'sortable-card' },
    { id: '4', name: '李四', type: 'sortable-card' },
    { id: '5', name: '老五', type: 'sortable-card' },
    { id: '6', name: '赵六', type: 'sortable-card' },
    { id: '7', name: '王七', type: 'sortable-card' },
  ]);

  const handleChange = (data, event) => {
    setItems(data);
  };
  return (
    <DndProvider backend={HTML5Backend}>
      <AsanySortable
        accept={['sortable-card']}
        tag="ul"
        style={{ listStyle: 'none', padding: 0 }}
        items={items}
        onChange={handleChange}
        itemRender={SortItem}
      />
    </DndProvider>
  );
};
```

## Maintainers

[@limaofeng](https://github.com/limaofeng).

## License

[MIT](LICENSE) © 李茂峰

---
_Source: https://npm.io/package/@asany/sortable · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
