fix: hide the mode switcher in small screen

This commit is contained in:
alt0
2022-10-11 10:23:12 +08:00
parent 57e37221dc
commit 19ce4a1d56
@@ -11,7 +11,7 @@ import {
useLocalTrigger,
useShowSettingsSidebar,
} from '@toeverything/datasource/state';
import { useCallback, useMemo } from 'react';
import { useCallback, useEffect, useMemo, useState } from 'react';
import { EditorBoardSwitcher } from './EditorBoardSwitcher';
import { fsApiSupported } from './FileSystem';
import { Logo } from './Logo';
@@ -23,6 +23,22 @@ export const LayoutHeader = () => {
useShowSettingsSidebar();
const { t } = useTranslation();
// because of header not compatible with small screen, hide the mode switcher in that case, this will be optimize in future.
const [hideSwitcher, setHideSwither] = useState(false);
const [rootEle, setRootEle] = useState<HTMLDivElement>();
useEffect(() => {
if (rootEle) {
const observer = new ResizeObserver(entries => {
setHideSwither(entries[0].contentRect.width < 970);
});
observer.observe(rootEle);
return () => {
observer.disconnect();
};
}
}, [rootEle]);
const warningTips = useMemo(() => {
if (!fsApiSupported()) {
return t('WarningTips.IsNotfsApiSupported');
@@ -42,7 +58,7 @@ export const LayoutHeader = () => {
}, [currentEditors]);
return (
<StyledContainerForHeaderRoot>
<StyledContainerForHeaderRoot ref={setRootEle}>
<StyledHeaderRoot>
<FlexContainer>
<Logo />
@@ -85,9 +101,11 @@ export const LayoutHeader = () => {
</IconButton>
</StyledHelper>
</FlexContainer>
<StyledContainerForEditorBoardSwitcher>
<EditorBoardSwitcher />
</StyledContainerForEditorBoardSwitcher>
{hideSwitcher ? null : (
<StyledContainerForEditorBoardSwitcher>
<EditorBoardSwitcher />
</StyledContainerForEditorBoardSwitcher>
)}
</StyledHeaderRoot>
</StyledContainerForHeaderRoot>
);