-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LA-7 Add animations & centering when adding new labels
- Loading branch information
Lucano Vera
committed
Dec 12, 2024
1 parent
8b98018
commit 9999ac4
Showing
5 changed files
with
87 additions
and
11 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
28 changes: 28 additions & 0 deletions
28
clients/admin-ui/src/features/taxonomy/hooks/useCenterScreenOnNode.ts
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,28 @@ | ||
import { useReactFlow } from "@xyflow/react"; | ||
import { useCallback } from "react"; | ||
|
||
interface UseCenterScreenOnNodeParams { | ||
positionAbsoluteX: number; | ||
positionAbsoluteY: number; | ||
nodeWidth: number; | ||
} | ||
|
||
const useCenterScreenOnNode = ({ | ||
positionAbsoluteX, | ||
positionAbsoluteY, | ||
nodeWidth, | ||
}: UseCenterScreenOnNodeParams) => { | ||
const { setCenter, getZoom } = useReactFlow(); | ||
|
||
const centerScreenOnNode = useCallback( | ||
() => | ||
setCenter(positionAbsoluteX + nodeWidth / 2, positionAbsoluteY, { | ||
duration: 500, | ||
zoom: getZoom(), | ||
}), | ||
[getZoom, positionAbsoluteX, positionAbsoluteY, nodeWidth, setCenter], | ||
); | ||
|
||
return { centerScreenOnNode }; | ||
}; | ||
export default useCenterScreenOnNode; |
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