UNPKG

analytica-frontend-lib

Version:

Repositório público dos componentes utilizados nas plataformas da Analytica Ensino

110 lines (109 loc) 3.78 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/hooks/useMobile.ts var useMobile_exports = {}; __export(useMobile_exports, { getDeviceType: () => getDeviceType, useMobile: () => useMobile }); module.exports = __toCommonJS(useMobile_exports); var import_react = require("react"); var MOBILE_WIDTH = 500; var TABLET_WIDTH = 931; var SMALL_MOBILE_WIDTH = 425; var EXTRA_SMALL_MOBILE_WIDTH = 375; var ULTRA_SMALL_MOBILE_WIDTH = 375; var TINY_MOBILE_WIDTH = 320; var DEFAULT_WIDTH = 1200; var getWindowWidth = () => { if (typeof window === "undefined") { return DEFAULT_WIDTH; } return window.innerWidth; }; var getDeviceType = () => { const width = getWindowWidth(); return width < TABLET_WIDTH ? "responsive" : "desktop"; }; var useMobile = () => { const [isMobile, setIsMobile] = (0, import_react.useState)(false); const [isTablet, setIsTablet] = (0, import_react.useState)(false); const [isSmallMobile, setIsSmallMobile] = (0, import_react.useState)(false); const [isExtraSmallMobile, setIsExtraSmallMobile] = (0, import_react.useState)(false); const [isUltraSmallMobile, setIsUltraSmallMobile] = (0, import_react.useState)(false); const [isTinyMobile, setIsTinyMobile] = (0, import_react.useState)(false); (0, import_react.useEffect)(() => { const checkScreenSize = () => { const width = getWindowWidth(); setIsMobile(width < MOBILE_WIDTH); setIsTablet(width < TABLET_WIDTH); setIsSmallMobile(width < SMALL_MOBILE_WIDTH); setIsExtraSmallMobile(width < EXTRA_SMALL_MOBILE_WIDTH); setIsUltraSmallMobile(width < ULTRA_SMALL_MOBILE_WIDTH); setIsTinyMobile(width < TINY_MOBILE_WIDTH); }; checkScreenSize(); window.addEventListener("resize", checkScreenSize); return () => window.removeEventListener("resize", checkScreenSize); }, []); const getFormContainerClasses = () => { if (isMobile) { return "w-full px-4"; } if (isTablet) { return "w-full px-6"; } return "w-full max-w-[992px] mx-auto px-0"; }; const getMobileHeaderClasses = () => { return "flex flex-col items-start gap-4 mb-6"; }; const getDesktopHeaderClasses = () => { return "flex flex-row justify-between items-center gap-6 mb-8"; }; const getHeaderClasses = () => { return isMobile ? getMobileHeaderClasses() : getDesktopHeaderClasses(); }; const getVideoContainerClasses = () => { if (isTinyMobile) return "aspect-square"; if (isExtraSmallMobile) return "aspect-[4/3]"; if (isSmallMobile) return "aspect-[16/12]"; return "aspect-video"; }; return { isMobile, isTablet, isSmallMobile, isExtraSmallMobile, isUltraSmallMobile, isTinyMobile, getFormContainerClasses, getHeaderClasses, getMobileHeaderClasses, getDesktopHeaderClasses, getVideoContainerClasses, getDeviceType }; }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { getDeviceType, useMobile }); //# sourceMappingURL=index.js.map