2021-09-27 12:59:37 +00:00
|
|
|
import React from 'react';
|
2021-09-30 09:05:04 +00:00
|
|
|
import styled, { css } from 'styled-components';
|
2021-09-27 12:59:37 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { Resizable } from 're-resizable';
|
2021-09-30 09:05:04 +00:00
|
|
|
import { isMobile, isMobileOnly, isTablet } from 'react-device-detect';
|
2021-10-01 08:54:22 +00:00
|
|
|
import {
|
|
|
|
mobile,
|
|
|
|
tablet,
|
|
|
|
isMobile as isMobileUtils,
|
|
|
|
isTablet as isTabletUtils,
|
|
|
|
isDesktop as isDesktopUtils,
|
|
|
|
} from '@appserver/components/utils/device';
|
2021-09-27 12:59:37 +00:00
|
|
|
|
|
|
|
const StyledCatalog = styled.div`
|
2021-09-30 09:05:04 +00:00
|
|
|
position: relative;
|
|
|
|
@media ${mobile} {
|
|
|
|
top: 8px;
|
2021-09-27 14:29:28 +00:00
|
|
|
}
|
2021-10-04 09:36:59 +00:00
|
|
|
top: ${(props) => isMobile && (props.showText ? '64px' : '56px')} !important;
|
2021-09-30 09:05:04 +00:00
|
|
|
|
2021-09-30 10:06:00 +00:00
|
|
|
z-index: ${(props) => (props.showText && (isMobileOnly || isMobileUtils()) ? '201' : '100')};
|
2021-09-27 12:59:37 +00:00
|
|
|
.resizable-block {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
2021-09-30 09:05:04 +00:00
|
|
|
min-width: ${(props) => (props.showText ? '256px' : '52px')};
|
|
|
|
width: ${(props) => (props.showText ? '256px' : '52px')};
|
2021-09-27 12:59:37 +00:00
|
|
|
height: 100% !important;
|
|
|
|
background: #f8f9f9;
|
2021-09-30 09:05:04 +00:00
|
|
|
overflow-y: auto;
|
|
|
|
overflow-x: hidden;
|
2021-10-01 13:49:27 +00:00
|
|
|
scrollbar-width: none;
|
|
|
|
|
|
|
|
&::-webkit-scrollbar {
|
|
|
|
width: 0;
|
|
|
|
height: 0;
|
|
|
|
}
|
2021-09-27 12:59:37 +00:00
|
|
|
.resizable-border {
|
|
|
|
div {
|
|
|
|
cursor: ew-resize !important;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@media ${tablet} {
|
|
|
|
min-width: ${(props) => (props.showText ? '240px' : '52px')};
|
|
|
|
max-width: ${(props) => (props.showText ? '240px' : '52px')};
|
|
|
|
.resizable-border {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@media ${mobile} {
|
|
|
|
display: ${(props) => (props.showText ? 'flex' : 'none')};
|
|
|
|
min-width: 100vw;
|
2021-09-30 09:05:04 +00:00
|
|
|
width: 100%;
|
2021-09-27 12:59:37 +00:00
|
|
|
margin: 0;
|
|
|
|
padding: 0;
|
|
|
|
}
|
2021-09-30 09:05:04 +00:00
|
|
|
|
|
|
|
${isTablet &&
|
|
|
|
css`
|
|
|
|
min-width: ${(props) => (props.showText ? '240px' : '52px')};
|
|
|
|
max-width: ${(props) => (props.showText ? '240px' : '52px')};
|
|
|
|
.resizable-border {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
`}
|
|
|
|
|
|
|
|
${isMobileOnly &&
|
|
|
|
css`
|
|
|
|
display: ${(props) => (props.showText ? 'flex' : 'none')};
|
|
|
|
min-width: 100vw !important;
|
|
|
|
width: 100%;
|
|
|
|
margin: 0;
|
|
|
|
padding: 0;
|
|
|
|
`}
|
2021-09-27 12:59:37 +00:00
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const Catalog = (props) => {
|
2021-09-29 09:26:26 +00:00
|
|
|
const { showText, setShowText, children, ...rest } = props;
|
2021-10-01 08:54:22 +00:00
|
|
|
const refTimer = React.useRef(null);
|
2021-09-27 12:59:37 +00:00
|
|
|
|
|
|
|
const enable = {
|
|
|
|
top: false,
|
|
|
|
right: !isMobile,
|
|
|
|
bottom: false,
|
|
|
|
left: false,
|
|
|
|
};
|
|
|
|
|
2021-09-29 09:26:26 +00:00
|
|
|
const hideText = React.useCallback((event) => {
|
2021-09-29 12:04:15 +00:00
|
|
|
event.preventDefault;
|
|
|
|
setShowText(false);
|
2021-09-29 09:26:26 +00:00
|
|
|
}, []);
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
2021-09-30 09:05:04 +00:00
|
|
|
if (isMobileOnly) {
|
2021-09-29 12:04:15 +00:00
|
|
|
window.addEventListener('popstate', hideText);
|
|
|
|
return () => window.removeEventListener('popstate', hideText);
|
|
|
|
}
|
2021-09-29 09:26:26 +00:00
|
|
|
}, [hideText]);
|
2021-10-01 08:54:22 +00:00
|
|
|
React.useEffect(() => {
|
|
|
|
window.addEventListener('resize', sizeChangeHandler);
|
|
|
|
return () => window.removeEventListener('resize', sizeChangeHandler);
|
|
|
|
});
|
|
|
|
|
2021-10-01 10:27:42 +00:00
|
|
|
React.useEffect(() => {
|
|
|
|
sizeChangeHandler();
|
|
|
|
}, []);
|
|
|
|
|
2021-10-01 08:54:22 +00:00
|
|
|
const sizeChangeHandler = () => {
|
|
|
|
clearTimeout(refTimer.current);
|
|
|
|
|
|
|
|
refTimer.current = setTimeout(() => {
|
2021-10-01 10:27:42 +00:00
|
|
|
if (isMobile && props.showText) props.setShowText(false);
|
|
|
|
if (isMobileUtils() && !isMobile && props.showText) props.setShowText(false);
|
|
|
|
if (isTabletUtils() && !isMobile && props.showText) props.setShowText(false);
|
2021-10-01 08:54:22 +00:00
|
|
|
if (isDesktopUtils() && !isMobile) props.setShowText(true);
|
2021-10-01 09:25:12 +00:00
|
|
|
}, 10);
|
2021-10-01 08:54:22 +00:00
|
|
|
};
|
2021-09-29 09:26:26 +00:00
|
|
|
|
2021-09-27 12:59:37 +00:00
|
|
|
return (
|
|
|
|
<StyledCatalog showText={showText} {...rest}>
|
|
|
|
<Resizable
|
|
|
|
enable={enable}
|
|
|
|
className="resizable-block"
|
|
|
|
handleWrapperClass="resizable-border not-selectable">
|
|
|
|
{children}
|
|
|
|
</Resizable>
|
|
|
|
</StyledCatalog>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
Catalog.propTypes = {
|
|
|
|
showText: PropTypes.bool,
|
2021-09-29 09:26:26 +00:00
|
|
|
setShowText: PropTypes.func,
|
2021-09-27 12:59:37 +00:00
|
|
|
children: PropTypes.any,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Catalog;
|