-
Notifications
You must be signed in to change notification settings - Fork 49
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
5e5fa95
commit 17231f2
Showing
2 changed files
with
60 additions
and
49 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
src/components/Universe/Graph/Connections/LineComponent.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,49 @@ | ||
import { Line } from '@react-three/drei' | ||
import gsap from 'gsap' | ||
import { forwardRef, useEffect } from 'react' | ||
import { Vector3 } from 'three' | ||
import { Line2 } from 'three-stdlib' | ||
|
||
type LineComponentProps = { | ||
source: Vector3 | ||
target: Vector3 | ||
isSelected: boolean | ||
lineWidth: number | ||
visible: boolean | ||
} | ||
|
||
const LineComponent = forwardRef<Line2, LineComponentProps>( | ||
({ source, target, isSelected, lineWidth, visible }, ref) => { | ||
useEffect(() => { | ||
const line = (ref as React.MutableRefObject<Line2 | null>).current | ||
|
||
if (line) { | ||
gsap.fromTo( | ||
line.material, | ||
{ linewidth: 5 }, | ||
{ | ||
linewidth: isSelected ? 2 : lineWidth, | ||
duration: 1, | ||
}, | ||
) | ||
} | ||
}, [isSelected, lineWidth, ref]) | ||
|
||
return ( | ||
<Line | ||
ref={ref} | ||
color="rgba(136, 136, 136, 1)" | ||
isLine2 | ||
lineWidth={1} | ||
opacity={1} | ||
points={[source, target]} | ||
transparent | ||
visible={visible} | ||
/> | ||
) | ||
}, | ||
) | ||
|
||
LineComponent.displayName = 'LineComponent' | ||
|
||
export default LineComponent |
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