scriptkavi / hooks

Empower your react project with accessible and customizable hooks. Copy paste the modern hooks and use them in your React or NextJS applications.
https://hooks.scriptkavi.com
MIT License
153 stars 3 forks source link

[feature] Right click context on either mouse hook or independent right click hook. #4

Closed iamkarshe closed 2 months ago

iamkarshe commented 3 months ago

Feature description

Either we update mouse hook to detect right click or have one more hook for right click event detection, even we can add context menu if required?

Existing mouse hook. https://hooks.scriptkavi.com/docs/hooks/mouse

After update we might have

const [mouse, ref] = useMouse()

// Either 
if (mouse.isRightClick) {}

// Or,
if (mouse.clickType === 'RIGHT_CLICK') {}

Affected component/components

Mouse

Additional Context

Though we have onContextMenu event already in React. Should we make hook around it?

import React from 'react';

const RightClickComponent = () => {
    const handleRightClick = (event) => {
        event.preventDefault(); // Prevent the default context menu from appearing
        console.log('Right-click detected');
        // You can add your custom context menu logic here
    };

    return (
        <div
            onContextMenu={handleRightClick}
            style={{
                width: '300px',
                height: '200px',
                backgroundColor: '#ffffff',
                border: '2px solid #000',
                display: 'flex',
                justifyContent: 'center',
                alignItems: 'center',
                fontSize: '1.5rem',
                textAlign: 'center',
                margin: '50px auto'
            }}
        >
            Right-click here!
        </div>
    );
};

export default RightClickComponent;

Before submitting

sunnynk19 commented 2 months ago

This issue has been automatically closed because it received no activity for a while. If you think it was closed by accident, please leave a comment. Thank you.