Skip to content

Commit

Permalink
feat: usecursor
Browse files Browse the repository at this point in the history
  • Loading branch information
drcmda committed Sep 22, 2021
1 parent b4b6b33 commit a32f01e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ The `native` route of the library **does not** export `Html` or `Loader`. The de
<li><a href="#usedetectgpu">useDetectGPU</a></li>
<li><a href="#usehelper">useHelper</a></li>
<li><a href="#useaspect">useAspect</a></li>
<li><a href="#usecursor">useCursor</a></li>
</ul>
<li><a href="#loading">Loaders</a></li>
<ul>
Expand Down Expand Up @@ -905,6 +906,17 @@ return (
<meshBasicMaterial map={imageTexture} />
```
#### useCursor
A small hook that sets the css body cursor according to the hover state of a mesh, so that you can give the use visual feedback when the mouse enters a shape. Arguments 1 and 2 determine the style, the defaults are: onPointerOver = 'pointer', onPointerOut = 'auto'.
```jsx
const [hovered, set] = useState()
useCursor(hovered, /*'pointer', 'auto'*/)
return (
<mesh onPointerOver={() => set(true)} onPointerOut={() => set(false)}>
```
# Modifiers
#### CurveModifier
Expand Down
2 changes: 1 addition & 1 deletion src/web/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { Html } from './Html'

export { useCursor } from './useCursor'
export { Loader } from './Loader'

export * from '../core'
Expand Down
10 changes: 10 additions & 0 deletions src/web/useCursor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as React from 'react'

export function useCursor(hovered: boolean, onPointerOver = 'pointer', onPointerOut = 'auto') {
React.useEffect(() => {
if (hovered) {
document.body.style.cursor = onPointerOver
return () => void (document.body.style.cursor = onPointerOut)
}
}, [hovered])
}

1 comment on commit a32f01e

@vercel
Copy link

@vercel vercel bot commented on a32f01e Sep 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.