Skip to content

Commit 9ef00f6

Browse files
committed
main ?? add title for side
1 parent 38b8e7a commit 9ef00f6

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

src/hooks/usePointerLock/usePointerLock.demo.tsx

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import type { CSSProperties } from 'react';
33

44
import { useRef } from 'react';
55

6+
import { cn } from '@/docs/src/utils';
7+
68
import { useEventListener } from '../useEventListener/useEventListener';
79
import { usePointerLock } from './usePointerLock';
810

@@ -11,31 +13,30 @@ const getSideStyles = (index: number) => ({
1113
transform: "rotateY(calc(90deg * var(--i))) translateZ(50px)"
1214
} as CSSProperties)
1315
const getBaseStyles = (index: number) => ({ "--i": index, transform: "rotateX(calc(90deg * var(--i))) translateZ(50px)" } as CSSProperties)
14-
const face = 'absolute top-0 left-0 w-full h-full border-1 border-solid border-black backface-hidden bg-cyan-500 opacity-50'
16+
const face = 'absolute top-0 left-0 w-full h-full border-1 border-solid border-black backface-hidden bg-cyan-300'
1517

1618

1719
const Demo = () => {
1820
const { element, unlock, lock } = usePointerLock();
19-
const positionRef = useRef({ x: 0, y: 0 });
21+
const positionRef = useRef({ x: 0, y: -45 });
2022

2123
useEventListener('mousemove', (event) => {
22-
positionRef.current = { x: positionRef.current.x + event.movementX, y: positionRef.current.y + event.movementY };
2324
if (!element) return
2425
const cube = element as HTMLElement;
25-
const x = positionRef.current.y + event.movementY / 2
26-
const y = positionRef.current.x + event.movementX / 2
27-
cube.style.transform = `rotateY(calc(${y} * 1deg)) rotateX(calc(${x} * 1deg))`
26+
positionRef.current.x -= event.movementY / 2
27+
positionRef.current.y += event.movementX / 2
28+
cube.style.transform = `rotateY(calc(${positionRef.current.y} * 1deg)) rotateX(calc(${positionRef.current.x} * 1deg))`
2829
}, { passive: true })
2930

3031
return (
31-
<div className='flex justify-center items-center perspective-normal h-32'>
32-
<div className='cursor-all-scroll relative w-[100px] h-[100px] transform-3d' onMouseDownCapture={lock} onMouseUpCapture={unlock}>
33-
<span className={face} style={getBaseStyles(1)} />
34-
<span className={face} style={getBaseStyles(-1)} />
35-
<span className={face} style={getSideStyles(0)} />
36-
<span className={face} style={getSideStyles(1)} />
37-
<span className={face} style={getSideStyles(2)} />
38-
<span className={face} style={getSideStyles(3)} />
32+
<div className='flex justify-center items-center perspective-normal h-32' >
33+
<div className='cursor-all-scroll relative w-[100px] h-[100px] transform-3d' style={{ transform: `rotateY(calc(-45 * 1deg))` }} onMouseDownCapture={lock} onMouseUpCapture={unlock}>
34+
<div className={face} style={getBaseStyles(1)} />
35+
<div className={face} style={getBaseStyles(-1)} />
36+
<div className={cn(face, 'text-lg text-gray-700 items-center flex justify-center')} style={getSideStyles(0)}>move me</div>
37+
<div className={face} style={getSideStyles(1)} />
38+
<div className={face} style={getSideStyles(2)} />
39+
<div className={face} style={getSideStyles(3)} />
3940
</div>
4041
</div>
4142
)

0 commit comments

Comments
 (0)