UNPKG

nextuiq

Version:

NextUIQ is a modern, lightweight, and developer-friendly UI component library for React and Next.js. Built with TypeScript and Tailwind CSS, it offers customizable, accessible, and performance-optimized components with built-in dark mode, theme customizat

48 lines (45 loc) 1.37 kB
import { useState, useEffect } from 'react'; const breakpoints = { "sm": 640, "md": 768, "lg": 1024, "xl": 1280, "2xl": 1536 }; const useBreakpoint = () => { const [width, setWidth] = useState(typeof window !== "undefined" ? window.innerWidth : 0); const [height, setHeight] = useState(typeof window !== "undefined" ? window.innerHeight : 0); useEffect(() => { const handleResize = () => { setWidth(window.innerWidth); setHeight(window.innerHeight); }; if (typeof window !== "undefined") { window.addEventListener("resize", handleResize); handleResize(); } return () => { if (typeof window !== "undefined") { window.removeEventListener("resize", handleResize); } }; }, []); const getCurrentBreakpoint = () => { if (width >= breakpoints["2xl"]) return "2xl"; if (width >= breakpoints.xl) return "xl"; if (width >= breakpoints.lg) return "lg"; if (width >= breakpoints.md) return "md"; if (width >= breakpoints.sm) return "sm"; return "xs"; }; return { breakpoint: getCurrentBreakpoint(), isMobile: width < breakpoints.md, isTablet: width >= breakpoints.md && width < breakpoints.lg, isDesktop: width >= breakpoints.lg, width, height, orientation: width > height ? "landscape" : "portrait" }; }; export { useBreakpoint };