UNPKG

@devgateway/dvz-ui-react

Version:

A modular, embeddable React component library for data visualization and UI, built with TypeScript. Provides reusable components for charts, maps, dashboards, and more, with built-in support for internationalization and Redux integration.

26 lines (25 loc) 1.05 kB
import { useState as u, useEffect as w, useCallback as t } from "react"; function p() { const n = typeof window < "u" && "screen" in window && "orientation" in window.screen, r = () => { if (n) { const { type: e, angle: a } = window.screen.orientation; return { type: e, angle: a }; } return { type: "portrait-primary", angle: 0 }; }, [o, i] = u(r); w(() => { if (!n) return; const e = () => i(r()); return window.screen.orientation.addEventListener("change", e), e(), () => { window.screen.orientation.removeEventListener("change", e); }; }, [n]); const c = t( (e = "portrait") => n && window.screen.orientation.lock ? window.screen.orientation.lock(e) : Promise.reject(new Error("Screen Orientation lock unsupported")), [n] ), s = t(() => n && window.screen.orientation.unlock ? window.screen.orientation.unlock() : Promise.reject(new Error("Screen Orientation unlock unsupported")), [n]); return { orientation: o, lock: c, unlock: s }; } export { p as useScreenOrientation };