-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: tool name cannot startwith number * fix: chatbox update * fix: chatbox * perf: drag ui * perf: drag component * drag component
- Loading branch information
Showing
16 changed files
with
203 additions
and
118 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { DragHandleIcon } from '@chakra-ui/icons'; | ||
import { Box } from '@chakra-ui/react'; | ||
import React from 'react'; | ||
import { DraggableProvided } from 'react-beautiful-dnd'; | ||
|
||
const DragIcon = ({ provided }: { provided: DraggableProvided }) => { | ||
return ( | ||
<Box {...provided.dragHandleProps}> | ||
<DragHandleIcon color={'myGray.500'} _hover={{ color: 'primary.600' }} /> | ||
</Box> | ||
); | ||
}; | ||
|
||
export default DragIcon; |
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 @@ | ||
import { Box } from '@chakra-ui/react'; | ||
import React, { useState } from 'react'; | ||
import { | ||
DragDropContext, | ||
DroppableProps, | ||
Droppable, | ||
DraggableChildrenFn, | ||
DragStart, | ||
DropResult | ||
} from 'react-beautiful-dnd'; | ||
|
||
type Props<T = any> = { | ||
onDragEndCb: (result: T[]) => void; | ||
renderClone?: DraggableChildrenFn; | ||
children: DroppableProps['children']; | ||
dataList: T[]; | ||
}; | ||
|
||
function DndDrag<T>({ children, renderClone, onDragEndCb, dataList }: Props<T>) { | ||
const [draggingItemHeight, setDraggingItemHeight] = useState(0); | ||
|
||
const onDragStart = (start: DragStart) => { | ||
const draggingNode = document.querySelector(`[data-rbd-draggable-id="${start.draggableId}"]`); | ||
setDraggingItemHeight(draggingNode?.getBoundingClientRect().height || 0); | ||
}; | ||
|
||
const onDragEnd = (result: DropResult) => { | ||
if (!result.destination) { | ||
return; | ||
} | ||
setDraggingItemHeight(0); | ||
|
||
const startIndex = result.source.index; | ||
const endIndex = result.destination.index; | ||
|
||
const list = Array.from(dataList); | ||
const [removed] = list.splice(startIndex, 1); | ||
list.splice(endIndex, 0, removed); | ||
|
||
onDragEndCb(list); | ||
}; | ||
|
||
return ( | ||
<DragDropContext onDragStart={onDragStart} onDragEnd={onDragEnd}> | ||
<Droppable droppableId="droppable" renderClone={renderClone}> | ||
{(provided, snapshot) => { | ||
return ( | ||
<Box {...provided.droppableProps} ref={provided.innerRef}> | ||
{children(provided, snapshot)} | ||
{snapshot.isDraggingOver && <Box height={draggingItemHeight} />} | ||
</Box> | ||
); | ||
}} | ||
</Droppable> | ||
</DragDropContext> | ||
); | ||
} | ||
|
||
export default DndDrag; | ||
|
||
export * from 'react-beautiful-dnd'; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.