URL Params Form (#420)

* feat create form to edit URL params in views
This commit is contained in:
asharonbaltazar
2023-06-05 13:54:03 -04:00
committed by GitHub
parent 5cb8020ab9
commit bfb483508d
17 changed files with 549 additions and 99 deletions
+17 -10
View File
@@ -1,18 +1,25 @@
import { useEffect } from 'react';
import { useCallback, useEffect } from 'react';
export const useKeyDown = (callback: () => void, targetKey: string) => {
const onKeyDown = (event: KeyboardEvent) => {
const targetKeyPressed = event.key === targetKey && !event.repeat;
if (targetKeyPressed) {
event.preventDefault();
callback();
}
};
type UseKeyDown = (callback: () => void, targetKey: string, options?: { isDisabled?: boolean }) => void;
export const useKeyDown: UseKeyDown = (callback, targetKey, options = {}) => {
const { isDisabled = false } = options;
const onKeyDown = useCallback(
(event: KeyboardEvent) => {
const targetKeyPressed = event.key === targetKey && !event.repeat;
if (targetKeyPressed && isDisabled === false) {
event.preventDefault();
callback();
}
},
[callback, isDisabled, targetKey],
);
useEffect(() => {
document.addEventListener('keydown', onKeyDown);
return () => {
document.removeEventListener('keydown', onKeyDown);
};
}, []);
}, [onKeyDown]);
};