All Projects → ethanselzer → React Cursor Position

ethanselzer / React Cursor Position

Licence: mit
A React component that decorates its children with mouse and touch coordinates relative to itself.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Cursor Position

Any Touch
👋 手势库, 按需2kb~5kb, 兼容PC / 移动端
Stars: ✭ 567 (+316.91%)
Mutual labels:  mouse, tap, drag, touch, pan
gesto
You can set up drag, pinch events in any browser.
Stars: ✭ 47 (-65.44%)
Mutual labels:  touch, drag, mouse
React Event Components
🛰 A set of React components designed to handle global events (interval, keyboard, touch, mouse, etc)
Stars: ✭ 271 (+99.26%)
Mutual labels:  mouse, touch
Tap
1Kb library for easy unified handling of user interactions such as mouse, touch and pointer events.
Stars: ✭ 541 (+297.79%)
Mutual labels:  tap, touch
Sortable
Reorderable drag-and-drop lists for modern browsers and touch devices. No jQuery or framework required.
Stars: ✭ 23,641 (+17283.09%)
Mutual labels:  drag, touch
lime
A library for drawing graphics on the console screen
Stars: ✭ 32 (-76.47%)
Mutual labels:  mouse, cursor
Pancake
Lightweight, Fast, Easy-to-use HTML5 2D game framework!
Stars: ✭ 79 (-41.91%)
Mutual labels:  touch, mouse
Creepyface
A JavaScript library that makes your face follow the pointer. 🤪🖱️👆
Stars: ✭ 412 (+202.94%)
Mutual labels:  mouse, touch
Dragscroll
micro library for drag-n-drop scrolling style
Stars: ✭ 989 (+627.21%)
Mutual labels:  mouse, drag
Inputsystem
An efficient and versatile input system for Unity.
Stars: ✭ 1,013 (+644.85%)
Mutual labels:  mouse, touch
Gesturerecognizerclosures
Closure support for handling gesture recognizers in Swift.
Stars: ✭ 84 (-38.24%)
Mutual labels:  tap, pan
linearmouse
🖱 The mouse and trackpad utility for Mac.
Stars: ✭ 1,151 (+746.32%)
Mutual labels:  mouse, cursor
react-sticky-mouse-tooltip
React tooltip component that follow mouse cursor.
Stars: ✭ 17 (-87.5%)
Mutual labels:  mouse, cursor
Hover On Touch
A pure Javascript Plugin for an alternative hover function that works on mobile and desktop devices. It triggers a hover css class on »Taphold« and goes to a possible link on »Tap«. It works with all html elements.
Stars: ✭ 256 (+88.24%)
Mutual labels:  tap, touch
React Rotation
React rotation component
Stars: ✭ 102 (-25%)
Mutual labels:  mouse, touch
gestures
A library for normalized events and gesture for desktop and mobile.
Stars: ✭ 31 (-77.21%)
Mutual labels:  tap, touch
Kursor
Cursor style with javascript and css
Stars: ✭ 140 (+2.94%)
Mutual labels:  mouse, cursor
react-fastclick
A react component that triggers click events for taps (short localized touches)
Stars: ✭ 20 (-85.29%)
Mutual labels:  tap, touch
React Prismazoom
A pan and zoom component for React, using CSS transformations.
Stars: ✭ 29 (-78.68%)
Mutual labels:  drag, pan
React Easy Swipe
Easy handler for common swipe operations
Stars: ✭ 85 (-37.5%)
Mutual labels:  mouse, touch

react-cursor-position

react-cursor-position is a primitive component for composing UI features that require notification of cursor or touch position changes. Position coordinates are plotted relative to the HTML element rendered by react-cursor-position. react-cursor-position re-renders child components with new position props when the cursor or touch position changes.

  • May be activated by Press, Tap, Touch, Hover and Click gestures
  • Supports scroll position changes during an active session

Status

CircleCI Coverage Status npm License

Demo

See the react-cursor-position demo site.

Experiment with react-cursor-position live on CodePen.

Installation

npm install --save react-cursor-position

Usage

If you are upgrading from v2x to v3x please see the release notes

