@uva-glass/component-library
Version:
React components UvA
34 lines (33 loc) • 1.04 kB
JavaScript
import { useState as p, useEffect as u } from "react";
const m = {
xs: 375,
sm: 576,
md: 768,
lg: 992,
xl: 1200,
xxl: 1400
}, h = () => {
const a = (e, t) => t ? `(min-width: ${e}px)` : `(max-width: ${e - 1}px)`, n = (e) => typeof window < "u" ? window.matchMedia(e).matches : !1, i = () => {
const e = {
xs: !1,
sm: !1,
md: !1,
lg: !1,
xl: !1,
xxl: !1
}, t = { ...e }, r = { ...e };
Object.entries(m).forEach(([s, o]) => {
t[s] = n(a(o, !0)), r[s] = n(a(o, !1));
});
const d = n("(orientation: portrait)") ? "portrait" : n("(orientation: landscape)") ? "landscape" : null, f = Object.keys(t).findLast((s) => t[s]) || "_initial";
return { greaterThan: t, lessThan: r, orientation: d, mediaType: f };
}, [c, l] = p(i());
return u(() => {
const e = () => l(i());
return window.addEventListener("resize", e), () => window.removeEventListener("resize", e);
}, []), c;
};
export {
h as useResponsive
};
//# sourceMappingURL=useResponsive.js.map