DocSpace-buildtools/web/ASC.Web.Common/src/components/Layout/index.js

49 lines
1.2 KiB
JavaScript
Raw Normal View History

import React, { useEffect } from "react";
2021-02-03 12:42:47 +00:00
import PropTypes from "prop-types";
import styled from "styled-components";
import { utils } from "asc-web-components";
2021-02-03 12:42:47 +00:00
import { inject, observer } from "mobx-react";
const { size } = utils.device;
const StyledContainer = styled.div``;
const Layout = (props) => {
const { children, isTabletView, setIsTabletView } = props;
useEffect(() => {
const isTablet = window.innerWidth <= size.tablet;
setIsTabletView(isTablet);
let mediaQuery = window.matchMedia("(max-width: 1024px)");
mediaQuery.addListener(isViewChangeHandler);
return () => mediaQuery.removeListener(isViewChangeHandler);
}, []);
const isViewChangeHandler = (e) => {
const { matches } = e;
setIsTabletView(matches);
};
return (
<StyledContainer className="Layout" isTabletView={isTabletView}>
{children}
</StyledContainer>
);
};
2021-02-03 12:42:47 +00:00
Layout.propTypes = {
isTabletView: PropTypes.bool,
children: PropTypes.any,
setIsTabletView: PropTypes.func,
};
2021-02-03 12:42:47 +00:00
export default inject(({ store }) => {
return {
2021-02-03 12:42:47 +00:00
isTabletView: store.settingsStore.isTabletView,
setIsTabletView: (isTablet) => {
store.settingsStore.isTabletView = isTablet;
},
};
2021-02-03 12:42:47 +00:00
})(observer(Layout));