A tiny higher order component to track mouse state.
import { Component } from 'react';
import { mouseAware } from 'react-mouse-aware';
@mouseAware({ // same as default options
inDelay: 0,
outDelay: 0,
inHandler: 'onMouseEnter',
outHandler: 'onMouseLeave',
key: 'isOver'
})
@mouseAware({
inDelay: 300,
outDelay: 100,
inHandler: 'onMouseDown',
outHandler: 'onMouseUp',
key: 'isPressed'
})
class CustomComponent extends Component {
render() {
// props will include the in and out handlers
let { isOver, isPressed, className, ...props } = this.props;
if (isOver) className += ' hovered'; // mouse is over component
if (isPressed) className += ' active'; // mouse has been held down for 300ms or was just released
return (
<div {...props} className={className}>
</div>
)
}
};
@mouseAware(options)
export default class Test extends React.Component {
/* your code */
}
class Test extends React.Component {
/* your code */
}
export default mouseAware(options)(Test);
Time in ms
to wait before setting the active
status to true
.
Time in ms
to wait before setting the active
status to false
.
Property name to expose the inHandler
as.
Property name to expose the outHandler
as.
Property name to expose the force open function as. This function will ignore the in delay
Property name to expose the force close function as. This function will ignore the out delay.
Property name to expose the active
status as.