source: imaps-frontend/node_modules/react-use/lib/factory/createBreakpoint.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.3 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var react_1 = require("react");
4var util_1 = require("../misc/util");
5var createBreakpoint = function (breakpoints) {
6 if (breakpoints === void 0) { breakpoints = { laptopL: 1440, laptop: 1024, tablet: 768 }; }
7 return function () {
8 var _a = react_1.useState(util_1.isBrowser ? window.innerWidth : 0), screen = _a[0], setScreen = _a[1];
9 react_1.useEffect(function () {
10 var setSideScreen = function () {
11 setScreen(window.innerWidth);
12 };
13 setSideScreen();
14 util_1.on(window, 'resize', setSideScreen);
15 return function () {
16 util_1.off(window, 'resize', setSideScreen);
17 };
18 });
19 var sortedBreakpoints = react_1.useMemo(function () { return Object.entries(breakpoints).sort(function (a, b) { return (a[1] >= b[1] ? 1 : -1); }); }, [breakpoints]);
20 var result = sortedBreakpoints.reduce(function (acc, _a) {
21 var name = _a[0], width = _a[1];
22 if (screen >= width) {
23 return name;
24 }
25 else {
26 return acc;
27 }
28 }, sortedBreakpoints[0][0]);
29 return result;
30 };
31};
32exports.default = createBreakpoint;
Note: See TracBrowser for help on using the repository browser.