If you are upgrading from v1x to v2x please see the release notes.

import ReactCursorPosition from 'react-cursor-position';
...

<ReactCursorPosition>
    <YourComponentOne/>
    <YourComponentTwo/>
</ReactCursorPosition>

react-cursor-position wraps its children in a div, which mouse and touch position are plotted relative to.

Each child component will receive the following props:

{
    detectedEnvironment: {
        isMouseDetected: false,
        isTouchDetected: false,
    },
    elementDimensions: {
        width: Number,
        height: Number
    },
    isActive: Boolean,
    isPositionOutside: Boolean,
    position: {
        x: Number,
        y: Number
    }
}

This structure may be customized by implementing mapChildProps API feature.

The information in detectedEnvironment is acquired from interaction with this component and will be unset until the first interaction.

Props API

All props are optional.

activationInteractionMouse : String - One of INTERACTIONS.HOVER (default), INTERACTIONS.CLICK. Import Interactions like this import ReactCursorPosition, { Interactions } from 'react-cursor-position'. See examples. for more.

activationInteractionTouch : String - One of INTERACTIONS.PRESS (default), INTERACTIONS.TAP, or INTERACTIONS.TOUCH. Import Interactions like this import ReactCursorPosition, { Interactions } from 'react-cursor-position'. See examples.

className : String - CSS class name(s) to be applied to the div rendered by react-cursor-position.

hoverDelayInMs : Number - Amount of time, in milliseconds, to delay hover interaction from activating. Defaults to 0.

hoverOffDelayInMs : Number - Amount of time, in milliseconds, to delay hover off interaciton from deactivating. Defaults to 0.

isEnabled : Boolean - Enable or disable cursor position monitoring without remounting. Defaults to true.

mapChildProps : Function - Model child component props to your custom shape. Function receives one parameter with the signature { isActive: Boolean, isPositionOutside: Boolean, position: { x: Number, y: Number } }.
It should return an object that is compatible with the props interface of your child components. See example demo.

onActivationChanged : Function - Called when the component is active. Function receives one parameter with the signature { isActive: Boolean }.

onPositionChanged : Function - Called when cursor or touch position changes. Function receives one parameter with the signature { elementDimensions: { width: Number, height: Number }, isPositionOutside: Boolean, position: { x: Number, y: Number } }.

onDetectedEnvironmentChanged : Function - Called when detected environment (mouse or touch) changes. Function receives one parameter with the signature { isMouseDetected: Boolean, isTouchDetected: Boolean }.

pressDurationInMs : Number - Milliseconds delay before press gesture is activated. Defaults to 500.

pressMoveThreshold : Number - Amount of movement, in pixels, allowed during press gesture detection. Defaults to 5.

shouldDecorateChildren : Boolean - Suppress decoration of child components by setting this prop false. Defaults to true.

shouldStopTouchMovePropagation : Boolean - Stop touchmove event bubbling when react-cursor-position is active. Defaults to false.

style : Object - Style to be applied to the div rendered by react-cursor-position.

tapDurationInMs : Number - Max milliseconds allowed for a screen touch to be considered a tap gesture. Defaults to 180.

tapMoveThreshold : Number - Amount of movement, in pixels, allowed during tap gesture detection. Defaults to 5.

Imperative API

reset: Invoking the reset method instructs react-cursor-position to recalculate its position relative to the page.

See API Examples section of the demo site for more.

Support

Please open an issue.

Example Project

git clone https://github.com/ethanselzer/react-cursor-position.git
cd react-cursor-position
npm install
npm run build
cd example
yarn
yarn start

If your default browser does not start automatically, open a new browser window and go to localhost:3000

Development

git clone https://github.com/ethanselzer/react-cursor-position.git
cd react-cursor-position
npm install
npm run #print available commands

The Example Project may be used in development of react-cursor-position.

To rebuild the source automatically when changes are made, run npm run build-watch.

Contributing

Please contribute by opening an issue or a pull request.

Attribution

Thanks to the following community members for opening GitHub Issues and Pull Requests. Your input is very much appreciated!

You are awesome! ✨💫

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].