Skip to content

Commit

Permalink
Merge pull request #56 from tuzkituan/main
Browse files Browse the repository at this point in the history
Version 1.2.10
  • Loading branch information
tuzkituan authored Feb 24, 2024
2 parents 148dac7 + d7b935d commit b7ade9e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
22 changes: 22 additions & 0 deletions lib/hooks/media.hook.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { useEffect, useState } from "react";

const useMediaQuery = (minWidth: number) => {
const [state, setState] = useState({
windowWidth: window.innerWidth,
isDesiredWidth: false,
});

useEffect(() => {
const resizeHandler = () => {
const currentWindowWidth = window.innerWidth;
const isDesiredWidth = currentWindowWidth < minWidth;
setState({ windowWidth: currentWindowWidth, isDesiredWidth });
};
window.addEventListener("resize", resizeHandler);
return () => window.removeEventListener("resize", resizeHandler);
}, [state.windowWidth]);

return state.isDesiredWidth;
};

export default useMediaQuery;
3 changes: 3 additions & 0 deletions lib/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,6 @@ export * from "./providers/zeni-provider";
// UTILS
export * from "./customization/theme/index";
export * from "./customization/theme/use-change-theme";

// HOOKS
export * from "./hooks/media.hook";
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "zeni-ui",
"private": false,
"version": "1.2.9-beta",
"version": "1.2.10-beta",
"type": "module",
"main": "dist/main.js",
"types": "dist/main.d.ts",
Expand Down

0 comments on commit b7ade9e

Please sign in to comment.