From ccc00c60281565399047b1d68df225fbb94d5904 Mon Sep 17 00:00:00 2001 From: harshithpabbati Date: Tue, 16 Nov 2021 11:04:15 +0530 Subject: [PATCH] Make the tray responsive for mobile --- custom/shared/components/Button/Button.js | 4 +- custom/shared/components/Tray/BasicTray.js | 74 ++++++++++++++++++---- custom/shared/hooks/useResponsive.js | 38 +++++++++++ custom/shared/icons/more-md.svg | 1 + 4 files changed, 104 insertions(+), 13 deletions(-) create mode 100644 custom/shared/hooks/useResponsive.js create mode 100644 custom/shared/icons/more-md.svg diff --git a/custom/shared/components/Button/Button.js b/custom/shared/components/Button/Button.js index 9bca12d..bb3d466 100644 --- a/custom/shared/components/Button/Button.js +++ b/custom/shared/components/Button/Button.js @@ -33,9 +33,9 @@ export const Button = forwardRef( const content = ( <> - {IconBefore && } + {IconBefore && } {children} - {IconAfter && } + {IconAfter && } ); diff --git a/custom/shared/components/Tray/BasicTray.js b/custom/shared/components/Tray/BasicTray.js index d9a80fb..94bbbcc 100644 --- a/custom/shared/components/Tray/BasicTray.js +++ b/custom/shared/components/Tray/BasicTray.js @@ -1,21 +1,26 @@ -import React from 'react'; +import React, { useState } from 'react'; import { NETWORK_ASIDE } from '@custom/shared/components/Aside/NetworkAside'; import { PEOPLE_ASIDE } from '@custom/shared/components/Aside/PeopleAside'; +import Button from '@custom/shared/components/Button'; import { DEVICE_MODAL } from '@custom/shared/components/DeviceSelectModal'; import { useCallState } from '@custom/shared/contexts/CallProvider'; import { useMediaDevices } from '@custom/shared/contexts/MediaDeviceProvider'; import { useUIState } from '@custom/shared/contexts/UIStateProvider'; +import { useResponsive } from '@custom/shared/hooks/useResponsive'; import { ReactComponent as IconCameraOff } from '@custom/shared/icons/camera-off-md.svg'; import { ReactComponent as IconCameraOn } from '@custom/shared/icons/camera-on-md.svg'; import { ReactComponent as IconLeave } from '@custom/shared/icons/leave-md.svg'; import { ReactComponent as IconMicOff } from '@custom/shared/icons/mic-off-md.svg'; import { ReactComponent as IconMicOn } from '@custom/shared/icons/mic-on-md.svg'; +import { ReactComponent as IconMore } from '@custom/shared/icons/more-md.svg'; import { ReactComponent as IconNetwork } from '@custom/shared/icons/network-md.svg'; import { ReactComponent as IconPeople } from '@custom/shared/icons/people-md.svg'; import { ReactComponent as IconSettings } from '@custom/shared/icons/settings-md.svg'; import { Tray, TrayButton } from './Tray'; export const BasicTray = () => { + const responsive = useResponsive(); + const [showMore, setShowMore] = useState(false); const { callObject, leave } = useCallState(); const { customTrayComponent, openModal, toggleAside } = useUIState(); const { isCamMuted, isMicMuted } = useMediaDevices(); @@ -31,7 +36,7 @@ export const BasicTray = () => { }; return ( - + toggleCamera(isCamMuted)} @@ -46,15 +51,48 @@ export const BasicTray = () => { > {isMicMuted ? : } - openModal(DEVICE_MODAL)}> - - - toggleAside(NETWORK_ASIDE)}> - - - toggleAside(PEOPLE_ASIDE)}> - - + {responsive.isMobile() && showMore && ( +
+ + + +
+ )} + {!responsive.isMobile() ? ( + <> + openModal(DEVICE_MODAL)}> + + + toggleAside(NETWORK_ASIDE)}> + + + toggleAside(PEOPLE_ASIDE)}> + + + + ) : ( + setShowMore(!showMore)}> + + + )} {customTrayComponent} @@ -63,6 +101,20 @@ export const BasicTray = () => { leave()} orange> +
); }; diff --git a/custom/shared/hooks/useResponsive.js b/custom/shared/hooks/useResponsive.js new file mode 100644 index 0000000..7f9742a --- /dev/null +++ b/custom/shared/hooks/useResponsive.js @@ -0,0 +1,38 @@ +import React, { useEffect, useState } from 'react'; + +let responsiveConfig = { + xs: 0, + sm: 576, + md: 768, + lg: 992, + xl: 1200, +}; + +export const useResponsive = () => { + const [windowSize, setWindowSize] = useState(window.innerWidth); + + const handleChangeWindowSize = () => setWindowSize(window.innerWidth); + + const getResponsiveConfig = (size) => { + const responsive = {}; + Object.keys(responsiveConfig).forEach(config => { + responsive[config] = size > responsiveConfig[config]; + }); + return responsive; + }; + + const isMobile = () => { + const config = getResponsiveConfig(windowSize); + return !config.md && !config.lg && !config.xl; + }; + + useEffect(() => { + window.addEventListener('resize', handleChangeWindowSize); + + return () => { + window.removeEventListener('resize', handleChangeWindowSize); + }; + }, []); + + return { config: getResponsiveConfig(windowSize), isMobile }; +}; \ No newline at end of file diff --git a/custom/shared/icons/more-md.svg b/custom/shared/icons/more-md.svg new file mode 100644 index 0000000..c792022 --- /dev/null +++ b/custom/shared/icons/more-md.svg @@ -0,0 +1 @@ + \ No newline at end of file