1 import { useEffect, useState } from 'react';
3 import useDrawer from '@proton/components/hooks/drawer/useDrawer';
5 const useDrawerWidth = () => {
6 const [sidebarWidth, setSidebarWidth] = useState(0);
7 const [appWidth, setAppWidth] = useState(0);
8 const { showDrawerSidebar, drawerSidebarMounted, appInView } = useDrawer();
11 if (!showDrawerSidebar || !drawerSidebarMounted) {
15 const sidebarElement = window.document.querySelector('.drawer-sidebar');
17 if (!sidebarElement) {
21 const sidebarResizeObserver = new ResizeObserver((entries) => {
22 setSidebarWidth(entries[0].contentRect.width);
25 // Only checks iframe root div widths changes (window resize or inner resize when column mailbox layout is set)
26 sidebarResizeObserver.observe(sidebarElement);
29 sidebarResizeObserver.disconnect();
31 }, [showDrawerSidebar, drawerSidebarMounted]);
38 const appElement = window.document.querySelector('.drawer-app');
44 const appResizeObserver = new ResizeObserver((entries) => {
45 setAppWidth(entries[0].contentRect.width);
48 appResizeObserver.observe(appElement);
51 appResizeObserver.disconnect();
55 return appWidth + sidebarWidth;
58 export default useDrawerWidth;