-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #927 from andreiwebdev/playground-tabs-draggable
Update - Make tabs in playground draggable
- Loading branch information
Showing
5 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
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
37 changes: 37 additions & 0 deletions
37
agenta-web/src/components/DraggableTabNode/DraggableTabNode.tsx
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,37 @@ | ||
import React from "react" | ||
import {useSortable} from "@dnd-kit/sortable" | ||
import {CSS} from "@dnd-kit/utilities" | ||
|
||
// Defines the props for DraggableTabNode component. | ||
interface DraggableTabNodeProps extends React.HTMLAttributes<HTMLDivElement> { | ||
"data-node-key": string // Unique identifier for the draggable item. | ||
} | ||
|
||
// This component wraps each tab label to make it draggable. | ||
const DraggableTabNode: React.FC<DraggableTabNodeProps> = ({ | ||
"data-node-key": key, | ||
children, | ||
...props | ||
}) => { | ||
// useSortable hook provides the necessary handlers and attributes for drag-and-drop. | ||
const {attributes, listeners, setNodeRef, transform, transition} = useSortable({id: key}) | ||
|
||
// CSS styles to apply transform and transition for the dragging effect. | ||
const style: React.CSSProperties = { | ||
...props.style, | ||
transform: CSS.Transform.toString(transform ? {...transform, scaleX: 1} : null), | ||
transition, | ||
userSelect: "none", | ||
cursor: "pointer", // Changes cursor to indicate draggability. | ||
} | ||
|
||
// Clones the children element to add refs and drag-and-drop related properties. | ||
return React.cloneElement(children as React.ReactElement, { | ||
ref: setNodeRef, | ||
style, | ||
...attributes, | ||
...listeners, | ||
}) | ||
} | ||
|
||
export default DraggableTabNode |
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