Skip to content

Commit

Permalink
feat: clsx
Browse files Browse the repository at this point in the history
  • Loading branch information
wkylin committed Dec 4, 2024
1 parent 3c3800b commit fe249a9
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 0 deletions.
3 changes: 3 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@
"antd": "^5.22.2",
"axios": "^1.7.8",
"blueimp-md5": "^2.19.0",
"clsx": "^2.1.1",
"cookies-js": "^1.2.3",
"copy-to-clipboard": "^3.3.3",
"cross-fetch": "^4.0.0",
Expand Down
9 changes: 9 additions & 0 deletions src/components/hooks/useBodyScrollLock/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const useBodyScrollLock = () => {

Check failure on line 1 in src/components/hooks/useBodyScrollLock/index.js

View workflow job for this annotation

GitHub Actions / Qodana for JS

ESLint

ESLint: Install the 'eslint' package
React.useLayoutEffect(() => {
const originalStyle = window.getComputedStyle(document.body).overflow;
document.body.style.overflow = 'hidden';
return () => (document.body.style.overflow = originalStyle);
}, []);
};

export default useBodyScrollLock
28 changes: 28 additions & 0 deletions src/components/hooks/useEventListener/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

const useEventListener = (type, handler, el = window) => {

Check failure on line 2 in src/components/hooks/useEventListener/index.js

View workflow job for this annotation

GitHub Actions / Qodana for JS

ESLint

ESLint: Install the 'eslint' package
const savedHandler = React.useRef();

React.useEffect(() => {
savedHandler.current = handler;
}, [handler]);

React.useEffect(() => {
const listener = e => savedHandler.current(e);

el.addEventListener(type, listener);

return () => {
el.removeEventListener(type, listener);
};
}, [type, el]);
}

export default useEventListener

// const updateCoords = React.useCallback(
// ({ clientX, clientY }) => {
// setCoords({ x: clientX, y: clientY });
// },
// [setCoords]
// );
// useEventListener('mousemove', updateCoords);
25 changes: 25 additions & 0 deletions src/components/hooks/useKeyPress/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const useKeyPress = targetKey => {

Check failure on line 1 in src/components/hooks/useKeyPress/index.jsx

View workflow job for this annotation

GitHub Actions / Qodana for JS

ESLint

ESLint: Install the 'eslint' package
const [keyPressed, setKeyPressed] = React.useState(false);

const downHandler = ({ key }) => {
if (key === targetKey) setKeyPressed(true);
};

const upHandler = ({ key }) => {
if (key === targetKey) setKeyPressed(false);
};

React.useEffect(() => {
window.addEventListener('keydown', downHandler);
window.addEventListener('keyup', upHandler);

return () => {
window.removeEventListener('keydown', downHandler);
window.removeEventListener('keyup', upHandler);
};
}, []);

return keyPressed;
};

export default useKeyPress

0 comments on commit fe249a9

Please sign in to comment.