source: imaps-frontend/node_modules/react-use/esm/factory/createBreakpoint.js

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

Update repo after prototype presentation

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