diff --git a/package.json b/package.json
index 72d3a8c..1c2f551 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "react-hook-mighty-mouse",
- "version": "1.4.24",
+ "version": "1.4.25",
"description": "React mouse hook",
"main": "./dist/react-hook-mighty-mouse.umd.js",
"module": "./dist/react-hook-mighty-mouse.es5.js",
diff --git a/src/react-hook-mighty-mouse/types.ts b/src/react-hook-mighty-mouse/types.ts
index e7d4d42..8a83c09 100644
--- a/src/react-hook-mighty-mouse/types.ts
+++ b/src/react-hook-mighty-mouse/types.ts
@@ -23,6 +23,8 @@ export type Mouse = {
left: boolean | null;
middle: boolean | null;
right: boolean | null;
+ wheelDown: boolean | null;
+ wheelUp: boolean | null;
};
/*
* Pressed keys
@@ -60,4 +62,10 @@ type SelectedElement = {
isHover: boolean;
};
-export type EventType = 'mousemove' | 'mousedown' | 'mouseup' | 'touchmove' | 'touchstart';
+export type EventType =
+ | 'mousemove'
+ | 'mousedown'
+ | 'mouseup'
+ | 'touchmove'
+ | 'touchstart'
+ | 'wheel';
diff --git a/src/react-hook-mighty-mouse/useMightyMouse.tsx b/src/react-hook-mighty-mouse/useMightyMouse.tsx
index e32b1c8..32c7d6f 100644
--- a/src/react-hook-mighty-mouse/useMightyMouse.tsx
+++ b/src/react-hook-mighty-mouse/useMightyMouse.tsx
@@ -11,6 +11,8 @@ const initMouse: Mouse = {
left: null,
middle: null,
right: null,
+ wheelDown: null,
+ wheelUp: null,
},
keyboard: {
ctrl: null,
@@ -55,6 +57,7 @@ const useMightyMouse = (
case 'mousemove':
case 'mousedown':
case 'mouseup':
+ case 'wheel':
const mouseEvent = event as MouseEvent;
clientX = mouseEvent.clientX;
clientY = mouseEvent.clientY;
@@ -65,6 +68,8 @@ const useMightyMouse = (
buttons.left = [1, 3, 5, 7].indexOf(mouseEvent.buttons) > -1;
buttons.right = [2, 3, 6, 7].indexOf(mouseEvent.buttons) > -1;
buttons.middle = [4, 5, 6, 7].indexOf(mouseEvent.buttons) > -1;
+ buttons.wheelDown = (event as WheelEvent).deltaY > 0;
+ buttons.wheelUp = (event as WheelEvent).deltaY < 0;
break;
case 'touchmove':
case 'touchstart':
@@ -160,6 +165,7 @@ const useMightyMouse = (
document.addEventListener('mousemove', onMouseTouchEvent);
document.addEventListener('mousedown', onMouseTouchEvent);
document.addEventListener('mouseup', onMouseTouchEvent);
+ document.addEventListener('wheel', onMouseTouchEvent);
document.addEventListener('mouseleave', onLeave);
document.addEventListener('keydown', onKeyEvent);
document.addEventListener('keyup', onKeyEvent);
@@ -173,6 +179,7 @@ const useMightyMouse = (
document.removeEventListener('mousemove', onMouseTouchEvent);
document.removeEventListener('mousedown', onMouseTouchEvent);
document.removeEventListener('mouseup', onMouseTouchEvent);
+ document.removeEventListener('wheel', onMouseTouchEvent);
document.removeEventListener('mouseleave', onLeave);
document.removeEventListener('keydown', onKeyEvent);
document.removeEventListener('keyup', onKeyEvent);
diff --git a/stories/Buttons/Buttons.tsx b/stories/Buttons/Buttons.tsx
index 0a8ece6..9f31440 100644
--- a/stories/Buttons/Buttons.tsx
+++ b/stories/Buttons/Buttons.tsx
@@ -13,6 +13,8 @@ const Buttons = () => {
{buttons.left ? Left 👇 : 'Left'}
{buttons.middle ? Middle 👇 : 'Middle'}
{buttons.right ? Right 👇 : 'Right'}
+ {buttons.wheelDown ? Wheel Down 👇 : 'Wheel Down'}
+ {buttons.wheelUp ? Wheel Up 👆 : 'Wheel Up'}
);
diff --git a/stories/Buttons/_StorybookTabs.tsx b/stories/Buttons/_StorybookTabs.tsx
index 7a90506..71e3b1d 100644
--- a/stories/Buttons/_StorybookTabs.tsx
+++ b/stories/Buttons/_StorybookTabs.tsx
@@ -18,6 +18,8 @@ const Buttons = () => {
{buttons.left ? Left 👇 : 'Left'}
{buttons.middle ? Middle 👇 : 'Middle'}
{buttons.right ? Right 👇 : 'Right'}
+ {buttons.wheelDown ? Wheel Down 👇 : 'Wheel Down'}
+ {buttons.wheelUp ? Wheel Up 👆 : 'Wheel Up'}
);
diff --git a/stories/MouseCheese/MouseCheese.scss b/stories/MouseCheese/MouseCheese.scss
index 0d9bc22..213f235 100644
--- a/stories/MouseCheese/MouseCheese.scss
+++ b/stories/MouseCheese/MouseCheese.scss
@@ -58,6 +58,65 @@
}
}
+ .size {
+ display: flex;
+ flex-direction: column;
+ justify-content: center;
+ align-items: center;
+ border: 2px solid black;
+ border-radius: 8px;
+ padding: 5px;
+ width: 180px;
+ margin-top: 5px;
+
+ .header {
+ font-size: 1em;
+ text-decoration: underline;
+ }
+
+ .columns {
+ display: flex;
+ flex-direction: row;
+ justify-content: center;
+ align-items: center;
+
+ .col-size-1 {
+ display: flex;
+ flex-direction: column;
+ justify-content: center;
+ align-items: center;
+ margin-right: 5px;
+
+ .row {
+ display: flex;
+ flex-direction: row;
+ justify-content: space-between;
+ align-items: center;
+ font-size: 0.85em;
+ margin-top: 5px;
+ min-width: 78px;
+ }
+ }
+
+ .col-size-2 {
+ display: flex;
+ flex-direction: column;
+ justify-content: center;
+ align-items: center;
+
+ .row {
+ display: flex;
+ flex-direction: row;
+ justify-content: space-between;
+ align-items: center;
+ font-size: 0.85em;
+ margin-top: 5px;
+ min-width: 60px;
+ }
+ }
+ }
+ }
+
.mouse-hover {
display: flex;
flex-direction: column;
@@ -103,18 +162,33 @@
text-decoration: underline;
}
- .keys {
+ .buttons {
display: flex;
- flex-direction: column;
+ flex-direction: row;
justify-content: space-between;
align-items: center;
margin-top: 5px;
+ font-size: 0.85em;
+ line-height: 20px;
+ padding-left: 20px;
- .key {
- font-size: 0.85em;
- line-height: 20px;
+ .btn-row1 {
+ min-width: 80px;
+ }
+ .btn-row2 {
+ min-width: 120px;
}
}
+
+ .keys {
+ display: flex;
+ flex-direction: column;
+ justify-content: space-between;
+ align-items: center;
+ margin-top: 5px;
+ font-size: 0.85em;
+ line-height: 20px;
+ }
}
}
}
diff --git a/stories/MouseCheese/MouseCheese.tsx b/stories/MouseCheese/MouseCheese.tsx
index aa03414..983fb32 100644
--- a/stories/MouseCheese/MouseCheese.tsx
+++ b/stories/MouseCheese/MouseCheese.tsx
@@ -9,11 +9,13 @@ const MouseCheese = () => {
position: { client },
selectedElement: {
position: { x, y, angle },
+ boundingRect,
isHover,
},
buttons,
keyboard,
} = useMightyMouse(true, 'cheese', { x: 125, y: 70 });
+
return (
@@ -41,25 +43,52 @@ const MouseCheese = () => {
angle: {angle &&
{angle.toFixed(0)}°
}
+
+
Cheese
+
+
+
+ Width:
{boundingRect.width && boundingRect.width.toFixed(0)}
+
+
+ Height:
{boundingRect.height && boundingRect.height.toFixed(0)}
+
+
+
+
+ Left:
{boundingRect.left && boundingRect.left.toFixed(0)}
+
+
+ Top:
{boundingRect.top && boundingRect.top.toFixed(0)}
+
+
+
+
Hovering Over Cheese
{isHover ? Yes 🧀 : 'No'}
-
Pressed mouse buttons 🖱️
-
-
{buttons.left ? Left 👇 : 'Left'}
-
{buttons.middle ? Middle 👇 : 'Middle'}
-
{buttons.right ? Right 👇 : 'Right'}
+
Mouse buttons 🖱️
+
+
+
{buttons.left ? Left 👇 : 'Left'}
+
{buttons.middle ? Middle 👇 : 'Middle'}
+
{buttons.right ? Right 👇 : 'Right'}
+
+
+
{buttons.wheelDown ? Wheel Down 👇 : 'Wheel Down'}
+
{buttons.wheelUp ? Wheel Up 👆 : 'Wheel Up'}
+
Pressed keys ⌨️
-
{keyboard.ctrl ? Ctrl 👇 : 'Ctrl'}
-
{keyboard.shift ? Shift 👇 : 'Shift'}
-
{keyboard.alt ? Alt 👇 : 'Alt'}
+
{keyboard.ctrl ? Ctrl 👇 : 'Ctrl'}
+
{keyboard.shift ? Shift 👇 : 'Shift'}
+
{keyboard.alt ? Alt 👇 : 'Alt'}
diff --git a/stories/MouseCheese/_StorybookTabs.tsx b/stories/MouseCheese/_StorybookTabs.tsx
index e90c8f7..1d53a6f 100644
--- a/stories/MouseCheese/_StorybookTabs.tsx
+++ b/stories/MouseCheese/_StorybookTabs.tsx
@@ -14,11 +14,13 @@ const MouseCheese = () => {
position: { client },
selectedElement: {
position: { x, y, angle },
+ boundingRect,
isHover,
},
buttons,
keyboard,
} = useMightyMouse(true, 'cheese', { x: 125, y: 70 });
+
return (
@@ -46,25 +48,52 @@ const MouseCheese = () => {
angle: {angle &&
{angle.toFixed(0)}°
}
+
+
Cheese
+
+
+
+ Width:
{boundingRect.width && boundingRect.width.toFixed(0)}
+
+
+ Height:
{boundingRect.height && boundingRect.height.toFixed(0)}
+
+
+
+
+ Left:
{boundingRect.left && boundingRect.left.toFixed(0)}
+
+
+ Top:
{boundingRect.top && boundingRect.top.toFixed(0)}
+
+
+
+
Hovering Over Cheese
{isHover ? Yes 🧀 : 'No'}
-
Pressed mouse buttons 🖱️
-
-
{buttons.left ? Left 👇 : 'Left'}
-
{buttons.middle ? Middle 👇 : 'Middle'}
-
{buttons.right ? Right 👇 : 'Right'}
+
Mouse buttons 🖱️
+
+
+
{buttons.left ? Left 👇 : 'Left'}
+
{buttons.middle ? Middle 👇 : 'Middle'}
+
{buttons.right ? Right 👇 : 'Right'}
+
+
+
{buttons.wheelDown ? Wheel Down 👇 : 'Wheel Down'}
+
{buttons.wheelUp ? Wheel Up 👆 : 'Wheel Up'}
+
Pressed keys ⌨️
-
{keyboard.ctrl ? Ctrl 👇 : 'Ctrl'}
-
{keyboard.shift ? Shift 👇 : 'Shift'}
-
{keyboard.alt ? Alt 👇 : 'Alt'}
+
{keyboard.ctrl ? Ctrl 👇 : 'Ctrl'}
+
{keyboard.shift ? Shift 👇 : 'Shift'}
+
{keyboard.alt ? Alt 👇 : 'Alt'}
@@ -134,6 +163,65 @@ const scss = `.mouse-cheese {
}
}
+ .size {
+ display: flex;
+ flex-direction: column;
+ justify-content: center;
+ align-items: center;
+ border: 2px solid black;
+ border-radius: 8px;
+ padding: 5px;
+ width: 180px;
+ margin-top: 5px;
+
+ .header {
+ font-size: 1em;
+ text-decoration: underline;
+ }
+
+ .columns {
+ display: flex;
+ flex-direction: row;
+ justify-content: center;
+ align-items: center;
+
+ .col-size-1 {
+ display: flex;
+ flex-direction: column;
+ justify-content: center;
+ align-items: center;
+ margin-right: 5px;
+
+ .row {
+ display: flex;
+ flex-direction: row;
+ justify-content: space-between;
+ align-items: center;
+ font-size: 0.85em;
+ margin-top: 5px;
+ min-width: 78px;
+ }
+ }
+
+ .col-size-2 {
+ display: flex;
+ flex-direction: column;
+ justify-content: center;
+ align-items: center;
+
+ .row {
+ display: flex;
+ flex-direction: row;
+ justify-content: space-between;
+ align-items: center;
+ font-size: 0.85em;
+ margin-top: 5px;
+ min-width: 60px;
+ }
+ }
+ }
+ }
+
.mouse-hover {
display: flex;
flex-direction: column;
@@ -179,17 +267,32 @@ const scss = `.mouse-cheese {
text-decoration: underline;
}
- .keys {
+ .buttons {
display: flex;
- flex-direction: column;
+ flex-direction: row;
justify-content: space-between;
align-items: center;
margin-top: 5px;
+ font-size: 0.85em;
+ line-height: 20px;
+ padding-left: 20px;
- .key {
- font-size: 0.85em;
- line-height: 20px;
+ .btn-row1 {
+ min-width: 80px;
}
+ .btn-row2 {
+ min-width: 120px;
+ }
+ }
+
+ .keys {
+ display: flex;
+ flex-direction: column;
+ justify-content: space-between;
+ align-items: center;
+ margin-top: 5px;
+ font-size: 0.85em;
+ line-height: 20px;
}
}
}