npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-mouse-handler

v0.4.4

Published

React 鼠标事件处理组件,通过这个高阶组件封装后,子组件具备光标样式设置(cursor)、鼠标事件回调(onMouseOver、onMouseMove、onMouseDown、onMouseUp、onMouseOut、onClick、onDragStar、onDrag、onDragEnd),在回调函数中可以拿到鼠标位置数据(localX、localY、globalX、globalY、dx、dy)

Downloads

6

Readme

react-mouse-handler

React 鼠标事件处理组件,通过这个高阶组件封装后,子组件具备光标样式设置(cursor)、鼠标事件回调(onMouseOveronMouseMoveonMouseDownonMouseUponMouseOutonClickonDragStaronDragonDragEnd),在回调函数中可以拿到鼠标位置数据(localXlocalYglobalXglobalYdxdy

install

npm install react-mouse-handler --save-dev

demo

自定义组件:

// MyComponent.js

import React,{Component} from "react";
import mouseHandler from "react-mouse-handler";

class MyComponent extends Component{
  render() {
    return <p>{this.props.children}</p>;
  }
}
MyComponent = mouseHandler(MyComponent);	// 使用高阶组件封装 MyComponent
export default MyComponent;

index.js 中使用刚刚封装的 MyComponent

// index.js

import ReactDOM from "react-dom";
import React,{Component} from "react";

class App extends Component {
  render() {
    return (
      <div>
        <p>App</p>
        <MyComponent
          cursor="help"                     // 鼠标经过组件时,光标会变成 help 样式
          canDrag={true}                    // 鼠标拖拽(按下并离开)组件时,光标样式保持不变
          onMouseMove={(e, position) => {
            console.log(e);                 // 原生的事件参数
            console.log(position.localX);   // 相对于父容器的局部坐标x
            console.log(position.localY);   // 相对于父容器的局部坐标y
            console.log(position.globalX);  // 相对于document的全局坐标x
            console.log(position.globalY);  // 相对于document的全局坐标y
            console.log(position.dx);       // 水平方向的移动增量(只有在onMouseMove、onDrag时有意义)
            console.log(position.dy);       // 垂直方向的移动增量(只有在onMouseMove、onDrag时有意义)
          }}
          onMouseOver={(e, position) => {
            // do something
          }}
          onMouseDown={(e, position) => {
            // do something
          }}
          onMouseUp={(e, position) => {
            // do something
          }}
          onMouseOut={(e, position) => {
            // do something
          }}
        >help</MyComponent>
      </div>
    )
  }
}
ReactDOM.render(<App/>,document.getElementById('root'));

update

| 版本 | 更新内容 | | ----- | ------------------------------------------------------------ | | 0.4.4 | 渲染规则:如果高阶组件传入children,就将原始组件的children覆盖。 | | 0.4.3 | 1、接口变更为:mouseHandler(canDrag:boolean, cursor:string)(MyComponent) 2、提供MouseContainer组件。3、修复 bug。 | | 0.4.2 | 修复重绘组件的 bug。 | | 0.4.1 | 修复组件卸载后,鼠标样式未还原的 bug。 | | 0.4.0 | 修复 style 被覆盖的 bug。 | | 0.3.0 | 1、新增 onClickonDragStartonDragonDrangEnd 回调。2、优化性能。 |