Skip to content

Commit 1b7f27c

Browse files
committed
Add example for dragOver
1 parent 44919d0 commit 1b7f27c

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

example/src/demos/FileDragDrop.tsx

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import React, { useState } from 'react'
2+
import { Canvas } from '@react-three/fiber'
3+
import { a, useSpring } from '@react-spring/three'
4+
import { OrbitControls } from '@react-three/drei'
5+
6+
export default function Box() {
7+
const [active, setActive] = useState(0)
8+
// create a common spring that will be used later to interpolate other values
9+
const { spring } = useSpring({
10+
spring: active,
11+
config: { mass: 5, tension: 400, friction: 50, precision: 0.0001 },
12+
})
13+
// interpolate values from commong spring
14+
const scale = spring.to([0, 1], [1, 2])
15+
const rotation = spring.to([0, 1], [0, Math.PI])
16+
const color = active ? spring.to([0, 1], ['#6246ea', '#e45858']) : spring.to([0, 1], ['#620000', '#e40000'])
17+
return (
18+
<Canvas>
19+
<a.mesh
20+
rotation-y={rotation}
21+
scale-x={scale}
22+
scale-z={scale}
23+
onDragOverEnter={() => setActive(1)}
24+
onDragOverLeave={() => setActive(0)}>
25+
<boxBufferGeometry />
26+
<a.meshBasicMaterial color={color} />
27+
</a.mesh>
28+
<OrbitControls />
29+
</Canvas>
30+
)
31+
}

example/src/demos/index.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const Test = { Component: lazy(() => import('./Test')) }
2424
const Viewcube = { Component: lazy(() => import('./Viewcube')) }
2525
const Portals = { Component: lazy(() => import('./Portals')) }
2626
const ViewTracking = { Component: lazy(() => import('./ViewTracking')) }
27+
const FileDragDrop = { Component: lazy(() => import('./FileDragDrop')) }
2728

2829
export {
2930
Animation,
@@ -50,4 +51,5 @@ export {
5051
MultiView,
5152
Portals,
5253
ViewTracking,
54+
FileDragDrop,
5355
}

0 commit comments

Comments
 (0)