Skip to content

Commit 8d7f5da

Browse files
committed
Add example for dragover event handling
1 parent 2ca8219 commit 8d7f5da

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

Diff for: 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+
}

Diff for: example/src/demos/index.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const Animation = { Component: lazy(() => import('./Animation')) }
44
const AutoDispose = { Component: lazy(() => import('./AutoDispose')) }
55
const ClickAndHover = { Component: lazy(() => import('./ClickAndHover')) }
66
const ContextMenuOverride = { Component: lazy(() => import('./ContextMenuOverride')) }
7+
const FileDragDrop = { Component: lazy(() => import('./FileDragDrop')) }
78
const Gestures = { Component: lazy(() => import('./Gestures')) }
89
const Gltf = { Component: lazy(() => import('./Gltf')) }
910
const Inject = { Component: lazy(() => import('./Inject')) }
@@ -30,6 +31,7 @@ export {
3031
AutoDispose,
3132
ClickAndHover,
3233
ContextMenuOverride,
34+
FileDragDrop,
3335
Gestures,
3436
Gltf,
3537
Inject,

0 commit comments

Comments
 (0)