# lee-react-drag

> 基于react的拖拽组件

Latest version **1.0.2** (published 2021-12-08) · ISC license · 0 weekly downloads

## Install

```sh
npm install lee-react-drag
pnpm add lee-react-drag
yarn add lee-react-drag
bun add lee-react-drag
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2021-12-08 |
| First published | 2021-12-07 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 37 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | lzh |
| Maintainers | sevenling |

## Links

- npm: https://www.npmjs.com/package/lee-react-drag
- npm.io page: https://npm.io/package/lee-react-drag

## Recent versions

- 1.0.2 (latest) — 2021-12-08
- 1.0.1 — 2021-12-07
- 1.0.0 — 2021-12-07

## README

<!--
 * @Author: lzh
 * @Date: 2021-12-07 15:58:35
 * @LastEditTime: 2021-12-08 09:31:48
 * @LastEditors: Please set LastEditors
 * @Description: 组件说明文档
 * @FilePath: \LeeDrag\README.md
-->
## Installation
```bash
npm install lee-react-drag
```
## Usage
```js
import React, { useState } from "react";
import LeeReactDrag from "lee-react-drag";

// 组件属性类型
interface ComponentType {
  id: string; // 组件唯一id
  attr: string; // 组件配置信息，x-横坐标点，y-纵坐标点，w-宽度，h-高度，opacity-透明度 .....
  children: ComponentType[]; // 属性同父组件
  hideStatus: number; // 隐藏状态 1-隐藏 2-展示
  lockStatus: number; // 锁定状态 1-锁定 2-解锁
}

export default ()=> {
  // 组件集合
  const [components, setComponents] = useState<ComponentType[]>([{
        id: "123",
        children: [],
        attr: '{"x":50,"y":50,"w":200,"h":200,"opacity":100}',
        hideStatus: 2,
        lockStatus: 2
      }]);
  // 选中组件id集合
  const [selectedIds, setSelectedIds] = useState<(string | number)[]>([]);

  // 更新组件
  const handleUpdateCom = (data: ComponentType | ComponentType[]) => {
    if (data instanceof Array) {
      setComponents(data);
    } else {
      setSelectedIds([data.id]);
    }
  };

  // 选择组件
  const handleSelectCom = (ids: (string | number)[]) => {
    setSelectedIds(ids);
  };

  return (
    <>
      <LeeReactDrag
        components={components}
        selectedIds={selectedIds}
        onChange={handleUpdateCom}
        onSelect={handleSelectCom}
        isEdit
      />
    </>
  );
}
```
### Lee React Drag Props
```js
components: ComponentType[],
selectedIds: string[], // 选中的组件id集合
onChange: (data: ComponentType | ComponentType[]) => void, // 更新组件信息
onSelect: (ids: (string | number)[]) => void, // 选择组件
isEdit: boolean = true, // 是否编辑状态
```

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