Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/components/CursorifyProvider/Cursorify/useMouseMoveEffect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@ const useMouseMoveEffect = (mouseRef: RefObject<HTMLDivElement>) => {
requestRef.current = requestAnimationFrame(animateMouse)
}

const handleMouseClick = () => {
dispatch({
type: "UPDATE_STYLE",
payload: "click",
});
};

const handleMouseRelease = () => {
dispatch({
type: "UPDATE_STYLE",
payload: "default",
});
};

const handleMouseMove: (e: MouseEvent) => void = (e) => {
if (mouseRef.current === null) return

Expand Down Expand Up @@ -81,8 +95,12 @@ const useMouseMoveEffect = (mouseRef: RefObject<HTMLDivElement>) => {
if (!mouseRef.current) return
animateMouse()
window.addEventListener('mousemove', handleMouseMove)
window.addEventListener("mousedown", handleMouseClick)
window.addEventListener("mouseup", handleMouseRelease)
return () => {
window.removeEventListener('mousemove', handleMouseMove)
window.removeEventListener("mousedown", handleMouseClick)
window.removeEventListener("mouseup", handleMouseRelease)
cancelAnimationFrame(requestRef.current)
}
}, [delay, opacity])
Expand Down
22 changes: 15 additions & 7 deletions src/components/DefaultCursor/DefaultCursor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,28 @@ import { CursorProps } from '../../types'

export const DefaultCursor: React.FC<CursorProps> = ({ disabled }) => {
const { style } = useCursorify()
const isPointed = !disabled && style === "pointer"
const isClicked = !disabled && style === "click"

return (
<div
style={{
width: '23px',
height: '23px',
borderRadius: '50%',
transition:
'opacity 0.1s ease-in-out, transform 0.1s ease-in-out, background-color 0.1s ease-in-out',
backgroundColor:
!disabled && style === 'pointer'
? 'rgba(210, 210, 210, 0.4)'
: 'rgba(210, 210, 210, 0.8)',
transform: !disabled && style === 'pointer' ? 'scale(2.3)' : 'scale(1)',
transition: isClicked
? "opacity 0.13s ease-in-out, transform 0.13s ease-in-out, background-color 0.08s ease-in-out"
: "opacity 0.1s ease-in-out, transform 0.1s ease-in-out, background-color 0.1s ease-in-out",
backgroundColor: isClicked
? "rgba(210, 210, 210, 0.2)"
: isPointed
? "rgba(210, 210, 210, 0.4)"
: "rgba(210, 210, 210, 0.8)",
transform: isClicked
? "scale(2)"
: isPointed
? "scale(2.3)"
: "scale(1)",
}}
/>
)
Expand Down
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type CursorStyle =
| 'contextMenu'
| 'help'
| 'pointer'
| 'click'
| 'progress'
| 'wait'
| 'cell'
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"target": "ESNext",
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"module": "ESNext",
"module": "NodeNext",
"skipLibCheck": true,

/* Bundler mode */
Expand Down