import React, { useCallback, useEffect } from 'react'; import PropTypes from 'prop-types'; import styled, { css } from 'styled-components'; import { VariableSizeList } from 'react-window'; import CustomScrollbarsVirtualList from '@appserver/components/scrollbar/custom-scrollbars-virtual-list'; import ArrowButton from './arrow-btn'; import Text from './text'; import ControlButtons from './control-btn'; import Item from './item'; import { isMobile, isMobileOnly } from 'react-device-detect'; import { tablet, mobile, isMobile as IsMobileUtils, isTablet as isTabletUtils, } from '@appserver/components/utils/device'; const StyledBox = styled.div` position: absolute; top: 1px; left: ${isMobile ? '-16px' : '-24px'}; ${isMobile && css` width: 100vw !important; max-width: 100vw !important; `} height: fit-content; min-width: 185px; ${(props) => props.changeWidth && !isMobile && css` width: ${(props) => `calc(${props.width}px + 24px)`}; `} z-index: 399; display: flex; flex-direction: column; background: #ffffff; filter: drop-shadow(0px 12px 40px rgba(4, 15, 27, 0.12)); border-radius: 0px 0px 6px 6px; @media ${tablet} { left: -16px; width: 100vw; max-width: 100vw !important; } `; const StyledContainer = styled.div` margin: 14px 0 7px; position: relative; top: -1px; align-items: center; min-width: 100px; max-width: calc(100vw - 32px); padding: ${isMobile ? '0px 16px' : '0px 24px'}; display: grid; grid-template-columns: ${(props) => props.canCreate ? 'auto auto auto auto 1fr' : 'auto auto auto 1fr'}; @media ${tablet} { top: ${!isMobile && '0px'}; padding: 0px 16px; grid-template-columns: ${(props) => (props.canCreate ? 'auto 1fr auto' : 'auto 1fr auto')}; } @media ${mobile} { } .arrow-button { margin-right: 15px; min-width: 17px; align-items: center; @media ${tablet} { padding: 0 0 0 8px; margin-left: -8px; margin-right: 16px; } } .add-button { margin-left: 16px; @media ${tablet} { margin-left: auto; & > div:first-child { padding: 0px 8px 8px 8px; margin-right: -8px; } } } .option-button { @media (min-width: 1024px) { margin-left: 8px; } @media ${tablet} { & > div:first-child { padding: 0px 8px 8px 8px; margin-right: -8px; } } } `; const Row = React.memo(({ data, index, style }) => { const isRoot = index === data[0].length - 1; return ( ); }); const DropBox = React.forwardRef( ( { width, changeWidth, isRootFolder, onBackToParentFolder, title, personal, canCreate, navigationItems, getContextOptionsFolder, getContextOptionsPlus, toggleDropBox, onClickAvailable, }, ref, ) => { const [dropBoxHeight, setDropBoxHeight] = React.useState(0); const countItems = navigationItems.length; const getItemSize = (index) => { if (index === countItems - 1) return 51; return isMobile || IsMobileUtils() || isTabletUtils() ? 36 : 30; }; React.useEffect(() => { const itemsHeight = navigationItems.map((item, index) => getItemSize(index)); const currentHeight = itemsHeight.reduce((a, b) => a + b); setDropBoxHeight( currentHeight > window.innerHeight - 95 ? window.innerHeight - 95 : currentHeight, ); }); return ( {Row} ); }, ); DropBox.propTypes = { width: PropTypes.number, changeWidth: PropTypes.bool, isRootFolder: PropTypes.bool, onBackToParentFolder: PropTypes.func, title: PropTypes.string, personal: PropTypes.bool, canCreate: PropTypes.bool, navigationItems: PropTypes.arrayOf(PropTypes.object), getContextOptionsFolder: PropTypes.func, getContextOptionsPlus: PropTypes.func, toggleDropBox: PropTypes.func, onClickAvailable: PropTypes.func, }; export default React.memo(DropBox);