{"id":13422386,"url":"https://github.com/mkosir/react-hook-mighty-mouse","last_synced_at":"2025-06-29T21:06:26.931Z","repository":{"id":44965478,"uuid":"212674094","full_name":"mkosir/react-hook-mighty-mouse","owner":"mkosir","description":"🐭  React hook that tracks mouse events on selected element - zero dependencies","archived":false,"fork":false,"pushed_at":"2022-01-15T12:10:02.000Z","size":10749,"stargazers_count":121,"open_issues_count":0,"forks_count":9,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-01T14:38:29.826Z","etag":null,"topics":["angle","coordinates","hook","location","mighty","mighty-mouse","mouse","mouse-tracking","react"],"latest_commit_sha":null,"homepage":"https://mkosir.github.io/react-hook-mighty-mouse","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mkosir.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-10-03T20:30:18.000Z","updated_at":"2024-09-14T13:21:45.000Z","dependencies_parsed_at":"2022-09-09T20:11:37.216Z","dependency_job_id":null,"html_url":"https://github.com/mkosir/react-hook-mighty-mouse","commit_stats":null,"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"purl":"pkg:github/mkosir/react-hook-mighty-mouse","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkosir%2Freact-hook-mighty-mouse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkosir%2Freact-hook-mighty-mouse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkosir%2Freact-hook-mighty-mouse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkosir%2Freact-hook-mighty-mouse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mkosir","download_url":"https://codeload.github.com/mkosir/react-hook-mighty-mouse/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkosir%2Freact-hook-mighty-mouse/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262667302,"owners_count":23345532,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["angle","coordinates","hook","location","mighty","mighty-mouse","mouse","mouse-tracking","react"],"created_at":"2024-07-30T23:00:43.456Z","updated_at":"2025-06-29T21:06:26.900Z","avatar_url":"https://github.com/mkosir.png","language":"TypeScript","funding_links":[],"categories":["UI Utilities","Packages","UI Components"],"sub_categories":["Device Input","Device Input/User Action"],"readme":"# React Mighty Mouse ![Mighty Mouse](mighty-mouse.png)\n\n[![npm version][npm-badge]][npm-url]\n[![npm bundle size][size-badge]][npm-url]\n[![Build Status][build-badge]][build-url]\n\n_React hook that tracks mouse events on selected element._\n\n![](demo.gif)\n\n## Demo\n\n**[Demos](https://mkosir.github.io/react-hook-mighty-mouse)** created with [React DemoTab 📑](https://github.com/mkosir/react-demo-tab)\n\n## Install\n\n```bash\nnpm install react-hook-mighty-mouse\n```\n\n## Features\n\n- Lightweight, zero dependencies 📦\n- Supports **mouse** and **touch** events\n- Mouse positions 🖱️ - client/page/screen [🔗demo](https://mkosir.github.io/react-hook-mighty-mouse/?path=/story/react-mighty-mouse--positions)\n- Mouse **relative position** to selected element [🔗demo](https://mkosir.github.io/react-hook-mighty-mouse/?path=/story/react-mighty-mouse--relative-position)\n- Mouse **angle** 0-360° 📐 relative to selected element [🔗demo](https://mkosir.github.io/react-hook-mighty-mouse/?path=/story/react-mighty-mouse--mouse-angle) - Eyes Follow 👀 [🔗demo](https://mkosir.github.io/react-hook-mighty-mouse/?path=/story/react-mighty-mouse--eyes-follow)\n- Track mouse **button** events [🔗demo](https://mkosir.github.io/react-hook-mighty-mouse/?path=/story/react-mighty-mouse--mouse-buttons)\n- Detect when mouse is **hovering** over selected element [🔗demo](https://mkosir.github.io/react-hook-mighty-mouse/?path=/story/react-mighty-mouse--mouse-over-selected-element)\n- Detect keys pressed on the **keyboard** ⌨️ [🔗demo](https://mkosir.github.io/react-hook-mighty-mouse/?path=/story/react-mighty-mouse--keyboard)\n\n## Example\n\n```jsx\nimport React from 'react';\nimport useMightyMouse from 'react-hook-mighty-mouse';\n\nconst App = () =\u003e {\n  const { position } = useMightyMouse();\n  return (\n    \u003cdiv\u003e\n      Mouse position x:{position.client.x} y:{position.client.y}\n    \u003c/div\u003e\n  );\n};\n\nReactDOM.render(\u003cApp /\u003e, document.getElementById('root'));\n```\n\n## Hook\n\n```js\nuseMightyMouse(\n  touchEnabled: boolean = true,\n  selectedElementId: string | null = null,\n  selectedElementOffset: { x: number; y: number } = { x: 0, y: 0 }\n  ): Mouse\n```\n\n\u003e ▶︎ indicates the default value if there's one\n\n### _Input Params_\n\n**touchEnabled**: _boolean_ ▶︎ `true`  \nBoolean to enable/disable touch.\n\n**selectedElementId**: _string | null_ ▶︎ `null`  \nSelected element id.\n\n**selectedElementOffset**: _{ x: number; y: number }_ ▶︎ `{ x: 0, y: 0 }`  \nSelected element offset object.\n\n### _Return values_\n\n_**Mouse** = {  \n\u0026nbsp;\u0026nbsp;**position** : {  \n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;**client** : { **x** : number | null, **y** : number | null },  \n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;**screen** : { **x** : number | null; **y** : number | null },  \n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;**page** : { **x** : number | null; **y** : number | null },  \n\u0026nbsp;\u0026nbsp;},  \n\u0026nbsp;\u0026nbsp;**buttons** : {  \n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;**left** : boolean | null,  \n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;**middle** : boolean | null,  \n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;**right** : boolean | null,  \n\u0026nbsp;\u0026nbsp;},  \n\u0026nbsp;\u0026nbsp;**keyboard** : {  \n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;**ctrl** : boolean | null,  \n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;**shift** : boolean | null,  \n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;**alt** : boolean | null,  \n\u0026nbsp;\u0026nbsp;},  \n\u0026nbsp;\u0026nbsp;**eventType** : string | null,  \n\u0026nbsp;\u0026nbsp;**selectedElement** : {  \n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;**position** : { **x** : number | null; **y** : number | null, **angle** : number | null },  \n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;**boundingRect** : { **left** : number | null; **top** : number | null, **width** : number | null, **height** : number | null },  \n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;**isHover** : boolean  \n\u0026nbsp;\u0026nbsp;},  \n}_\n\n## Development\n\n_Easily set up a local development environment!_\n\nBuild all the examples and starts storybook server on [localhost:9009](http://localhost:9009):\n\n- clone\n- `npm install`\n- `npm start`\n\nOR\n\nClone this repo on your machine, navigate to its location in the terminal and run:\n\n```bash\nnpm install\nnpm link # link your local repo to your global packages\nnpm run build:watch # build the files and watch for changes\n```\n\nClone project repo that you wish to test with react-hook-mighty-mouse library and run:\n\n```bash\nnpm install\nnpm link react-hook-mighty-mouse # link your local copy into this project's node_modules\nnpm start\n```\n\n**Start coding!** 🎉\n\n## Contributing\n\nAll contributions are welcome!\n\n## Roadmap\n\n- Add throttle parameter (hook \"updating\")\n\n[npm-url]: https://www.npmjs.com/package/react-hook-mighty-mouse\n[npm-badge]: https://img.shields.io/npm/v/react-hook-mighty-mouse.svg\n[size-badge]: https://img.shields.io/bundlephobia/minzip/react-hook-mighty-mouse.svg\n[build-badge]: https://travis-ci.com/mkosir/react-hook-mighty-mouse.svg\n[build-url]: https://travis-ci.com/mkosir/react-hook-mighty-mouse\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkosir%2Freact-hook-mighty-mouse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmkosir%2Freact-hook-mighty-mouse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkosir%2Freact-hook-mighty-mouse/lists"}