UNPKG

@mui/x-date-pickers

Version:

The community edition of the Date and Time Picker components (MUI X).

44 lines (42 loc) 2.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useIsLandscape = void 0; var React = _interopRequireWildcard(require("react")); var _utils = require("@mui/utils"); var _utils2 = require("../utils/utils"); function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } function getOrientation() { if (typeof window === 'undefined') { return 'portrait'; } if (window.screen && window.screen.orientation && window.screen.orientation.angle) { return Math.abs(window.screen.orientation.angle) === 90 ? 'landscape' : 'portrait'; } // Support IOS safari if (window.orientation) { return Math.abs(Number(window.orientation)) === 90 ? 'landscape' : 'portrait'; } return 'portrait'; } const useIsLandscape = (views, customOrientation) => { const [orientation, setOrientation] = React.useState(getOrientation); (0, _utils.unstable_useEnhancedEffect)(() => { const eventHandler = () => { setOrientation(getOrientation()); }; window.addEventListener('orientationchange', eventHandler); return () => { window.removeEventListener('orientationchange', eventHandler); }; }, []); if ((0, _utils2.arrayIncludes)(views, ['hours', 'minutes', 'seconds'])) { // could not display 13:34:44 in landscape mode return false; } const orientationToUse = customOrientation || orientation; return orientationToUse === 'landscape'; }; exports.useIsLandscape = useIsLandscape;