Skip to content

Commit 7bfd7e7

Browse files
committed
feat: update docs
1 parent d1d0905 commit 7bfd7e7

File tree

8 files changed

+245
-5
lines changed

8 files changed

+245
-5
lines changed

.dumirc.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ export default defineConfig({
2727
features: {
2828
'zh-CN': [
2929
{ title: '功能齐全', details: '全面继承 Sortable.js 的所有功能'},
30-
{ title: '灵活使用', details: '支持组件、指令、函数式调用,总有一款是您喜欢的'},
30+
{ title: '灵活使用', details: '支持组件、函数式调用,总有一款是您喜欢的'},
3131
{ title: '自定义容器', details: '将指定容器作为拖拽容器'}
3232
],
3333
'en-US': [
3434
{ title: 'Fully functional', details: 'Full inheritance of all the features of Sortable.js'},
35-
{ title: 'Use flexibly', details: 'Support components, instructions, and function calls, there is always one you like'},
35+
{ title: 'Use flexibly', details: 'Support components, and function calls, there is always one you like'},
3636
{ title: 'Custom containers', details: 'Drag and drop the specified container'}
3737
],
3838
},

docs/guide/index.en-US.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ In `Sortablejs` official `React` components in the past, the drag-and-drop list
3636

3737
```ts
3838
import React, { useRef, useState } from "react"
39-
import { ReactDraggablePlush } from 'react-draggable-plus'
39+
import { ReactDraggablePlush } from "react-draggable-plus"
4040
const Demo = () => {
4141
const el = useRef<any>(null)
4242
const [list, setList] = useState([{

docs/guide/index.zh-CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ nav:
3232

3333
```ts
3434
import React, { useRef, useState } from "react"
35-
import { ReactDraggablePlush } from 'react-draggable-plus'
35+
import { ReactDraggablePlush } from "react-draggable-plus"
3636
const Demo = () => {
3737
const el = useRef<any>(null)
3838
const [list, setList] = useState([{

src/basic/demo.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useRef, useState } from "react"
2-
import { ReactDraggablePlush } from 'react-draggable-plus'
2+
import { ReactDraggablePlush } from "react-draggable-plus"
33
import PreviewList from "react-draggable-plus/builtins/PreviewList"
44

55
const Demo = () => {

src/custom-clone/demo.tsx

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import React, { useState } from "react"
2+
import { ReactDraggablePlush } from 'react-draggable-plus'
3+
import PreviewList from "react-draggable-plus/builtins/PreviewList"
4+
import Sortable from "sortablejs"
5+
6+
const Demo = () => {
7+
const data = [
8+
{
9+
name: 'Joao',
10+
id: 1
11+
},
12+
{
13+
name: 'Jean',
14+
id: 2
15+
},
16+
{
17+
name: 'Johanna',
18+
id: 3
19+
},
20+
{
21+
name: 'Juan',
22+
id: 4
23+
}
24+
]
25+
const [list, setList] = useState(data)
26+
const [list2, setList2] = useState(data.map(item => ({
27+
name: `${item.name}-2`,
28+
id: `${item.id}-2`
29+
})))
30+
31+
const group:Sortable.GroupOptions = { name: "people", pull: "clone" , put: false }
32+
33+
const onClone = (element: Record<'name' | 'id', string>) => {
34+
const len = list2.length
35+
return {
36+
name: `${element.name}-clone-${len}`,
37+
id: `${element.id}-clone-${len}`
38+
}
39+
}
40+
41+
return <>
42+
<div className="flex">
43+
<ReactDraggablePlush
44+
list={list}
45+
setList={setList}
46+
animation={150}
47+
group={ group }
48+
sort={false}
49+
className="flex flex-col gap-2 p-4 w-300px h-360px m-auto bg-gray-500/5 rounded"
50+
clone={onClone}
51+
>
52+
{
53+
list.map(item => {
54+
return <div className="cursor-move h-30 bg-gray-500/5 rounded p-3" key={item.id}>{item.name}</div>
55+
})
56+
}
57+
</ReactDraggablePlush>
58+
<ReactDraggablePlush
59+
list={list2}
60+
setList={setList2}
61+
animation={150}
62+
group="people"
63+
className="flex flex-col gap-2 p-4 w-300px h-360px m-auto bg-gray-500/5 rounded"
64+
>
65+
{
66+
list2.map(item => {
67+
return <div className="cursor-move h-30 bg-gray-500/5 rounded p-3" key={item.id}>{item.name}</div>
68+
})
69+
}
70+
</ReactDraggablePlush>
71+
</div>
72+
<div className="flex justify-between">
73+
<PreviewList list={list} className="m-auto"></PreviewList>
74+
<PreviewList list={list2} className="m-auto"></PreviewList>
75+
</div>
76+
</>
77+
}
78+
79+
export default Demo

src/custom-clone/function.tsx

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import React, { useRef, useState } from "react"
2+
import { useDraggable } from "react-draggable-plus"
3+
import PreviewList from "react-draggable-plus/builtins/PreviewList"
4+
import Sortable from "sortablejs"
5+
6+
const Function = () => {
7+
const el1 = useRef<any>(null)
8+
const el2 = useRef<any>(null)
9+
10+
const data = [
11+
{
12+
name: 'Joao',
13+
id: '1'
14+
},
15+
{
16+
name: 'Jean',
17+
id: '2'
18+
},
19+
{
20+
name: 'Johanna',
21+
id:'3'
22+
},
23+
{
24+
name: 'Juan',
25+
id: '4'
26+
}
27+
]
28+
const group:Sortable.GroupOptions = { name: "people", pull: "clone", put: false}
29+
const [list1, setList1] = useState(data)
30+
const [list2, setList2] = useState(data.map(item => ({
31+
name: `${item.name}-2`,
32+
id: `${item.id}-2`
33+
})))
34+
35+
useDraggable(el1, list1, setList1, {
36+
animation: 150,
37+
group,
38+
sort: false,
39+
clone: (element: Record<'name' | 'id', string>) => {
40+
const len = list2.length
41+
return {
42+
name: `${element.name}-clone-${len}`,
43+
id: `${element.id}-clone-${len}`
44+
}
45+
}
46+
})
47+
48+
useDraggable(el2, list2, setList2, {
49+
animation: 150,
50+
group: 'people',
51+
})
52+
53+
return <>
54+
<div className="flex">
55+
<div
56+
className="flex flex-col gap-2 p-4 w-300px h-300px m-auto bg-gray-500/5 rounded overflow-auto"
57+
ref={el1}
58+
>
59+
{
60+
list1.map(item => {
61+
return <div
62+
key={item.id}
63+
className="cursor-move h-30 bg-gray-500/5 rounded p-3"
64+
>
65+
{ item.name }
66+
</div>
67+
})
68+
}
69+
</div>
70+
<div
71+
className="flex flex-col gap-2 p-4 w-300px h-300px m-auto bg-gray-500/5 rounded overflow-auto"
72+
ref={el2}
73+
>
74+
{
75+
list2.map(item => {
76+
return <div
77+
key={item.id}
78+
className="cursor-move h-30 bg-gray-500/5 rounded p-3"
79+
>
80+
{ item.name }
81+
</div>
82+
})
83+
}
84+
</div>
85+
</div>
86+
<div className="flex justify-between">
87+
<PreviewList list={list1} className="m-auto"></PreviewList>
88+
<PreviewList list={list2} className="m-auto"></PreviewList>
89+
</div>
90+
</>
91+
}
92+
93+
export default Function

src/custom-clone/index.en-US.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: Custom Clone
3+
nav:
4+
title: Demo
5+
order: 4
6+
toc: content
7+
---
8+
9+
# Custom Clone
10+
11+
12+
We can pass a function through the `clone` attribute to customize the cloned node, and `JSON.parse(JSON.stringify())` is used internally to implement cloning. You can also choose to use `lodash` or other third-party libraries. Clone, this function is commonly used in low-code scenarios, such as dragging form elements to the canvas, and a new component element needs to be cloned.
13+
14+
When we use this function, we need to pay attention to:
15+
1. The `pull` attribute in the `group` attribute of the cloned component must be `clone`, otherwise it cannot be cloned.
16+
2. The `name` attribute in the `group` of the cloned component must be consistent with the `name` attribute in the `group` of the cloned component, otherwise it cannot be cloned.
17+
18+
<Alert>
19+
Note: When we use the `clone` attribute, we need to regenerate a unique `key`, otherwise it will cause the component to render abnormally.
20+
</Alert>
21+
22+
## Component Usage
23+
24+
<code src="./demo.tsx"
25+
title="Clone using components"
26+
description="Pass through the pull.clone attribute of the group to realize clone">
27+
</code>
28+
29+
## Function Usage
30+
31+
<code src="./function.tsx"
32+
title="Cloning using function"
33+
description="Use function to pass options to achieve cloning">
34+
</code>

src/custom-clone/index.zh-CN.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: 自定义克隆
3+
nav:
4+
title: 演示
5+
order: 4
6+
toc: content
7+
---
8+
9+
# 自定义克隆
10+
11+
我们可以通过 `clone` 属性传递一个函数,来自定义克隆的节点,内部使用 `JSON.parse(JSON.stringify())`实现克隆,您也可以选择使用 `lodash` 或者其他第三方库的方式进行克隆,此功能常用与低代码场景,比如拖拽表单元素到画布中,需要克隆一个新的组件元素。
12+
13+
我们在使用该功能时,需要注意:
14+
1. 被克隆组件的 `group` 属性中的 `pull` 属性必须为 `clone`,否则无法克隆。
15+
2. 被克隆组件中的 `group` 中的 `name` 属性必须与克隆组件的 `group` 中的 `name` 属性一致,否则无法克隆。
16+
17+
<Alert>
18+
注意:当我们使用 `clone` 属性时,需要重新生成一个唯一的 `key`,否则会导致组件渲染异常。
19+
</Alert>
20+
21+
## 组件使用
22+
23+
<code src="./demo.tsx"
24+
title="使用组件自定义克隆"
25+
description="使用组件属性进行自定义克隆">
26+
</code>
27+
28+
29+
## 函数使用
30+
31+
<code src="./function.tsx"
32+
title="自定义克隆"
33+
description="传递 clone 属性,实现自定义克隆">
34+
</code>

0 commit comments

Comments
 (0)