-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6cd021f
commit 35be9a0
Showing
9 changed files
with
263 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React, { forwardRef } from 'react'; | ||
|
||
const ATable = (props, ref) => { | ||
return ( | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>Id</th> | ||
<th>Name</th> | ||
</tr> | ||
</thead> | ||
<tbody ref={ref}> | ||
{props?.list?.map((item) => { | ||
return ( | ||
<tr key={item.name} className="cursor-move"> | ||
<td>{item.id}</td> | ||
<td>{item.name}</td> | ||
</tr> | ||
); | ||
})} | ||
</tbody> | ||
</table> | ||
); | ||
}; | ||
export default forwardRef(ATable); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React, { useRef, useState } from 'react'; | ||
import { ReactDraggablePlus } from 'react-draggable-plus'; | ||
import PreviewList from 'react-draggable-plus/builtins/PreviewList'; | ||
import ATable from './ATable'; | ||
|
||
const Demo = () => { | ||
const [list, setList] = useState([ | ||
{ | ||
name: 'Joao', | ||
id: 1, | ||
}, | ||
{ | ||
name: 'Jean', | ||
id: 2, | ||
}, | ||
{ | ||
name: 'Johanna', | ||
id: 3, | ||
}, | ||
{ | ||
name: 'Juan', | ||
id: 4, | ||
}, | ||
]); | ||
const atEl = useRef(null) | ||
return ( | ||
<div> | ||
<div> | ||
<ReactDraggablePlus list={list} setList={setList} animation={150} target={atEl}> | ||
<ATable list={list} ref={atEl}></ATable> | ||
</ReactDraggablePlus> | ||
</div> | ||
<div className="flex justify-between"> | ||
<PreviewList list={list} /> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Demo; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React, { useRef, useState } from 'react'; | ||
import { useDraggable } from 'react-draggable-plus'; | ||
import PreviewList from 'react-draggable-plus/builtins/PreviewList'; | ||
import ATable from './ATable'; | ||
|
||
const Function = () => { | ||
const [list, setList] = useState([ | ||
{ | ||
name: 'Joao', | ||
id: 1, | ||
}, | ||
{ | ||
name: 'Jean', | ||
id: 2, | ||
}, | ||
{ | ||
name: 'Johanna', | ||
id: 3, | ||
}, | ||
{ | ||
name: 'Juan', | ||
id: 4, | ||
}, | ||
]); | ||
const atEl = useRef(null); | ||
useDraggable(atEl, list, setList); | ||
|
||
return ( | ||
<div> | ||
<ATable list={list} ref={atEl}></ATable> | ||
<div className="flex justify-between"> | ||
<PreviewList list={list} /> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Function; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
--- | ||
title: Specify the target container | ||
nav: | ||
title: 演示 | ||
order: 5 | ||
toc: content | ||
--- | ||
|
||
# Specify the target container | ||
|
||
Since many components that need to be dragged are not our immediate child elements in our usual use, we need to specify a target container to complete the drag function. We can specify the target container through the `target` attribute. | ||
|
||
Here we take the third-party component as an example, assuming `a-table` is a third-party component | ||
|
||
### ATable.tsx | ||
|
||
```ts | ||
import React, { forwardRef } from 'react'; | ||
|
||
const ATable = (props, ref) => { | ||
return ( | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>Id</th> | ||
<th>Name</th> | ||
</tr> | ||
</thead> | ||
<tbody ref={ref}> | ||
{props?.list?.map((item) => { | ||
return ( | ||
<tr key={item.name} className="cursor-move"> | ||
<td>{item.id}</td> | ||
<td>{item.name}</td> | ||
</tr> | ||
); | ||
})} | ||
</tbody> | ||
</table> | ||
); | ||
}; | ||
|
||
export default forwardRef(ATable); | ||
``` | ||
|
||
## Component Usage | ||
|
||
<code src="./demo.tsx" | ||
title="Use components to manipulate target containers" | ||
description="Locate the ref element specified by target"> | ||
</code> | ||
|
||
## Function Usage | ||
|
||
<code src="./function.tsx" | ||
title="Use function to manipulate target containers" | ||
description="Locate the ref element specified by target"> | ||
</code> | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
--- | ||
title: 指定目标容器 | ||
nav: | ||
title: 演示 | ||
order: 5 | ||
toc: content | ||
--- | ||
|
||
# 指定目标容器 | ||
|
||
由于我们平时使用的过程中,很多需要拖拽的组件并非我们的直系子元素,所以我们需要指定一个目标容器,来完成拖拽的功能,我们可以通过 `target` 属性来指定目标容器。 | ||
|
||
此处我们以第三方组件为例,假设`a-table`为第三方组件 | ||
|
||
### ATable.tsx | ||
|
||
```ts | ||
import React, { forwardRef } from 'react'; | ||
|
||
const ATable = (props, ref) => { | ||
return ( | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>Id</th> | ||
<th>Name</th> | ||
</tr> | ||
</thead> | ||
<tbody ref={ref}> | ||
{props?.list?.map((item) => { | ||
return ( | ||
<tr key={item.name} className="cursor-move"> | ||
<td>{item.id}</td> | ||
<td>{item.name}</td> | ||
</tr> | ||
); | ||
})} | ||
</tbody> | ||
</table> | ||
); | ||
}; | ||
|
||
export default forwardRef(ATable); | ||
``` | ||
|
||
## 组件使用 | ||
|
||
<code src="./demo.tsx" | ||
title="使用组件操作目标容器" | ||
description="找到target指定的ref元素"> | ||
</code> | ||
|
||
## 函数使用 | ||
|
||
<code src="./function.tsx" | ||
title="使用function操作目标容器" | ||
description="找到target指定的ref元素"> | ||
</code> | ||
|
||
|
||
|