Skip to content
This repository was archived by the owner on May 27, 2024. It is now read-only.

Commit 0137184

Browse files
committed
feat: Improved keyboard hook + upgrade deps
1 parent 4815f2b commit 0137184

File tree

3 files changed

+912
-678
lines changed

3 files changed

+912
-678
lines changed

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@psycle/repsycle",
3-
"version": "0.0.29",
3+
"version": "0.0.30",
44
"description": "Psycle Research front-end toolkit",
55
"author": "Psycle Research",
66
"keywords": [
@@ -39,12 +39,12 @@
3939
"@rollup/plugin-commonjs": "^20.0.0",
4040
"@rollup/plugin-node-resolve": "^13.0.4",
4141
"@rollup/plugin-typescript": "^8.3.0",
42-
"@storybook/addon-actions": "^6.5.10",
43-
"@storybook/addon-essentials": "^6.5.10",
44-
"@storybook/addon-links": "^6.5.10",
45-
"@storybook/builder-webpack5": "^6.5.10",
46-
"@storybook/manager-webpack5": "^6.5.10",
47-
"@storybook/react": "^6.5.10",
42+
"@storybook/addon-actions": "^6.5.12",
43+
"@storybook/addon-essentials": "^6.5.12",
44+
"@storybook/addon-links": "^6.5.12",
45+
"@storybook/builder-webpack5": "^6.5.12",
46+
"@storybook/manager-webpack5": "^6.5.12",
47+
"@storybook/react": "^6.5.12",
4848
"@types/react": "^17",
4949
"@types/react-dom": "^17",
5050
"@typescript-eslint/eslint-plugin": "^5.21.0",
@@ -55,7 +55,7 @@
5555
"eslint-plugin-jsx-a11y": "^6.5.1",
5656
"eslint-plugin-react": "^7.29.4",
5757
"eslint-plugin-react-hooks": "^4.5.0",
58-
"eslint-plugin-storybook": "^0.6.4",
58+
"eslint-plugin-storybook": "^0.6.6",
5959
"eslint-plugin-unused-imports": "^2.0.0",
6060
"install-peers-cli": "^2.2.0",
6161
"prettier": "^2.6.2",

src/hooks.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,8 @@ export function usePointerPosition() {
3030
window.addEventListener('pointermove', updatePosition, false)
3131

3232
return () => {
33-
window.removeEventListener(
34-
'pointermove',
35-
updatePosition,
36-
false,
37-
)
38-
window.removeEventListener(
39-
'pointerenter',
40-
updatePosition,
41-
false,
42-
)
33+
window.removeEventListener('pointermove', updatePosition, false)
34+
window.removeEventListener('pointerenter', updatePosition, false)
4335
}
4436
})
4537

@@ -283,15 +275,18 @@ export function useSetState<T>(
283275
}
284276

285277
export function useKeyPress(
286-
targetKey: string,
278+
targetKey: string | string[],
287279
handler: (event: KeyboardEvent) => void,
288280
) {
289281
const handlerRef = useRef(handler)
290282
handlerRef.current = handler
291283

292284
useEffect(() => {
293285
const handleDown = (event: KeyboardEvent) => {
294-
if (event.key === targetKey) {
286+
if (
287+
(Array.isArray(targetKey) && targetKey.includes(event.key)) ||
288+
event.key === targetKey
289+
) {
295290
handlerRef.current.call(window, event)
296291
}
297292
}

0 commit comments

Comments
 (0)